9. Intro to Scheduling Flashcards

1
Q

What are the three states of a thread?

A

Running (executing instructions on a CPU), ready (not executing, but capable), and waiting/blocking/sleeping (not executing, not able to start yet)

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

Why does a thread transition from running to ready?

A

it was descheduled

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

Why does a thread transition from running to waiting?

A

it performed a blocking system call

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

Why does a thread transition from waiting to ready?

A

the event the thread was waiting for happened

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

Why does a thread transition from ready to running?

A

it was scheduled

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

Why does a thread transition from running to terminated?

A

it exited or hit a fatal exception

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

What is scheduling?

A

The process of choosing the next thread (or threads) to run on the CPU(s)

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

Why do we schedule threads?

A

We generally have more threads than cores to run them on, so we need to multiplex the CPU.

We (with the kernel) are also in charge of allocating the CPU and must try to make good decisions so applications can run properly

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

When are the 4 times that scheduling happens?

A
  1. When a thread voluntarily gives up the CPU by calling yield().
  2. When a thread makes a blocking system call and must sleep until the call completes
  3. When a thread exits.
  4. When the kernel decides that a thread has run for long enough (preemptive policy, not cooperative)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What makes a scheduling policy preemptive as opposed to cooperative?

A

The kernel preempts (or stops) a thread that has not requested to be stopped

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

What is the rationale behind having a way for threads to voluntarily give up the CPU?

A

yield() can be a useful way of allowing a well-behaved thread to tell the CPU that it has no more useful work to do (which is inherently cooperative)

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

What is the mechanism component of scheduling?

A

How we switch between threads

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

What is the policy component of scheduling?

A

How we choose the next thread to run

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

How do we switch between threads?

A

Perform a context switch and move threads between the ready, running, and waiting queues

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

Is this an example of scheduling policy or mechanism:

Deciding what thread to run

A

Policy

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

Is this an example of scheduling policy or mechanism:

Context switch

A

Mechanism

17
Q

Is this an example of scheduling policy or mechanism:

Maintaining the running, ready, and waiting queues

A

Mechanism

18
Q

Is this an example of scheduling policy or mechanism:

Giving preference to interactive tasks

A

Policy

19
Q

Is this an example of scheduling policy or mechanism:

Using timer interrupts to stop running threads

A

Mechanism

20
Q

Is this an example of scheduling policy or mechanism:

Choosing a thread to run at random

A

Policy

21
Q

Why (and in what ways) does the scheduling implementation impact other parts of the system?

A

Using other system resources requires the CPU.

Intelligent scheduling makes a modestly-powered system seem fast and responsive.

Stupid scheduling makes a powerful system seem sluggish and laggy.

22
Q

What is system “responsiveness”?

A

When you give the computer an instruction or input, it responds in a timely manner (it doesn’t have to finish, just show you that it’s started)

23
Q

What are some examples of responsive tasks we use computers for?

A

Web browsing (clicking a link retrieves a webpage), editing (typing a key, it’s rendered on screen), chatting (hit send, text transmits to target)

24
Q

What is system “continuity”?

A

When you ask the computer to perform a continuous task, it does so smoothly

25
Q

How does system continuity imply active waiting?

A

You are not interacting with the computer, but you are expecting it to continue to perform a task you have initiated

26
Q

What are some examples of continuous tasks?

A

Blinking a cursor, playing music or a movie, and web animations

27
Q

What is system “completion”?

A

When we ask the computer to perform a task - or it performs one on our behalf - which we expect to take a long time, we want it to complete (eventually)

28
Q

How does completion imply passive waiting?

A

You are asking the computer to continue to deliver interactive performance while working on your long-running tasks (background tasks)

29
Q

What are some examples of background tasks?

A

Performing a system backup and indexing the files on my computer

30
Q

What are the conflicting goals of scheduling?

A

Scheduling is a balance between meeting deadlines and optimizing resource allocation.

31
Q

What does it mean to achieve optimal resource allocation?

A

Carefully allocate tasks so that all resources are constantly in use.

32
Q

Give an example of how responsiveness requires unpredictable deadlines for processes.

A

When the user moves the mouse, I need to be ready to stop the current process redraw the cursor

33
Q

Given an example of how continuity requires predicable deadlines

A

Every 5 ms I need to write more data to the sound card buffer

34
Q

What metrics do we use to evaluate a scheduling algorithm?

A

How well does it meet deadlines and how completely does it allocate system resources?

Note: on human-facing systems, deadlines (or interactivity) usually wins

35
Q

How can a failure to meet process deadlines result in a fatal error (as opposed to an annoying “laggy” experience)?

A

The motion_stop function needed to be called but the OS didn’t get around to scheduling the thread set to call that function before the robot drove off a cliff.