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.
| Parameter | Meaning | Typical range |
|---|---|---|
| Period | Time between consecutive job releases | Microseconds to seconds |
| Worst-case execution time | Longest time one job can need | Fraction of the period |
| Relative deadline | Time allowed from release to completion | Often equal to the period |
| Jitter | Variation in release or completion time | Ideally microseconds or less |
| Utilization | Execution time divided by period | Between 0 and 1 per 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.
| Class | Effect of a missed deadline | Typical examples |
|---|---|---|
| Hard real time | System failure, possibly dangerous | Airbag control, flight control, pacemakers |
| Firm real time | Late result is useless but not harmful | Video frame decoding, packet processing |
| Soft real time | Quality degrades gradually | Audio playback, user interfaces, games |
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.
| Algorithm | Priority type | Strength | Weakness |
|---|---|---|---|
| Rate-monotonic | Fixed, by period | Simple and well analyzed | Lower guaranteed utilization |
| Deadline-monotonic | Fixed, by deadline | Handles deadlines shorter than periods | Same bound issues as RMS |
| Earliest deadline first | Dynamic, by deadline | Full processor utilization | Unpredictable behavior under overload |
| Cyclic executive | Static timetable | Fully deterministic | Rigid and hard to change |
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.
| System | Facility | Behavior |
|---|---|---|
| Linux SCHED_FIFO | Static priorities 1 to 99 | Runs until it blocks or is preempted |
| Linux SCHED_RR | Static priorities with a time slice | Round-robin among equal priorities |
| Linux SCHED_DEADLINE | Runtime, deadline and period per task | EDF with bandwidth reservation |
| Windows | Real-time priority class, levels 16 to 31 | Above all dynamic priorities |
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.