Which tasks correspond to the Linux kernel scheduler?

In Linux at Kernel level we have threads/tasks (belonging to Kernel and user), eg,

swapper: is a kernel thread (process 0), the ancestor of all processes, created from scratch during the initialization phase of Linux by the start_kernel() function. Also

init: an additional kernel thread, process 1 (init process)

HelloWorld: A thread for user program

My question is about the Kernel scheduler, that performs the following jobs:

-Schedule tasks within a fixed amount of time (ie context-switching)

-Calculate the timeslices dynamically (short/long vs priority based)

-Assigns process priorities dynamically (when needed)

-Monitoring the processes to its jobs (does this include any further?)

More specifically my questions becomes: Which thread/task(s) at Kernel level correspond to the scheduler? Should it be 'scheduler' etc or Does any other task from kernel do its job?

PS:

"swapper" in kernel is an idle thread/task with lowest priority (halt) [1]. Does this do anything other than "step-down"?

Does Linux create a dedicated instance of scheduler for each core in multi-core system? If no, then how it does on multicore?

[1] Why do we need a swapper task in linux?


The Linux scheduler does not have a task or thread corresponding to it. The Linux scheduler code, mainly the schedule() function, is run when the timer used for scheduling issues an interrupt or when it is explicitly called in the kernel code (eg as part of a system call).

On multicore, the scheduler code is run independently on each core. The timer interrupt received on Core 0 is usually broadcast by using IPIs (Inter-Processor Interrupts) to the other cores. If the platform has per CPU timers, then Linux usually uses these to issue the interrupt required for scheduling instead of using IPIs.


I don't think there is a separate thread that runs the scheduler. schedule() is the function which does the scheduling. Some of the places where schedule() function may be called from:

  1) A process(A user space or kernel space) which is executing the kernel code wants to wait for some event (calls any of the wait functions)
  2) A process which calls schedule() function to yield the processor for itself for sometime.
  3) Every time when a timer interrupt is generated.

Like this there may be many places where the schedule() function may be invoked.

链接地址: http://www.djcxy.com/p/84852.html

上一篇: 调度程序在内核模式下运行的进程

下一篇: 哪些任务对应于Linux内核调度程序?