Lecture 6 about 75 min 32 quiz questions

CPU Scheduling

Every CPU scheduling algorithm on the syllabus, each with the slide's worked example reproduced number by number: FCFS, SJF, SRTF, priority, round robin, multilevel queues, and multiprocessor scheduling.

What you will be able to do

  • Define the five scheduling criteria and say whether each is maximised or minimised.
  • Draw a Gantt chart for FCFS, SJF, SRTF, priority, and round robin and compute completion, turnaround, waiting, and response times.
  • Predict the next CPU burst with exponential averaging.
  • Explain convoy effect, starvation, aging, and the effect of the time quantum.
  • Schedule a multilevel queue and a multilevel feedback queue example and count context switches.
  • Contrast asymmetric and symmetric multiprocessor scheduling and compute per-core utilisation.
1

CPU bursts, the dispatcher, and preemption

A process alternates between computing and waiting. The scheduler only cares about the computing parts.

During its lifetime a process goes through a sequence of CPU bursts and I/O bursts. It computes for a while, then waits for a device, then computes again. In a multiprogrammed system many processes compete for the CPU at once, each wanting to finish its current CPU burst. The CPU scheduler, also called the short-term scheduler, picks one process from the ready queue.

cpu burstload, add, store, branchi/ocpu burstlong compute loopi/owrite filecpushorti/oreadcpu burstcomputei/onetworkcpuexittimeCPU burstI/O burststarts and ends with a CPU burst, I/O-bound means many short CPU bursts
Load, add, store: CPU burst. Wait for I/O: I/O burst. Repeat until the last CPU burst ends with a system call to terminate.

The scheduler decides; the dispatcher acts. The dispatcher module gives control of the CPU to the process selected by the short-term scheduler. That involves switching context, switching to user mode, and jumping to the proper location in the user program to restart it. The time this takes is the dispatch latency.

Non-preemptive versus preemptive scheduling

Non-preemptive

  • A running process keeps the CPU until it completes or blocks (switches to waiting)
  • Scheduler runs only at those two moments
  • Simple, no timer needed
  • Examples: FCFS, non-preemptive SJF, non-preemptive priority

Preemptive

  • A running process can be forced to release the CPU while neither complete nor blocked
  • Triggered when the time quantum expires in a time-sharing system
  • Or when a higher-priority process becomes ready
  • Examples: SRTF, preemptive priority, round robin
1 of 9
2

Scheduling criteria and the formulas you will use

Five metrics, two to maximise and three to minimise. Plus the four formulas every numerical needs.

Scheduling criteria and optimisation direction

CriterionDefinition from the slidesGoal
CPU utilisationKeep the CPU as busy as possibleMaximise
ThroughputNumber of processes that complete execution per time unitMaximise
Turnaround timeTime to execute a particular process: submission to terminationMinimise (average)
Waiting timeTime a process has spent waiting in the ready queueMinimise (average)
Response timeTime from request submission until the first response is produced, not the complete outputMinimise (average)
Meeting deadlinesReal-time systems must finish before a deadlineGuarantee

The four formulas

  1. 1

    Completion time (CT)

    Read it straight off the Gantt chart: the instant the process finishes its last unit of CPU.

  2. 2

    Turnaround time (TAT)

    TAT = CT - AT. Completion minus arrival. Everything from entering the system to leaving it.

  3. 3

    Waiting time (WT)

    WT = TAT - BT. Turnaround minus burst. Time in the ready queue, which is all the time the process was around but not running.

  4. 4

    Response time (RT)

    RT = first CPU time - AT. When the process first touches the CPU minus its arrival. For non-preemptive algorithms this equals waiting time.

2 of 9
3

First-Come, First-Served (FCFS)

One FIFO queue, no preemption, and a nasty convoy effect.

  • A single FIFO ready queue. Whoever arrived first runs first.
  • Non-preemptive, so it is not suitable for time-sharing systems.
  • Simple to implement and understand.
  • Average waiting time depends heavily on the order in which processes enter the system.

Worked example 1: P1 = 24, P2 = 3, P3 = 3, all arrive at 0 in order P1, P2, P3

  1. 1

    Gantt chart

    P1 runs 0 to 24, P2 runs 24 to 27, P3 runs 27 to 30.

  2. 2

    Completion times

    CT: P1 = 24, P2 = 27, P3 = 30.

  3. 3

    Turnaround

    All arrive at 0, so TAT = CT: 24, 27, 30. Average (24 + 27 + 30) / 3 = 27.

  4. 4

    Waiting

    WT = TAT - BT: P1 = 0, P2 = 24, P3 = 27. Average (0 + 24 + 27) / 3 = 17.

  5. 5

    Response

    First CPU time minus arrival: 0, 24, 27. Average 17. For FCFS response equals waiting.

Worked example 2: same processes, order P2, P3, P1. Gantt: P2 0 to 3, P3 3 to 6, P1 6 to 30.

ProcessBurstCTRTTATWT
P124306306
P233030
P336363
Average3133

Worked example 3: five processes with different arrival times. Gantt: P3 0 to 2, idle 2 to 3, P1 3 to 7, P5 7 to 10, P2 10 to 13, P4 13 to 14.

ProcessArrivalBurstCTTATWT
P134740
P2531385
P302220
P4511498
P5431063
Average5.83.2

Read example 3 carefully. P3 finishes at 2 but P1 does not arrive until 3, so the CPU sits idle from 2 to 3. At time 7, three processes are waiting: P5 arrived at 4, P2 and P4 both arrived at 5. FCFS takes P5 first. P2 and P4 tie on arrival, and the slide breaks the tie by process id.

FCFS: advantages and disadvantages

AdvantagesDisadvantages
Simple and easy to understandProcesses with less execution time suffer: waiting time is often long
Favours CPU-bound processes over I/O-bound processes
Convoy effect: a long first burst makes every short process wait, raising average waiting time
Not suitable for time-sharing, where each user needs a share of the CPU at regular intervals
3 of 9
4

Shortest Job First and Shortest Remaining Time First

Optimal on paper. The catch: you have to know the future.

SJF associates with each process the length of its next CPU burst and gives the CPU to the process with the smallest one. FCFS breaks ties. It comes in two flavours: non-preemptive SJF, which lets the running burst finish, and preemptive SJF, better known as Shortest Remaining Time First (SRTF), which compares the newcomer's burst against the running process's remaining time.

Optimality claims from the slides

  • Non-preemptive SJF is optimal if all processes are ready simultaneously: it gives the minimum average waiting time for a given set.
  • SRTF is optimal if processes may arrive at different times.

Worked example: non-preemptive SJF. Gantt: P1 0 to 7, P3 7 to 8, P2 8 to 12, P4 12 to 16.

ProcessArrivalBurstCTRTTATWT
P1077070
P224126106
P3418343
P454167117
Average484

Why does P1 run first when it is the longest? At time 0 it is the only process present. Non-preemptive means it keeps the CPU until 7. At 7 the ready queue holds P2 (4), P3 (1), P4 (4). Shortest is P3. Then P2 and P4 tie on burst; FCFS breaks the tie in favour of P2, which arrived earlier.

Worked example: SRTF on the same four processes

  1. 1

    Time 0 to 2

    Only P1 is present. It runs, remaining burst drops from 7 to 5.

  2. 2

    Time 2: P2 arrives

    P2 needs 4, P1 has 5 remaining. 4 is smaller, so P1 is preempted. P2 runs 2 to 4, remaining 2.

  3. 3

    Time 4: P3 arrives

    P3 needs 1, P2 has 2. Preempt P2. P3 runs 4 to 5 and completes. CT(P3) = 5.

  4. 4

    Time 5: P4 arrives

    Ready: P1 (5 left), P2 (2 left), P4 (4). Shortest is P2. It runs 5 to 7 and completes. CT(P2) = 7.

  5. 5

    Time 7

    Ready: P1 (5), P4 (4). P4 runs 7 to 11. CT(P4) = 11.

  6. 6

    Time 11

    P1 finishes its remaining 5: 11 to 16. CT(P1) = 16.

SRTF results. Gantt: P1 0 to 2, P2 2 to 4, P3 4 to 5, P2 5 to 7, P4 7 to 11, P1 11 to 16.

ProcessArrivalBurstCTRTTATWT
P107160169
P2247051
P3415010
P45411262
Average0.573

SJF: advantages and disadvantages

AdvantagesDisadvantages
Frequently used for long-term scheduling, where job lengths are declaredJob completion time must be known in advance, which is hard to predict
Optimal for average waiting timeMay cause starvation if shorter processes keep coming
Favours shorter jobs over long jobsCannot be implemented directly at the level of short-term CPU scheduling

The big problem: nobody knows the exact length of the next CPU burst. The fix is to predict it from the recent past using exponential averaging. Let t(n) be the actual length of the n-th burst and tau(n+1) the prediction for the next one, with alpha between 0 and 1:

Exponential averagingtext
1tau(n+1) = alpha * t(n) + (1 - alpha) * tau(n)
2
3alpha = 0 : tau(n+1) = tau(n) recent history ignored, prediction never changes
4alpha = 1 : tau(n+1) = t(n) only the last burst counts
5alpha = 1/2 : equal weight to the last burst and the whole earlier history

Worked example: alpha = 0.5, tau1 = 5, actual bursts P1 = 4, P2 = 8, P3 = 5, P4 = 6. Predict P5.

  1. 1

    tau2

    0.5 x 4 + 0.5 x 5 = 2 + 2.5 = 4.5

  2. 2

    tau3

    0.5 x 8 + 0.5 x 4.5 = 4 + 2.25 = 6.25

  3. 3

    tau4

    0.5 x 5 + 0.5 x 6.25 = 2.5 + 3.125 = 5.625

  4. 4

    tau5

    0.5 x 6 + 0.5 x 5.625 = 3 + 2.8125 = 5.8125. The predicted next burst for P5 is 5.8125.

4 of 9
5

Priority-based scheduling

An integer decides everything. Read the slide to learn whether small or large means important.

  • A priority number (integer) is associated with each process.
  • The CPU goes to the process with the highest priority. Convention on the slides: smallest integer = highest priority, unless the example says otherwise.
  • Both preemptive and non-preemptive variants exist.
  • SJF is a priority scheme where the priority is the (remaining) burst time.

Worked example: non-preemptive priority, all arrive at 0, lower number = higher priority. Gantt: P2 0 to 1, P5 1 to 6, P1 6 to 16, P3 16 to 18, P4 18 to 19.

ProcessPriorityBurstCTRTTATWT
P1310166166
P2111010
P34218161816
P45119181918
P5256161
Average8.2128.2

Worked example: preemptive priority, higher number = higher priority

  1. 1

    Input

    P1 arrives 0, priority 2, burst 4. P2 arrives 1, priority 3, burst 3. P3 arrives 2, priority 4, burst 1. P4 arrives 3, priority 5, burst 5. P5 arrives 4, priority 5, burst 2.

  2. 2

    0 to 1

    P1 alone. Runs 1 unit, 3 left.

  3. 3

    1 to 2

    P2 arrives with priority 3 > 2. Preempts P1. Runs 1 unit, 2 left.

  4. 4

    2 to 3

    P3 arrives with priority 4 > 3. Preempts P2. Runs its single unit and completes. CT(P3) = 3.

  5. 5

    3 to 8

    P4 arrives with priority 5, the highest. Runs. At time 4, P5 arrives with equal priority 5. Equal priority does not preempt, so P4 finishes all 5 units. CT(P4) = 8.

  6. 6

    8 to 10

    P5 (priority 5) runs its 2 units. CT(P5) = 10.

  7. 7

    10 to 12

    P2 (priority 3) finishes its remaining 2. CT(P2) = 12.

  8. 8

    12 to 15

    P1 (priority 2) finishes its remaining 3. CT(P1) = 15.

Preemptive priority results computed with the formulas. Gantt: P1 0 to 1, P2 1 to 2, P3 2 to 3, P4 3 to 8, P5 8 to 10, P2 10 to 12, P1 12 to 15.

ProcessArrivalPriorityBurstCTRTTATWT
P10241501511
P2133120118
P32413010
P43558050
P545210464
Average0.87.64.6

Priority scheduling: advantages and disadvantages

AdvantagesDisadvantages
The relative importance of each process can be precisely definedStarvation: if high-priority processes keep using the CPU, low-priority ones may be postponed indefinitely
Deciding which process gets which priority level is itself a problem
5 of 9
6

Round Robin (RR)

Everyone gets a slice. The size of the slice is the whole design.

  • Each process gets a small unit of CPU time, the time quantum q. When it elapses the process is preempted and added to the end of the ready queue.
  • Newly arriving processes, and processes finishing their I/O bursts, join the end of the ready queue.
  • With n processes in the ready queue and quantum q, no process waits more than (n - 1) x q time units for its next turn.
  • q large: RR degenerates into FCFS.
  • q small: processor sharing. Each of the n processes appears to have its own processor running at 1/n of the real speed. But too small a q means the context switch overhead dominates.

Worked example: q = 20, P1 = 53, P2 = 17, P3 = 68, P4 = 24, all arrive at 0

  1. 1

    Round 1

    P1 0 to 20 (33 left). P2 20 to 37, completes since 17 < 20. P3 37 to 57 (48 left). P4 57 to 77 (4 left).

  2. 2

    Round 2

    P1 77 to 97 (13 left). P3 97 to 117 (28 left). P4 117 to 121, completes.

  3. 3

    Round 3

    P1 121 to 134, completes. P3 134 to 162, completes.

  4. 4

    Completion times

    P1 = 134, P2 = 37, P3 = 162, P4 = 121.

RR q = 20 results. Gantt: P1 0 to 20, P2 20 to 37, P3 37 to 57, P4 57 to 77, P1 77 to 97, P3 97 to 117, P4 117 to 121, P1 121 to 134, P3 134 to 162.

ProcessBurstCTRTTATWT
P153134013481
P21737203720
P3681623716294
P4241215712197
Average28.5113.573

Compare with SJF on the same set, which would give an average waiting time near 38. RR trades a longer average wait for a far better response time and a guarantee of no starvation. Typically RR has higher average turnaround than SJF but better response.

Open the scheduling simulatorEnter any process set, choose FCFS, SJF, SRTF, priority, or RR, and get the Gantt chart with completion, turnaround, waiting, and response times. Use it to check every worked example on this page.

Round robin: advantages and disadvantages

AdvantagesDisadvantages
Every process gets an equal share of the CPUToo short a quantum raises overhead and lowers CPU efficiency
Cyclic, so no starvationToo long a quantum gives poor response to short processes
Average waiting time under RR is often long
6 of 9
7

Multilevel Queue and Multilevel Feedback Queue

Split the ready queue into several queues, then decide whether processes may move between them.

MLQ versus MLFQ

Multilevel Queue (MLQ)

  • Ready queue divided into subqueues
  • Processes are permanently assigned to a subqueue by memory size, priority, or type (foreground versus background)
  • Each queue has its own scheduling algorithm
  • Higher-priority queues are served first; lower queues can starve

Multilevel Feedback Queue (MLFQ)

  • Enhancement of MLQ: processes can move between queues
  • Queues separate processes by CPU burst behaviour
  • A process that uses a lot of CPU is demoted to a lower-priority queue
  • A process waiting too long in a low queue is promoted: aging prevents starvation

Worked example: MLQ with Q1 (SRTF) > Q2 (FCFS) > Q3 (RR, q = 2)

  1. 1

    Input

    P1 arrives 0 burst 3 in Q1. P2 arrives 0 burst 4 in Q1. P3 arrives 7 burst 2 in Q2. P4 arrives 6 burst 4 in Q2. P5 arrives 10 burst 5 in Q1. P6 arrives 5 burst 3 in Q3.

  2. 2

    0 to 3

    Q1 has P1 (3) and P2 (4). SRTF picks P1. Completes at 3.

  3. 3

    3 to 7

    P2 runs. P6 (Q3) arrives at 5 and P4 (Q2) arrives at 6, but Q1 outranks them. P2 completes at 7.

  4. 4

    7 to 10

    Q1 empty. Q2 has P4 (arrived 6) and P3 (arrived 7). FCFS picks P4. At 10, P5 arrives in Q1 and preempts P4, which has 1 unit left.

  5. 5

    10 to 15

    P5 runs its 5 units in Q1. Completes at 15.

  6. 6

    15 to 18

    Back to Q2. The slide runs P3 (15 to 17) then the preempted P4 (17 to 18), treating the preempted process as re-queued at the tail. CT(P3) = 17, CT(P4) = 18.

  7. 7

    18 to 21

    Q3, round robin q = 2: P6 runs 18 to 20, quantum expires, runs 20 to 21 and completes.

Answers the slide asks for

  • Gantt: P1, P2, P4, P5, P3, P4, P6, P6 with boundaries at 3, 7, 10, 15, 17, 18, 20, 21.
  • Status at t = 20: Q1, Q2, and Q3 are all empty (P6 is running, not queued).
  • TAT(P4) = 18 - 6 = 12. TAT(P6) = 21 - 5 = 16.
  • Number of context switches = 7, one at each boundary between consecutive execution slots, including the P6 quantum expiry at 20.

Worked example: MLFQ with Q1 (RR q = 8), Q2 (RR q = 16), Q3 (FCFS). P1 = 33, P2 = 17, P3 = 48, P4 = 24, all arrive at 0

  1. 1

    Q1 pass, q = 8

    P1 0 to 8 (25 left), P2 8 to 16 (9 left), P3 16 to 24 (40 left), P4 24 to 32 (16 left). None finished, all demoted to Q2.

  2. 2

    Q2 pass, q = 16

    P1 32 to 48 (9 left, demoted to Q3). P2 48 to 57, completes. P3 57 to 73 (24 left, demoted). P4 73 to 89, completes exactly at the quantum.

  3. 3

    Q3, FCFS

    P1 89 to 98, completes. P3 98 to 122, completes.

MLFQ results. Gantt: P1 0 to 8, P2 8 to 16, P3 16 to 24, P4 24 to 32, P1 32 to 48, P2 48 to 57, P3 57 to 73, P4 73 to 89, P1 89 to 98, P3 98 to 122.

ProcessBurstCTRTTATWT
P1339809865
P2175785740
P3481221612274
P42489248965
Average1291.561

MLQ and MLFQ: advantages and disadvantages

AdvantagesDisadvantages
MLQDifferent scheduling for different kinds of processesStarvation: lower-level processes may never execute or wait a very long time
MLFQFlexible; processes move between queues, so CPU hogs sink and interactive jobs stay responsiveComplex; moving processes around adds CPU overhead
7 of 9
8

What real operating systems use

Windows, Linux, and macOS all landed on variants of the same two ideas.

Schedulers in real operating systems, as stated on the slides

OSSchedulerKey details
Windows (NT-based)Multilevel feedback queue32 priority levels, 0 to 31. Levels 0 to 15 are normal priorities. Levels 16 to 31 are soft real-time and need privileges to assign. Level 0 is reserved for the OS.
LinuxCompletely Fair Scheduler (CFS)Fair queuing with complexity O(log N) for N tasks in the run queue. Choosing a task is constant time; reinserting a task after it runs costs O(log N).
macOSMultilevel feedback queueFour priority bands for threads: normal, system high priority, kernel mode only, and real-time. Threads are scheduled preemptively.

Notice the convergence. Two of the three use a multilevel feedback queue, the algorithm from the previous section, because it rewards interactive bursts and demotes CPU hogs without being told which is which. Linux took a different route: instead of fixed priority levels, CFS tracks how much CPU each task has had and always runs the one that has had the least, which is fairness enforced by bookkeeping rather than by queues.

8 of 9
9

Multiple-processor scheduling and multicore issues

More CPUs means load sharing, more complexity, and a worked three-core example.

With multiple CPUs available, load sharing becomes possible: work is distributed among the processors. Scheduling is more complex than on a single processor. The slides split approaches into two types.

Asymmetric versus symmetric multiprocessing

Asymmetric

  • One master processor handles all scheduling decisions, I/O processing, and resource allocation
  • Other processors execute only user code
  • Simple, and reduces the need for data sharing
  • Master can become a bottleneck

Symmetric (SMP)

  • Each processor is self-scheduling
  • Either a common ready queue or a private queue per processor
  • Each processor examines the ready queue and selects a process
  • Needs locking on shared queues; used by nearly all modern OSes

Worked example: 3 identical cores, global preemptive priority (smaller number = higher priority)

  1. 1

    Input

    P1 0/9/pri 2, P2 0/5/pri 1, P3 1/7/pri 3, P4 2/4/pri 2, P5 3/6/pri 1, P6 5/3/pri 2, P7 6/5/pri 1, P8 8/4/pri 3. Ties: earlier arrival, then smaller id. Free cores: lowest-numbered core first. Preemption victim: lowest priority running, then largest remaining burst.

  2. 2

    Time 0

    P2 (pri 1) to C1, P1 (pri 2) to C2. C3 idle.

  3. 3

    Time 1

    P3 arrives, C3 is free, P3 to C3.

  4. 4

    Time 2

    P4 (pri 2) arrives, all cores busy. Lowest-priority running is P3 (pri 3). P4 preempts P3 on C3. P3 has 6 left.

  5. 5

    Time 3

    P5 (pri 1) arrives. Running: P2 (1), P1 (2, 6 left), P4 (2, 3 left). Victim: priority 2 with the largest remaining, P1. P5 takes C2; P1 back to ready with 6 left.

  6. 6

    Time 5

    P2 completes on C1 (CT 5). P6 arrives. Ready: P1 (pri 2, arrived 0), P6 (pri 2, arrived 5), P3 (pri 3). C1 takes P1 by earlier arrival.

  7. 7

    Time 6

    P4 completes on C3 (CT 6). P7 (pri 1) arrives and takes C3.

  8. 8

    Time 8

    P8 (pri 3) arrives. All cores busy with priority 1, 2, 1. No preemption. Ready: P6, P3, P8.

  9. 9

    Time 9

    P5 completes on C2 (CT 9). C2 takes P6 (pri 2).

  10. 10

    Time 11

    P1 completes on C1 and P7 completes on C3 (both CT 11). Ready: P3 and P8, both pri 3. P3 arrived first, so P3 to C1, P8 to C3.

  11. 11

    Time 12 to 17

    P6 completes at 12 on C2, which then idles. P8 completes at 15 on C3, which then idles. P3 completes at 17 on C1.

Three-core results. C1: P2 0 to 5, P1 5 to 11, P3 11 to 17. C2: P1 0 to 3, P5 3 to 9, P6 9 to 12, idle. C3: idle 0 to 1, P3 1 to 2, P4 2 to 6, P7 6 to 11, P8 11 to 15, idle.

ProcessArrivalBurstPriorityCTTATWT
P109211112
P2051550
P317317169
P4242640
P5361960
P65321274
P76511150
P88431573

CPU utilisation as printed on the slide

  • Utilisation of a core = busy time / total elapsed time, where total elapsed time is 17, the moment the last process finishes.
  • CPU1: 17 / 17 x 100 = 100%.
  • CPU2: 12 / 17 x 100 = 70.58%.
  • CPU3: 15 / 17 x 100 = 88.23%.

Multicore issues

  • Locking system: resources are shared across processors, so a locking scheme is needed to serialise access and keep it safe.
  • Shared data: if multiple processors access the same data at the same time, the data can become inconsistent. Protocols or locks protect it.
  • Cache coherence: shared data sits in several local caches. If one processor changes a memory block, another may be left with an invalid cached copy without being told. A coherence protocol keeps all caches showing a consistent view.
9 of 9

Before the exam

The lines worth memorising, and the mistakes that lose marks.

Remember this

  1. 1Dispatcher: switch context, switch to user mode, jump to the right instruction. Its delay is dispatch latency.
  2. 2Non-preemptive: runs until it completes or blocks. Preemptive: can be forced off by quantum expiry or a higher-priority arrival.
  3. 3Maximise CPU utilisation and throughput. Minimise turnaround, waiting, and response time.
  4. 4TAT = CT - AT, WT = TAT - BT, RT = first start - AT. Response equals waiting only when non-preemptive.
  5. 5FCFS: FIFO, non-preemptive, convoy effect. P1=24, P2=3, P3=3: avg WT 17 in order P1 P2 P3 but 3 in order P2 P3 P1.
  6. 6SJF non-preemptive is optimal when all arrive together. SRTF is optimal with staggered arrivals. Slide set: SJF avg WT 4, SRTF avg WT 3.
  7. 7Exponential averaging: tau(n+1) = alpha t(n) + (1 - alpha) tau(n). alpha = 0.5, tau1 = 5, bursts 4, 8, 5, 6 gives 4.5, 6.25, 5.625, 5.8125.
  8. 8Priority: smallest integer usually means highest priority, but read the slide. Starvation fixed by aging. SJF is priority with burst as priority.
  9. 9RR: quantum q, preempted process goes to the tail, max wait (n - 1) q. q large behaves like FCFS; q small behaves like processor sharing but with heavy overhead.
  10. 10RR q=20 with 53, 17, 68, 24: CT 134, 37, 162, 121, avg WT 73.
  11. 11MLQ: permanent queues, each with its own algorithm, lower queues can starve. MLFQ: processes move between queues, demote CPU hogs, promote long waiters.
  12. 12MLQ slide: TAT P4 = 12, TAT P6 = 16, 7 context switches. MLFQ slide: avg WT 61.
  13. 13Windows: MLFQ, 32 levels, 16 to 31 real-time, 0 reserved. Linux: CFS, O(log N). macOS: MLFQ with four bands, preemptive.
  14. 14Asymmetric: one master does all scheduling. Symmetric: every processor self-schedules from a common or private queue.
  15. 15Core utilisation = busy time / total elapsed. Multicore issues: locking, shared data consistency, cache coherence.

Exam traps

  • Computing waiting time by counting gaps on a Gantt chart. Always use WT = TAT - BT; preempted processes wait in several stretches.
  • Setting response time equal to waiting time for preemptive algorithms. Response uses the first start only; waiting counts every later delay too.
  • Letting non-preemptive SJF preempt a running process when a shorter job arrives. Only SRTF does that.
  • Forgetting idle gaps in FCFS with arrivals. If nobody has arrived, the CPU idles and the chart has a hole.
  • Assuming smaller priority number always means higher priority. The preemptive slide example reverses it. Read the convention every time.
  • Preempting on equal priority. Equal priority does not preempt; the running process continues and the newcomer waits.
  • Believing a large quantum makes RR better. Too large and RR becomes FCFS with all its convoy problems; too small and switching overhead dominates.
  • Confusing MLQ and MLFQ. MLQ assignment is permanent. MLFQ lets processes move, which is what prevents starvation.

Quiz yourself

One question at a time with instant feedback. Your best score is saved.

Timed version →
Q 1 / 32 · Criteriaeasyscore 0

Which pair of scheduling criteria should both be maximised?

Not quite

CPU utilisation and throughput are the two criteria to maximise. Turnaround, waiting, and response times are all minimised.

Finished reading?

Mark this lecture as done

Take the quiz above first so your score is saved here.