Scheduling Flashcards

1
Q

What does a scheduler do? What are its main components? What happens when a task is scheduled?

A

Scheduler puts threads on the CPU for execution.
Has a run queue and scheduling algorithm
Steps: Perform context switch, Enter user mode, Set PC, Execute

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

What is a ready queue and how do tasks end up there?

A

A ready queue is where tasks a ready to be put on the CPU. They end up there by:

  1. Initiating an I/O request
  2. Having their time slice on the CPU expire
  3. Being forked by a parent thread
  4. Initiated a wait
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is run to completion scheduling?

A

Once a tasks has been scheduled on the CPU, it runs until completion

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

What is First-Come-First-Served?

A

Tasks are scheduled onto CPU based on when it arrives. Use FIFO queue

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

What is Shortest Job First?

A

Exactly what it sounds like, you can use an ordered queue or a tree

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

What is preemptive scheduling?

A

Unlike run-to-completion scheduling, tasks can be interrupted. (SJF - if a shorter job enters the queue, interrupt current one)

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

How does the scheduler know how long a task will take to run?

A

History, last run time, windowed average of last n times

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

What is priority scheduling?

A

Run the task with the highest priority next - can use preemption if higher priority comes into the queue. Can have a queue for each priority level

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

What is thread starvation?

A

When a lower priority task is stuck in the run queue because higher priority tasks keep showing up

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

What is priority aging?

A

A technique used to combat thread starvation - set priority to some function of (assigned priority, time in queue)

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

What is priority inversion?

A

When a lower priority thread holds a mutex needed by a higher priority thread. Higher priority thread will be kept waiting and lower thread will finish first

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

How to combat priority inversion?

A

Temporarily boost the priority of mutex owner (the lower priority task) to match that of the thread that is waiting until mutex is released

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

What is round-robin scheduling?

A

Every task gets an equal time slice and the scheduler places them on the CPU in order.

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

Pros and Cons of RR Scheduling with time slices

A

+ shorter tasks finish sooner (w/o heuristics), more responsive, length I/O ops initiated sooner
- high overheads when timeslice expires

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

How to choose a timeslice based on I/O vs CPU bound

A

Want time(context switching)&raquo_space; timeslice. CPU Bounds = want larger time slice, I/O Bound == smaller slices

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

What data structure can we use to determine if a task is CPU or I/O bound and assign it an appropriate timeslice?

A

Use Multi-level Feedback Queue (MLFQ)

17
Q

What is a multi-level feedback queue?

A

Have different levels for different time slices. Tasks enter at smallest slice. If they don’t yield before the slice expires, they stay there, if they do yield, they move down

18
Q

Describe the O(1) Linux Scheduler

A

Has two priority level buckets (real time and user). Time slice based on priority, feedback based on how long it took to run in the past. Real time always has higher priority than user and gets longer slices. Longer wait times means the thread is more interactive, so gets longer timeslice in the future.

19
Q

Describe the run queue of the O(1) Scheduler

A

Has two run queues - active and expired. Tasks stay in active queue until their timeslices have completely expired (might take multiple runs). When there are no more tasks ini active array, the arrays are swapped.

20
Q

Why was the O(1) Scheduler replaced?

A

It did not work well for real time applications and as apps moved to more and more responsive tasking, the jittering became a problem

21
Q

What is the Completely Fair Scheduler (CFS)?

A

Scheduler for linux non-real time tasks. Based on vruntime. Red-black tree with tasks based on vruntime. Smallest runtime task gets scheduled on CPU. Once it’s no longer the smallest, switch it out for another. vruntime increases more slowly for higher priority based tasks

22
Q

Types of CPUs

A

Shared Memory Multiprocessor (SMP) - each CPU has its own private cache. LLC may or may not be shared by CPUs. Multi-core systems - CPU has internal cores with their own caches, LLC shared by all cores.

23
Q

Scheduling on multi-core systems

A

Want to maximize cache-affinity (keep tasks on same CPU to keep cache hot) - have individual run queue / scheduler

24
Q

What is hyperthreading?

A

Hardware support for multiple execution contexts - can switch threads more easily. Want to schedule a CPU bound and an I/O bound thread together

25
Q

How to make sure to schedule a CPU- and I/O Bound thread together (hyperthreading)

A

Use hardware counters - high CPI == memory bound, low CPI == CPU bound

26
Q

rewatch last couple of lectures

A

lecture