Real-time scheduling

On this page 8

Real-time scheduling is the part of an operating system that decides which task runs on the processor so that every task meets its timing deadline, not merely so that the system is fast on average. In operating systems, a real-time scheduler is judged by predictability: the worst-case delay between an event and the response must be known and bounded.

The approach matters wherever a late answer is a wrong answer, such as engine control, industrial robots, audio processing, medical devices and avionics. It builds on familiar ideas such as preemptive multitasking and priority scheduling, but adds timing analysis that proves in advance whether a set of tasks is schedulable.

How real-time scheduling differs from general-purpose scheduling

A general-purpose scheduler, such as a multilevel feedback queue or a fair-share scheduler, aims for high throughput and fairness among processes. A real-time scheduler aims for bounded latency: it accepts lower average performance in exchange for guarantees about the worst case.

Real-time work is usually modeled as tasks with timing parameters. A periodic task releases a job every period, each job needs at most its worst-case execution time (WCET), and each job must finish by its relative deadline. The scheduler uses these parameters, together with fixed or dynamic priorities, to choose which ready job runs next.

ParameterMeaningTypical range
PeriodTime between consecutive job releasesMicroseconds to seconds
Worst-case execution timeLongest time one job can needFraction of the period
Relative deadlineTime allowed from release to completionOften equal to the period
JitterVariation in release or completion timeIdeally microseconds or less
UtilizationExecution time divided by periodBetween 0 and 1 per task
Timing parameters of a real-time task

Hard, firm and soft real-time systems

Real-time systems are classified by the consequence of a missed deadline. The class determines how strict the analysis must be and which operating system is acceptable.

ClassEffect of a missed deadlineTypical examples
Hard real timeSystem failure, possibly dangerousAirbag control, flight control, pacemakers
Firm real timeLate result is useless but not harmfulVideo frame decoding, packet processing
Soft real timeQuality degrades graduallyAudio playback, user interfaces, games
Classes of real-time requirements

Hard real-time systems normally run on a dedicated real-time operating system (RTOS) such as FreeRTOS, Zephyr, QNX or VxWorks, where every kernel path has a known bound. Soft real-time work often runs acceptably on a general-purpose kernel with real-time scheduling classes.

Main real-time scheduling algorithms

Two algorithm families dominate theory and practice. Fixed-priority scheduling assigns each task a constant priority, while dynamic-priority scheduling recalculates priority for every job based on its deadline.

Rate-monotonic scheduling (RMS) gives higher priority to tasks with shorter periods and is optimal among fixed-priority policies when deadlines equal periods. The classic Liu and Layland result guarantees schedulability if total utilization stays below n(2^(1/n) − 1), which approaches about 69 percent for many tasks. Earliest deadline first (EDF) always runs the job with the nearest absolute deadline and can schedule any independent periodic task set on one processor up to 100 percent utilization.

AlgorithmPriority typeStrengthWeakness
Rate-monotonicFixed, by periodSimple and well analyzedLower guaranteed utilization
Deadline-monotonicFixed, by deadlineHandles deadlines shorter than periodsSame bound issues as RMS
Earliest deadline firstDynamic, by deadlineFull processor utilizationUnpredictable behavior under overload
Cyclic executiveStatic timetableFully deterministicRigid and hard to change
Comparison of common real-time algorithms

Exact verification uses response-time analysis, which computes the worst-case completion time of each task including interference from higher-priority tasks, blocking and interrupt overhead. The task set is accepted only if every response time is within its deadline.

Priority inversion and resource sharing

Shared resources break simple priority rules. Priority inversion occurs when a high-priority task waits for a lock held by a low-priority task, while a medium-priority task preempts the lock holder and delays both. The 1997 Mars Pathfinder resets are the textbook case of this failure.

  • Priority inheritance: the lock holder temporarily inherits the priority of the highest waiting task.
  • Priority ceiling protocol: each lock carries a ceiling priority, which prevents deadlock and chained blocking.
  • Lock-free design: short critical sections or message passing reduce shared state altogether.

Any analysis must include the maximum blocking time a task can suffer, otherwise the calculated response times are optimistic and unsafe.

Real-time scheduling in Linux and Windows

Mainstream desktop and server systems such as Linux and Windows provide real-time scheduling classes that sit above normal time-sharing. They give strong priority guarantees, but full determinism also depends on interrupt handling, memory management and drivers.

SystemFacilityBehavior
Linux SCHED_FIFOStatic priorities 1 to 99Runs until it blocks or is preempted
Linux SCHED_RRStatic priorities with a time sliceRound-robin among equal priorities
Linux SCHED_DEADLINERuntime, deadline and period per taskEDF with bandwidth reservation
WindowsReal-time priority class, levels 16 to 31Above all dynamic priorities
Real-time scheduling facilities in common operating systems

Linux protects the system with real-time throttling, which by default reserves about 5 percent of each second for non-real-time work. The PREEMPT_RT patch set, merged into the mainline kernel in version 6.12, makes most kernel code preemptible and turns interrupt handlers into schedulable threads, reducing worst-case latency to tens of microseconds on suitable hardware.

Common mistakes and limitations

The most frequent error is to measure average latency and treat it as a guarantee. Rare events such as cache misses, page faults, power-state transitions and system management interrupts set the worst case, so measurement tools such as cyclictest must run for hours under realistic load.

  • Unlocked memory: page faults add milliseconds; real-time tasks should lock their memory.
  • Runaway tasks: a SCHED_FIFO loop without blocking can starve the rest of the system.
  • Multicore assumptions: uniprocessor bounds do not apply directly to global multiprocessor scheduling.

In simple terms

Real-time scheduling is about being on time, every time. A normal computer tries to be quick on average. A real-time system must promise that each job finishes before a fixed moment.

Think of a train timetable. A train that is usually early but sometimes very late is a bad train. A train that always arrives at exactly 8:05 is a good one. The scheduler decides which job runs first so that no deadline is missed.

A practical example

An industrial robot controller runs Linux with the PREEMPT_RT kernel on a four-core processor. Its motion control loop must run every 1 ms and finish within 300 microseconds, while a camera task runs every 33 ms and a user interface runs as an ordinary process.

Engineers place the control loop in SCHED_FIFO at priority 90 on an isolated core, lock its memory and move device interrupts to other cores. A 24-hour cyclictest run under full network and disk load shows a maximum latency of about 40 microseconds. The result is a robot arm that moves smoothly and never misses a control cycle, even while operators use the touchscreen.