【Linux 内核】调度器 ② ( sched_class 调度类结构体源码 | 源码路径 linux-5.6.18\kernel\sched\sched.h )
生活随笔
收集整理的這篇文章主要介紹了
【Linux 内核】调度器 ② ( sched_class 调度类结构体源码 | 源码路径 linux-5.6.18\kernel\sched\sched.h )
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 一、調度器
- 二、sched_class 調度類結構體
一、調度器
上一篇博客 【Linux 內核】調度器 ( 調度器概念 | 調度器目的 | 調度器主要工作 | 調度器位置 | 進程優先級 | 搶占式調度器 | Linux 進程狀態 | Linux 內核進程狀態 ) 介紹了 " 調度器 " 概念 ,
Linux 內核的 " 進程調度 " 是按照 設計好的調度算法 安排的 , 該算法對應的功能模塊 稱為 " 調度器 " , 英文名稱是 Scheduler ;
" 調度器 " 可以 切換 " 進程狀態 " , 主要是 " 就緒狀態 " 與 " 執行狀態 " 這兩個狀態之間相互切換 ;
" 搶占式調度器 " 概念 : 如果 " 調度器 " 支持 " 就緒狀態 " 與 " 運行狀態 " 之間可以相互轉換 , 則該調度器稱為 " 搶占式調度器 " ;
二、sched_class 調度類結構體
Linux 內核源碼 linux-5.6.18\kernel\sched\sched.h 中 , 定義的 struct sched_class 調度類結構體 , 就是 " 調度器 " 對應的類 ;
struct sched_class 調度類結構體源碼如下 :
struct sched_class {const struct sched_class *next;#ifdef CONFIG_UCLAMP_TASKint uclamp_enabled; #endifvoid (*enqueue_task) (struct rq *rq, struct task_struct *p, int flags);void (*dequeue_task) (struct rq *rq, struct task_struct *p, int flags);void (*yield_task) (struct rq *rq);bool (*yield_to_task)(struct rq *rq, struct task_struct *p, bool preempt);void (*check_preempt_curr)(struct rq *rq, struct task_struct *p, int flags);struct task_struct *(*pick_next_task)(struct rq *rq);void (*put_prev_task)(struct rq *rq, struct task_struct *p);void (*set_next_task)(struct rq *rq, struct task_struct *p, bool first);#ifdef CONFIG_SMPint (*balance)(struct rq *rq, struct task_struct *prev, struct rq_flags *rf);int (*select_task_rq)(struct task_struct *p, int task_cpu, int sd_flag, int flags);void (*migrate_task_rq)(struct task_struct *p, int new_cpu);void (*task_woken)(struct rq *this_rq, struct task_struct *task);void (*set_cpus_allowed)(struct task_struct *p,const struct cpumask *newmask);void (*rq_online)(struct rq *rq);void (*rq_offline)(struct rq *rq); #endifvoid (*task_tick)(struct rq *rq, struct task_struct *p, int queued);void (*task_fork)(struct task_struct *p);void (*task_dead)(struct task_struct *p);/** The switched_from() call is allowed to drop rq->lock, therefore we* cannot assume the switched_from/switched_to pair is serliazed by* rq->lock. They are however serialized by p->pi_lock.*/void (*switched_from)(struct rq *this_rq, struct task_struct *task);void (*switched_to) (struct rq *this_rq, struct task_struct *task);void (*prio_changed) (struct rq *this_rq, struct task_struct *task,int oldprio);unsigned int (*get_rr_interval)(struct rq *rq,struct task_struct *task);void (*update_curr)(struct rq *rq);#define TASK_SET_GROUP 0 #define TASK_MOVE_GROUP 1#ifdef CONFIG_FAIR_GROUP_SCHEDvoid (*task_change_group)(struct task_struct *p, int type); #endif };總結
以上是生活随笔為你收集整理的【Linux 内核】调度器 ② ( sched_class 调度类结构体源码 | 源码路径 linux-5.6.18\kernel\sched\sched.h )的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Linux 内核】调度器 ① ( 调度
- 下一篇: 【Linux 内核】调度器 ③ ( sc