后来调到__setscheduler() 真正进行进程优先级设置,
/* Actually do priority change: must hold rq lock. */
static void
__setscheduler(struct rq *rq, struct task_struct *p, int policy, int prio)
{
p->policy = policy;// 你通过sched_setscheduler()传入的sched policy就是最终赋予给(task_struct*)p->policy
p->rt_priority = prio;//你通过sched_setscheduler()传入的prio 最终却赋予给了(task_struct*)p->rt_priority,怎么样? 没忽悠你吧,传入的非实时进程优先级值真的只能是0!!!
p->normal_prio = normal_prio(p);//接下来看 p->normal_prio 是怎么回事?
/* we are holding p->pi_lock already */
p->prio = rt_mutex_getprio(p);
if (rt_prio(p->prio))
p->sched_class = &rt_sched_class;
else
p->sched_class = &fair_sched_class;
set_load_weight(p);
}

看下normal_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;//如果你是实时进程,p->prio = 99 - 你通过sched_setscheduler()传入的优先级值,这下明白了吧,watchdog 进程通过sched_setscheduler() 设置的优先级值为99, 这样一算之后真正 p->prio 为0, 也就是linux kernel 中最高优先级的实时进程!
else
prio = __normal_prio(p);// 非实时进程的优先级,可真费劲,接着看?
return prio;
}
看下__normal_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;//逗我呢吧,非实时进程的优先级通过sched_setscheduler()设置的值并没有赋予p->prio,而是直接取的p->static 的值
p->static 的值从哪来的呢?
}
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-40531-3.html
海浪不会不在
人口只及中国的十分之一
于是俺们厂里买了好多跟废品差不多的浙商设备
函数加油
我估计很多还是雇佣的