Linux - KernelThis forum is for all discussion relating to the Linux kernel.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
"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? ) .
"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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.