- delta_exec = now - curr->exec_start; 计算出当前CFS运行队列的进程 , 距离上次更新虚拟时间的差值
- curr->exec_start = now; 更新exec_start的值
- curr->sum_exec_runtime += delta_exec; 更新当前进程总共执行的时间
- 通过 calc_delta_fair 计算当前进程虚拟时间
- 通过 update_min_vruntime 函数来更新CFS运行队列中最小的 vruntime 的值
pick_next_entitypick_next_entity 函数会从就绪队列中选择最适合运行的调度实体(虚拟时间最小的调度实体) , 即从 CFS 红黑树最左边节点获取一个调度实体 。
static struct sched_entity *pick_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *curr){ struct sched_entity *left = __pick_first_entity(cfs_rq); ------(1) struct sched_entity *se; /* * If curr is set we have to see if its left of the leftmost entity * still in the tree, provided there was anything in the tree at all. */ if (!left || (curr && entity_before(curr, left))) left = curr; se = left; /* ideally we run the leftmost entity */ /* * Avoid running the skip buddy, if running something else can * be done without getting too unfair. */ if (cfs_rq->skip == se) { struct sched_entity *second; if (se == curr) { second = __pick_first_entity(cfs_rq); ------(2) } else { second = __pick_next_entity(se); ------(3) if (!second || (curr && entity_before(curr, second))) second = curr; } if (second && wakeup_preempt_entity(second, left) < 1) se = second; } /* * Prefer last buddy, try to return the CPU to a preempted task. */ if (cfs_rq->last && wakeup_preempt_entity(cfs_rq->last, left) < 1) se = cfs_rq->last; /* * Someone really wants this to run. If it's not unfair, run it. */ if (cfs_rq->next && wakeup_preempt_entity(cfs_rq->next, left) < 1) se = cfs_rq->next; clear_buddies(cfs_rq, se); return se;} - 从树中挑选出最左边的节点
- 选择最左的那个调度实体 left
- 摘取红黑树上第二左的进程节点
put_prev_entityput_prev_entity 会调用 __enqueue_entity 将prev进程(即current进程)加入到 CFS 队列 rq 上的红黑树 , 然后将 cfs_rq->curr 设置为空 。
static void __enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se){ struct rb_node **link = &cfs_rq->tasks_timeline.rb_root.rb_node; //红黑树根节点 struct rb_node *parent = NULL; struct sched_entity *entry; bool leftmost = true; /* * Find the right place in the rbtree: */ while (*link) { ------(1) parent = *link; entry = rb_entry(parent, struct sched_entity, run_node); /* * We dont care about collisions. Nodes with * the same key stay together. */ if (entity_before(se, entry)) { ------(2) link = &parent->rb_left; } else { link = &parent->rb_right; leftmost = false; } } rb_link_node(&se->run_node, parent, link); ------(3) rb_insert_color_cached(&se->run_node, ------(4) &cfs_rq->tasks_timeline, leftmost);}
推荐阅读
-
-
-
[自由者运动]身高2米18已被NCAA看中,未来打进NBA不是梦,17岁男篮小将闪耀
-
尼日利亚_社会|尼日利亚婚礼演变成屠杀,骑摩托牧民疯狂开枪致18人死亡30人受伤
-
人民日报中央厨房 工人加班干劲足,国庆假期惠州项目建设不放假
-
-
-
英超那些事|第90分钟上场,触球2次就结束,巴萨1.2亿先生迷失!争冠战被遗忘
-
轮胎585克车架轻过Tarmac闪电发布碟刹公路Aethos
-
落叶知秋 中国能排在第几?,全球五大科技强国公布:德国进不了前三
-
-
新浪网港股恒生指数开盘涨0.12%美团点评涨1.93%
-
斑马|老太太横穿马路被撞,交警判断责任55分,对方只给3万就不出面
-
军事第N区|美专家无情将其大脸:完全是给普京送大礼,特朗普闯大祸了
-
富丰财经“拿下”韵达,官宣入股,背后老板财富450亿,阿里再下一城
-
拉钩上吊一百年不许变z|这些法师才是上分的首选英雄,王者荣耀:S21新赛季
-
-
科学|NASA新发布:火星探测任务揭示了遥远行星的可居性
-
烫发|五六十岁的女人别乱烫发,这几种卷发好看又接地气,减龄又显气质
-
「养老金」一次性补缴6万元,每个月领1500元养老金,你是否愿意?