这部分一直搞不清楚,捋一下。
sched_class即调度器,是具体调度策略的实现。调度策略有
#define SCHED_NORMAL 0
#define SCHED_FIFO 1
#define SCHED_RR 2
#define SCHED_BATCH 3
/* SCHED_ISO: reserved but not implemented yet */
#define SCHED_IDLE 5
这些策略中,normal,batch用于普通进程,fifo,rr用于实时进程,idle空闲进程。
调度器实现了stop_sched_class->dl_sched_class->rt_sched_class->cfs_sched_class->idle_sched_class。
每个cpu上都有个struct rq
/*
* This is the main, per-CPU runqueue data structure.
*
* Locking rule: those places that want to lock multiple runqueues
* (such as the load balancing or the thread migration code), lock
* acquire operations must be ordered by ascending &runqueue.
*/
struct rq {
/* runqueue lock: */
raw_spinlock_t lock;
/*
* nr_running and cpu_load should be in the same cacheline because
* remote CPUs use both these fields when doing load calculation.
*/
unsigned int nr_running;
/* 三个调度队列:CFS调度,RT调度,DL调度 */
struct cfs_rq cfs;
struct rt_rq rt;
struct dl_rq dl;
/* stop指向迁移内核线程, idle指向空闲内核线程 */
struct task_struct *curr, *idle, *stop;
/* ... */
}
每个rq都有三个调度队列,cfs,rt,dl。如下图
这些调度队列中,cfs和dl是红黑树结构,rt是队列(双向?),节点都是sched_entity,分别由相应类型的调度器维护。
暂时就这么多吧
资料来源——https://zhuanlan.zhihu.com/p/363785756,https://www.cnblogs.com/LoyenWang/p/12249106.html