LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   Linux kernel Scheduling in Multicore (https://www.linuxquestions.org/questions/linux-kernel-70/linux-kernel-scheduling-in-multicore-4175480485/)

anup.estuff 10-11-2013 10:02 PM

Linux kernel Scheduling in Multicore
 
I have some doubts regarding some linux kernel scheduling.

1) Does linux kernel(schedular to be specific) always runs on CPU-0?
2) One Scenario:
One kernel thread running on CPU - 0, goes into sleep with interrupts disabled.
In this case, will the schedular run on other CPU?
if Yes, how is the selection made out of the remaining core so as to which will run
the schedular, is this decision made while disabling interrupts on CPU - 0?

jailbait 10-12-2013 07:34 PM

"1) Does linux kernel(schedular to be specific) always runs on CPU-0?"

No

"One kernel thread running on CPU - 0, goes into sleep with interrupts disabled.
In this case, will the schedular run on other CPU?"

A kernel thread going into sleep does not stop any CPU. It just stops the thread. The scheduler can run on any CPU at any time.

"how is the selection made out of the remaining core so as to which will run
the schedular"

The scheduler runs on the same CPU as the kernel routine that called the scheduler.

---------------------
Steve Stites

anup.estuff 10-12-2013 09:24 PM

Quote:

Originally Posted by jailbait (Post 5044651)
"1) Does linux kernel(schedular to be specific) always runs on CPU-0?"

No

"One kernel thread running on CPU - 0, goes into sleep with interrupts disabled.
In this case, will the schedular run on other CPU?"

A kernel thread going into sleep does not stop any CPU. It just stops the thread. The scheduler can run on any CPU at any time.

"how is the selection made out of the remaining core so as to which will run
the schedular"

The scheduler runs on the same CPU as the kernel routine that called the scheduler.

---------------------
Steve Stites

Thanks for taking your time for replying, I appreciate.
I have one more doubt.
When interrupts are disabled on one CPU, and suppose all the other CPU's receive timer interrupt exactly at the same time,
on which CPU will the schedular run? ( as per my current knowledge timer interrupt interrupt is one of the way the schedular gets invoked)
Is there any selection algorithm OR a voting mechanism to decide as to who will run the schedular?( or is it the case that schedular runs on each of the cores? ) .

jailbait 10-13-2013 12:08 PM

"When interrupts are disabled on one CPU, and suppose all the other CPU's receive timer interrupt exactly at the same time,
on which CPU will the schedular run? "

Interrupts being disabled on one CPU is irrelevant to the question. Timer interrupts are generated by the hardware. So if multiple CPUs generate simultaneous timer interrupts then the scheduler will be running simultaneously as threads on multiple CPUs. Whenever one of the CPUs reach the point where single threading is necessary because the scheduler is manipulating system control blocks then that instance of the scheduler will issue interrupts to the other CPUs stopping the other CPUs. When multi-threading is again permissible then that scheduler thread will start all of the CPUs that it stopped. The order that the CPUs run through the single threading code is determined by the order in which they issue the stop to the other CPUs. I don't know how the hardware decides which CPU(s) to stop when two or more CPUs happen to issue the stop interrupt simultaneously.

-------------------------
Steve Stites

sundialsvcs 10-14-2013 09:44 AM

IIRC, that statement about "stopping the other CPUs" is not quite accurate. What actually would happen is this:
  • The interrupt may be received by more than one CPU at a time.
  • Therefore, multiple CPUs may enter the scheduler at more or less the same time.
  • Spinlocks are used wherever any of the CPUs may be manipulating a particular shared data-structure, so that only one of the CPUs (it's unpredictable which one ...) will proceed.
Each CPU or core makes its own scheduling decisions. The scheduler is designed so that they may do so fairly.


All times are GMT -5. The time now is 05:51 AM.