ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
When the cpu is running a process, how does it go back to kernel and run schedule()? How can kernel implements the algorithm.
Is that every time when a process began running, the cpu set a timer, when the timeslice has run out, the cpu run the schedule()?
While, I read that the kernel only preempt when it's preemptable, what if the process is not preemptalbe?
The book says that preemptable means it is not holding any mutex.
Have a look at ../Documentation/scheduler/sched-design-CFS.txt
A (small) part of which is;
Quote:
Originally Posted by CFS
Summing up, CFS works like this: it runs a task a bit, and when the task
schedules (or a scheduler tick happens) the task's CPU usage is "accounted
for": the (small) time it just spent using the physical CPU is added to
p->se.vruntime. Once p->se.vruntime gets high enough so that another task
becomes the "leftmost task" of the time-ordered rbtree it maintains (plus a
small amount of "granularity" distance relative to the leftmost task so that we
do not over-schedule tasks and trash the cache), then the new leftmost task is
picked and the current task is preempted.
The kernel ultimately "runs the show," and one of several things that it can do for its own amusement is to hand-over control to some user program for a few milliseconds now-and-then. (Control will always be returned to the kernel, by means of some hardware or software-generated interrupt or another, just a few milliseconds hence...)
The term, "kernel," can actually mean several things in-practice. It is often used to refer to any code that is executed in supervisor state, not merely to the system's dispatcher (schedule.c). For example, we often talk about "kernel threads," which are, in fact, dispatchable things ... handled by the very same scheduler albeit under different rules. We also use the term in connection with dispatchable things that aren't treated as processes or threads, such as first/second level interrupt handlers ("top half / bottom half"), etc.
The scheduler's essential task is "to decide what this particular CPU or core should do next."
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.