Variants of Priority Scheduling Algorithms for ... - Semantic Scholar

2 downloads 0 Views 308KB Size Report
Springer-Verlag Berlin Heidelberg 2006. Variants of Priority Scheduling Algorithms for. Reducing Context-Switches in Real-Time Systems. Biju K. Raveendran* ...
Variants of Priority Scheduling Algorithms for Reducing Context-Switches in Real-Time Systems Biju K. Raveendran*, K. Durga Prasad, Sundar Balasubramaniam**, and S. Gurunarayanan BITS, Pilani,Rajasthan, India – 333031 {biju, f2001287, sundarb, sguru}@bits-pilani.ac.in

Abstract. In systems with power constraints, context switches in a task schedule result in wasted power consumption. We present variants of priority scheduling algorithms – Rate Monotonic and Earliest Deadline First - that reduce the number of context switches in a schedule. We prove that our variants output feasible schedules whenever the original algorithms do. We present experimental results to show that our variants significantly reduce the number of context switches. Our results also show that the number of context switches in the schedules output by these algorithms is close to the minimum possible number. Keywords: Real time systems, scheduling, low power, preemption, and context switches.

1 Introduction Power consumption is a limiting factor in most real-time embedded systems, due to limited battery life. This issue has been addressed at various levels – at the architectural level (e.g. DVS, DFS, caching), at the systems level (e.g. process management, memory management, compilation techniques), and at the applications level (e.g. data structures and algorithm design). At the operating systems level, there have been three primary approaches to address the power consumption problem: process scheduling techniques [1-13], paging systems [14], and performance tuning [15]. Various scheduling algorithms have been proposed to exploit energy-saving techniques at hardware level such as Dynamic Voltage Scaling and Dynamic Frequency Scaling [2, 3]. There are other scheduling algorithms that use support from memory hierarchy features [4], or compilers [5] to reduce power consumption. Most of these power-aware scheduling techniques are dependent on platform-specific features such as clocks, device characteristics, or memory technologies. One architecture-independent factor that affects power consumption of a process schedule is the cost of pre-emptions (or context switches) [16]. Context switch * **

Supported by Microsoft Research, India through a Ph.D. research fellowship. Supported by Microsoft Research, India through the Embedded Systems research grant 2004-06.

S. Chaudhuri et al. (Eds.): ICDCN 2006, LNCS 4308, pp. 466 – 478, 2006. © Springer-Verlag Berlin Heidelberg 2006

Variants of Priority Scheduling Algorithms for Reducing Context-Switches

467

duration is a hidden, unproductive duration in a schedule. Context switch duration includes the time taken for saving the context of the current process / thread and loading the context of the next process / thread. Typically, the duration of a context switch between threads is less than that between processes but even the former is not insignificant. For the rest of the paper, we assume that we are referring to process contexts, but most of the issues related to context switching between processes are applicable for threads as well. Various factors specific to the architecture and the operating system affect the context switch duration. For instance, the impact of register sets, floating point units, and caching schemes on context switch times have been reported in [17] and [18]. Gooch [18] also refers to the impact of the process queue on context switching time – in particular, the strong correlation between context switch time and the length of the run (process) queue. The direct impact of context switches in a schedule is the time spent in the act of context switching [15]. This time – dependent on the specific architecture and the operating system – is small but not insignificant. The number of context switches in a schedule may add up to a significant delay in the execution of a process and thus affect its schedulability. The total time spent in context switches would also result in wasted power consumption. An indirect but more significant impact of context switches could be due to data movement across the memory hierarchy i.e. cache block replacement and page replacement in RAM. In fact, the additional energy consumption due to this indirect impact has been reported to be significantly higher [6][15]. The amount of energy wasted due to context switches in a schedule is proportional to the product of the number of context switches in the schedule and the average impact of a context switch. A power-aware scheduling algorithm should account for the impact of context switches on power consumption. We address this issue through variants of priority scheduling algorithms (Rate Monotonic and Earliest Deadline First) that reduce the number of context switches in a schedule. Several scheduling algorithms have been designed to be preemption-aware, i.e. they reduce the number of preemptions or context-switches. We discuss these algorithms in Section 2. In Section 3, we describe our approach to reduce the number of context switches in a schedule and we present variants of well-known priority-scheduling algorithms – RM and EDF. In Section 4, we prove the correctness of our algorithms. In Section 5, we present experimental results to demonstrate the effectiveness of our algorithms in reducing context switches. In Section 6 we conclude.

2 Related Work Various techniques have been proposed in the literature for reducing the number of context switches in a schedule. The techniques vary in complexity from simple, inexpensive heuristics to exhaustive search. Some techniques attempt to reduce the number of context switches while others address the indirect impact of context switches by reducing data movement in memory hierarchy. In [7], Oh and Yang propose a variant of the Least Laxity First Algorithm to reduce context switches in a schedule. When there is tie in the laxity between two processes the modified LLF algorithm continues the execution of the active process while

468

B.K. Raveendran et al.

freezing the priority of the other process. This heuristic fixes the frequent contextswitching problem of LLF without affecting its optimality. The approach is simple and effective in addressing the limitation of LLF but it does not aggressively remove unnecessary context switches. In [8, 9], Wang and Saksena, describe a fixed priority scheduled algorithm that reduces context switches by assigning an active priority known as pre-emption threshold for each job. Pre-emption thresholds are assigned by a branch-and-bound algorithm using lateness heuristic. This approach is limited to fixed priority scheduling as threshold assignment may take exponential time. Lee et. al [6, 10] address the impact of context switches on caching behavior by proposing a new algorithm known as Limited Preemptive Scheduling (LPS). LPS uses data flow analyses techniques to determine the preemption points with small cache loading costs. The primary limitation of this approach is that it requires extensive data flow analyses and therefore may not be suitable for dynamic scheduling. Our approach focuses on aggressive reduction of the number of context switches without relying on extensive computations. Our heuristic is not so simple as the MLLF heuristic but it is much more efficient than the exhaustive search used in [8] or the data flow technique used in [10]. Apart from the above techniques there have been other approaches where context reduction has been considered in conjunction with other techniques or goals. For instance, [11] demonstrates a pre-emption control technique for scheduling in processors with Dynamic Voltage Scaling. This technique is effective in reducing unnecessary context switches caused by dynamic voltage scaling particularly under low or medium processor utilization levels. As such this technique may not be effective in reducing context switches while scheduling under non-DVS processors (nor equivalently under high processor utilization levels when DVS by itself is not useful). Our algorithm aggressively reduces the number of context switches independent of the use of DVS. In [12], Vahid et. al. propose a modification to the Maximum Urgency First (MUF) scheduling algorithm [13] known as MMUF. MUF addresses the issue of schedulability of critical tasks in the presence of transient overloads. MMUF is a hybrid priority algorithm that is a generalization of RM, EDF, LLF, MLLF, and MUF. Like MLLF, MMUF lets the currently active process to continue running in the presence of other processes with the same priority. Thus with respect to reduction in context switches, MMUF is almost the same as MLLF. Our algorithm does not address the issue of transient overloads nor critical tasks.

3 Algorithms Our approach to context switch reduction is similar to the one used in [7] and [12]: defer the preemption of an active process when it can be guaranteed that any process that is delayed will not miss its deadline. But the heuristics in MLLF and MMUF are weak. MLLF defers preemption only when there is a tie in the priority (i.e. laxity in this case) to begin with. The priority of the delayed process is frozen for the extension period. But if a higher priority process could have been delayed without missing the

Variants of Priority Scheduling Algorithms for Reducing Context-Switches

469

deadline, MLLF would not do this. MMUF uses the same heuristic as MLLF. Thus in the best-case scenario, MLLF and MMUF perform as well as EDF but no better. We adopt a more aggressive approach that considers deferrals even in the presence of higher priority processes – without affecting the schedulability of the delayed processes. Our heuristic maximizes the extension period of the active process by considering the deadlines of all processes in the ready queue whose priority is same as or higher than the active process. Based on this heuristic, we present a scheduling algorithm (RCSS) parameterized by a priority function. By choosing the appropriate priority function, variants of EDF (named EDF_RCS) and of RM (named RM_RCS) are obtained from our algorithm. Schedulability of tasks is preserved by these variants i.e. the variant (say RM_RCS) is optimal if and when the original algorithm (say RM) is optimal. We present the algorithms below. We use the following notation in the algorithms: readyQ(t) : the ready queue at time t ordered by priority. deadline(J) : deadline of a job J. period(J) : period of a job J (i.e period of task T, where J is an instance of T). execution_time(J) : execution time of a job J. remaining_time(J,t) : execution time of a job J still remaining at time t. slack(J,t) : deadline(J) – t – remaining_time(J,t) Algorithm Reduced Context Switches Scheduling (RCSS) Input: A list L of tasks T1, T2, … Tn, their periods and execution times. A priority function priority, that is job-level fixed. Assumptions: Arrival times for first instances of all tasks are assumed to be 0. period(J) for a job J is the same as period(T) where J is an instance of task T. For each job J, it is assumed that deadline(J) = arrival_time(J) + period(J). Output: A feasible schedule for L or failure. begin Let Cur be the job with the highest priority; schedule Cur; For every time unit t when there is at least one arrival or a departure or a deferred switch: Let J be the job with the highest priority in readyQ(t) if (Cur is to depart) then Cur = J ; schedule Cur; else if (priority(Cur) >= priority(J)) then continue with Cur; else ExtensionTime_Cur = extension_time(Cur, t); if (ExtensionTime_Cur==0) then preempt Cur; Cur = J; schedule Cur; else if (ExtensionTime_Cur > 0) then mark a deferred switch at t + ExtensionTime_Cur; continue with Cur upto t + ExtensionTime_Cur; else fail; end RCSS

470

B.K. Raveendran et al.

// This function computes the maximum time period up to which each of the queued //jobs can be deferred; the minimum of these deferral times is the period for which the //current job can be continued. function int extension_time(current_job, t) begin Let j1, j2, …, jm be the jobs in readyQ(t) such that priority(j1) >= priority(j2) >= … >= priority(jm) >= priority(current_job) return mini[slack(ji, t) – Σk