Download presentation
Presentation is loading. Please wait.
Published byPresley Hawkey Modified over 9 years ago
1
CSE 522 Real-Time Scheduling (1) Computer Science & Engineering Department Arizona State University Tempe, AZ 85287 Dr. Yann-Hang Lee yhlee@asu.edu (480) 727-7507 1
2
Event and Time-Driven Threads Create a task with (name, priority, options, stacksize, main, …) initialization external trigger? Take actions and change system state ISR: to set/ clear events start_time=time( ) Task initialization computation Sleep(period - ( time( ) -start_time) ) 2
3
Multiple Events in One Thread void compute() { if (event1) then action1; if (event2) then action2; if (event3) then action3;. } or { for (i=0, i<n, i++) if event[i] then action[i]; } void compute() { if (event1) then action1; else if (event2) then action2; else if (event3) then action3;. } or { for (i=0, i<n, i++) { if event[i] then { action[i]; break;} } } 3
4
Real-time System Specification Logical correctness requirements: The computation produces correct outputs. Models of computation to describe inputs and computations Additional requirements on resource, security, reliability, etc. Finite state machine good for control logic and protocols, transition and activity Data flow – modular computations that are triggered by the availability of input data. Temporal correctness requirements: The computation produces outputs at the right time When the computation can get started and should be completed 4
5
Specification Patterns CategoryPatternExample Duration (stimuli and responses) minimum duration The system has a minimum 'off' period of 120 seconds before it reenters the cranking mode. maximum duration The system can only operate in engine cranking mode for no longer than 10 seconds at one time Periodic bounded recurrence The ABS controller checks for wheel skidding every 10 milliseconds.") Real-time order bounded response The detection of and response to rapid deceleration must occur within 0.015 seconds. bounded invariance If Error 502 is received, then the braking system is inhibited for 10 seconds. (S. Konrad and B.H.C. Cheng “Real-time specification patterns”, ICSE 2005) 5
6
RT Specification in FSM Duration of staying in a state Periodic activity in a state Bounded response for each transition Accumulated delay between multiple transitions Hierarchical FSM a state encloses a FSM enter a state activate a FSM Concurrent FSM FSMs run in parallel (active simultaneously) up down idle open 6
7
RT Embedded Systems: Terminology Some problem terms: job, task, process, activity, action, procedure, event, time, deadline, latency, slack time, execution time, aperiodic, sporadic, jitter, priority Job: unit of work that is scheduled and executed in the system control law computation, send a packet, read sensor data Task: set of jobs Processor: CPU + Bus + I/O Time (instant) and duration (interval) Release time, completion time, deadline (absolute or relative) 7
8
Terminology Hard deadline: late result is little or no value, or may lead to disaster need to validate (can you guarantee it?) Soft deadline: late result may still be useful probability of missing deadlines 95% of telephone switch connects in 10 seconds How serious is serious ? Tardiness: min{ 0, deadline - completion time} Usefulness: function of tardiness completion time value 8
9
Terminology: Temporal Parameters Release time: fixed ( r ), jitter [ r- , r+ ], sporadic or aperiodic Execution time: uncertainty from memory refresh, contention due to DMA, cache misses, interrupts, OS overhead execution path variations WCET: a “deterministic” parameter for the worst- case execution time a conservative measure an assumption to make scheduling and validation easier how can you measure the WCET of a job? 9
10
Task Model Periodic task T i : (examples ??) constant (or bounded) period, p i : inter-release time between two consecutive jobs phase i, utilization i = e i / p i, deadline (relative) D i Aperiodic and sporadic: (examples ??) uncertain interarrival times but with a minimum separation aperiodic: with a soft or no deadline sporadic: with a hard deadline ii i +p i i +3p i i +2p i eiei DiDi 10
11
waiting executing ready blocked suspended dispatched wake-up Task Functional Parameters Preemptivity: suspend the executing job and switch to the other one should a job (or a portion of job) be preemptable context switch: save the current process status (PC, registers, etc.) and initiate a ready job transmit a UDP package, write a block of data to disk, a busy waiting loop Preemptivity of resources: concurrent use of resources or critical section lock, semaphore, disable interrupts How can a context switch be triggered? Assume you want to preempt an executing job -- why a higher priority job arrives run out the time quantum 11
12
Task Scheduling Schedule: to determine which job is assigned to a processor at any time valid schedule: satisfies constraints (release time, WCET, precedence, etc.) feasible schedule: meet job deadlines Need an algorithm to generate a schedule optimal scheduling algorithm: always find a feasible schedule if and only if a feasible schedule exists Scheduler or dispatcher: the mechanism to implement a schedule 12
13
Clock-driven a schedule determines (off-line) which job to be executed at each instant static or cyclic predicable and deterministic scheduler: invoked by a timer multiple tables for different operation modes Task Scheduling p 1 = 6, e 1 = 3, d 1 = 6 p 2 = 8, e 2 = 3, d 2 = 8Major cycle = lcm (6,8) = 24 13
14
Weighted Round-robin interleave job executions allocate a time slice to each job in the FIFO queue time slice may vary while sharing the processor good for pipelined jobs Task Scheduling p 1 = 6, e 1 = 3, d 1 = 6 p 2 = 8, e 2 = 3, d 2 = 8Major cycle = lcm (6,8) = 24 14
15
Priority-driven The highest-priority job gets to run until completion or blocked processor never idle if jobs are waiting (work conserving) preemptive or nonpreemptive priority assignment can be static or dynamic scheduler just look at the priority queue for waiting jobs (list schedule) Task Scheduling p 1 = 6, e 1 = 3, d 1 = 6 p 2 = 8, e 2 = 3, d 2 = 8Major cycle = lcm (6,8) = 24 15
16
dkdk didi JkJk JiJi rkrk ( r k ) dkdk didi JkJk JkJk JiJi (non-EDF) (EDF) Earliest-deadline First (EDF) Schedule Priority preemptive scheduling a job with earliest (absolute) deadline has the highest priority does not require the knowledge of execution time Optimal if single processor, no resource contention, preemption why it is optimal: assume a feasible schedule 16
17
Least Slack Time (LST) Schedule Priority preemptive scheduling based on slack (laxity) time ( d i - e i * ) schedule instants: when jobs are released or completed. optimal for preemptive single processor schedule 17 J1J2J3J1J2J3 Slack time LST
18
Non-preemptive or multiple processors scheduling anomaly --- the schedule fails after we reduce job execution times Non-optimality of EDF T1T2T3T1T2T3 D1D1 D2D2 D3D3 Missed deadline idle ( all jobs meet their deadline under EDF after increasing e 1 ) 18
19
Predicable System With variant job execution times, do we know when a task is started or completed? If the start time and completion time are predicable, then we can determine whether a schedule is feasible or not Two extreme condition: maximal schedule: all jobs take their maximal execution times minimal schedule: all jobs take their minimal execution times A job is predicable iff its start time and complete time are predicable: s - ( J i ) s ( J i ) s + ( J i ) f - ( J i ) f ( J i ) f + ( J i ) The execution of every job in a set of independent, preemptive jobs with fixed release time is predictable when scheduled in a priority-driven manner on one processor (proved by induction) 19
20
On-line vs. Off-line Scheduling Off-line scheduling: the schedule is computed off-line and is based on the knowledge of the release times and execution times of all jobs. For deterministic systems: with fixed set of functions and job characteristics does not vary or vary only slightly. On-line scheduling: a scheduler makes each scheduling decision without knowledge about the jobs that will be released in the future. there is no optimal on-line schedule if jobs are non-preemptive when a job is released, the system can serve it or wait for the future jobs r1r1 r2r2 D2D2 D1D1 r1r1 r3r3 D 1 and D 3 ( should wait for J 2 ) ( should begin J 1 ) J1J1 J3J3 J2J2 J1J1 20
21
Clock-Driven Scheduling Assumption: system must be deterministic (with few aperiodic or sporadic jobs) periodic tasks ( I, p i, e i, D i ) Cyclic schedule: ( t k, T(t k ) ) -- at instance t k, run task set T(t k ) or idle Scheduler: Need a major cycle A table with entries for all t k in major cycle Timer interrupts at t k. An example: T1 =(4,1), T2 = (5,1.8), T3 = (20,1), T4 = (20,2) hyperperiod (major cycle) = 20 21 T 1 T 3 T 2 T 1 T 4 T 2 T 1 T 2 T 1 T 1 T 2
22
0102030405060 Major and Minor Cycle Model Time is divided into equal-sized frame minor cycle = length of frame Major cycle = length of schedule = k * minor_cycle An example: A=(10,4) B=(20,6) C=(30,5) major cycle=60, minor cycle=10 scheduling string AB_AC_AB_AC_AB_A_ Jobs must be done within a minor cycle limit timing error to one frame suspend and resume as background, continue, or abort if overrun 22
23
Determination of Minor Cycle (frame) Major cycle: H = LCM ( p i ) Frame: f devides H Tasks can be done within one minor cycle --- f e i There is at least one minor cycle between release time and deadline assume a frame starts at t task arrives at t’ t with a deadline D to have time for execution in the second frame, we need t + 2f t’ + D since t’ - t gcd ( f, p i ), we have a sufficient condition 2f - gcd ( f, p i ) D i t t+f t+2f t’ t’+D 23
24
Examples of Major/Minor Cyclic Scheduling Three tasks (15, 1, 14) (20, 2, 26) and (22,3) H = 660, f 3, and f = 3, 4, 5, 10, or 11 f can not too big since 2f - gcd(….) 14 f can be 3, 4, and 5 Three tasks (4, 1) (5, 2, 7) and (20, 5) H=20, f 5, but f 4 job slices: divide the 3rd task to (20, 1) (20, 3) and (20, 1) f can be 4 T 1 T 2 T 3,,1 T 1 T 3,2 T 1 T 2 T 3,3 T 1 T 2 T 1 T 2 24
25
Examples of Major/Minor Cyclic Scheduling Two tasks (100, 20) and (75, 15) choose f=25 run 1st task in high frequency (period =75) run 2nd task in higher frequency (period =50) harmonic set of periods 25
26
An Example A1 must be done at least every 10ms, and takes 1ms A2 must be completed with 5ms when E occurs and takes 2 ms E must be detected by polling and is detectable for at least 0.5 ms E would not occur twice within 50 ms polling of E takes 0 overhead 26 0.5ms
27
Major/Minor Cyclic Scheduling There should be a periodic polling action for E Assume a timer of 0.5ms to activate polling operation and no polling overhead Should be an interval of 2ms to execute A2 for an arbitrary 5ms interval May detect E in the first frame and execute A2 in the second frame period=2.5ms A2 takes 2ms if E, otherwise is 0 WCET=2ms Should be an interval of 1ms to execute A1 for an arbitrary 10ms interval Period= 10ms, WCET= 1ms Since 2ms + 1ms > 2.5ms, we will divide A1 into two parts of 0.5ms A2 A1_1 A2 A1_2 A2 A2 27
28
Algorithm to Find Major/Minor Cyclic Schedule Assume tasks can be sliced (or preemptable) choose f that divides H and 2f - gcd ( f, p i ) D i For each f, construct a network flow diagram a source and a sink a vertex for each job J i,j (task instance) and an edge from the source with a capacity e i a vertex for each frame f k and an edge from each frame to the sink with a capacity f if J i,j can be scheduled in f k, add an edge between the vertices with a capacity f Find the maximal flow from the source to the sink feasible schedule if the maximal flow equals to the total execution time 28
29
source sink J 1,1 f1f1 Example Three tasks (4, 1) (5, 2, 7) and (20, 5) H=20, f = 2 or 4 29
30
Aperiodic Tasks A periodic server follows the cyclic schedule A aperiodic server looks at the aperiodic task queue runs at the background Slack stealing slack time: how much each periodic task can be delayed Assume all tasks must be completed before the end of their frames and aperiodic tasks are not preemptable at frame k, e k is allocated to periodic tasks slack time: s= f - e k at the beginning of frame k, find a aperiodic task j with an execution time e j that is less than s try to run the other aperiodic task with a slack time: s=s - e j Do slack stealing at the beginning of each frame and then examine the queue when idle 30
31
Summary of Cyclic Schedule Pros simple, table-driven, easy to validate (knows what is doing at any moment) fit well for harmonic periods and small system variations static schedule deterministic, static resource allocation, no preemption small jitter no scheduling anomalies Cons difficult to change (need to re-schedule all tasks) fixed released times for the set of tasks difficult to deal with different temporal dependencies schedule algorithm may get complex (NP-hard) doesn’t support aperiodic and sporadic tasks efficiently 31
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.