LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-15-2011, 02:44 AM   #1
dspjm
Member
 
Registered: Dec 2010
Distribution: Scientific Linux Slackware
Posts: 91

Rep: Reputation: 2
When does the kernel run schduling?


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.

Last edited by dspjm; 10-15-2011 at 02:46 AM.
 
Old 10-15-2011, 03:27 AM   #2
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
The kernel gets control either at the end of the timeslice, or when a system function is called, including I/O.
 
Old 10-15-2011, 04:22 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
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.
 
Old 10-15-2011, 06:30 AM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940
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."
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Does a kernel module run in kernel or user space? paliga Linux - General 4 10-31-2010 07:22 AM
schduling error aarsh Linux - Software 2 05-04-2010 03:22 AM
[SOLVED] Can I run a xen kernel alongside my Lenny kernel and chose through grub? minrich Linux - Virtualization and Cloud 2 01-23-2010 05:41 AM
Can't run kernel config after APT kernel install rollo Debian 9 04-12-2006 05:06 PM
Cant run X/KDM after new kernel build, even on old kernel bbska Slackware 2 02-25-2004 10:23 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration