linux内核调度:调度策略与调度器类-小结

linux内核5种主要调度策略:linux/sched.h

 

4种调度器类

idle_sched_class

作用:每个cup的第一个pid=0线程:swapper,是一个静态线程。启动流程:

创建流程SMP_init-->__cpu_up()--->Core.c@init_idle(idle, cpu);

...

idle->sched_class = &idle_sched_class;//属于idel_sched_class的rq调度模型

....

#if defined(CONFIG_SMP)

sprintf(idle->comm, "%s/%d", INIT_TASK_COMM, cpu);设置线程名称swapper

#endif

 

Core.c (trunk\kernel\kernel\sched):        sprintf(idle->comm, "%s/%d", INIT_TASK_COMM, cpu);--->线程的名称

Init_task.h (trunk\kernel\include\linux):        .comm                = INIT_TASK_COMM,

Init_task.h (trunk\kernel\include\linux):#define INIT_TASK_COMM "swapper"

 

调度类属于idel_sched_class,所以在ps里面是看不到的。一般运行在开机过程和cpu异常的时候做dump

stop_sched_class

优先级最高的线程,会中断所有其他线程,且不会被其他任务打断。

作用

1.发生在cpu_stop_cpu_callback 进行cpu之间任务migration;

2.HOTPLUG_CPU的情况下关闭任务。

rt_sched_class

RT

作用实时线程

fair_sched_class

CFS(公平)

用:

一般常规线程

 

目前系統中,Scheduling Class的优先级顺序为 Stop-Task > Real-Time > Fair > Idle-Task,开发者可以根据己的设计需求,來把所属的Task配置到不同的Scheduling Class.

 

5 种调度策略

策略

描述

所在的调度器类

SCHED_NORAML(也称SCHED_OTHER)

(最常见的策略)、sched_normal 或者 sched_other是Linux默认的调度策略,其值为0 非实时进程的调度策略,也就是分时调度策略。分时进程则通过nice和counter值决定权值,nice越小,counter越大,被调度的概率越大,也就是曾经使用了cpu最少的进程将会得到优先调

CFS

SCHED_BATCH

(除了不能抢占外与常规任务一样,允许任务运行更长时间,更好地使用高速缓存,适合于成批处理的工作)、

CFS

SCHED_IDLE

(它甚至比nice 19还有弱,为了避免优先级反转使用)

CFS

SCHED_RR

(循环调度,拥有时间片,结束后放在队列末)

RT

SCHED_FIFO

(没有时间片,可以运行任意长的时间);

RT

 

       SCHED_OTHER   the standard round-robin time-sharingpolicy;

 

       SCHED_BATCH   for "batch" style execution ofprocesses; and

 

       SCHED_IDLE    for running very low priority backgroundjobs.

 

       For each of the above policies,param->sched_priority must be 0.

 

       Various "real-time" policiesare also supported, for special time-

       critical applications that need precisecontrol over the way in which

       runnable threads are selected forexecution.  For the rules governing

       when a process may use these policies,see sched(7).  The real-time

       policies that may be specified in policyare:

 

       SCHED_FIFO    a first-in, first-out policy; and

 

       SCHED_RR      a round-robin policy.

 

其中前面三种策略使用的是cfs调度器类,后面两种使用rt调度器类

-----------------------------------------------------------------------------------------------------------------------------------

  

实时进程将得到优先调用,实时进程根据实时优先级决定调度权值分时进程则通过nicecounter值决定权值,nice越小,counter越大,被调度的概率越大,也就是曾经使用了cpu最少的进程将会得到优先调度

你可能感兴趣的:(kernel,调度,linux内核)