What does the linux scheduler return when there are no tasks left in the queue -
the linux scheduler calls scheduler algorithm finds next task in task list.
what scheduling algorithm return if there no tasks left?
below piece of code
struct rt_info* sched_something(struct list_head *head, int flags) { /* logic */ return some_task; // task's value if there no tasks left. }
there special "idle" task pid=0, called swapper
(why need swapper task in linux?). task scheduled cpu core when there no other task ready run. there several idle tasks - 1 each cpu core
source kernel/sched/core.c
http://lxr.free-electrons.com/source/kernel/sched/core.c?v=3.16#l3160
3160 /** 3161 * idle_task - return idle task given cpu. 3162 * @cpu: processor in question. 3163 * 3164 * return: idle task cpu @cpu. 3165 */ 3166 struct task_struct *idle_task(int cpu) 3167 { 3168 return cpu_rq(cpu)->idle; 3169 } 3170
so, pointer task stored in runqueue (struct rq
) kernel/sched/sched.h:
502 * main, per-cpu runqueue data structure. ... */ 508 struct rq { 557 struct task_struct *curr, *idle, *stop;
there init code in sched/core.c:
4517 /** 4518 * init_idle - set idle thread given cpu 4519 * @idle: task in question 4520 * @cpu: cpu idle task belongs 4524 */ 4525 void init_idle(struct task_struct *idle, int cpu)
i think, idle task run kind of loop special asm commands inform cpu core there no useful job...
this post http://duartes.org/gustavo/blog/post/what-does-an-idle-cpu-do/ says idle task executes cpu_idle_loop
kernel/sched/idle.c (there may custom version of loop arch , cpu - called cpu_idle_poll(void)
-> cpu_relax();
):
40 #define cpu_relax() asm volatile("rep; nop") 45 static inline int cpu_idle_poll(void) .. 50 while (!tif_need_resched()) 51 cpu_relax(); 221 if (cpu_idle_force_poll || tick_check_broadcast_expired()) 222 cpu_idle_poll(); 223 else 224 cpuidle_idle_call();
Comments
Post a Comment