7. Context Switching Flashcards
What is the one historical limitation of the CPU?
It is super expensive
Why do computers come with multiple CPUs?
Transistor density, following Moore’s Law, has increased to a point where thermal and energy-management issues arise. In order to mitigate those thermal and energy management issues while still keeping up with the performance gains promised by Moore’s Law, we add more and more CPUs.
What is batch scheduling?
Scheduling jobs sequentially without any interactive users.
Start Job A, finish Job A, start Job B, finish Job B, etc
What are the problems with batch scheduling?
It is highly inefficient. Each job will use parts of the computer which are very slow. In the time it takes to do a disk read on Job A, the computer could have been processing other, faster parts of Job B.
What was the ultimate solution to the problem of batch scheduling?
Context switching. While a time-expensive operation is occurring, like a disc read, the OS can context switch to another job and make progress on that while the disc read completes.
Why did operating systems emerge?
Partly to hide delays caused by slow devices (disc, etc) to keep the processor (CPU) active and not waiting around burning clock cycles.
How is the illusion of concurrency accomplished when multiple interactive processes are running?
Keep in mind certain human perceptual limits (15 ms delay to be perceived as interactive; 40 ms delay on 25 fps video to appear smooth).
The processors rapidly switch between tasks, within those perceptual limits, to create the notion of concurrency
What is a context switch?
When a processor transitions from processing one thread to processing another thread.
How does the operating system get control of the CPU?
Hardware interrupts, software interrupts, or software exceptions. If these don’t happen, the OS relies on timer interrupts (which are hardware interrupts).
What are timer interrupts used for?
They are generated by a timer device to ensure that the operating system regains control of the system at regular intervals.
Timer interrupts are the basis of preemptive scheduling.
What is preemptive scheduling?
Scheduling where the OS does not wait for a process to yield or finish before initiating a context switch to schedule another process.
What must be true about the process state at the moment of a context switch out and a context switch back into the process?
The process’s state must be identical.
What does thread state consist of?
Registers & Stack
We rely on memory protection to keep the stack unchanged until we restart the thread
What is the first thing that happens when the interrupt service routine is triggered?
Saving thread state (registers and stack). This saved state is known as a trap frame
What is a trap frame?
The object which contains the saved state of a thread (its stack and register values)