进程管理-调度器 sched_class 结构体-fair_sched_class rt_sched_class 对象及优先级

news2024/7/4 5:21:07

调度器 sched_class 结构体

调度器 需要做的动作都抽象出来,放在 接口 sched_class 里面,结构体定义在 linux/kernel/sched/sched.h

里面都是 函数指针, 定义了各种调度操作。

示例:

enqueue_task  -  将 task * p 加入到 rq 里面;

需要  根据这儿的函数原型,实现函数,然后将函数指针填入到 sched_class 定义的对象里面。

kernel 中定义了 5 个 sched_class 的对象; stop_sched_class ; dl_sched_class ; rt_sched_class ; fair_sched_class ; idle_sched_class ;

1779struct sched_class {

1785        void (*enqueue_task) (struct rq *rq, struct task_struct *p, int flags);
1786        void (*dequeue_task) (struct rq *rq, struct task_struct *p, int flags);
1787        void (*yield_task)   (struct rq *rq);
1788        bool (*yield_to_task)(struct rq *rq, struct task_struct *p);
1789
1790        void (*check_preempt_curr)(struct rq *rq, struct task_struct *p, int flags);
1791
1792        struct task_struct *(*pick_next_task)(struct rq *rq);
1793
1794        void (*put_prev_task)(struct rq *rq, struct task_struct *p);
1795        void (*set_next_task)(struct rq *rq, struct task_struct *p, bool first);
1796
1797#ifdef CONFIG_SMP
1798        int (*balance)(struct rq *rq, struct task_struct *prev, struct rq_flags *rf);
1799        int  (*select_task_rq)(struct task_struct *p, int task_cpu, int sd_flag, int flags);
1800        void (*migrate_task_rq)(struct task_struct *p, int new_cpu);
1801
1802        void (*task_woken)(struct rq *this_rq, struct task_struct *task);
1803
1804        void (*set_cpus_allowed)(struct task_struct *p,
1805                                 const struct cpumask *newmask);
1806
1807        void (*rq_online)(struct rq *rq);
1808        void (*rq_offline)(struct rq *rq);
1809#endif
1810
1811        void (*task_tick)(struct rq *rq, struct task_struct *p, int queued);
1812        void (*task_fork)(struct task_struct *p);
1813        void (*task_dead)(struct task_struct *p);
1814
1815        /*
1816         * The switched_from() call is allowed to drop rq->lock, therefore we
1817         * cannot assume the switched_from/switched_to pair is serliazed by
1818         * rq->lock. They are however serialized by p->pi_lock.
1819         */
1820        void (*switched_from)(struct rq *this_rq, struct task_struct *task);
1821        void (*switched_to)  (struct rq *this_rq, struct task_struct *task);
1822        void (*prio_changed) (struct rq *this_rq, struct task_struct *task,
1823                              int oldprio);
1824
1825        unsigned int (*get_rr_interval)(struct rq *rq,
1826                                        struct task_struct *task);
1827
1828        void (*update_curr)(struct rq *rq);
1829
1830#define TASK_SET_GROUP          0
1831#define TASK_MOVE_GROUP         1
1832
1833#ifdef CONFIG_FAIR_GROUP_SCHED
1834        void (*task_change_group)(struct task_struct *p, int type);
1835#endif
1836} __aligned(STRUCT_ALIGNMENT); /* STRUCT_ALIGN(), vmlinux.lds.h */
1837

stop_sched_class ; dl_sched_class ; rt_sched_class ; fair_sched_class ; idle_sched_class优先级

声明在:   linux/kernel/sched/sched.h 中; 1863 ~1867 行

1850/* Defined in include/asm-generic/vmlinux.lds.h */
1851extern struct sched_class __begin_sched_classes[];
1852extern struct sched_class __end_sched_classes[];
1853
1854#define sched_class_highest (__end_sched_classes - 1)
1855#define sched_class_lowest  (__begin_sched_classes - 1)
1856
1857#define for_class_range(class, _from, _to) \
1858        for (class = (_from); class != (_to); class--)
1859
1860#define for_each_class(class) \
1861        for_class_range(class, sched_class_highest, sched_class_lowest)
1862
1863extern const struct sched_class stop_sched_class;
1864extern const struct sched_class dl_sched_class;
1865extern const struct sched_class rt_sched_class;
1866extern const struct sched_class fair_sched_class;
1867extern const struct sched_class idle_sched_class;
1868

1851 ~ 1855 通过 链接 脚本中的  __begin_sched_class ;  __end_sched_class

得到优先级最高的 调度器 sched_class_highest ; 优先级最低的调度去 sched_class_lowest 

1860 的 for each sched class 就是从 highest 来时遍历的

kernel/sched/core.c 中,查找下一个 将要运行task 的函数, pick_next_task

4362 ~ 4364 - 从 highest sched class 找的,找到就返回,找不到才使用 低优先级的 sched class 

4327/*
4328 * Pick up the highest-prio task:
4329 */
4330static inline struct task_struct *
4331pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf)
4332{

4361        for_each_class(class) {
4362                p = class->pick_next_task(rq);
4363                if (p)
4364                        return p;
4365        }

4369}

include\asm-generic\vmlinux.lds.h 中对 各个调度器 对象 进行了排序

127 */
 128#define SCHED_DATA                              \
 129        STRUCT_ALIGN();                         \
 130        __begin_sched_classes = .;              \
 131        *(__idle_sched_class)                   \
 132        *(__fair_sched_class)                   \
 133        *(__rt_sched_class)                     \
 134        *(__dl_sched_class)                     \
 135        *(__stop_sched_class)                   \
 136        __end_sched_classes = .;

以 fair_sched_class 为例: 定义在 kernel/sched/fair.c#L254 

注意,里面的  __section 说明,将这个结构体都放在了  __fait_sched_class 这个 section 里面; 上面的 vmlinux.lds.h 中才使用这个 section 

11179/*
11180 * All the scheduling class methods:
11181 */
11182const struct sched_class fair_sched_class
11183        __section("__fair_sched_class") = {
11184        .enqueue_task           = enqueue_task_fair,
11185        .dequeue_task           = dequeue_task_fair,
11186        .yield_task             = yield_task_fair,
11187        .yield_to_task          = yield_to_task_fair,
11188
11189        .check_preempt_curr     = check_preempt_wakeup,
11190
11191        .pick_next_task         = __pick_next_task_fair,
11192        .put_prev_task          = put_prev_task_fair,
11193        .set_next_task          = set_next_task_fair,

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1886559.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

如何养成爱自己的习惯:吸引世间美好,改变命运

在这个快节奏、高压力的时代,我们常常被各种事务所困扰,内心难以得到真正的宁静。然而,古老的智慧告诉我们,“静”是宇宙万物的根源,是生命恢复的根本。本文将探讨如何养成“静”的习惯,从而吸引世间美好&a…

Apache POI、EasyPoi、EasyExcel

&#xff08;一&#xff09;Apache PoI 使用 &#xff08;二&#xff09;EasyPoi使用 &#xff08;三&#xff09;EasyExcel使用 官方文档&#xff1a; 写Excel | Easy Excel 官网 写 使用注解在字段上进行标识 使用最简单的方法二即可 /*** 最简单的写* <p>* 1. 创建…

入门PHP就来我这(纯干货)04

~~~~ 有胆量你就来跟着路老师卷起来&#xff01; -- 纯干货&#xff0c;技术知识分享 ~~~~ 路老师给大家分享PHP语言的知识了&#xff0c;旨在想让大家入门PHP&#xff0c;并深入了解PHP语言。 我们接着《想入门PHP就来我这&#xff08;纯干货&#xff09;03》继续往下学习&am…

忘记家里的wifi密码用iPhone苹果手机怎么找回?

忘记家里的wifi密码用iPhone苹果手机怎么找回&#xff1f; 1、打开iPhone苹果手机上的设置&#xff1b; 2、在iPhone苹果手机设置里找到并进入无线局域网&#xff1b; 3、选择要找回密码的wifi&#xff0c;且已连接&#xff0c;并点击后面的更多进入&#xff1b; 4、进入无线局…

Excel分组求和

目录 1 参考文章2 UNIQUE函数分组3 SUMIF函数分组求和 1 参考文章 1.整体思路&#xff1a;https://blog.csdn.net/Alice_loong/article/details/135580130 2.UNIQUE函数&#xff1a;https://mp.weixin.qq.com/s?__bizMzI3OTcwNDE3OQ&mid2247487044&idx1&sna28108…

浅谈Web性能测试(原创)

一、性能测试不是什么高技术的活&#xff1a; 说到性能测试&#xff0c;很多工作时间较短的新同事或者应届生就很害怕。 为什么害怕&#xff0c;因为感觉无从下手&#xff0c;不知道该做什么、怎么做、做到什么程度&#xff1f; 一听性能测试首先想到的是各种专业的性能测试…

Echarts-柱状图

1.案例1 1.1代码 option = {textStyle: {color: #fff // 标题文字颜色为白色},tooltip: {trigger: axis,axisPointer: {type: shadow,},},legend: {textStyle: {color: white}},grid: {top: 15%,left: 4%,right: 4%,bottom: 7%,containLabel: true},xAxis:{type: category,da…

分文件编译(简单学生系统)

定义学生基本信息 ①输出所有学生信息 ②删除某个学生后&#xff0c;输出所有学生信息 ③修改某个学生信息后&#xff0c;输出所有学生信息 ④查找某个学生的信息 main.c #include"k11*.h" int main(int argc, const char *argv[]) {struct student p[4]{{"…

ShareX:不仅仅是截图工具

名人说&#xff1a;莫道谗言如浪深&#xff0c;莫言迁客似沙沉。 ——刘禹锡《浪淘沙》 创作者&#xff1a;Code_流苏(CSDN)&#xff08;一个喜欢古诗词和编程的Coder&#x1f60a;&#xff09; 目录 一、软件介绍1、ShareX2、核心功能 二、下载安装1、下载2、安装 三、使用方法…

CentOS7.9下yum升级Apache HTTP Server2.4.6到2.4.60

CentOS7.9系统默认的Apache版本 在CentOS7.9上&#xff0c;如果使用yum安装Apache HTTP Server是最多到2.4.6版本的&#xff0c;这是因为el7下官方仓库的最高版本就是2.4.6&#xff0c;证据如下&#xff1a; $ yum info httpd ...... Installed Packages Name : httpd…

虚拟纪念展馆建设的重大意义:重新定义纪念活动的未来

一、什么是虚拟纪念展馆&#xff1f; 虚拟纪念展馆是一种利用3D、VR等技术在线展示历史事件、人物或文化遗产的数字化空间。这些展馆通过虚拟现实、增强现实和3D建模等技术手段&#xff0c;创建出身临其境的体验&#xff0c;使参观者可以在互联网上以互动方式探索和学习。 二、…

Golang | Leetcode Golang题解之第205题同构字符串

题目&#xff1a; 题解&#xff1a; func isIsomorphic(s, t string) bool {s2t : map[byte]byte{}t2s : map[byte]byte{}for i : range s {x, y : s[i], t[i]if s2t[x] > 0 && s2t[x] ! y || t2s[y] > 0 && t2s[y] ! x {return false}s2t[x] yt2s[y] …

nginx 只有图片等静态资源时 监听80端口 会404 NOT FOUND

解决方法 删除 /var/nginx/sites-enabled 原因&#xff1a;当nginx没有设置首页路径index时&#xff0c;sites-enabled目录中配置的优先级会高于nginx.conf 导致404 NOT FOUND sites-enabled文件中的default会将80端口索引至默认值&#xff1a;/var/www/html目录下&#xff…

Redis基础教程(八):redis集合(Set)

&#x1f49d;&#x1f49d;&#x1f49d;首先&#xff0c;欢迎各位来到我的博客&#xff0c;很高兴能够在这里和您见面&#xff01;希望您在这里不仅可以有所收获&#xff0c;同时也能感受到一份轻松欢乐的氛围&#xff0c;祝你生活愉快&#xff01; &#x1f49d;&#x1f49…

职场小白必备待办工具有哪些 适合新手的待办app

初入职场的小白们&#xff0c;常常会遇到各种挑战。从最初的迷茫&#xff0c;到对工作的逐步熟悉&#xff0c;每一步都需要时间和精力的投入。尤其是当面对繁多的工作任务时&#xff0c;如何快速有效地完成它们&#xff0c;成为了许多职场新人需要面对的问题。 在这个快节奏的…

数字集群手持终端是什么_鼎跃安全

在当今快速发展的科技时代&#xff0c;通信技术的进步为各行各业带来了巨大的变革。尤其是在公共安全、应急救援和交通运输等领域&#xff0c;通信的及时性和可靠性变得尤为重要。数字集群手持终端作为一种专用于数字集群通信系统的便携式设备&#xff0c;数字集群手持终端是一…

AI模特换装试衣软件定制服务公司

&#x1f31f; 最强AI模特换装试衣模型训练、定制服务公司出炉 —— 触站AI&#x1f680; &#x1f3a8; 在AI技术的浪潮中&#xff0c;触站AI以其专业和创新&#xff0c;成为企业AI图像领域的技术解决方案服务公司&#xff0c;为设计界带来了革命性的变化。 &#x1f6e0;️ …

PDF一键转PPT文件!这2个AI工具值得推荐,办公必备!

PDF转换为PPT文件&#xff0c;是职场上非常常见的需求&#xff0c;过去想要把PDF文件转换为PPT&#xff0c;得借助各种文件转换工具&#xff0c;但在如今AI技术主导的大背景下&#xff0c;我们在选用工具时有了更多的选择&#xff0c;最明显的就是基于AI技术打造的AI格式转换工…

恢复的实现技术-日志和数据转储

一、引言 在系统正常运行的情况下&#xff0c;事务处理的恢复机制应采取某些技术措施为恢复做好相应的准备&#xff0c;保证在系统发生故障后&#xff0c;能将数据库从一个不一致的错误状态恢复到一个一致性状态 恢复技术主要包括 生成一个数据库日志&#xff0c;来记录系统中…

机械行业常见问题及ERP解决办法

机械行业在全球经济一体化和技术进步背景下&#xff0c;面临着越来越多的挑战。为了在激烈的市场竞争中立于不败之地&#xff0c;企业需要找到合适的方法优化生产流程、降低成本、提升客户满意度。因此&#xff0c;有效地利用企业资源规划&#xff08;ERP&#xff09;解决方案变…