Optimal Priority and Threshold Assignment for Fixed-priority Preemption Threshold Scheduling∗ Leo Hatvani Sara Afshar Reinder J. Bril Technische Universiteit Mälardalen University (MDH) Technische Universiteit Eindhoven (TU/e) Västerås, Sweden Eindhoven (TU/e) The Netherlands sara.afshar@mdh.se The Netherlands l.hatvani@tue.nl Mälardalen University (MDH) Västerås, Sweden r.j.bril@tue.nl ABSTRACT the flexibility of dynamic-priority algorithms, fixed-priority Fixed-priority preemption-threshold scheduling (FPTS) is a scheduling algorithms are a de facto standard in industry generalization of fixed-priority preemptive scheduling (FPPS) due to their lower implementation and execution overhead and fixed-priority non-preemptive scheduling (FPNS). Since compared to dynamic-priority algorithms. FPPS and FPNS are incomparable in terms of potential Another way of classifying scheduling algorithms is whether schedulability, FPTS has the advantage that it can schedule they allow a task that is currently executing to be preempted any task set schedulable by FPPS or FPNS and some that or not, these are preemptive and non-preemptive schedul- are not schedulable by either. FPTS is based on the idea that ing algorithms. Recently, new scheduling approaches have each task is assigned a priority and a preemption threshold. been proposed as an alternative to the extremes of fully pre- While tasks are admitted into the system according to their emptive and non-preemptive scheduling. One such scheduling priorities, they can only be preempted by tasks that have approach is called fixed-priority preemption threshold schedul- priority higher than the preemption threshold. ing (FPTS) [12, 11] where each task τi is annotated by a This paper presents a new optimal priority and preemption preemption threshold θi besides its priority πi . Preemption threshold assignment (OPTA) algorithm for FPTS which in threshold for a task specifies which tasks can preempt it and general outperforms the existing algorithms in terms of the is always greater than or equal to the priority of that task. size of the explored state-space and the total number of worst If a task’s priority is higher than the preemption threshold case response time calculations performed. The algorithm is of the currently executing task, it is allowed to preempt the executing task. This means that as soon as the task starts based on back-tracking, i.e. it traverses the space of potential priorities and preemption thresholds, while pruning infeasible executing, its effective priority is increased to its preemption paths, and returns the first assignment deemed schedulable. threshold. We present the evaluation results where we compare the There are two special cases of the FPTS scheduling algo- complexity of the new algorithm with the existing one. We rithm. First, when the preemption threshold of every task is show that the new algorithm significantly reduces the time equal to the task’s priority, FPTS becomes equivalent to the needed to find a solution. Through a comparative evaluation, FPPS scheduling algorithm. Second, when all preemption we show the improvements that can be achieved in terms of thresholds are equal to the highest priority in the system, schedulability ratio by our OPTA compared to a deadline FPTS becomes equivalent to FPNS, as no task can preempt monotonic priority assignment. any other task. FPTS improves the schedulability compared to both ap- proaches by leveraging the preemption of higher priority tasks CCS Concepts under FPPS and the blocking incurred by non-preemptive •Computer systems organization → Embedded soft- execution of lower priority tasks under FPNS. An optimal pri- ware; •Software and its engineering → Real-time schedu- ority and threshold assignment (OPTA) algorithm for FPTS lability; is any algorithm that for a given set of tasks determines if it can be scheduled by means of FPTS and when it can be scheduled provides task priorities and thresholds. The 1. INTRODUCTION original OPTA for FPTS has been introduced by Wang and Scheduling theory has been widely studied over the years Saksena [12]. However, the high computation time required to provide effective scheduling solutions for real-time em- to find a feasible solution using this algorithm, if such exists, bedded systems. Scheduling algorithms can be divided into warrants research into more efficient approaches [6]. In this fixed-priority and dynamic-priority, where the priorities of paper, we introduce a new OPTA algorithm for FPTS which tasks stay the same throughout the execution of the system effectively can decrease the computation time of finding a for the former ones and change depending on some parameter feasible solution. Our algorithm is based on (i) backtracking, for the latter ones. Even though it can be said that they lack (ii) pruning to reduce the search space, and (iii) a heuristic ∗This work is supported by the ARTEMIS Joint Undertaking to traverse the search space. project EMC2 (grant agreement 621429). Contributions: In this paper we propose an algorithm for EWiLi’16, October 6th, 2016, Pittsburgh, USA. optimal priority and threshold assignment. Moreover, we Copyright retained by the authors. show by means of experimental results that the computation The preemption of a higher priority task is postponed until time for finding a priority and threshold assignment for a set the next preemption point of a running task. This approach of tasks that can make them schedulable, if such a combina- is also referred to as cooperative scheduling. tion exists, is growing considerably slower compared to the Worst-case response time analysis for FPTS as well as existing solution when the number of tasks increases. Fur- an optimal priority and preemption threshold assignment ther, we present the schedulability results of comparing our algorithm was first presented in [12]. Later, in [10], it has proposed algorithm with FPPS and FPTS under a deadline been shown that the analysis in [12] was optimistic, and a monotonic assignment. Finally, we present a comparative revised analysis was presented. evaluation of FPTS with a deadline monotonic priority as- Worst-case response time analysis of periodic real-time signment and optimal preemption thresholds and our OPTA, tasks under fixed-priority scheduling with deferred preemption which clearly illustrates the advantage of our OPTA. (FPDS)has been studied in [4, 5, 8]. In [3], Bril et. al have shown that the analysis presented in [4, 5] is both pessimistic 2. MOTIVATION EXAMPLE and optimistic where they have revised the analysis. In this section we show by means of an example that the deadline monotonic priority assignment is not optimal for 4. SYSTEM MODEL FPTS. 4.1 Task Specification Table 1: Specifications of TI task set. The system consist of a single processor including a set of n independent sporadic tasks. Each task τi is denoted task Ci Ti = Di πiDM πi θi Ri by < Ci , Di , Ti >, where Ci ∈ R+ denotes the worst-case τ1 1 7 1 1 1 1 execution time, Di ∈ R+ denotes the relative deadline and τ2 8 23 2 2 2 21 Ti ∈ R+ is the minimum inter-arrival time. We assume a τ3 10 25 3 4 2 25 constrained-deadline task model, i.e., Di ≤ Ti (even though τ4 3 33 4 3 2 25 we use a generalized analysis). Let us consider a task set TI which consists of 4 tasks as 4.2 FPTS Scheduling presented in Table 1. The tasks are characterized by their Tasks are further annotated by unique priorities πi ∈ N worst-case computation time Ci , minimum inter-arrival time and preemption thresholds θi ∈ N. For both, smaller values Ti , deadline Di , preemption thresholds θi , and priority πi . denote higher priorities. Whenever we compare priorities or The smaller numbers denote higher priorities. All tasks have thresholds, we compare their numerical values, i.e. πi < πj implicit deadlines, i.e. Ti = Di , and the priorities πiDM are means that task πi has a higher priority than πj . Preemption assigned based on deadline monotonic priority assignment, thresholds are always greater than or equal to the correspond- i.e. the task with the smallest deadline has the highest ing priorities θi ≤ πi . priority. At utilization U TI ≈ 0.982, TI is not schedulable Given these priorities and thresholds, the tasks are sched- under FPTS. If the priorities of τ3 and τ4 are exchanged (as uled as follows. If there are no running tasks, the task τi in πi ) TI becomes schedulable under FPTS with preemption with the highest priority among the simultaneously released thresholds θi and worst-case response times Ri . tasks starts executing. As soon as it starts executing it can be preempted only by tasks τj that have priority greater 3. RELATED WORK than its preemption threshold πj < θi . In the situation when the executing task has a higher priority than the preempted Preemption Threshold Scheduling (PTS) has been pro- task τi and waiting task τj where θi ≤ πj , τi will always posed by Wang and Saksena in [12]. Under this approach, start executing before τj . besides a regular priority, each task is assigned a preemption threshold up to where it can prevent preemptions. The pre- emption is allowed only when the priority of a ready task is 5. RESPONSE TIME ANALYSIS higher than the threshold of the running task. Deferred Preemptions Scheduling (DPS) has first been in- 5.1 Analysis troduced by Baruah [1] under Earliest Deadline First (EDF). While worst-case response time analysis for FPTS policy Under this approach, for each task the longest interval that has been published several times [12, 10], in this paper we can be executed non-preemptively is specified. Two types employ the exact analysis presented by Keskin et al. [7] with of implementation exist for this approach based on how the the added assumption that there is no jitter. non-preemptive regions are implemented: Floating model A task τi releases an infinite series of jobs τik . Each of and Activation-triggered model implementation. Under the these jobs faces two kinds of delays to its execution: blocking former model, non-preemptive regions are specified in the and interference. Blocking (1) comes from the lower priority code by inserting specific primitives that disable and enable tasks that have a preemption threshold equal to or higher preemption. Under the later model, non-preemptive regions than the priority of the current task. are specified by setting a timer at the arrival of a higher priority task which lasts for the specified non-preemptive Bi = max(0, max Cj ) (1) ∀j:θj ≤πi <πj interval. Fixed Preemption Points (FPP) has been proposed by Since the sequence of jobs released by the task τi is infinite, Burns [4]. Under FPP, preemption is allowed only at prede- we need to determine how many jobs should be analyzed to fined points during a task’s execution. As a results, a task is determine whether the entire task is schedulable or not. This divided into a number of non-preemptive execution chunks. calculation is based on the worst-case level-i active period [3] and is given as the smallest positive Li that satisfies (2). we can inspect that while blocking value Bi in (4) influences Li only the start time of the task, if the same computation Li = B i + Cj (2) time is allocated to a higher priority, it is introduced into Tj the computation of starting time (4) and optionally finishing ∀j:πj ≤πi time (5) as Cj . The maximum number li of jobs of τi that can be executed in this level-i active period is given by (3). Lemma 1. Let τi be a task and T be a set of schedulable Li tasks with assigned priorities and thresholds. If task τi is li = (3) not schedulable in the context of T with the lowest priority Ti ∀πj ∈ T : πi > πj and any preemption threshold, it will not Given the knowledge of how many jobs need to be analyzed, be schedulable if additional tasks are added to T . we can compute their worst-case start time Sik for 0 ≤ k < li as the smallest positive value Sik that satisfies (4). From the worst case response time equations, it is trivial ⎧ to deduce that adding more interference will never reduce ⎪ Sik ⎨ Bi + kCi + ∀j:πj <πi Tj Cj ⎪ if Bi > 0 the response time. Sik = ⎪ ⎪ ⎩ kCi + 1 + Sik Cj if Bi = 0 ∀j:πj <πi Tj 6. OPTIMAL PRIORITY AND THRESHOLD (4) ASSIGNMENT Likewise, other tasks may preempt the observed job, thus causing interference. This quantity is encompassed by calcu- In this section, we present an OPTA algorithm for FPTS. lating each job’s worst-case finalization time Fik . It can be The algorithm is optimal in the sense that it will find a found as the smallest positive Fik that satisfies (5). feasible priority and thresholds assignment that makes a ⎧ task set schedulable if such solution exists. Similar to the ⎪ ⎪ Sik + Ci + OPTA in the work by Wang and Saksena [12] (including the ⎪ ⎪ ⎪ ⎪ correction discussed in Section 7), the algorithm proposed in ⎨ Fik − STik Cj if Bi > 0 ∀j:πj <θi Tj this paper is based on (i) backtracking, (ii) pruning the search Fik = j ⎪ ⎪ Sik + Ci + space, and (iii) a heuristic for traversing the search space. ⎪ ⎪ ⎪ ⎪ However, unlike the Wang-Saksena OPTA, our algorithm (1) ⎩ Fik − 1 + Sik Cj if Bi = 0 assigns priorities in a descending order, i.e. from the highest ∀j:πj <θi Tj Tj (5) to the lowest priority, rather than in ascending order, (2) Finally, according to (6), we compute the worst-case re- determines preemption thresholds of tasks while the priority sponse time as the maximum of response times of all jobs ordering is determined, rather than determining preemption within the worst-case level-i active period. thresholds after the priority ordering is completed and (3) uses the notion of blocking tolerance rather than lateness in Ri = max (Fik − kTi ) (6) the heuristic. ∀k:0≤k