CS 244 Introduction to Embedded Systems and Ubiquitous
CS 244 -Introduction to Embedded Systems and Ubiquitous Computing Instructor: Eli Bozorgzadeh Computer Science Department UC Irvine Winter 2010 - CS 244
CS 244 – Lecture 4 Real Time Scheduling Winter 2010 - CS 244 2
Hardware Components Embedded Systems Design Hardware Flow Concept Specification HW/SW Partitioning Estimation Exploration ign s De …) , t u yo a L is, s e nth y (S De sig n (Co mp ila tio n, …) Software Components Winter 2010 - CS 244 Validation and Evaluation (area, power, performance, …) 3
Reuse of standard software components n Knowledge from previous designs to be made available in the form of intellectual property (IP, for SW & HW). q q n Operating systems Middleware Real-time data bases Standard software (MPEG-x, GSM-kernel, …) Includes standard approaches for scheduling (requires knowledge about execution times). Winter 2010 - CS 244 4
Software Components n n Prediction of execution time Scheduling in real-time systems q q q n Embedded operating systems q n Classification of scheduling algorithms Aperiodic scheduling Periodic scheduling Real-time OS Middleware Winter 2010 - CS 244 5
Worst Case Execution Time n Def. : The worst case execution time (WCET) is an upper bound on the execution times of tasks. q Computing such a bound is undecidable n Possible for programs without recursion and finite loops q n Pipeline hazards, interrupts, caches serious overestimates Approaches: q q for hardware: typically requires hardware synthesis for software: requires availability of machine programs; complex analysis Winter 2010 - CS 244 6
Average Execution Time n Estimated cost and performance values q n Difficult to generate sufficiently precise estimates; Balance between run-time and precision Accurate cost and performance values q Can be done with normal tools (such as compilers). As precise as the input data is. Winter 2010 - CS 244 7
Real-Time Scheduling n Assume that we have a task graph G=(V, E). A schedule of G is a mapping, V T, of a set of tasks V to start times from domain T. n Schedules have to respect a set of constraints, such as resource, dependency, and deadlines. n q Scheduling is the process of finding such a mapping. During the design of embedded systems, scheduling has to be performed several times n q early rough scheduling as well as late precise scheduling Winter 2010 - CS 244 8
Classification of Scheduling Algorithms Winter 2010 - CS 244 9
Hard and soft deadlines Def. : A time-constraint (deadline) is called hard if not meeting that constraint could result in a catastrophe [Kopetz, 1997]. All other time constraints are called soft. n n We will focus on hard deadlines. Winter 2010 - CS 244 10
Periodic and aperiodic tasks Def. : Tasks which must be executed once every p units of time are called periodic tasks. p is called their period. Each execution of a periodic task is called a job. q All other tasks are called aperiodic. n Def. : Aperiodic tasks requesting the processor at unpredictable times are called sporadic, if there is a minimum separation between the times at which they request the processor. n Winter 2010 - CS 244 11
Preemptive and Non-preemptive Scheduling n. Preemptive and non-preemptive scheduling: Non-preemptive schedulers are based on the assumption that tasks are executed until they are done. As a result the response time for external events may be quite long if some tasks have a large execution time. q Preemptive schedulers have to be used if some tasks have long execution times or if the response time for external events is required to be short. Winter 2010 - CS 244 12
Static and dynamic scheduling Dynamic scheduling: Processor allocation decisions (scheduling) done at run-time. n Static scheduling: Processor allocation decisions (scheduling) done at design-time. n q Dispatcher allocates processor when interrupted by a timer. The timer is controlled by a table generated at design time. Winter 2010 - CS 244 13
Time-Triggered Systems n Entirely time-triggered system q q q n Temporal control structure is encoded in a Task-Descriptor List (TDL) that contains the cyclic schedule for all activities of the node. This schedule considers the required precedence and mutual exclusion relationships among the tasks such that an explicit coordination of the tasks by the operating system at run time is not necessary. . . The dispatcher is activated by the synchronized clock tick. q q n the temporal control structure of all tasks is established a priori by off-line support-tools. It looks at the TDL, and then performs the action that has been planned for this instant. [Kopetz] The only practical means of providing predictability. It can be easily checked if timing constraints are met. q Response to sporadic events may be poor. Winter 2010 - CS 244 14
Centralized and Distributed Scheduling n Centralized and distributed scheduling q n Mono- and multi-processor scheduling q n Multiprocessor scheduling either locally on one or distributed on several processors Simple scheduling algorithms handle single processors, more complex algorithms handle multiple processors. Online- and offline scheduling: q q Online scheduling is done at run-time based on the information about the tasks arrived so far. Offline scheduling assumes prior knowledge about arrival times, execution times, and deadlines. Winter 2010 - CS 244 15
Schedulability A set of tasks is said to be schedulable under a given set of constraints, if a schedule exists for that set of tasks and constraints. n q q Exact tests are NP-hard in many situations. Sufficient tests: sufficient conditions for guaranteeing a schedule are checked. n q Small probability of false negative. Necessary tests: checking necessary conditions. Can be used to show that no schedule exists. n Always not possible to prove even if no schedule exists. Winter 2010 - CS 244 16
Cost Functions n Cost function: Different algorithms aim at minimizing different functions. n Def. : Maximum lateness is defined as the difference between the completion time and the deadline, maximized over all tasks. q Maximum lateness is negative if all tasks complete before their deadline. Winter 2010 - CS 244 17
Simple Tasks without any interprocess communication are called simple tasks (S-tasks). n q n S-tasks can be either ready or running. API of an S-task in a TT system: Two OS Calls q q q TERMINATE TASK and ERROR The TERMINATE TASK system call is executed whenever the task has reached its termination point. In case of an error that cannot be handled within the application task, the task terminates its operation with the ERROR system call. [Kopetz, 1997]. Winter 2010 - CS 244 18
Scheduling with no Precedence Constraints n Let {Ti } be a set of tasks. Let: q q ci be the execution time of Ti , di be the deadline interval, that is, the time between Ti becoming available and the time until which Ti has to finish execution. li be the laxity or slack, defined as li = di - ci Winter 2010 - CS 244 19
Uniprocessor with Equal Arrival Times n. Earliest q q Due Date (EDD): Given a set of n independent tasks, any algorithm that executes the tasks in order of non-decreasing deadlines is optimal with respect to minimizing the maximum lateness. Proof: See [Buttazzo, 2002] EDD requires all tasks to be sorted by their deadlines. Complexity is O(n log(n)). Winter 2010 - CS 244 20
Earliest Deadline First (EDF) n. Different q arrival times Preemption potentially reduces lateness. n. Theorem [Horn 74]: Given a set of n independent tasks with arbitrary arrival times, any algorithm that at any instant executes the task with the earliest absolute deadline among all the ready tasks is optimal with respect to minimizing the maximum lateness. n. Earliest deadline first (EDF): each time a new ready task arrives, it is inserted into a queue of ready tasks, sorted by their deadlines. If a newly arrived task is inserted at the head of the queue, the currently executing task is preempted. q If sorted lists are used, the complexity is O(n 2) Winter 2010 - CS 244 21
Earliest Deadline First (EDF) Earlier deadline preemption Later deadline no preemption Winter 2010 - CS 244 22
Least laxity, Least Slack Time First npriorities = decreasing function of the laxity (the less laxity, the higher the priority); dynamically changing priority; preemptive. Requires calling the scheduler periodically, and to recompute the laxity. Overhead for many calls of the scheduler and many context switches. Detects missed deadlines early. 23 Winter 2010 - CS 244
LL/LSF Properties LL/LSF is also an optimal scheduling for uni-processor systems. n q BUT… uses Dynamic priorities, therefore cannot be used with a fixed priority OS. n. LL/LSF scheduling requires the knowledge of the execution time q May not know this in advance! Winter 2010 - CS 244 24
Scheduling without Preemption Optimal schedules may leave processor idle to finish tasks with early deadlines arriving late. n q Knowledge about the future is needed for optimal scheduling algorithms n No online algorithm can decide whether or not to keep idle. EDF is optimal among all sched. algorithms not keeping the processor idle at certain times. n If arrival times are known a priori, the sched. problem becomes NP-hard in general. n q Branch and bound techniques are typically used. Winter 2010 - CS 244 25
Scheduling with Precedence Constraints Task graph and possible schedule: Schedule can be stored in a table. (can be used by dispatcher/OS) Winter 2010 - CS 244 26
Synchronous Arrival Times n Optimal algorithm for minimum latency q Latest Deadline First (LDF) n. LDF [Lawler, 1973]: Generation of total order compatible with the partial order described by the task graph (LDF performs a topological sort). LDF reads the task graph and inserts tasks with no successors into a queue. It then repeats this process, putting tasks whose successor have all been selected into the queue. n q At run-time, the tasks are executed in the generated total order. q LDF is non-preemptive and is optimal for uni-processors. Latest Deadline First (LDF) Winter 2010 - CS 244 27
Asynchronous Arrival Times This case can be handled with a modified EDF algorithm. n q The key idea is to transform the problem from a given set of dependent tasks into a set of independent tasks with different timing parameters [Chetto 90] This algorithm is optimal for uni-processor systems. n If preemption is not allowed, the heuristic algorithm developed by [Stankovic and Ramamritham 1991] can be used. n Winter 2010 - CS 244 28
Periodic Scheduling T 1 T 2 n. For periodic scheduling, the best that we can do is to design an algorithm which will always find a schedule if one exists. q A scheduler is defined to be optimal iff it will find a schedule if one exists. Winter 2010 - CS 244 29
Periodic scheduling n Let q q pi be the period of task Ti, ci be the execution time of Ti, di be the deadline interval, that is, the time between a job of Ti becoming available and the time after which the same job Ti has to finish execution. li be the laxity or slack, defined as li = di - ci Winter 2010 - CS 244 30
Accumulated Utilization Accumulated execution time divided by period Accumulated utilization: Necessary condition for schedulability (with m=number of processors): Winter 2010 - CS 244 31
Rate Monotonic (RM) Scheduling Well-known technique for scheduling independent periodic tasks [Liu, 1973]. n Assumptions: n q q q n All tasks that have hard deadlines are periodic. All tasks are independent. di=pi, for all tasks. ci is constant and is known for all tasks. The time required for context switching is negligible Establish condition for schedulability! Winter 2010 - CS 244 32
Rate Monotonic (RM) Scheduling n RM Schedulability Condition q For a single processor with n tasks, the following equation must hold for the accumulated utilization µ: q Winter 2010 - CS 244 33
Rate Monotonic (RM) Scheduling RM policy: The priority of a task is a monotonically decreasing function of its period. low period: high priority At any time, a highest priority task among all those that are ready for execution is allocated. If all assumptions are met, schedulability is guaranteed. Maximum utilization as a function of the number of tasks: Winter 2010 - CS 244 34
Example: RM-generated schedule Period T 1: 2 T 2: 6 T 3: 6 Execution Time 0. 5 2 1. 75 T 1 preempts T 2 and T 3 do not preempt each other. Winter 2010 - CS 244 35
Case of failing RM scheduling Task 1: period 5, execution time 2 Task 2: period 7, execution time 4 µ=2/5+4/7=34/35 0. 97 2(21/2 -1) 0. 828 Not enough idle time Missed deadline Missing computations scheduled in the next period Winter 2010 - CS 244 36
Properties of RM Scheduling n RM scheduling is based on static priorities. q q This allows RM scheduling to be used in standard OS, such as Windows NT. A huge number of variations of RM scheduling exists. In the context of RM scheduling, many formal proofs exist. The idle capacity is not required if the period of all tasks is a multiple of the period of the highest priority task n q Necessary condition for schedulability: µ 1 Winter 2010 - CS 244 37
EDF n n EDF can also be applied to periodic scheduling. EDF optimal for every period q optimal for periodic scheduling n q trivially! EDF must be able to schedule the example in which RMS failed. Winter 2010 - CS 244 38
Comparison EDF/RMS RMS: EDF: T 2 not preempted, due to its earlier deadline. Winter 2010 - CS 244 39
EDF: Properties n EDF requires dynamic priorities q EDF cannot be used with a standard operating system just providing static priorities. Winter 2010 - CS 244 40
Dependent Tasks The problem of deciding whether or not a schedule exists for a set of dependent tasks and a given deadline is NP-complete [Garey/Johnson]. n Strategies: q q Add resources, so that scheduling becomes easier Split problem into static and dynamic part so that decisions during run-time is minimized. Winter 2010 - CS 244 41
Sporadic Tasks n If sporadic tasks were connected to interrupts, the execution time of other tasks would become very unpredictable. q q Introduction of a sporadic task server, periodically checking for ready sporadic tasks; Sporadic tasks are essentially turned into periodic tasks. Winter 2010 - CS 244 42
Summary Prediction of execution time n Scheduling in real-time systems n q q q Classification of scheduling algorithms Aperiodic scheduling Periodic scheduling Winter 2010 - CS 244 43
- Slides: 43