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

Speaker 1Speaker 2

Real-Time Systems and Scheduling

16:00
0:00-16:00
  1. Michael

    Before we get into today’s topic, two announcements: a quiz will be released after class and is due at 11:00 a.m. Friday. Lab 3 is due next Monday, and there won’t be extensions, so plan your work accordingly.

  2. Maria

    And today’s topic is real-time systems. We’ll define what makes a system real-time, look at how its operating system needs differ from a general-purpose one, and then study real-time scheduling on a uniprocessor. Multiprocessor scheduling is on the broader agenda, but the material we’re discussing today focuses on the uniprocessor schedulers.

  3. Michael

    The defining feature of a real-time system is that it has both functional requirements and temporal requirements. It’s not enough for the system to produce the right result; it also has to produce it within a specified time. That’s why deadlines and strict time constraints are central.

  4. Maria

    So the usual performance measures, like average response time, don’t tell the whole story. A real-time system cares about whether each individual job meets its deadline. One late response can matter even if the system’s average response time looks excellent.

  5. Michael

    Exactly. The key idea is predictability, not simply speed. A system could be fast on average but unpredictable, and that’s a problem if a task must finish on time. We need to be able to estimate how long jobs take and reason about whether deadlines can be met.

  6. Maria

    There are three useful categories of real-time deadlines: soft, firm, and hard. They differ in what happens to the value—or the consequences—of a result when it arrives late.

  7. Michael

    In a soft real-time system, finishing before the deadline gives the task its full value. Once the deadline is missed, the value declines as the result gets later, eventually reaching zero. A late result may still be useful for a while, just less and less useful.

  8. Maria

    A firm deadline is different: the result has full value if it arrives on time, but no value if it arrives late. Finishing late doesn’t necessarily cause a disaster, but there’s no benefit in completing that job after its deadline.

  9. Michael

    And with a hard real-time deadline, missing it can cause serious harm. The late result can have negative utility because there’s a penalty or dangerous consequence. That’s why examples like electronic engine control and flight control belong near the hard end of the spectrum.

  10. Maria

    The categories help us think of real-time behavior as a spectrum. Computer simulations usually don’t have a strict deadline, while a user interface benefits from responsiveness but can often tolerate an occasional slow response. Cruise control is an example of soft real time; engine control and flight control can involve hard deadlines.

  11. Michael

    That distinction explains why a general-purpose operating system isn’t automatically suitable for real-time work. General-purpose systems often optimize for throughput or average performance. A real-time operating system has to support predictable timing and deadline guarantees instead.

  12. Maria

    That difference shows up in several familiar operating-system areas: scheduling and multitasking, system calls, interrupt handling, synchronization, and memory management. Priority matters especially when tasks have different deadlines; a high-priority task shouldn’t be held up unnecessarily by a lower-priority one.

  13. Michael

    That’s where priority inversion becomes a concern. In ordinary synchronization, a task may lock a mutex and other tasks wait for it. In a real-time system, we also have to ask whether a task with an urgent deadline is being delayed behind a task with a much less urgent one.

  14. Maria

    A real-time operating system should offer predictability and timeliness, including ways to establish that deadlines will be met when the workload satisfies the right conditions. It should also be fault tolerant, so one fault doesn’t bring down an entire system, and should account for peak loads and maintainability.

  15. Michael

    Let’s start at the hardware level with the bus connecting the processor and devices to memory. Direct memory access, or DMA, lets a device transfer data without the processor handling every step, which can improve performance. But when the device and CPU share a bus, heavy device traffic can delay the processor—including a processor running a high-priority real-time task.

  16. Maria

    One way to make that contention more predictable is to divide bus access into time slices. If the CPU is guaranteed particular slices, it can estimate how much access to memory it will get. Without that kind of control, a burst of network or other device traffic could unexpectedly delay CPU work.

  17. Michael

    Caches create a related issue. They speed up memory access, but the time for a load depends on whether the data is in the cache. A cache hit is fast; a miss takes longer to fetch data from farther away, potentially from memory or storage. That variation makes execution time less predictable.

  18. Maria

    You might say, ‘Just analyze the worst case and assume every access misses.’ That can help establish a worst-case bound for an individual task. But if many tasks interact, share locks, and pass work along, allowing each task a wide range of possible execution times makes it much harder to analyze the workload as a whole.

  19. Michael

    So some real-time designs avoid caches altogether, even though that sacrifices performance. The point isn’t that caches are always unusable; it’s that their timing variability can make predictability harder, and a system may choose simpler timing behavior over faster average execution.

  20. Maria

    System calls are another issue. In the general-purpose approach discussed here, a system-call handler may disable interrupts while it runs. If a task enters a long system call, a newly ready task with a much closer deadline may not be able to take over the processor promptly.

  21. Michael

    That can cause a missed deadline and undermine predictability. Allowing system-call work to be preempted is one possible real-time approach: an urgent task can interrupt lower-priority work rather than waiting for the system call to finish.

  22. Maria

    Interrupts are trickier because they arrive asynchronously from external events. If interrupt handlers can interrupt one another freely, a stream of new interrupts might keep preempting earlier handlers. But if handlers are non-preemptive, an event that arrives at an unfortunate time can also cause unpredictable delays.

  23. Michael

    One option is to disable device interrupts and keep the timer interrupt so the scheduler can still switch tasks. Then tasks poll devices themselves. That makes device handling and data-transfer timing easier to estimate, and the kernel doesn’t need to contain each device’s logic.

  24. Maria

    The trade-off is that polling wastes processor time, particularly when device events are infrequent. It also means every task that needs a device may need its own driver logic. Changing or adding a device can require changes to those tasks.

  25. Michael

    A second option keeps interrupts disabled except for the timer, but puts polling routines in the kernel instead of in every task. That’s more modular because device details stay out of application tasks, and the routines can be timed. But polling still wastes CPU time, and device changes now require kernel changes; I/O may also take extra communication steps through the kernel.

  26. Maria

    A third option enables interrupts but makes interrupt handlers and device-driver handlers as small as possible. Rather than doing substantial work in the handler, it signals or wakes a task that handles the event. The operating system schedules that task like other work, with an appropriate priority and deadline.

  27. Michael

    That approach avoids the busy waiting of polling and keeps device work out of long interrupt handlers. It still involves communication between the handler or driver and the task, and unexpected device activity can create delays. But keeping the handlers lightweight reduces the cost and likelihood of those delays.

  28. Maria

    Memory management also affects timing. General-purpose systems commonly give each process a separate virtual address space for protection, then translate virtual addresses into physical addresses through page tables.

  29. Michael

    Because page-table translation takes time, processors often use a small cache called a translation lookaside buffer, or TLB. A TLB hit makes translation fast; a miss requires additional work to find the mapping. As with ordinary caches, that hit-or-miss variation complicates predictable timing.

  30. Maria

    Some real-time systems avoid virtual memory and use physical memory directly to reduce that source of timing uncertainty. That choice gives up flexibility and can introduce security risks, but it may be acceptable in systems designed for a single user or a specific embedded task.

  31. Michael

    Paging creates another source of delay. When physical memory is full, an operating system may move a page to disk and bring another page into memory. Disk transfers are time-consuming, so a real-time task could be delayed unexpectedly if one of its pages is not resident.

  32. Maria

    A technique called pinning can help: the system marks a task’s pages so they cannot be evicted from physical memory. That way, the task avoids paging delays for those pages while it runs.

  33. Michael

    Dynamic memory allocation is also difficult to predict. An allocator may use strategies such as first fit or best fit, and the time it takes to find a suitable block depends on the state of the free-memory list. The search may finish quickly—or require examining much more of the list.

  34. Maria

    Allocation can also cause fragmentation. For example, you might free a three-block region while other allocations remain, leaving enough free memory in total for a four-block request but not enough contiguous space. Moving existing allocations to combine the free space may not be safe, because the program could have multiple pointers to the old location.

  35. Michael

    One option is to allocate fixed-size blocks. That can prevent some external-fragmentation problems, though it may waste space inside a block—internal fragmentation. Another common real-time choice is to prohibit dynamic allocation and allocate everything statically. That reduces flexibility but improves predictability.

  36. Maria

    Recursion can be hard to bound too. If the number of recursive calls depends on runtime input, the amount of work—and potentially the time it takes—may be unbounded. Real-time programming languages and systems may restrict features like dynamic allocation or recursion to make timing easier to establish.

  37. Michael

    Now let’s turn to scheduling. A general-purpose scheduler may aim to improve average throughput, but real-time scheduling focuses on individual tasks and their worst-case response times. Again, the objective is predictable deadline satisfaction, not simply fast average performance.

  38. Maria

    The lecture focuses especially on periodic tasks. A periodic task releases jobs at a fixed period, P. Each job has a worst-case execution time, and a hard relative deadline—usually no later than the next period. If a deadline isn’t specified, assume it equals the period.

  39. Michael

    A task is the recurring activity; each individual occurrence is a job. You can think of the task as a class and each released job as an instance. For a periodic task, those instances arrive repeatedly, so distinguishing jobs lets us talk about their separate release times and deadlines.

  40. Maria

    Task utilization is its job’s worst-case execution time divided by the task’s period. For instance, if a task needs four time units every seven time units, its utilization is four-sevenths. The lecture also distinguishes irregular tasks without hard deadlines from sporadic tasks that arrive irregularly but do have hard deadlines.

  41. Michael

    Tasks can also be independent or dependent, and they can be preemptible or non-preemptible. Those characteristics affect how a scheduler can arrange their work and what kinds of timing guarantees are possible.

  42. Maria

    There are three priority styles to know. A static scheduler gives each task a priority that never changes. A dynamic scheduler assigns priorities to jobs, and each job keeps its assigned priority, though different jobs from the same task may get different priorities. A fully dynamic scheduler can change a job’s priority over time.

  43. Michael

    Rate monotonic scheduling is an example of a static scheduler. Earliest deadline first, or EDF, is a dynamic scheduler. Least laxity first is an example of a fully dynamic scheduler.

  44. Maria

    A schedule is feasible if every job meets its deadline. A task set is schedulable under a scheduling class if some algorithm in that class can produce a feasible schedule for it. An algorithm is optimal with respect to a class if it succeeds for every task set that is schedulable by any algorithm in that class.

  45. Michael

    Why not simply use round robin? Consider three periodic tasks with periods and deadlines of two, five, and ten time units, and execution times of one, one, and three. If all are ready at the beginning, round robin gives each a turn, but it can delay the first task’s next job until that job misses its deadline.

  46. Maria

    That example shows why taking turns without regard to deadlines isn’t enough. Real-time scheduling needs to consider the urgency of each job, rather than treating all ready work as equally important.

  47. Michael

    Rate monotonic scheduling assigns fixed priorities to tasks: the shorter the task’s period, the higher its priority. So a task that releases jobs more frequently outranks one with a longer period, and those task priorities remain fixed.

  48. Maria

    In the three-task example, the task with period two has the highest priority, the task with period five comes next, and the task with period ten has the lowest priority. The scheduler always runs the highest-priority ready job, preempting lower-priority work when necessary. In the example, this ordering lets all the jobs meet their deadlines.

  49. Michael

    But rate monotonic doesn’t succeed on every workload. In the lecture’s other example, fixed priorities leave a lower-priority job waiting while a higher-priority job runs, and the third task’s deadline is missed. So the fact that priorities follow a simple rule doesn’t guarantee feasibility for every possible task set.

  50. Maria

    There is a useful sufficient guarantee. For N periodic tasks, if the sum of their utilizations is at most N times two to the power of one over N, minus one, rate monotonic is guaranteed to produce a feasible schedule under the assumptions being used.

  51. Michael

    As the number of tasks grows, that utilization bound approaches about 0.67. It’s important to read the condition carefully: if utilization is below the bound, the guarantee applies. If it’s above the bound, that does not prove rate monotonic will fail; it only means this test no longer guarantees success.

  52. Maria

    For the example where rate monotonic failed, the task utilizations are one-third, two-fifths, and two-eighths. Together they’re about 0.98. With three tasks, the bound is about 0.78, so the workload is above the guaranteed range—and, in that particular example, rate monotonic does fail.

  53. Michael

    EDF takes a different approach: assign priorities to jobs according to their deadlines. The job with the earliest deadline gets the highest priority, and that priority ordering can differ as new jobs arrive.

  54. Maria

    EDF is optimal among online scheduling algorithms in the sense we defined. If a task set can be scheduled feasibly by an online scheduler, EDF can also schedule it feasibly. That claim is about task sets that are schedulable in the first place; it doesn’t mean every possible workload is feasible.

  55. Michael

    In the earlier workload where rate monotonic missed a deadline, EDF compares actual job deadlines instead of fixed task priorities. When a new job arrives, it can move ahead of a job with a later deadline; the lecture’s schedule shows EDF meeting the deadlines in that workload.

  56. Maria

    So the central contrast is clear: rate monotonic uses a task’s period to set a permanent priority, while EDF uses each job’s deadline to set priority. Rate monotonic is optimal within the static-priority class, and EDF is optimal among online schedulers under the definitions we covered.

  57. Michael

    And the broader lesson is that real-time design is about being able to reason about timing from the hardware up through the operating system and application. Bus access, caches, interrupts, memory management, and scheduling can all affect whether a job meets its deadline.

  58. Maria

    That’s the material we covered today: what real-time deadlines mean, why predictability matters, how system design choices affect timing, and how rate monotonic and EDF schedule periodic work. Remember that the quiz is due at 11:00 a.m. Friday, and Lab 3 is due next Monday with no extensions.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent