1.4 Outline and Contributions
2.1.2 Real-Time Computing
Task Scheduling
Most complex computing systems use an Operating System (OS), a software layer between hardware and the functionality-implementing application tasks (see Figure 2.1). The OS manages the computer resources (processors, main memory, disks, I/O devices) and provides services as well as a hardware abstraction that is easier to program [Tanenbaum and Woodhull, 2006].
Modern operating systems are so-called multitasking systems, designed to handle multiple application tasks (also known as processes) concurrently. The tasks share the hardware and operating system resources in order to increase the resource uti-lization. Moreover, the division of the functionality into multiple tasks eases software development. Tasks may depend on each other and cooperatively implement func-tionality, or they may be unrelated except of being executed on the same hardware.
Definition 2. Operating System. An operating system is a software layer that manages the hardware resources, controls the execution of tasks, and provides services and hardware abstraction to tasks and programmers.
The Central Processing Unit (CPU) has to be managed by time-multiplexing:
only a single task can use it at any time. The CPU resource management is known as scheduling. According to a specific scheduling policy, the OS assigns the processor at each point in time to exactly one of the tasks. The idle task is executed when no task is executable, a special task without functionality. The scheduler is the operating system’s component that implements the scheduling policy.
Definition 3. Task. A task is a schedulable unit of computation that is executed by the CPU in a sequential manner.
The suspension of the running task in order to execute another task is called context switch. The OS saves the necessary information (basically the content of the registers) to allow a future continuation of the task’s execution at the exact
same point [Horner, 1989]. A context switch might for example be performed when the running task has to wait for the end of an I/O operation or after a maximum allowable time of uninterrupted execution. A timer is used to determine when the time slot of the currently running task expires [Tanenbaum and Woodhull, 2006].
Schedulers that are able to suspend tasks during their execution in order to make a scheduling decision are called preemptive. A non-preemptive scheduler always lets a task run to completion. Preemptive schedulers prevent a task from blocking all other tasks and therefore avert the failure of the whole system if a task is executing an infinite loop [Nutt, 2000]. The interruption of the running task is called preemption.
Different scheduling algorithms pursue different goals. Possible criteria are fair-ness (even shares of the computation time for the tasks), processor utilization (avoid idle time), or response time (respond to requests quickly). An interactive system should for example minimize the response time to prevent user frustration [Tanen-baum and Woodhull, 2006].
Definition 4. Task Schedule. Given a set of tasks {τ1, ..., τn}, a schedule is an integer step function s which at any time t assigns a task τk (1 ≤ k ≤ n) to the processor: s(t) = k (if the processor is idle at time t: s(t) = 0) [Buttazzo, 2000]. A schedule is generated by the scheduler of an operating system.
Introduction to Real-Time Computing
Real-time systems are characterized by precise and strict timing constraints for their execution: they are required to guarantee response times. Real indicates that these timing constraints are derived from the embedded system’s environment, as a system interacts in a well-defined relation to the physical time [Olderog and Dierks, 2008].
A real-time system fails not only if its results are wrong, but also if it cannot provide these results prior to the given deadlines [Kopetz, 1997].
It is important to understand that real-time behavior does not demand that the results have to be produced very fast. Real-time computing should not be mistaken for high performance computing. Real-time expresses the quality of predictability, achieved through deterministic behavior of the embedded system, i.e., the time re-quired to complete any function must be limited and predictable. As long as the results are provided prior to the deadline, the performance is sufficient. Real-time systems guarantee the adherence to the system’s time limits, not extra fast compu-tation [Stankovic, 1988].
Definition 5. Real-Time System. A real-time system is a computer system with timing constraints, which ”relate the execution of a task to real time, which is physical
2.1 Embedded Real-Time Systems 17
time in the environment of the computer executing the task” [Lee and Seshia, 2011].
These constraints are typically specified in terms of response time deadlines, by which the execution of a task must be completed. The correctness of the system depends not only on the logical results of the computation, but also on the time at which these results are available.
An OS that is designed to guarantee response times of the executed tasks is termed Real-Time Operating System (RTOS). Required are a deterministic behavior of all OS components, keeping of time in well-defined relation to the physical time, and a task scheduler that controls the task execution according to a policy that guarantees compliance of all tasks with their timing constraints.
Definition 6. Real-Time Operating System. A real-time operating system is an operating system that is able to control the execution of tasks with timing constraints and to guarantee that these constraints are met.
Real-time systems can be categorized into hard and soft real-time systems. For a hard real-time system, a miss of a deadline (i.e., result not available prior to it) is unacceptable and leads to the failure of the entire system, with catastrophic consequences in a safety-critical system. An example is the control of a car’s airbag:
if the airbag control unit does not trigger the ignition not later than 30 milliseconds after the first moment of vehicle contact, the airbag is not fully inflated when the passenger’s head hits the steering-wheel.
In contrast, the value of a result of a soft real-time system decreases after the deadline, but the system does not automatically fail. It could be demanded that the proportion of tardy operations does not exceed a specific limit. The quality of the system’s result would decrease, but without rendering it useless [Freedman et al., 1996]. An example is a video messenger system. If it fails to handle the transfer and processing of some frames on time, the display freezes temporary, lowering the service quality.
Real-Time Task Model
The scheduling decisions of an RTOS have to be based on information about the timing constraints of the real-time tasks. These constraints are specified with the following parameters (Figure 2.2) [Buttazzo, 2000]:
• Arrival time a: time at which a task becomes ready for execution (synonym:
release time).
t d f a
C
R D
Figure 2.2: Parameters of a real-time task (upward arrow indicates task arrival, downward arrow indicates deadline)
• Computation time C: duration needed by the processor to execute the task.
The task can run for a single time span of length C or for multiple time spans which add up to a total of C. If the computation time of a task varies, the maximum possible computation time has to be considered, the so-called Worst-Case Execution Time (WCET).
• Finishing time f: time at which the task finishes its execution.
• Absolute deadline d: time by which the execution of the task must be finished.
The difference between absolute deadline d and arrival time a is called relative deadline D.
• Response time R: time span between finishing time f and arrival time a. A task completes in time if its response time is less than or equal to its relative deadline.
• Lateness L: difference between finishing time f and absolute deadline d. It represents the delay of a task’s completion, with a negative lateness in case of a completion before the deadline.
One distinguishes between periodic and aperiodic real-time tasks. Both kinds are characterized by an infinite sequence of instances, but consecutive instances of a periodic task are activated regularly with a time lag of exactly one period T . The relative deadline D of a periodic task is often equal to its period [Buttazzo, 2000].
Periodic tasks are used to read or produce data at a given rate, for example the periodic readout and processing of sensor data. Aperiodic tasks are not activated regularly at a constant time. External events cause the activation of an aperiodic task instance to handle it. An Interrupt Service Routine (ISR) is an example for an aperiodic task [Briand and Roy, 1999, Buttazzo, 2000].
Definition 7. Periodic Real-Time Task. A periodic real-time task τ is a task with an infinite sequence of identical computation activities (instances), which are activated at a constant rate based on the periodT . The first instance is released at the
2.1 Embedded Real-Time Systems 19
phaseφ. The activation time of the kth instance is given byφ + (k− 1) · T [Buttazzo, 2000]. In the context of this thesis, the real-time constraints are specified by the relative deadline D, which is equal to the tasks period T (implicit deadlines): the execution of the kth instance must be finished at φ + k· T .
Real-time systems typically execute a set of periodic real-time tasks.
Definition 8. Task Set. A task set is a set of periodic real-time tasks that is executed by a real-time operating system. The utilization factor U is the fraction of processor time spent in the execution of it. It is a measure of the computational load on the processor and for a task set of n tasks given by [Buttazzo, 2000]:
U =
The scheduler of a real-time operating system has to guarantee that all real-time tasks are executed in compliance with their timing constraints. A schedule is feasible if all tasks are executed according to their constraints. A task set is schedulable if there is an algorithm that can produce a feasible schedule [Buttazzo, 2000]. The most important scheduling algorithms for real-time systems are presented in this section.
Real-time scheduling algorithms can be classified as follows [Buttazzo, 2000]:
Offline and online scheduling differ in regard to the time at which the scheduling decisions are taken. Offline algorithms create the entire schedule before runtime.
The result is stored and enforced at runtime [Xu and Parnas, 1993]. This is of course only applicable to static systems with complete information at design time about the points in time at which requests for task computation occur. Storing the entire schedule is possible since the schedule of a periodic task set repeats itself every hyperperiod, equal to the least common multiple of all task periods. Online algorithms take the scheduling decisions at runtime and can consider dynamic task set changes such as the entering of a new task [Stankovic et al., 1998].
Fixed and dynamic priority scheduling differ in regard to whether the scheduling decisions are based on static or dynamic task parameters. Fixed priority scheduling is based on static parameters, which never change during execution (equal for all task instances). Dynamic priority scheduling algorithms determine the task priorities at each scheduling event based on dynamic parameters [Stankovic et al., 1995].
In the following, three common algorithms are presented: Timeline Scheduling as an offline algorithm, Rate Monotonic Scheduling as a fixed-priority online algorithm, and Earliest Deadline First as a dynamic-priority online algorithm.
Timeline Scheduling (TS).Timeline Scheduling (also known as Cyclic (Executive) Scheduling [Baker and Shaw, 1989]) is an offline clock-driven scheduling algorithm, which divides the time axis into slices of equal length, the so-called minor cycle.
One or more tasks are assigned to each minor cycle. This assignment must follow the frequencies of the tasks. For example, if a task’s frequency is twice as high as the frequency of another task, it is assigned to twice as many minor cycles. The tasks within a minor cycle are scheduled successively in a non-preemptive manner (resulting in a low implementation complexity). The optimal length for the minor cycle is the greatest common divisor of the task periods. The schedule repeats itself after each hyperperiod, called major cycle. TS guarantees a feasible schedule if the sum of the worst-case execution times of all tasks within each time slice is less than or equal to the minor cycle [Buttazzo, 2000].
Rate Monotonic Scheduling (RM).RM is a preemptive online algorithm for peri-odic tasks and schedules according to fixed priorities, which are assigned based on the rate of their requests: the shorter the period (equal for all task instances and known at design time), the higher the task’s priority [Liu and Layland, 1973a]. RM preempts the running task at any time when a task with a higher priority becomes ready to run. The produced schedules are optimal for the class of fixed-priority scheduling algorithms for periodic tasks with hard deadlines: if RM fails to produce a feasible schedule for a specific task set, no other algorithm of this class can. RM guarantees the schedulability of a set of n periodic tasks if the utilization factor U is less than n(21/n− 1), which converges for large n to ln 2 ≈ 69% [Liu and Layland, 1973a]. This bound is sufficient, but not necessary, and the schedulable utilization is for many task sets higher [Lehoczky et al., 1987b].
Earliest Deadline First Scheduling (EDF).EDF is a preemptive online algorithm and schedules based on dynamic priorities: the earlier the absolute deadline of the current task instance, the higher its priority [Liu and Layland, 1973a]. EDF is optimal for the class of dynamic priority scheduling algorithms: it minimizes the maximum lateness [Dertouzos, 1974], implicating that it guarantees to produce a feasible schedule if one exists. EDF is applicable to periodic and aperiodic tasks since it does not depend on periodicity [Horn, 1974].
Many real-time systems are characterized by a hybrid task set of periodic hard real-time and aperiodic soft real-time tasks. The periodic tasks might be scheduled by RM or EDF. The aperiodic tasks are often scheduled in background: whenever no periodic task is running, the idle processor is used to execute aperiodic tasks. Back-ground scheduling can be realized without modification of the periodic task scheduler
2.1 Embedded Real-Time Systems 21
by two ready queues: a high-priority queue for periodic tasks and a low-priority queue for aperiodic tasks. The head of the low-priority queue is only dispatched when the high-priority queue is empty [Buttazzo, 2000, Stallings, 2005]. However, a high uti-lization of the periodic task set leaves in many cases infrequent background service opportunities, resulting in a large average response time for aperiodic requests.
Servers are a technique to improve the average response time of aperiodic tasks.
A server is a periodic task with the purpose to service aperiodic requests. It is scheduled like any other periodic task and uses its execution time to run aperiodic tasks. In contrast to background scheduling, aperiodic tasks do not have automat-ically the lowest priority, but are executed with the priority of the server. The service of the server is limited by its budget, which is reduced whenever the server runs. If none is left, the server cannot execute aperiodic tasks until its capacity is replenished [Lehoczky et al., 1987a]. There are different types of servers, varying in when and to which amount the budget is replenished. For a detailed overview see [Buttazzo, 2000].