- 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);}
推荐阅读
-
生存:中国最难生存的城市,月入上万只够生活,是承载很多人梦
-
阴虚体质的表现症状及调理方法 阴虚体质会变成阳虚吗
-
谭松韵|我们这十年:谭松韵演农民,成功复制赵丽颖戏路,观众缘不降反增
-
-
老王球鞋交流|奢侈品强强联手!Dior×AJ1低帮实拍细节测评
-
人工智能|我国首艘百吨级无人艇完成试航:全程自主航行
-
『山东鲁能』下午两点!李铁收到一个好消息,国足最后4战40强赛有望大获全胜
-
##五月将会有各种机缘加身,运势彻底好转,正偏财接连进账的3属相!
-
-
清澈如初|产品销量全国第一!高新区这家高科技企业又获奖啦
-
给妈妈的生日贺卡怎么做 给妈妈的生日贺卡怎么做好看
-
中国早期的指南针也被称为什么?A 中国早期的指南针也被称为什么
-
#IT168网#Watch将有望配备Touch ID,爆料:Apple
-
起泡酒是不是就是香槟,起泡酒和香槟的区别香槟入门推荐-
-
周杰伦|继林俊杰购买虚拟土地后 周杰伦也入局元宇宙:晒出NFT新年礼物
-
-
司寇|春秋鲁国:孔子当大司寇不到七天,为何下令诛杀少正卯?
-
王者荣耀世冠总决赛今日上演,Ts与DYG谁能称霸?
-
贵州省原副省长王晓光受贿贪污内幕交易,一审获刑20年
-
「尚车快报」新款别克英朗2020款典范怎么样?来自大鱼号|《尚车快报》