How Linux scheduler schedules processes on multi-core processors?

Multi-core processors exploits thread level parallelism, it means that multiple threads runs in parallel. Suppose, a process has only one thread then, do the other cores remain idle during the execution of this process? In linux system, scheduler consider processes and threads both as a task. It doesn't differentiate between process and thread while scheduling it. So, does this means that different cores executes different threads of different processes in parallel?

When context-switch happens, does this happen only for one core or for all the cores of the cpu?

Answers


You are right: processes and threads are the same from the Linux scheduler's point of view. These tasks are queued according to the scheduler's rules and wait for their turn.

There are scheduling rules such as priority or CPU affinity (to prevent a thread to migrate to another core and preserve cache data).

A context switch may happen on a core every fixed amount of time (a time slice) because the CPU automatically runs some kernel code periodically to permit preemption. Depending on the scheduler's rules, a task can be run for many time slices. A context switch can also occur when a thread calls functions that makes it unrunnable (eg. waiting for IO).

In some cases, if not all, there is one scheduling process per core which does all that.

There is also a similar question on superuser


Need Your Help

Dependency Property and callback

c# wpf

I have a property defined as a dependency property this way:

Compiling ettercap 0.7.4.1 from source under Ubuntu 11.10 (linker error)

c gcc ubuntu compiler-errors

I would like to compile ettercap 0.7.4.1 unter ubuntu 11.10 However, I just can't get it to compile. These are the steps I am executing: