免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2068 | 回复: 1
打印 上一主题 下一主题

最近在看进程调度部分,ULK3和源码感觉有点对不上,请各位指点 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-05-16 11:39 |只看该作者 |倒序浏览
贴一段ULK3的描述,摘自7.4.3描述recalc_task_prio( ) 功能的第三点

Checks whether the process is not a kernel thread, whether it is awakening from the TASK_UNINTERRUPTIBLE state (p->activated field equal to -1; see step 5 in the previous section), and whether it has been continuously asleep beyond a given sleep time threshold. If these three conditions are fulfilled, the function sets the p->sleep_avg field to the equivalent of 900 ticks (an empirical value obtained by subtracting the duration of the base time quantum of a standard process from the maximum average sleep time). Then, it jumps to step 8.

The sleep time threshold depends on the static priority of the process; some typical values are shown in Table 7-2. In short, the goal of this empirical rule is to ensure that processes that have been asleep for a long time in uninterruptible modeusually waiting for disk I/O operations get a predefined sleep average value that is large enough to allow them to be quickly serviced, but it is also not so large to cause starvation for other processes.


现在给大家贴上源码,摘自2.6.11.1内核
static void recalc_task_prio(task_t *p, unsigned long long now)
{
        unsigned long long __sleep_time = now - p->timestamp;
        unsigned long sleep_time;

        if (__sleep_time > NS_MAX_SLEEP_AVG)
                sleep_time = NS_MAX_SLEEP_AVG;
        else
                sleep_time = (unsigned long)__sleep_time;

        if (likely(sleep_time > 0)) {
                /*
                 * User tasks that sleep a long time are categorised as
                 * idle and will get just interactive status to stay active &
                 * prevent them suddenly becoming cpu hogs and starving
                 * other processes.
                 */
                if (p->mm && p->activated != -1 &&//注意这里,和ULK3上说的一致吗???
                        sleep_time > INTERACTIVE_SLEEP(p)) {
                                p->sleep_avg = JIFFIES_TO_NS(MAX_SLEEP_AVG -
                                                DEF_TIMESLICE);
                } else {
                        /*
                         * The lower the sleep avg a task has the more
                         * rapidly it will rise with sleep time.
                         */
                        sleep_time *= (MAX_BONUS - CURRENT_BONUS(p)) ? : 1;

                        /*
                         * Tasks waking from uninterruptible sleep are
                         * limited in their sleep_avg rise as they
                         * are likely to be waiting on I/O
                         */
                        if (p->activated == -1 && p->mm) {
                                if (p->sleep_avg >= INTERACTIVE_SLEEP(p))
                                        sleep_time = 0;
                                else if (p->sleep_avg + sleep_time >=
                                                INTERACTIVE_SLEEP(p)) {
                                        p->sleep_avg = INTERACTIVE_SLEEP(p);
                                        sleep_time = 0;
                                }
                        }

                        /*
                         * This code gives a bonus to interactive tasks.
                         *
                         * The boost works by updating the 'average sleep time'
                         * value here, based on ->timestamp. The more time a
                         * task spends sleeping, the higher the average gets -
                         * and the higher the priority boost gets as well.
                         */
                        p->sleep_avg += sleep_time;

                        if (p->sleep_avg > NS_MAX_SLEEP_AVG)
                                p->sleep_avg = NS_MAX_SLEEP_AVG;
                }
        }

        p->prio = effective_prio(p);
}

论坛徽章:
0
2 [报告]
发表于 2008-05-16 15:44 |只看该作者
我感觉if (p->mm && p->activated == -1 &&//这里应该是==-1才和ULK3上说的一致吗。。
                        sleep_time > INTERACTIVE_SLEEP(p)) {
                                p->sleep_avg = JIFFIES_TO_NS(MAX_SLEEP_AVG -
                                                DEF_TIMESLICE);
                }
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP