The following excerpt is from Linux Kernel Development(LKD) by Robert Love.
These contexts represent the breadth of the kernel’s activities. In fact, in Linux, we can generalize that each processor is doing exactly one of three things at any given moment:
- In user-space, executing user code in a process
- In kernel-space, in process context, executing on behalf of a specific process
- In kernel-space, in interrupt context, not associated with a process, handling an interrupt
This list is inclusive. Even corner cases fit into one of these three activities: For exam- ple, when idle, it turns out that the kernel is executing an idle process in process context in the kernel.
What I grasped from above is that when in Kernel-space, there are only two contexts(it's inclusive, according to Love), i.e., process context & interrupt context. To my understanding, the kernel enters process context when a process invokes a system call(e.g., read(), write(), etc.), while interrupt context happens when the kernel handles an interrupt.
But there are far more other functionalities in the kernel, for instance, there are kernel threads scheduled to do routine works(e.g., reclaiming memory), and even the scheduler itself is neither invoked by a system call nor by an interrupt.
So I wonder why the text says there are only two contexts in the kernel...?
even the scheduler itself is neither invoked by a system call nor by an interrupt
- then when do you think is it invoked? IT's invoked on both, when a process doesyield()
and when an interrupt fires.kernel threads scheduled to do routine works(e.g., reclaiming memory)
kernel handling is composed of top half and low half of work. The top is done in interrupts (register doing routine work), the low (do routing work) executes in low half. – KamilCuk