linux cfs调度算法理解

cfs调度算法理解

时间片计算方法

整体理解:根据优先级权重分享调度周期的时间
公式:
sched_slice = (task_load / rq_load_total) * sched_latency

sched_latency 在linux上面是有配置i的,当任务小于8个的时候,使用sched_latency , 如果大于8个的话, rq上面的任务个数*sched_granurity.

ubuntu 上面的配置如下:

调度周期 sched_latency,即调度队列中所有任务时间片执行一次的时间

对应的函数代码:

  680 /*
  681  * We calculate the wall-time slice from the period by taking a part
  682  * proportional to the weight.
  683  *
  684  * s = p*P[w/rw]
  685  */
  686 static u64 sched_slice(struct cfs_rq *cfs_rq, struct sched_entity *se)
  687 {
  688         u64 slice = __sched_period(cfs_rq->nr_running + !se->on_rq);
  689
  690         for_each_sched_entity(se) {
  691                 struct load_weight *load;
  692                 struct load_weight lw;
  693
  694                 cfs_rq = cfs_rq_of(se);
  695                 load = &cfs_rq->load;
  696
  697                 if (unlikely(!se->on_rq)) {
  698                         lw = cfs_rq->load;
  699
  700                         update_load_add(&lw, se->load.weight);
  701                         load = &lw;
  702                 }
  703                 slice = __calc_delta(slice, se->load.weight, load);
  704         }
  705         return slice;
  706 }

第688行计算调度周期

  206 /*
  207  * delta_exec * weight / lw.weight
  208  *   OR
  209  * (delta_exec * (weight * lw->inv_weight)) >> WMULT_SHIFT
  210  *
  211  * Either weight := NICE_0_LOAD and lw \e sched_prio_to_wmult[], in which case
  212  * we're guaranteed shift stays positive because inv_weight is guaranteed to
  213  * fit 32 bits, and NICE_0_LOAD gives another 10 bits; therefore shift >= 22.
  214  *
  215  * Or, weight =< lw.weight (because lw.weight is the runqueue weight), thus
  216  * weight/lw.weight <= 1, and therefore our shift will also be positive.
  217  */
  218 static u64 __calc_delta(u64 delta_exec, unsigned long weight, struct load_weight *lw)
  219 {
  220         u64 fact = scale_load_down(weight);
  221         int shift = WMULT_SHIFT;
  222
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值