CS139-lecture-20210930

CPU scheduling #

image_2021-09-30-13-55-06

Long term scheduling

  • job scheduling
  • decides which process should enter the ready state

Short term scheduling

  • cpu scheduling
  • decides which ready process should run next on the CPU
image_2021-09-30-13-54-49 image_2021-09-30-13-56-59

Recall the overall state diagram for a process:

image_2021-09-30-14-02-03

Non-preemptive vs preemptive scheduling #

image_2021-09-30-14-02-27

Preemptive here basically means “pause”. So the non-preemptive scheduling can only work in cases 1 and 4 (from prior slides). Preemptive scheduling can happen in cases 1-4.

Dispatcher #

image_2021-09-30-14-05-03

Criteria #

image_2021-09-30-14-05-13

These criteria can be used to evaluate the scheduler’s quality.

Waiting time is the total amount of time waiting, whereas response time is how long it takes until the request is submitted, but not necesarily completed.

image_2021-09-30-14-10-48

Waiting time #

image_2021-09-30-14-10-54

Note the assumptions in the above slide for later slides. Since each process runs to completion, this is non preemptive scheduling.

First come first served #

image_2021-09-30-14-14-16

This is based on a FIFO queue.

image_2021-09-30-14-17-07

By putting the shorter processes first, the overall average wait time is much better. So, the order in which the processes enter the queue really matters.

image_2021-09-30-14-18-42

With a FIFO schedule, a slow process may create a blockage, known as the convoy effect:

image_2021-09-30-14-18-55

Shortest job first #

image_2021-09-30-14-19-51

Minimal spanning tree algorithms, like Prim’s and Kruskal’s, share the same underlying principle to a shortest job first scheduler. Shortest job first is a greedy algorithm.

image_2021-09-30-14-30-02

Shortest remaining time first (preemptive) #

image_2021-09-30-14-30-40 image_2021-09-30-14-30-48 image_2021-09-30-14-39-52

Response time #

image_2021-09-30-14-40-44 image_2021-09-30-14-41-25 image_2021-09-30-14-43-11

\( P_1 \) ’s response time is 0.