Learning about the CPU scheduling internals – part 3
Let’s begin by exploring the topic of preemption.
Preemptible kernel
Please visualize this hypothetical situation: you’re running on a system with just one CPU core. An analog clock app is running on the GUI along with a C program, a.out
, whose one line of code is (groan) while (1);
. So, what do you think: will the CPU - hogger while 1 process indefinitely hog the CPU, thus causing the GUI clock app to stop ticking (will its second hand stop moving altogether)?
A little thought (and experimentation) will reveal that, indeed, the GUI clock app keeps ticking in spite of the naughty CPU hogger app! This is really the whole point of having an OS-level scheduler: it can, and does, preempt (kick out!) the CPU-hogging user space process. (We briefly discussed the CFS algorithm previously; CFS will cause the aggressive CPU-bound process to accumulate a huge vruntime
value and thus move more to the right...