How does the Linux scheduler plan processes on multi-core processors?

Multi-core processors use the parallelism thread level, which means that multiple threads are running in parallel. Suppose a process has only one thread, and the rest of the cores remain inactive during the execution of this process? In a linux system, the scheduler considers processes and threads as a task. He does not distinguish between process and flow in planning. So, does this mean that different cores execute different threads of different processes in parallel?

When switching context, does this happen for only one core or for all processor cores?

+2
source share
1 answer

You are right: the processes and threads are the same from the point of view of the Linux scheduler. These tasks are queued in accordance with the scheduler rules and wait for their turn.

There are scheduling rules, such as priority or proximity of the processor (to prevent the thread from moving to another core and storing cache data).

A context switch can occur on the kernel every fixed period of time (time slice), because the CPU automatically runs some kernel code periodically to allow prevention. Depending on the scheduler rules, a task can be performed for many time fragments. A context switch can also occur when a thread calls functions that make it impossible (for example, waiting for I / O).

In some cases, if not all, there is one scheduling process for the kernel that does all of this.

There is also a similar question on superuser

+1
source

All Articles