Selecting a Scheduling Policy for Embedded Real-Time Monitor and Control Systems1 Qingxu Deng, Mingsong Lv, Ge Yu School of Information Science and Engineering, Northeastern University Shenyang 110004 China
[email protected],
[email protected],
[email protected]
Abstract. An integrated solution to guarantee real-time requirements in embedded real-time monitor and control systems is presented in this paper. First a typical task model is abstracted from such a control system, together with specific characteristics of the tasks. These system characteristics lead to a hybrid scheduling policy of the rate monotonic algorithm and the sporadic server algorithm. The feasibility and rationality of such a policy are also analyzed. The rate monotonic algorithm is extended in this paper, providing a schedulability test that incorporates factors such as context switching overhead and task synchronization.
1
Introduction
Varies working environments lead to different type of embedded systems. Among these systems, a major one is industrial monitor and control system, which plays an important role in product lines. The background of this paper is such an industrial embedded system designed for real-time control of large-scale electro-mechanical devices. In the reality, characteristics of different embedded systems may vary a lot. For example, major tasks in industrial control systems are hard real-time tasks, while key tasks of mass consumption systems often have soft real-time requirements. Currently there are mainly four different types of scheduling algorithms: static table driven algorithms, static priority based algorithms, dynamic priority based algorithms and bandwidth preserving algorithms. Since there is not an all-purpose scheduling policy applicable for every real-time system, the goal of this paper is to find a scheduling policy for our control system that can meet its specific real-time requirements. The following sections are organized as follows. Section 2 presents a typical task model and the scheduling objectives. The reasons of using a hybrid policy are given in Section 3. An extended RM algorithm that takes resource sharing and system overhead into consideration is also given in this section. Section 4 gives a case study and conclusion remarks are given in Section 5. 1
This work was supported by the National High Technology Research and Development Program of China (2002AA1z2308, 2002AA118030), and the National Natural Science Foundation of China (60473073).
Z. Wu et al. (Eds.): ICESS 2004, LNCS 3605, pp. 494-501, 2005. Springer-Verlag Berlin Heidelberg 2005
Selecting a Scheduling Policy for Embedded Monitor and Control Systems
2
495
Typical Task Model and Scheduling Objectives
The system is designed to serve high-pressure pumps for boilers. The core part of the system is abstracted into a task model, which is illustrated in Figure.1. Descriptions of tasks are illustrated in Table.1.
Fig. 1. A Typical task model of embedded real-time industrial control systems
Table 1. Introduction to major tasks in the model Module DCPM DBM SCI DM UQM EDM
Full-Name
Functionality
Data Collection & Processing Module Data Back-up Module System Configuration Interface Display Module
Process sensor data and store parsed data into IMDB Back-up memory data to Disks periodically or when error occurs Send commands to sensors and parameters to DCPM Display memory data in a friendly way to end users Provide users with querying interface for memory data A process to make deep analysis of in-memory data
User Query Module Expert Diagnostic Module
RT Specs.
Arrival Pattern
Hard
Periodic
Hard
Periodic
Hard
Aperiodic
Soft
Periodic
Soft
Aperiodic
Soft
Aperiodic
Considering the overall system, we can give some real-time requirements according to the controlled devices and task characteristics. First, system lifetime is one of the major aspects to characterize an embedded system. Our embedded industrial control system has a long lifetime. During this phase, hardware and software design are scarcely changed. Second, tasks in a real-time system can be sorted into hard or soft ones according to criticality, or classified into periodic or aperiodic ones by their arrival patterns. It can be seen from Table.1 that the system is composed of tasks with different real-time characteristics, and this may impose more
496
Qingxu Deng, Mingsong Lv, and Ge Yu
requirements on scheduling polices. Third, the tasks in this system are logically loosecoupling, but they are data-centrically coupled by sharing IMDB. Data sharing introduces priority inversion problems and synchronization blocking, so some mechanisms are required to guarantee data consistency and predictable system behaviors. In summary, the embedded real-time control system has a complex task set composed of both control tasks and user applications. Data sharing plays a key role in this system. According to foregoing work, the following scheduling objectives can be given. • High Predictability: In our system, all deadlines of hard real-time tasks should be guaranteed and high responsiveness should be provided to soft real-time tasks; predictable system behavior should also be guaranteed under transient overload. There is always a trade-off between high predictability and flexibility, and we choose to compromise flexibility to achieve high predictability. • Low Scheduling Overhead: Embedded resources, such as computation capacity, memory and power supply, are still limited in embedded systems, although hardware technology has been greatly improved. This may impose limitations to the design of scheduling policy, so scheduling overhead should not be ignored. • Capability of Handling Hybrid Task Set: Typical embedded control systems usually have hybrid tasks, which makes the system hard to handle. The scheduling policy should have the flexibility to deal with such a kind of task sets. • Incorporating Resource Sharing: Ideal scheduling algorithms are developed assuming that tasks are independent of each other, and data sharing is a key characteristic of typical control systems. Resource sharing in priority based preemptive systems often introduces priority inversion and unpredictable blocking, which should be avoided to achieve higher predictability.
3
Scheduling Policy Selection and the Extended RM Algorithm
Up till now, there are many scheduling algorithms that are comprehensively studied. Our focus in this paper is priority-based preemptive algorithms, which are implemented in most real-time systems. Priority-based algorithms can be further classified into static or dynamic algorithms by considering whether priorities of tasks can be changed during the running time. 3.1
Motivations and Reasons to Select a Hybrid Solution
There is no single algorithm that can satisfy all the scheduling requirements since all the scheduling algorithms are designed for specific task sets with specific assumptions. This is the motivation to a hybrid policy. An integration of Rate Monotonic algorithm and Sporadic Server algorithm can meet the real-time scheduling requirements of our system.
Selecting a Scheduling Policy for Embedded Monitor and Control Systems
497
The rate monotonic algorithm is selected from the following visions: • High Predictability: High predictability is proved to be one of the superiorities of RM algorithm and a deterministic schedule can be calculated off-line. The internal mechanism guarantees predictable behavior even under transient overload. • Low Scheduling Overhead: Compared to dynamic priority algorithms, RM has a very low scheduling overhead since priorities are assigned a prior. This property is often required as a key scheduling objective in embedded systems. • Incorporation of Resource Sharing: Priority Ceiling Protocol, presented in [1], is widely used to handle resource-sharing problems in real-time systems. This protocol can be well incorporated into RM scheduler without too much alteration to schedulability test. • Engineering Simplicity: There are extensive studies and implementations of RM algorithm in most embedded real-time operating systems. These experiences are quite helpful to our implementation in the view of engineering simplicity. Sporadic Server, presented in [2], is selected for the following reasons: • High Responsiveness: Compared with Polling Server and Deferrable Server, Sporadic Server can provide a higher responsive efficiency to sporadic tasks. • Guaranteeing Hard Deadline: The Sporadic Server provides a uniform scheduling solution for both hard and soft sporadic tasks and deadlines of tasks with limited arriving frequencies can be guaranteed. • PCP Compatible: If some conditions are met when integrating the two algorithms, Priority Ceiling Protocol can be adopted to resolve resource sharing problems under such a hybrid policy. We choose this hybrid solution because, on one hand, the hybrid algorithm can meet the requirements that the system has on both periodic and sporadic tasks; and on the other hand, the Sporadic Server can be easily incorporated into the RM scheduler, since the Sporadic Server can be treated as an equivalently sized periodic task with a phase shifting. Sporadic Server can be considered as one of the extensions to RM algorithm. 3.2
The Extended Rate Monotonic Algorithm
Rate Monotonic algorithm [3] is advanced to schedule periodic hard real-time tasks. The key principle of this algorithm is that the priority of a task is assigned inversely to its period. The following assumptions should be satisfied: tasks are all periodic, deadlines are equal to periods, no dependencies among tasks, and run-time for each task is constant. RM schedulability test is given considering the worst-case situation when all tasks start simultaneously. We call the test FRMS in brief. FRMS: Given a task set with n tasks, and each task is characterized by its worstcase execution time C and period T, the task set is schedulable using RM priority assignment if inequation (1) is satisfied. n
∑
i =1
C i / T i ≤ n ( 2 1 / n − 1)
(1)
498
Qingxu Deng, Mingsong Lv, and Ge Yu
FRMS is a sufficient but not necessary schedulability test with low utilization threshold. In 1989, Lehoczky and Liu Sha advanced a sufficient and necessary schedulability test in [4]. We call it ERMS in brief. ERMS: Given a task set with n tasks listed in priority descending order, define Li in equation (2). The task set is schedulable if max{1≤i≤n} Li ≤1. Here Si referes to the scheduling points for the ith task. i
Li = min {t∈Si } ∑ C j ⋅ t T j / t
(2)
j =1
To extend the fundamental RM schedulability test, we first make an assumption that all tasks are independent of each other. In priority based preemptive systems, the PCP protocol [7] is a widely used policy, which is proved to be able to handle priority inversion, chained blocking and deadlock problems. The protocol works as follows: Each shared resource in the system is assigned a priority of the highest task that may access this resource. A job J starts a new critical section only if J’s priority is higher than all priority ceilings of all the semaphores currently locked by jobs other than J. The job J can be blocked by lower priority tasks at most once. If Bi is defined as the longest blocked duration that task i may have in the worse case, then the FRMS test can be revised to inequation (3) and the definition of Li in ERMS is changed to equation (4), hence resource sharing is taken into consideration. n
Ci
∑T i =1
i
B B + max 1 ,..., n −1 ≤ n ⋅ 2 1 / n − 1 T n −1 T1
(
i Li = min {t∈Si } ∑ C j ⋅ t T j + Bi / t j =1
)
(3)
(4)
The assumption that context switching overhead is zero is also impractical and should be reconsidered. Since in our policy schedulability test is performed offline, we only focus on runtime overhead. Runtime overhead occurs when scheduling is activated. The implementation of the scheduling driven policy may lead to different scheduling activations. In [10], Katcher presented the integrated interrupt event-driven scheduling, which is used in our system. The author also gave the building blocks of runtime overhead. Cint represents the time to handle an interrupt; the time to execute the scheduling code is Csched; Cstore and Cload is the time to save and load the TCB of a task; Ctrap represents the time to handle the trap generated by normal completion of a task. Katcher’s analysis of scheduling activations is not enough since PCP protocol is not considered in his theory. The scheduler is activated in four situations: the release and termination of a task, and the blocking and wakening of a task with respect to resource sharing. The overheads are defined in equation (5), (6) and (7). Cpreempt = Cint + Csched + Cstore + Cload
(5)
Cexit = Ctrap + Cload
(6)
Selecting a Scheduling Policy for Embedded Monitor and Control Systems
Cblock = Cwake = Csched + Cstore + Cload
499
(7)
During system runtime, there is no deterministic method to tell exactly how many times a low priority job may be preempted, so normal preemption overhead is added to the execution time of the preempting job. When considering blocking-triggered preemption, the PCP protocol guarantees that each task may experience at most once, so the overhead can also be calculated into the execution time of the preempting task. In the worst case, we define Ci’ = Ci + Cpreempt + Cexit + Cblock + Cwake. If we replace C in FRMS and ERMS with C’, then we get two more precise schedulability tests that can take context switching overhead into consideration. The third extension to RM algorithm is the incorporation of Sporadic Server, since the algorithm enables the original RM scheduler to handle hard or soft sporadic tasks. Reasons why Sporadic Server is selected is given in Section 3.1. The Sporadic Server is intrinsically a bandwidth preserving algorithm since it preserves processor for sporadic tasks. The success of Sporadic Server is its specific replenishing policy. More results on Sporadic Server can be found in [2].
4
A Case Study
A case study is presented from the implementation of the system for one specific pump. The task set in this study contains 6 tasks and parameters of each task are illustrated in Table.2. For sporadic tasks, period means minimum inter-arrival time. Total worst-case context switching overhead for each task is 50ms. Table 2. Real-time parameters of six major tasks
Task T1 T2 T3 T4 T5 T6
Priority 1 5 2 3 4 6
Hard /Soft Hard Hard Hard Soft Soft Soft
Periodic /Sporadic Periodic Periodic Sporadic Periodic Sporadic Periodic
Period (s) 2 60 2 2 10 60
Computation Time(s) Total Shared Res. 0.4 0.05 1.0 0.12 0.4 0.10 0.4 0.05 0.5 0.12 2.9 0.12
The 6 tasks are assigned priority from 1 to 6 with the smallest number for the highest priority. IMDB is assigned highest priority according to PCP principles. Sporadic tasks can be treated as equivalent-sized periodic tasks when analyzing schedulability. A typical testing process may have four major steps. Step 1: Add the task with the highest priority into the Scheduling Task Set; Step 2: Test the schedulability of the task set with FRMS. If failed, execute Step 3; if all the tasks are in the task set, return TRUE; if not, go to Step 4; Step 3: Test the Schedulability of the task set with ERMS. If failed, return FALSE; if all tasks are in the task set, return TRUE; if not, go to Step 4; Step 4: Add another task with highest priority into the task set, and go to Step 2.
500
Qingxu Deng, Mingsong Lv, and Ge Yu
First assume that all soft real-time tasks do not exist, so the three hard real-time tasks can be scheduled with FRMS since inequation (8) holds. 0.4 + 2 × 0.05 1 + 2 × 0.05 0.4 + 2 × 0.05 0.1 1/ 3 + + + ≤ 3× 2 −1 2 60 2 2
(
)
(8)
If all soft real-time tasks are added, total system utilization is improved, making the less imprecise FRMS test yield failure. So we have to use ERMS to check the schedulability for the second round. Detailed process will not be presented, the result is that for all tasks from T1 to T6, the schedulable condition is satisfied at scheduling point 2, 2, 2, 4, 8, 22, respectively. The deadlines of the six tasks are shown to be guaranteed according to the extended hybrid policy presented above. In some special conditions, period transformation technique can be adopted to raise the priority of a task, resolving the mapping of real criticality to priority. In conclusion, the RM algorithm guarantees that all hard real-time tasks meet their deadlines and the Sporadic Server algorithm can provide the shortest response time for soft real-time tasks.
5
Conclusion
This paper illustrates a whole process of guaranteeing the real-time requirements of an embedded real-time industrial control system from analysis of system characterizations to selection and extension of suitable scheduling policies. Representative control systems have specific real-time requirements, such as high predictability, low scheduling overhead and resource sharing. From previous work by other people, we conclude that a hybrid of RM algorithm and Sporadic Server algorithm with extended approaches is eligible for scheduling in our control system, and it’s also helpful for selecting scheduling policies for similar systems.
References 1. 2. 3. 4. 5. 6. 7.
Sha, L., Rajkumar, R., and Lehoczky, J.P.: Priority Inheritance Protocols: An Approach to Real-Time Synchronization. IEEE Transactions on Computers, Vol.39, No.9. (1990) Sprunt, B., Sha, L., and Lehoczky, J.P.: Aperiodic Task Scheduling for Hard-Real-Time Systems. Real-Time Systems, Vol.1, No.1. (1989)17–60 Liu, C.L. and Layland J.W.: Scheduling Algorithms for Multiprogramming in a HardReal-Time Environment. Journal of the ACM, Vol.20, No.1. (1973)46–61 Lehoczky, J.P., Sha, L., and Ding, Y.: The Rate Monotonic Scheduling Algorithm: Exact Characterization and Average Case Behavior. Proceedings of 10th Real-time Systems Symposium. (1989)166–171 Goossens, J., and Macq, C.: Performance Analysis of Various Scheduling Algorithms for Real-Time Systems Composed of Aperiodic and Periodic Tasks. The 5th International Conference on Information Systems, Analysis and Synthesis. (1999) Jane, W.S. Liu.: Real-Time Systems. Pearson Education Press. (2002) Ramamritham, K., and Stankovic, J.A.: Scheduling Algorithms and Operating Systems Support for Real-Time Systems. Proceedings of IEEE, Vol.82, No.1. (1994)55–67
Selecting a Scheduling Policy for Embedded Monitor and Control Systems 8.
501
Stankovic, J.A.: Misconceptions About Real-Time Computing: A Serious Problem for Next-Generation Systems. IEEE Computer, Vol.21, No.10. (1988)10–19 9. Stankovic, J.A., and Ramamritham, K.: What is Predictability for Real-Time Systems? Real-time Systems, Vol.2, No.4. (1990)247–254 10. Katcher, D. I., Arakawa, H., and Strosnider, J. K.: Engineering and analysis of fixed priority schedulers. IEEE Transactions on Software Engineering, Vol.19, No.9. (1993)