1) Context Switch –
·
Whenever an interrupt arrives, the CPU must do
a state-save of
the currently running process, and then switch into kernel mode to handle the
interrupt, and then do a state-restore of
the interrupted process.
·
Similarly, a context switch occurs
when the time slice for one process has expired and a new process is to be loaded
from the ready queue. This will be instigated by a timer interrupt, which will
then cause the current process's state to be saved and the new process's state
to be restored.
·
Saving and restoring states involves saving and
restoring all of the registers and program counter(s), as well as the process
control blocks described above.
·
Context switching happens VERY frequently, and
the overhead of doing the switching is just lost CPU time, so context switches (state
saves & restores) need to be as fast as possible. Some hardware has special
provisions for speeding this up, such as a single machine instruction for
saving or restoring all registers at once.