Sub topic 17
Multiprocessor and Real-Time Scheduling: A Short Overview
This chapter assumes that you understand process states, context switches, priorities, preemption, and basic scheduling formulas. It also assumes that you can read a simple Gantt chart.
Multiprocessor Scheduling
A multiprocessor system has two or more CPUs, often called cores. The scheduler must choose both which process runs and which CPU runs it.
Two common designs are:
- Asymmetric multiprocessing: One CPU performs scheduling and system tasks. Other CPUs mainly run user processes.
- Symmetric multiprocessing (SMP): Every CPU can schedule processes. Modern general-purpose systems commonly use SMP.
An SMP scheduler may use one shared ready queue or one queue per CPU.
| Design | Main advantage | Main cost |
|---|---|---|
| Shared ready queue | Simple load balancing | More lock contention |
| Per-CPU queues | Better scalability | Work may become unevenly distributed |
Load balancing moves work from a busy CPU to an idle CPU. Processor affinity tries to keep a process on the same CPU. Affinity can improve cache performance because the process's recently used data may still be in that CPU's cache. However, strict affinity can leave another CPU idle.
A process can also have multiple threads running at the same time on different CPUs. This is true parallelism. On a single CPU, threads only take turns through context switches.
Real-Time Scheduling
A real-time system must respond within timing limits. Each task has a deadline, which is the latest acceptable finishing time. A task also has a worst-case execution time (WCET), meaning the maximum processor time it may need.
- Hard real-time: Missing a deadline is considered a system failure.
- Soft real-time: Missing an occasional deadline reduces quality but may not cause failure.
Real-time scheduling focuses on predictability, not just average CPU utilization.
Rate Monotonic Scheduling (RMS) assigns higher priority to tasks with shorter periods. A period is the time between repeated releases of a task. RMS uses fixed priorities.
Earliest Deadline First (EDF) gives the highest priority to the ready task whose deadline is soonest. EDF uses dynamic priorities.
For periodic tasks on one CPU, a basic utilization measure is:
U = Σ (execution time / period)
For example, tasks with execution-period pairs (1, 4) and (2, 8) have utilization 1/4 + 2/8 = 0.5. They use half of the CPU in the ideal repeated case. Utilization alone does not prove that every deadline will be met, because release times and priority rules also matter.
Exam Method
For a scheduling question:
- Identify the number of CPUs.
- List each task's release time, execution time, priority, and deadline.
- State whether scheduling is preemptive.
- Track each CPU separately.
- Check completion against every deadline.
Exercise
Two independent tasks each require 3 ms and are released at time 0. How long does their processor execution take on two idle CPUs, ignoring scheduling overhead?
Show answer
Both tasks can run simultaneously, so both finish after 3 ms.