Chinaunix首页 | 论坛 | 博客
  • 博客访问: 429272
  • 博文数量: 123
  • 博客积分: 2686
  • 博客等级: 少校
  • 技术积分: 1349
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-23 22:11
文章分类
文章存档

2012年(3)

2011年(10)

2010年(100)

2009年(10)

我的朋友

分类: LINUX

2010-09-22 12:17:16

Computing priority:
[The kernel uses a simpler scale ranging from 0 to 139 inclusive to represent priorities internally. Again, lower values mean higher priorities. The range from 0 to 99 is reserved for real-time processes. The nice values [−20, +19] are mapped to the range from 100 to 139]

Three priorities must be taken into account:
dynamic priority    (task_struct->prio),
normal priority     (task_struct->normal_prio),
and static priority (task_struct->static_prio).

static priority is the starting point of calculations. Assume that it has been set and that the kernel want to compute the other priority. This is done by one line:

p->prio = effective_prio(p);




/*
 * Calculate the current priority, i.e. the priority
 * taken into account by the scheduler. This value might
 * be boosted by RT tasks, or might be boosted by
 * interactivity modifiers. Will be RT if the task got
 * RT-boosted. If not then it returns p->normal_prio.
 */


static int effective_prio(struct task_struct *p)
{
    p->normal_prio = normal_prio(p);
    /*
     * If we are RT tasks or we were boosted to RT priority,
     * keep the priority unchanged. Otherwise, update priority
     * to the normal priority:
     */

    if (!rt_prio(p->prio))
        return p->normal_prio;
    return p->prio;
}



/*
 * Calculate the expected normal priority: i.e. priority
 * without taking RT-inheritance into account. Might be
 * boosted by interactivity modifiers. Changes upon fork,
 * setprio syscalls, and whenever the interactivity
 * estimator recalculates.
 */

static inline int normal_prio(struct task_struct *p)
{
    int prio;

    if (task_has_rt_policy(p))
        prio = MAX_RT_PRIO-1 - p->rt_priority;
    else
        prio = __normal_prio(p);
    return prio;
}



/*
 * __normal_prio - return the priority that is based on the static prio
 */



static inline int __normal_prio(struct task_struct *p)
{
    return p->static_prio;
}



p->prio is set with the method shown above when a newly created task is woken up with wake_up_new_task(), and when the static priority was changed with system call nice().

Notice that when a process forks off a child process, the current static priority will be inherited from parent. The dynamic priority is set to normal priority of parent, in case priority booted by RT-Mutexes pass to child.
阅读(873) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~