cgroup cpu group 源码分析

这段代码描述了Linux公平调度器(CFS)在选择下一个任务时的逻辑。它首先尝试更新当前运行队列的当前任务,然后检查运行队列的运行状态,如果需要,进行节流和去队列操作。当选择新的调度实体时,会根据CGroup层级找到对应的CFS运行队列,并可能遍历到最底层的任务实体。这个过程涉及到CPU资源在不同CGroup之间的分配和管理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

cpu group pick_next函数

以下代码来自 pick_next_task_fair

 6739         /*
 6740          * Because of the set_next_buddy() in dequeue_task_fair() it is rather
 6741          * likely that a next task is from the same cgroup as the current.
 6742          *
 6743          * Therefore attempt to avoid putting and setting the entire cgroup
 6744          * hierarchy, only change the part that actually changes.
 6745          */
 6746
 6747         do {
 6748                 struct sched_entity *curr = cfs_rq->curr;
 6749
 6750                 /*
 6751                  * Since we got here without doing put_prev_entity() we also
 6752                  * have to consider cfs_rq->curr. If it is still a runnable
 6753                  * entity, update_curr() will update its vruntime, otherwise
 6754                  * forget we've ever seen it.
 6755                  */
 6756                 if (curr) {
 6757                         if (curr->on_rq)
 6758                                 update_curr(cfs_rq);
 6759                         else
 6760                                 curr = NULL;
 6761
 6762                         /*
 6763                          * This call to check_cfs_rq_runtime() will do the
 6764                          * throttle and dequeue its entity in the parent(s).
 6765                          * Therefore the nr_running test will indeed
 6766                          * be correct.
 6767                          */
 6768                         if (unlikely(check_cfs_rq_runtime(cfs_rq))) {
 6769                                 cfs_rq = &rq->cfs;
 6770
 6771                                 if (!cfs_rq->nr_running)
 6772                                         goto idle;
 6773
 6774                                 goto simple;
 6775                         }
 6776                 }
 6777
 6778                 **se = pick_next_entity(cfs_rq, curr);**
 6779                 **cfs_rq = group_cfs_rq(se);**
 6780         } while (cfs_rq);
  279 /* runqueue "owned" by this group */
  280 static inline struct cfs_rq *group_cfs_rq(struct sched_entity *grp)
  281 {
  282         return grp->my_q;
  283 }

1) 如果cpu 原始rq pick_next_entity选择的是非cgoup节点, 那么6779行返回空,即 my_q为空
2) 如果6778行选择的cgroup的根节点的sched_entity,那么会根据cgroup层次结构遍历一次遍历, 到最后的一层节点选出的sched_entity的my_q为空,则为真正的task entity

group share 计算

4.19 calc_group_shares

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值