Preemption Threshold Scheduling: Stack Optimality, Enhancements and Analysis
Total Page:16
File Type:pdf, Size:1020Kb
Preemption Threshold Scheduling: Stack Optimality, Enhancements and Analysis Rony Ghattas and Alexander G. Dean Center for Embedded Systems Research Department of Electrical and Computer Engineering NC State University Raleigh, NC 27695 {rony ghattas,alex dean}@ncsu.edu Abstract Many high-volume embedded systems are built Using preemption threshold scheduling (PTS) in a around low-end commercial off-the-shelf (COTS) mi- multi-threaded real-time embedded system reduces sys- crocontrollers because of their low cost. These devices tem preemptions and hence reduces run-time overhead may have very little RAM. Even in systems with larger while still ensuring real-time constraints are met. How- amounts of RAM, running out of memory can be a ever, PTS offers other valuable benefits. In this paper common problem. Embedded systems tend to evolve we investigate the use of PTS for hard real-time sys- over time, with each new generation of software ac- tem with limited RAM. Our primary contribution is creting a new layer onto the existing code base. Hence, to prove the optimality of PTS among all preemption- over a long enough period of time data memory re- limiting methods for minimizing a system’s total stack quirements can easily exceed available memory, mak- memory requirements. We then discuss characteristics ing RAM a precious resource. This makes the use of of PTS and show how to reduce average worst-case re- real-time kernels for low-end embedded systems partic- sponse times. We also introduce a unified framework ularly hard if not impossible. for using PTS with existing fixed-priority (e.g. rate- These issues and problems inherent in preemptive or deadline-monotonic), or dynamic-priority schedul- real-time kernels have led to the emergence of several ing algorithms (e.g. earliest-deadline first). methods and standards for designing more efficient ker- We evaluate the performance of PTS and our im- nels with reduced preemption overheads. As the main provements using synthetic workloads and a real-time consumer of low-end microcontrollers, the automotive workload. We show PTS is extremely effective at reduc- industry was the first to realize the need for more effi- cient operating systems by developing the OSEK/VDX ing stack memory requirements. Our enhancements to 2 PTS improve worst-case response-times as well. standard . Several OSEK/VDX-compliant real-time kernels have been developed. LiveDevices (Realogy) 1. Introduction [8,9] introduced several variations of their real-time ar- Complex real-time embedded applications often use chitect (RTA) operating system that utilizes the single- a real-time operating system (RTOS). Most operating shot execution (SSX) model which enables tasks to systems, however, employ fully-preemptive schedulers, share a single stack while dividing them into mutually which can have excessive preemption overheads. In non-preemptive groups. Other OSEK/VDX-compliant addition to direct preemption overheads (e.g. CPU kernels were also developed to be more efficient in some time and energy), significant memory support is usu- way [7, 18]. Outside of the automotive industry, other ally needed. Many low-end RTOS’s statically allocate efficient RTOS design techniques have been developed. dedicated space in RAM for each of the application’s One very promising technique is Preemption Threshold task’s stacks (e.g. uC/OS-II, FreeRTOS, AvrX, etc.) Scheduling (PTS) presented in ThreadX[10], a com- which can be prohibitively expensive for systems with mercial real-time kernel by Express Logic Inc, and in- little RAM or many tasks [4, 5, 15]. This stack space vestigated initially by Wang and Saksena [23,25]. PTS must be large enough to accommodate worst-case func- tries to minimize preemptions as much as possible while tion call nesting, local variable allocation, and possibly preserving the system’s schedulability. the task control block and context. Many kernels also Minimizing preemptions to reduce overhead and im- allocate additional space in each task’s stack area for servicing interrupts (e.g. uC/OS-II and FreeRTOS)1. in hardware like AvrX[4]. 2The OSEK/VDX standard includes specifications for embed- 1Some kernels use more efficient techniques for servicing inter- ded operating systems, communication subsystems, and embed- rupts like emulating a separate interrupt stack if not supported ded network management systems. prove the system’s memory utilization is an ad-hoc pro- support PTS, resulting in the stack resource policy with cess which has not been adequately examined to date. preemption thresholds (SRPT). The SRPT inherits all In this paper we analyze and enhance PTS. First, we of the properties of the SRP in the sense that it pre- show that PTS leads to the optimal stack space utiliza- vents priority inversions, deadlocks, as well as bounds tion attainable by any known priority-driven schedul- the maximum time any task can be blocked. ing algorithm (e.g. RM, DM, EDF, etc). Hence, Since dynamic-priority task scheduling schemes can given a particular real-time application, we provide be much more efficient than static-priority schemes, the application engineer with a limit on the amount it is of particular interest to know if PTS applies to of memory that can be saved by limiting preemptions these schemes. Gai’s [11] work enables the use of while not violating any of the workload’s real-time con- PTS in dynamic-priority schemes through the use of straints. Second, we build a framework for PTS that the preemption levels concept, also introduced earlier naturally applies to both fixed-priority and dynamic- by Baker[3], which enable static analysis of dynamic- priority schemes. Third, we discuss some characteris- priority systems. Another dynamic preemption thresh- tics of PTS, including undesired side-effects of preemp- old scheme was presented by He et al.[12] which uses an tion limiting in general (e.g. deteriorated system re- earliest-deadline-first algorithm to dynamically change sponsiveness and robustness), and show how some can the task priorities as well as their preemption thresh- be reduced. Finally, through simulations, we quantify olds. Our work on PTS for dynamic-priority schemes application characteristics (e.g. workload utilization, builds on Gai et al. and Baker’s work since, in contrast type of scheduling scheme used, etc.) that affect PTS to He’s et al. work, we enable the system developer to to help developers of real-time applications. analyze and verify a design at design time while avoid- This paper is divided into six sections. In section ing all the additional run-time overheads of dynam- 2 we present a brief overview of some of the work ad- ically updating preemption thresholds in addition to dressing preemption threshold scheduling and how it priorities. To this end, we modify an existing preemp- relates to our work. In section 3 we present the back- tion thresholds search algorithm to apply to both fixed- ground material this paper is based on, and the termi- and dynamic-priority schemes. The search can be done nology used throughout this study. Section 4 contains offline to obtain the optimal preemption threshold as- the main theoretical results of this paper: proving the signment which remains fixed at run-time (incurring optimality properties of PTS and discussing how to no overhead). minimize some undesirable side-effects. In section 5 we Many other studies investigated PTS and presented present a case study and simulations to assess workload extensions to its basic concepts. Building on Wang’s characteristics that affect the effectiveness of PTS. Fi- work for fixed-priority schemes, Regehr[20] presented nally, in section 6 we present our conclusions. two abstractions that can be used to force the PTS scheduler to group tasks into non-preemptive groups. 2. Related Work Regehr also investigated the presence of WCET un- The term preemption threshold scheduling (PTS) certainty and presented algorithms for finding fault- was first coined by Wang and Saksena[23,25] after they tolerant PTS schedules. The incorporation of PTS investigated the concept of preemption thresholds intro- into many real-time design settings was also addressed. duced by Express Logic Inc. in their real-time kernel Kimetal.[14]showedhowPTScanbeusedwithdy- ThreadX[10]. PTS results in a dual-priority scheme namic voltage scaling to render efficient schedules that where each task has a nominal priority, which it uses to optimize the energy usage of the system. Saksena et preempt other tasks, and a preemption threshold which al.[22], and Wang et al[23] also addressed using PTS is its effective priority while executing. The real-time in a real-time object oriented framework, showing how analysis of this dual-priority scheme was pioneered by real-time object oriented models can be synthesized au- Wang et al.[23, 25] and by Davis et al.[9]. In these tomatically into a real-time task set implemented in a studies, preemption between tasks was limited to oc- fixed-priority PTS scheme. cur only when necessary to maintain system schedula- In summary, PTS provides real-time systems devel- bility. Tasks that run non-preemptively with respect opers a method to design efficient real-time schedules to each other can be mapped into the same run-time in a variety of settings. Our work on PTS is comple- thread and share the same run-time stack minimizing mentary to, or can be used in combination with, most the memory requirements and other preemption over- of the other known methods and schemes for using PTS heads. Our work builds directly on Wang’s et al. work to minimize the overheads of preemptions and obtain by proving the optimality of their preemption threshold more efficient real-time schedules. assignment method as well as enhancing its timeliness. Many resource sharing protocols and real-time syn- 3.