1. Home
  2. Explore
  3. Computer Science
  4. Real-Time Systems and Scheduling

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Real-Time Systems and Scheduling

Real-Time Systems and Scheduling

What Defines a Real-Time System?

A real-time system is defined by both what it computes and when it must compute it. Its operating system must handle tasks with deadlines and other time constraints. The central concern is therefore not simply how much work the system completes, but whether each time-critical task completes in time.

In general-purpose computing, performance is often described using averages, such as average response time or overall throughput. In a real-time system, averages can hide a failure: one late response may be critical even if all other responses are fast. The relevant question is whether each individual job meets its deadline.

A central real-time requirement is predictability: the ability to determine or guarantee how long tasks and system operations may take. Predictability is not the same as speed. A system can perform quickly on average yet behave unpredictably; a real-time system prioritizes bounded, analyzable behavior.

Predictability matters more than average speed: the system must be able to establish whether time constraints will be met, including under demanding conditions.


Types of Real-Time Systems

The consequences of missing a deadline determine how a real-time system is classified. The value of a completed task can be understood in relation to its deadline.

Soft real-time systems

In a soft real-time system, a task has a deadline, but missing it does not cause a catastrophic failure. A late result may still be useful, although its value decreases as it becomes later. After some point, completing the task has no value.

Examples include user interfaces, where responsiveness matters but an occasional delay is usually tolerable, and some forms of vehicle cruise control.

Firm real-time systems

In a firm real-time system, a result is useful only if it is produced by its deadline. If the deadline is missed, the result has no value, but lateness does not necessarily cause a harmful failure.

Hard real-time systems

In a hard real-time system, missing a deadline can cause serious harm. A late result may have negative consequences rather than merely losing value. Examples include electronic engine control and flight-control systems, where people or equipment may be at risk.

Real-world systems do not always fit perfectly into a single category. They can be viewed along a spectrum from systems with no meaningful deadlines to hard real-time systems.


General-Purpose and Real-Time Operating Systems

General-purpose operating systems are commonly designed to maximize overall performance and throughput. Real-time operating systems must instead support timely and predictable completion of individual tasks.

This difference affects many operating-system mechanisms:

  • Multitasking and scheduling: general-purpose systems often optimize throughput or average response time. Real-time systems must reason about task priorities, worst-case execution times, and deadline satisfaction.

  • System calls: system-call handling that temporarily prevents other work from running can delay a higher-priority task.

  • Interrupt handling: long or non-preemptible interrupt handlers can prevent time-critical tasks from running.

  • Interprocess communication and synchronization: ordinary locking can cause high-priority tasks to wait for lower-priority tasks, creating priority inversion.

  • Memory management and hardware behavior: caching, paging, and dynamic allocation can make operation times variable and difficult to predict.

A real-time operating system should provide:

  • Predictability: deadlines can be analyzed and, under stated assumptions, guaranteed.

  • Timeliness: tasks with hard, firm, or soft deadlines can be handled according to their time constraints.

  • Fault tolerance: a fault in one part of the system should be contained where possible rather than bringing down the entire system.

  • Peak-load handling: the system should be designed to behave acceptably during heavy workloads, not only during average operation.

  • Maintainability: the system should be organized so that it can be understood and changed without undermining its timing guarantees.


Hardware and Microarchitecture

DMA and shared memory buses

Direct memory access (DMA) allows an input/output device to transfer data without requiring the CPU to perform every step of the transfer. This can improve general-purpose performance, but it can also create timing uncertainty if the CPU and devices share a bus to memory.

If devices use the bus heavily, they can delay CPU memory accesses. A high-priority task may therefore be delayed by activity from an input/output device.

One way to make bus access more predictable is to divide bus access into time slices. If the CPU is guaranteed a known share of bus time, its memory operations can be analyzed against that allocation. Without such sharing rules, bus demand from devices can vary unpredictably and delay CPU work.

Caches

A cache keeps recently used data close to the processor to make future accesses faster. This usually improves performance, but it can make execution time harder to predict:

  • A cache hit can complete quickly.

  • A cache miss requires accessing a slower level of memory.

  • The system may not know in advance which accesses will hit or miss.

A common real-time strategy is to avoid caches, or to use hardware and software arrangements that make their effects predictable. Avoiding caches simplifies timing analysis but sacrifices performance.

It is possible to analyze tasks using conservative worst-case cache-miss assumptions. However, variable execution times become especially difficult to reason about when many tasks depend on each other, share locks, or execute in chains. Establishing a guarantee for each task in isolation may not be enough to guarantee the behavior of the whole workload.


System Calls, Interrupts, and Input/Output

Why ordinary system-call handling can cause problems

A system call is a synchronous request made by the currently running task. In many general-purpose systems, a system-call handler runs with interrupts disabled or otherwise cannot be interrupted for some period.

If a task enters a long-running system call, a higher-priority task may become ready while the handler is executing. If the system cannot preempt the handler, the higher-priority task may miss its deadline.

Allowing system-call handling to be preempted can reduce this problem, provided the operating system is designed to preserve correct behavior when preemption occurs.

Why interrupts require special care

An interrupt is triggered asynchronously by an external event rather than being requested directly by the currently running task. Long or non-preemptible interrupt handling can make execution time unpredictable: the number and timing of external events may vary, changing how long a task waits to run.

Allowing interrupts to preempt one another without control can also cause problems. A stream of new interrupts might repeatedly interrupt ongoing handling, delaying the original event. Real-time systems therefore aim to keep interrupt work short and carefully structured.

Three approaches to handling input/output

1. Let each task handle its own input/output

One approach is to disable most interrupts, retaining the timer interrupt needed for scheduling, and require each task that uses a device to handle that device directly. Because interrupts are not managing the device activity, a task may poll the device to determine whether input or output is ready.

Benefits:

  • Tasks can have more predictable execution because they are not continually interrupted by device events.

  • Polling can make the duration of device checks and transfers easier to estimate.

  • The kernel does not need to be changed whenever device-handling logic is added.

Costs:

  • Polling can waste CPU time, especially when device events are infrequent.

  • Each task may need substantial device-specific logic.

  • Changing or adding a device can require changes to multiple tasks.

2. Put periodic device polling in kernel routines

A second approach also disables most interrupts but places device-handling logic in kernel routines. A timer periodically wakes these routines, which poll devices and handle any available data.

Benefits:

  • Device details are kept out of individual tasks, making the design more modular.

  • The execution time of the polling routines can be estimated.

  • Avoiding unpredictable interrupt activity helps prevent unbounded interruption delays.

Costs:

  • Polling still consumes CPU time.

  • The kernel must be modified when devices are added, removed, or changed.

  • Input/output may require extra communication between tasks and kernel routines, adding delay.

3. Use minimal interrupt handlers to activate tasks

A third approach allows interrupts but keeps interrupt handlers as small as possible. Rather than performing substantial device work inside the handler, the handler records or communicates the event and creates or wakes a task to handle it. The operating system then schedules that task like other tasks, with its own priority and deadline as appropriate.

Benefits:

  • Interrupt handling is lightweight, reducing the time spent in interrupt context.

  • Busy waiting is avoided, so CPU time is not wasted continually polling devices.

  • Device-specific work can be separated from the kernel and handled in tasks.

  • The approach can reduce the likelihood and impact of long interrupt delays.

Costs:

  • Communication is needed between the interrupt-handling path and the device-handling task.

  • Interrupt-related delays are not eliminated entirely; unexpected device activity can still affect timing.

This approach resembles a division between a very short initial interrupt action and later processing, but the key real-time idea is to move substantial work into schedulable tasks rather than doing extensive logic inside the interrupt handler.


Memory Management in Real-Time Systems

Virtual memory and address translation

General-purpose operating systems often give each process its own virtual address space to support protection and isolation. Virtual addresses are translated into physical addresses using mappings stored in a page table. Virtual and physical memory are commonly divided into fixed-size pages.

Because looking up a page-table mapping can be slow, processors often use a small cache of recent translations called a translation lookaside buffer (TLB). A TLB hit makes translation fast; a miss requires additional work. This variation introduces another source of timing uncertainty.

One way to avoid this uncertainty is to use physical memory directly rather than relying on virtual memory and translation. This can make timing more predictable, but it reduces flexibility and can weaken protection between tasks or users. It may be acceptable in some embedded systems, which are often built for a specific purpose and controlled by a single owner, but the trade-off depends on the system’s security and isolation needs.

Paging and pinning memory

In systems where physical memory is smaller than the virtual address space, the operating system may keep some pages on persistent storage and move them into memory when needed. This process is called paging.

If physical memory is full and a needed page is absent, the operating system may have to:

  1. Evict a page currently in physical memory.

  2. Write it back to storage if necessary.

  3. Load the needed page from storage.

Storage access is much slower than ordinary memory access, so paging can cause large and unpredictable delays.

For a real-time task, an operating system may pin its pages in physical memory so that they cannot be evicted. This prevents paging delays from disrupting that task, although it uses physical memory that could otherwise be available to other work.

Dynamic memory allocation and fragmentation

Dynamic memory allocation, such as heap allocation, allows a program to request memory while it runs. Allocation algorithms may use strategies such as first fit, best fit, or worst fit. Their execution time can vary: a free block might be found quickly or only after searching a long list.

Dynamic allocation can also create fragmentation:

  • External fragmentation: enough free memory may exist in total, but it is split into separated blocks. A request for one large contiguous block can fail because no individual free block is large enough.

  • Internal fragmentation: an allocated block may be larger than the requested amount, leaving some of that block unused.

External fragmentation cannot always be fixed by moving allocated blocks. Programs may hold multiple pointers to the same location, and a memory-management library generally cannot safely find and update every copy.

Real-time systems can reduce allocation uncertainty by:

  • Using fixed-size memory blocks, which may increase internal fragmentation but simplify allocation.

  • Avoiding dynamic allocation and reserving the required memory statically before execution.

Static allocation reduces flexibility but makes memory use and timing easier to analyze.

Recursion

Recursion can make execution time difficult to bound when the depth of recursion depends on input data or other runtime conditions. If the number of recursive calls is not known in advance, the amount of work may be unbounded or difficult to prove.

For this reason, some real-time programming environments restrict recursion or use language and runtime features designed to support stronger timing guarantees.


Real-Time Tasks and Jobs

A task describes a unit of work or an ongoing activity. A periodic task produces repeated instances of that work. Each individual instance is called a job.

For example, a periodic task with period PPP releases one job every PPP time units. Each job is characterized by its worst-case execution time, denoted by CCC, and by a deadline.

For an implicit-deadline periodic task, the relative deadline equals the period. If no different deadline is specified, the relative deadline is typically assumed to be PPP. In that case, each job must finish before the next job’s deadline.

A task’s utilization is the fraction of processor time it requires in the long run:

U=CPU = \frac{C}{P}U=PC​

where CCC is the job’s worst-case execution time and PPP is the task’s period.

Real-time workloads may also include:

  • Periodic tasks: jobs arrive at regular intervals.

  • Aperiodic tasks: jobs arrive irregularly and do not necessarily have hard deadlines.

  • Sporadic tasks: jobs arrive irregularly but have hard timing constraints.

  • Independent tasks: tasks do not depend on or synchronize with one another.

  • Dependent tasks: tasks interact, share resources, or otherwise depend on one another.

  • Preemptible tasks: a running job can be interrupted so another job can execute.

  • Non-preemptible tasks: once started, a job cannot be interrupted.


Scheduling Terminology

Static, dynamic, and fully dynamic priorities

Scheduling policies can be grouped by what receives a priority and whether that priority changes.

  • Static scheduling: each task receives a priority, and that priority never changes. Rate-monotonic scheduling is an example.

  • Dynamic scheduling: each job receives a priority when it is considered for execution. A task’s different jobs may have different priorities, but an individual job’s priority remains fixed. Earliest-deadline-first scheduling is an example.

  • Fully dynamic scheduling: priorities are assigned to jobs and may change as time passes. Least-laxity-first scheduling is an example.

Feasible schedules and schedulability

A feasible schedule is one in which every job meets its deadline.

A task set is schedulable under a scheduling class if at least one algorithm in that class can produce a feasible schedule for it.

A scheduling algorithm is optimal with respect to a class if it can produce a feasible schedule for every task set that is schedulable by some algorithm in that class. Optimality is always relative to a specified class and its assumptions. It does not mean that the algorithm can schedule every possible workload.


Why General-Purpose Scheduling May Be Inadequate

General-purpose schedulers often aim to improve average performance or throughput. These goals do not guarantee that each real-time job will finish before its deadline.

For example, round-robin scheduling gives tasks turns of processor time. It can provide a fair allocation of CPU time without considering whether a job has an urgent deadline. In the lecture example, round robin failed to complete a job from the shortest-period task in time, even though real-time policies could prioritize jobs according to their timing needs.

A real-time scheduler must account for the urgency of individual jobs, their execution requirements, and the deadlines they must meet.


Rate-Monotonic Scheduling

Rate-monotonic (RM) scheduling is a static-priority policy for periodic tasks. It assigns higher priority to tasks with shorter periods:

  • A task with a short period releases jobs frequently and receives a high fixed priority.

  • A task with a long period receives a lower fixed priority.

  • Each task keeps the same priority over time.

Under the standard assumptions of the classic result—such as independent, periodic, preemptible tasks on a uniprocessor, known worst-case execution times, and deadlines equal to periods—RM is optimal among fixed-priority scheduling policies. If another static-priority scheduler can feasibly schedule a task set under those assumptions, RM can do so as well.

RM utilization bound

For nnn periodic tasks, let task iii have worst-case execution time CiC_iCi​ and period PiP_iPi​. Its utilization is Ui=CiPiU_i = \frac{C_i}{P_i}Ui​=Pi​Ci​​. The classic sufficient bound is:

∑i=1nCiPi≤n(21/n−1)\sum_{i=1}^{n} \frac{C_i}{P_i} \leq n\left(2^{1/n}-1\right)∑i=1n​Pi​Ci​​≤n(21/n−1)

If the total utilization is at or below this bound, RM is guaranteed to produce a feasible schedule under the theorem’s assumptions.

For n=3n=3n=3, the bound is approximately 0.780.780.78. As the number of tasks increases, the bound approaches ln⁡2\ln 2ln2, or approximately 0.6930.6930.693.

This is a sufficient bound, not a necessary one. If utilization exceeds the bound, RM may still schedule the workload successfully, but the bound no longer provides a guarantee.

A lecture example used three tasks with utilizations 13\frac{1}{3}31​, 25\frac{2}{5}52​, and 28\frac{2}{8}82​. Their total utilization is approximately 0.980.980.98, which exceeds the three-task RM bound. RM failed to produce a feasible schedule in that example. The failure does not imply that all task sets above the bound are unschedulable; it means only that the utilization test gives no guarantee there.


Earliest-Deadline-First Scheduling

Earliest-deadline-first (EDF) is a dynamic-priority policy. At each scheduling decision, the job with the earliest absolute deadline receives the highest priority.

Unlike RM, EDF assigns priorities to jobs rather than assigning one permanent priority to each task. A task’s jobs can therefore receive different priorities depending on their deadlines.

On a preemptive uniprocessor, under the standard assumptions for EDF feasibility, EDF is optimal among online scheduling algorithms: if an online algorithm can feasibly schedule a task set, EDF can also do so. “Online” means that the scheduler makes decisions as jobs arrive and execute, rather than relying on a fully predetermined schedule.

In an example where RM failed, EDF selected whichever currently available job had the nearest deadline. As new jobs arrived, the scheduler compared their deadlines with those of jobs already waiting and ran the most urgent one. This deadline-based priority assignment allowed EDF to meet the deadlines in that example.


Least-Laxity-First Scheduling

Least-laxity-first (LLF) is a fully dynamic scheduling policy. It assigns priority according to a job’s laxity, or slack: the amount of time remaining before the deadline after accounting for the job’s remaining execution time.

A job with less laxity is more urgent. Because laxity changes as time passes and execution progresses, LLF priorities can change during a job’s lifetime. This makes LLF more dynamically responsive, but it also requires the scheduler to update priorities as conditions change.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent