I'm reading "Understanding the Linux Kernel, 3rd Edition", and in Chapter 5, Section "Kernel Preemption", it says:
All process switches are performed by the
switch_to
macro. In both preemptive and nonpreemptive kernels, a process switch occurs when a process has finished some thread of kernel activity and the scheduler is invoked. However, in nonpreemptive kernels, the current process cannot be replaced unless it is about to switch to User Mode.
I still don't see the difference here between non-preemptive and preemptive kernels, because any way you need to wait for the current process to switch to user mode.
Say there is a process p running in kernel mode, and whose time quantum expires, then the scheduler_tick()
is called, and it sets the NEED_RESCHED
flag of p.
But schedule()
is invoked only when p switch to user mode (right?).
So what if p never switches to user mode?
And if it switched to user mode but it takes a "long" time between the moment scheduler_tick()
set NEED_RESCHED
and the moment p actually switched to user mode - then it used more than its quantum?