昨天讲到了利用两个查表的方式来计算,会比直接计算来的节省运算资源,今天就来看看到底要vruntime到底要怎麽计算。
vruntime 的公式如下
将2^32 / weight 用 inv_weight取代,就变成以下的式子
这部分的计算出现在 kernel/sched/fair.c
内的cal_delta_fair()
static inline u64 calc_delta_fair(u64 delta, struct sched_entity *se)
{
if (unlikely(se->load.weight != NICE_0_LOAD))
delta = __calc_delta(delta, NICE_0_LOAD, &se->load);
return delta;
}
static u64 __calc_delta(u64 delta_exec, unsigned long weight, struct load_weight *lw) /// calculate delta
{
u64 fact = scale_load_down(weight);
u32 fact_hi = (u32)(fact >> 32);
int shift = WMULT_SHIFT;
int fs;
__update_inv_weight(lw);
if (unlikely(fact_hi)) {
fs = fls(fact_hi);
shift -= fs;
fact >>= fs;
}
fact = mul_u32_u32(fact, lw->inv_weight);
fact_hi = (u32)(fact >> 32);
if (fact_hi) {
fs = fls(fact_hi);
shift -= fs;
fact >>= fs;
}
return mul_u64_u32_shr(delta_exec, fact, shift);
}
以上的部分就是就是vruntime的计算方式,以及其相关的函数。
以上的部分就是就是vruntime的计算方式,以及其相关的函数。
最後提一下在 task_struct
里面关於排程的重要数据结构 sched_entity
,在这个结构里面包含了所有排程所需要的资讯。
struct sched_entity {
/* For load-balancing: */
struct load_weight load; //排程的权重
struct rb_node run_node;
struct list_head group_node;
unsigned int on_rq;
u64 exec_start;
u64 sum_exec_runtime;
u64 vruntime;
u64 prev_sum_exec_runtime;
u64 nr_migrations;
struct sched_statistics statistics;
#ifdef CONFIG_FAIR_GROUP_SCHED
int depth;
struct sched_entity *parent;
/* rq on which this entity is (to be) queued: */
struct cfs_rq *cfs_rq;
/* rq "owned" by this entity/group: */
struct cfs_rq *my_q;
/* cached value of my_q->h_nr_running */
unsigned long runnable_weight;
#endif
#ifdef CONFIG_SMP
/*
* Per entity load average tracking.
*
* Put into separate cache line so it does not
* collide with read-mostly values above.
*/
struct sched_avg avg;
#endif
};
<<: D14.5 - 用 Swift 和公开资讯,打造投资理财的 Apps { 来个中场回亿番 }
>>: Day9 Redis组态档设定-LAZY FREEING/THREADED IO/KERNEL OOM CONTROL/APPEND ONLY MODE
Logs - 挖掘系统内部发生的状况 系列文章 (1/4) - Logs 与 Filebeat 的基...
我们在前面的时候有提过 interface 是用来定义物件的型别,对物件的形状进行描述。在物件导向程...
在正式撰写程序前,本期内容想汇整几个我曾碰到的问题,往後在碰到以下这些问题时,能更快找出解决方法。 ...
延续上回~~ 四、再往底下看是主要的Main Content,也就是对於使用者来说目光会停留最久的区...
MVC与MVVM MVC MVC是一个前後端架构,分为三个部分: 视图(View),为画面显示的地方...