linux kernel goodness计算分析

编程入门 行业动态 更新时间:2024-10-09 01:22:35

<a href=https://www.elefans.com/category/jswz/34/1770067.html style=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计算分析

本文发布于:2024-02-07 05:11:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1753422.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:linux   kernel   goodness

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!