|
ENEE 642:Software Systems Implementation |
Spring 2000, Prof. D. Stewart |
A real-time system is one in which the correctness of the computations not only depends upon the logical correctness of the computations but also upon the time at which the result is produced.
A real-time system can be classified as either hard or soft. The distinction, however, is very fuzzy.
Hard Real-Time: Missing a deadline results in the failure of performance degradation of the system.
Soft Real-Time: The system will properly perform as long as deadlines are met most of the time. Missing a few deadlines will not affect the system.
Most complex real-time systems use preemptive multitasking. To ensure that timing constraints are met, priorities must be assigned according to different rules than typical desktop systems. In this handout, we review some real-time scheduling algorithms, along with the advantages and disadvantages of doing so.
Real-time scheduling algorithms can be
Transient Overload: The state of a real-time system when at least one task will fail because of a lack of CPU time available.
Guaranteed Task: A task is said to be guaranteed if it will always meet its deadlines, even in a transient overload situation.
Task Set: The set of all tasks which may execute on the same processor.
Critical Task Set: The set of guaranteed tasks. It must be a subset of the task set
Task Utilization: percentage of CPU utilization required by a task, in the worst case. Utilization of task i is
Ui = Ci/Ti , where Ti = period of task i, and Ci = worst case execution time of task i.
Schedulable bound: maximum worst-case utilization for which a task set will not miss any deadlines. The value is scheduler dependent; the maximum value is 100%.
In this section, we take a look at various scheduling algorithms, and show whether or not each task meets its deadline.
Assume the following two tasks, P1 and P2; how do we schedule them?
The deadline for each task is assumed to be the start of next period. If we use a highest-priority-first algorithm, there are two possibilities
Let us consider each case separately. Case 1 is shown in See Fixed-Priority, P1 > P2. All tasks meet their respective deadlines, while Case 2 is shown in See Fixed-Priority, P1 < P2. -- P2 misses half of its deadlines. In the second case, the task set is not schedulable, even though total utilization is less than 100%.
The Rate-Monotonic Algorithm (RMA) is a procedure for assigning fixed priorities to tasks to maximize the possibility that the task set is schedulable. The basic algorithm is to do the following:
RMA is an optimal fixed priority algorithm. This means that if a task set cannot be scheduled using the rate monotonic algorithm, then it cannot be scheduled using any fixed priority algorithm.
One major problem for the RMA is that the schedulable bound is less than 100%. Specifically, it has been proven that the worst case schedulable bound is as low as 69%, while the average schedulable bound is 88%. This means that even though the total processor utilization is less than 100%, if that utilization is higher than the schedulable bound, then there is no guarantee that the task set will meet all deadlines.
Example, Case 3 in See Fixed-Priority, P1 > P2. P2 misses some deadlines is a modification of Case 1
Using rate monotonic algorithm, assign Priority P1 > Priority P2
An alternative to fixed priority scheduling is dynamic priority scheduling, where priority is a function of time. There exist the following optimal dynamic priority algorithms:
If a task set cannot be scheduled with one of these algorithms, then it cannot be scheduled with any algorithm. The schedulable bound in each of these cases is 100%. Thus, as long as total utilization is less than 100%, then task set is schedulable. As an example, consider the task set in Case 3, that was not schedulable using a fixed-priority scheduling algorithm. In Case 4, we see that the task set is indeed schedulable when using EDF.
Advantage: A critical set can be specified, thus tasks can be selectively chosen during a transient overload
Disadvantage: Worst case schedulable bound is 69% (average case 88%)
Disadvantage: Deadline Failures are difficult to detect
Advantage: Schedulable bound is 100%
Advantage: Deadline Failures can be detected
Disadvantage: Cannot specify a critical task set, thus no control of which tasks fail during a transient overload
As with processes in non-real-time systems, real-time tasks must often share resources, using the same mechanisms, such as shared memory, semaphores, messages, and locks. Sometimes, a real-time task must block until the shared resource is available. What happens if a high-priority process needs the resource immediately in order to not miss a deadline, but a lower-priority process is holding the resource?
We define Priority Inversion as the blocking of a high priority task due to a lower priority task locking a shared resource. For example, See Example of Priority Inversion illustrates the priority version problem. The task set consists of 3 tasks:
For this example, we are not concerned with their period or execution time.
Assume a resource R1 shared between PH and PL, and PL acquires the resource first.
There have been many solutions proposed for addressing problems such as priority inversion. For example:
See Priority inheritance protocol for solving priority inversion problem illustrates the priority inheritance solution to the priority inversion problem. Although this solution has some merits, it is usually used because the method is deadlock-prone, and it is difficult to analyze since the number of times a task can be preempted due to resource usage is not bounded.
A better solution is the priority ceiling protocol. Theoretically it provides the desired result. In practice, however, it is expensive to implement, as significant setup time and overhead is required.