To finish this discussion, a quick word on the (scheduler) context switch. The job of the context switch (in the context of the CPU scheduler) is quite obvious: before simply switching to the next task, the OS must save the state of the previous, that is, the currently executing, task; in other words, the state of current. You will recall from Chapter 6, Kernel Internals Essentials – Processes and Threads, that the task structure holds an inline structure to store/retrieve the thread's hardware context; it's the member struct thread_struct thread (on the x86, it's always the very last member of the task struct). In Linux, an inline function, kernel/sched/core.c:context_switch(), performs the job, switching from the prev task (that is, from current) to the next task, the winner of this scheduling round or preemption. This switch is essentially performed in two (arch-specific) stages:
- The memory (MM) switch: Switch an arch...