7. Context Switching Flashcards

1
Q

What is the one historical limitation of the CPU?

A

It is super expensive

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why do computers come with multiple CPUs?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is batch scheduling?

A

Scheduling jobs sequentially without any interactive users.

Start Job A, finish Job A, start Job B, finish Job B, etc

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the problems with batch scheduling?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What was the ultimate solution to the problem of batch scheduling?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Why did operating systems emerge?

A

Partly to hide delays caused by slow devices (disc, etc) to keep the processor (CPU) active and not waiting around burning clock cycles.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How is the illusion of concurrency accomplished when multiple interactive processes are running?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a context switch?

A

When a processor transitions from processing one thread to processing another thread.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How does the operating system get control of the CPU?

A

Hardware interrupts, software interrupts, or software exceptions. If these don’t happen, the OS relies on timer interrupts (which are hardware interrupts).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are timer interrupts used for?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is preemptive scheduling?

A

Scheduling where the OS does not wait for a process to yield or finish before initiating a context switch to schedule another process.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What must be true about the process state at the moment of a context switch out and a context switch back into the process?

A

The process’s state must be identical.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does thread state consist of?

A

Registers & Stack

We rely on memory protection to keep the stack unchanged until we restart the thread

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the first thing that happens when the interrupt service routine is triggered?

A

Saving thread state (registers and stack). This saved state is known as a trap frame

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a trap frame?

A

The object which contains the saved state of a thread (its stack and register values)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Why do threads switch to a separate kernel stack when executing in the kernel?

A

The kernel doesn’t trust (or want to pollute) the user thread’s stack.