linux kernel goodness计算分析"/>
linux kernel goodness计算分析
今天早上8点过出去买了点东西,回来就赶紧打开source insight看kernel code,跟妹子聊了会天,现在开始分析:
/*
*这个函数是来确定如何描述一个进程
返回值:
-1000:从不选择这个
0:过期进程,重新计算计数值(但它仍旧可能被选中)
正值:goodness值(越大越好)
+1000:实时进程,选择这个
*/static inline int goodness(struct task_struct * p, int this_cpu, struct mm_struct *this_mm)
{int weight;/** select the current process after every other* runnable process, but before the idle thread.* Also, dont trigger a counter recalculation.*/weight = -1;if (p->policy & SCHED_YIELD) //p->policy表示进程的调度策略,SCHED_YIELD是一种策略,是为了从小分配而让出CPU,就是直接返回啦!
#define SCHED_YIELD 0x10goto out;/** Non-RT process - normal case first.*///SCHED_OTHER表示分时调度策略if (p->policy == SCHED_OTHER) {/** Give the process a first-approximation goodness value* according to the number of clock-ticks it has left.** Don't do any other calculations if the time slice is* over..*/weight = p->counter;if (!weight)goto out;#ifdef CONFIG_SMP/* Give a largish advantage to the same processor... *//* (this is equivalent to penalizing other processors) */if (p->processor == this_cpu)weight += PROC_CHANGE_PENALTY;
#endif/* .. and a slight advantage to the current MM */if (p->mm == this_mm || !p->mm)weight += 1;weight += 20 - p->nice;goto out;}/** Realtime process, select the first one on the* runqueue (taking priorities within processes* into account).*/weight = 1000 + p->rt_priority;
out:return weight;
}这个函数比较简单吧,就是计算进程goodness值,对于分时策略,会对一些情况weight有些加成;实时进程直接就给最大了。
其实如果木有神马ATT汇编,内核源码看起来还是很爽的,只是写了一个函数,今天计划把进程调度看完,跟书同步吧,至少把书上的字看完呢!
更多推荐
linux kernel goodness计算分析
发布评论