Lecture 8 - CPU Scheduling Flashcards

1
Q

What is scheduling?

A

Scheduling refers to a set of policies and mechanisms to control the sequence of jobs (work) to be performed by a computer system

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

What is allocation? How is it different than scheduling?

A

Suppose we have jobs and some resources, allocation determines which jobs get to use which resources

Scheduling on the other hand determines the sequence of execution

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

What’s are the 3 goals of CPU scheduling?

A

Consider a single CPU case:
• Maximize CPU utilization
• Minimize job response times
• Maximize throughput

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

What are the 3 pieces of information that we need to perform scheduling?

A
  1. Resources
    • Lets assume only one CPU
    • We have I/O resources
    • Memory used in a shared manner
2. Jobs
• Number of processes
• Process creation rate, termination rate
• How long a process runs
• How long a process uses CPU versus I/O
  1. Other issues
    • Scheduling policies, priorities
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Define CPU burst and I/O burst. Which one’s faster?

Why do these clarify why multiprocessing is beneficial?

A

They define the amount of time each of these resources are used. CPU burst is much faster.

While a process is in CPU burst, the I/O is idle, and vice versa. We can utilize the idle resources more efficiently with multiprocessing.

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

What is a CPU-bound and I/O bound process? Give one example of each.

A

Not all processes have an even mix of CPU and I/O usage…

  1. CPU-bound process.
    A number crunching program may do a lot of computation and minimal I/O:
  2. I/O-bound process.
    A data processing job may do little computation and a lot of I/O:
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Do long CPU bursts happen more often than short bursts?

A

No, the opposite is true. 2 millisecond is the most likely burst.

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

What is the role of the Short-term scheduler?

A

Short-term scheduler selects from among the processes in ready queue, and allocates the CPU to one of them
* Queue may be ordered in various ways

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

Name 4 occasions when CPU scheduling decisions take place.

Which one of these are non-preemptive, and which ones are preemptive?

A

CPU scheduling decisions may take place when a process:

  1. Switches from running to waiting state
  2. Switches from running to ready state
  3. Switches from waiting to ready
  4. Terminates

Scheduling under 1 and 4 is non-preemptive.
All other scheduling is preemptive.

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

Name three occasions where preemptive scheduling occurs in OSs.

A

Consider access to shared data
Consider preemption while in kernel mode
Consider interrupts occurring during crucial OS activities

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

What are the 9 evaluation criteria for schedulers? Explain each briefly.

A
  1. CPU utilization
    * defined as the capacity used divided by the total capacity
    * varies from 100% (completely used) to 0% (not used at all!)
  2. Efficiency
    * Useful work divided by Total work.
  3. Throughput
    * defined as the number of jobs completed per unit time
  4. Turnaround time
    * time to complete a job. It is the wall clock time elapsed between the completion and arrival events of the job
  5. Waiting time
    * total time spent waiting in the ready queue
  6. Service time
    * total time spent servicing the job. Total time the job spent in the active queue
  7. Response time
    * wall clock time elapsed between the time the first response (first run) is produced and the arrival of the job
  8. Fairness
  9. Deadlines
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do we design a scheduler?

A
  1. select one or more primary performance criteria
  2. rank them in order of importance
  • performance criteria may not be independent of each other (e.g., increased processor utilization leads to longer response times) so the design of a scheduler usually involves a careful balance of the requirements
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the two scheduling policies? Explain each briefly and give two examples.

What kind of jobs are each good for?

A
  1. Non-Preemptive
    * Scheduler does not interrupt running process
    * Current process runs until it blocks, waiting for an event or a resource, or it terminates
    - > First-Come-First-Served (FCFS)
    - > Shortest Job first (SJF)

Good for “background” batch jobs.

  1. Preemptive
    * Scheduler forces current process to release the CPU
    * Eviction of process occurs at clock interrupt, I/O interrupts
    - > Round-Robin (RR)
    - > Priority

Good for “foreground” interactive jobs.

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

Define the First-Come-First-Served (FCFS) scheduling policy.

What kind of jobs is it best for? Worst?

How is the relative importance of jobs measured?

Name 3 problems with FCFS.

A

FCFS = First-In-First-Out (FIFO)

  • simplest scheduling policy
  • arriving jobs are inserted into the tail (rear) of the ready queue
  • job to be executed next is removed from the head (front) of the queue

FCFS performs better for long jobs. Worst for interactive jobs.

Relative importance of jobs measured only by arrival time (poor choice)

Problems

  1. A long CPU-bound job may hog the CPU
  2. Short (or I/O-bound) jobs have to wait for long periods
  3. Can lead to a lengthy queue of ready jobs, known as the “convoy effect”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Define the Shortest Job First (SJF) scheduling policy.

Name 2 problems with SJF.

A
  • selects the job with the shortest (expected) processing time first
  • Shorter jobs are always executed before long jobs

Problem with SJF

  1. need to know or estimate the processing time of each job
  2. long running jobs may starve for the CPU when there is a steady supply of short jobs.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What’s a preemptive version of Shortest Job First?

A

Preemptive SJF is also called Shortest Remaining Time First (SRTF)

17
Q

Name one method to determine the next CPU burst in SJF.

A
  1. Can be done by using the length of previous CPU bursts, using exponential averaging
    Tn+1 = tn*alpha + (1-alpha)tn-1 + (1-alpha)^j *tn-j + …(1-alpha)^n+1 * T0
    where Tn is guess, tn is previous, alpha is 0
18
Q
Calculate average waiting time of following Shortest Remaining Time First scheduling:
Process, Arrival, Burst
P1   0   8
P2   1   4
P3   2   9
P4   3   5
A

[(10-1) + (1-1) + (17-2) + (5-3)]/4 = 6.5 msec

19
Q

Explain how the Round-Robin Scheduling policy works.

What are three criteria its efficiency depends on?

What kind of job’s is it most suitable for? least?

A
  • Periodically preempt a running job
  • CPU suspends the current job when time-slice expires
  • Job is rescheduled after all other ready jobs are executed at least once

Efficiency of RR depends on

  • Time-slice length
  • If too short, CPU will be spending too much time on context switching
  • If too long, interactive jobs will suffer (becomes a FCFS policy)

Good for interactive jobs.
Not suitable for long batch jobs

20
Q

Explain how the Priority-based Scheduling policy works.

How do we prevent starvation?

A
  • Each process is assigned a priority
  • Process chosen for execution based on priority (highest priority first)
  • Priority + preemption allows preemption when a higher priority process comes in

To prevent starvation:
Priority + aging boosts the priority as a process stays in the ready queue

21
Q

Rank FCFS, RR, SJF in order of increasing processing overhead.

A

FCFS, RR, SJF (potentially, if plenty of mini jobs)

22
Q

Explain the difference between Long-Term, Medium-term and Short-term scheduling.

A

Long-term (job) scheduling is done when a new process is created. It controls the degree of multi-programming

Medium-term scheduling involves suspend/resume processes by swapping them out of or in to memory.

Short-term (process or CPU) scheduling occurs most frequently and decides which process to execute next

23
Q

Define 3 characteristics of Interactive scheduling

What does the priority of processes depend on? How is it determined?

A
  1. Time-sliced
  2. Priority-Based,
  3. Preemptive

Priority depends on expected time to block

  • interactive threads should have high priority
  • compute threads should have low priority

Determine priority using past history

  • processor usage causes decrease
  • sleeping causes increase
24
Q

Explain Lottery scheduling using 25 lottery tickets

What’s the problem with lottery scheduling?

A

25 lottery tickets are distributed equally to you and your four friends
* you give 5 tickets to your one thread
* they give one ticket each to their threads
A lottery is held for every scheduling decision
* your thread is 5 times more likely to win than the others

Problem: It’s not deterministic.

25
Q

Why is Stride scheduling (Proportional-Share Scheduling) better than Lottery scheduling?

A

It’s purely deterministic and completely fair.

26
Q

Explain how metered processes work.

A

Each thread has a meter, which runs only when the thread is running on the processor
* At every clock tick
give processor to thread that’s had the least processor time as shown on its meter
* in case of tie, thread with lowest ID wins

27
Q

Name three issues with metered processes.

A
  1. Some threads may be more important than others
  2. What if new threads enter system?
  3. What if threads block for I/O and synchronization?
28
Q

How does the Mafia metered processes work? How does it solve the traditional meter issues?

A

Each thread pays a bribe
the greater the bribe, the slower the meter runs

to simplify bribing, you buy “tickets”
one ticket is required to get a fair meter
two tickets get a meter running at half speed
three tickets get a meter running at 1/3 speed
etc.

29
Q

Draw a Mafia metered process graph with P=1 Q=2 R =3, arriving in this order. At what time would each have a meter value of 1?

A

P = 1, Q = 5, r = 6

30
Q

How do we enforce a process from leaving and entering a mafia metered schedule to restart?

A

leaving x = meter_value - global clock

arrives = global clock + x

31
Q

How would we schedule an Editor, Video, and Audio on a computer using the ticketing algorithm?

A

Editor: would have most tickets (10), long waits and short bursts

Video: (3)

Audio: (2)

32
Q

What’s the role of Multilevel Priority Scheduler?

A

To have several queues for each priority level. The jobs go into the queue that corresponds to their priority level. So if the job has priority 1 it goes into Queue 1. If the job has priority k it goes into Queue k and so on.

33
Q

How does ML answer the question:

  1. “What happens to a job if another job shows up in another queue”
  2. “What happens to a job when it gets selected to run - does it run to completion or stop after sometime?”
A
  1. If a job arrives at a higher priority queue it will preempt a job that is running from a lower priority queue
  2. ML introduces two rules here: one queue is preemptive and another is non-preemptive. The preemptive is very much like the Round-Robin algorithm. You run a job for certain duration and then preempt it, put it at the end of the queue, run the next one at the head of the queue (assuming of course all higher queues are still empty)
34
Q

What is the biggest problem with ML?

Why is a two level priority ML with systems tasks taking higher priority over user tasks not a good idea for an interactive workstation?

A

Selecting the priority value for the jobs.

This could only starve the user tasks, and make the system sluggish.

35
Q

What is the purpose of Multi-Level Feedback (MLF) queue scheduler?

A

The purpose of the scheduler is to isolate tasks that are interactive from the tasks that non interactive (tasks that consumer CPU in single long burst).

36
Q

How can we tell if the process is an Interactive Job

A

CPU burst sizes are very small compared to I/O activity.

37
Q

Explain how the MLF designed in class works.

A
  1. Pick a job from Queue k only when there are no jobs in Queue 1 to k-1
  2. Run a job from Queue k to a maximum time of 2^(k-1)*T where T is the time for which Queue 1 jobs are run.
  3. If a job runs for more than allotted amount of time ( that is it is running at the end of the time quantum), it is put into the next queue. So the job goes from Queue k to Queue k+1.
  4. A job arriving in Queue 1 would preempt the execution of job from Queue k, where k>1. If we don’t, then we would violate the priority condition for certain duration of time.
38
Q

Does a job ever escalate in priority in an MLF? if so, when?

A

We need to escalate the priority (push it to a Queue higher than the one it is in) if it goes to wait well before the quantum elapses.

Let a job be in Queue k, where k>1. If the job goes to wait in less than T seconds of run time, it should go to Queue 1. If it goes to wait in greater than T but less than T + 2T seconds, it should get into Queue 2 and so on.