Why is context-switching an expensive procedure and expensive in terms of what?
context-switch, operating-system
Solution
"Why is context switching expensive?" What do they mean by expensive, and expensive in terms of what? In terms of time it takes to execute the task?
There are several reasons for the overhead of context switching.
First,the steps for saving the context itself takes a lot of effort. All the process registers have to be saved. That includes the general registers, process state registers, and on some systems specialized registers (e.g., floating point).
Second, restoring the context for the new process is equally time consuming.
Third, memory caches have to be flushed and reloaded for the new process.
Fourth, there is overhead in determining what process to execute next.
(And probably some others that I have not listed).
All of this takes time.
Problem
In my Operatingsystems class, one of the questions to know for the exam is "Why is context switching expensive?" What do they mean by expensive, and expensive in terms of what? In terms of time it takes to execute the task?