1 / 31

CSE 522 Real-Time Scheduling (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. Event and Time-Driven Threads. Create a task with (name, priority, options, stacksize , main, …). initialization.

chace
Download Presentation

CSE 522 Real-Time Scheduling (1)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSE 522 Real-Time Scheduling (1) Computer Science & Engineering DepartmentArizona State University Tempe, AZ 85287 Dr. Yann-Hang Leeyhlee@asu.edu(480) 727-7507

  2. Event and Time-Driven Threads Create a task with (name, priority, options, stacksize, main, …) initialization Task initialization external trigger? start_time=time( ) ISR: to set/ clear events computation Take actions and change system state Sleep(period - ( time( ) -start_time) )

  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; } } }

  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

  5. Specification Patterns (S. Konrad and B.H.C. Cheng “Real-time specification patterns”, ICSE 2005)

  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 open idle down

  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)

  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 value completion time

  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?

  10. Task Model • Periodic task Ti: (examples ??) • constant (or bounded) period, pi: inter-release time between two consecutive jobs • phase i, utilization i = ei / pi, deadline (relative) Di • Aperiodic and sporadic: (examples ??) • uncertain interarrival times but with a minimum separation • aperiodic: with a soft or no deadline • sporadic: with a hard deadline Di ei i+pi i+2pi i i+3pi

  11. wake-up waiting ready suspended dispatched blocked executing 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

  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

  13. Task Scheduling • 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 p1= 6, e1= 3, d1= 6 p2= 8, e2= 3, d2= 8 Major cycle = lcm (6,8) = 24

  14. Task Scheduling • 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 p1= 6, e1= 3, d1= 6 p2= 8, e2= 3, d2= 8 Major cycle = lcm (6,8) = 24

  15. Task Scheduling • Priority-driven • The highest-priority job gets to run until completion or blocked • processor never idle if jobs are waiting (work conserving) • preemptive ornonpreemptive • priority assignment can be static or dynamic • scheduler just look at the priority queue for waiting jobs (list schedule) p1= 6, e1= 3, d1= 6 p2= 8, e2= 3, d2= 8 Major cycle = lcm (6,8) = 24

  16. Earliest-deadline First (EDF) Schedule Ji Jk (non-EDF) dk di rk ( rk) Jk Jk Ji (EDF) dk di 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

  17. J1 J2 J3 Slack time LST Least Slack Time (LST) Schedule Priority preemptive scheduling based on slack (laxity) time ( di - ei* ) • schedule instants: when jobs are released or completed. • optimal for preemptive single processor schedule

  18. Non-optimality of EDF • Non-preemptive or multiple processors • scheduling anomaly --- the schedule fails after we reduce job execution times D1 D3 D2 T1 T2 T3 Missed deadline idle ( all jobs meet their deadline under EDF after increasing e1 )

  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- ( Ji )  s ( Ji )  s+ ( Ji ) • f - ( Ji )  f ( Ji )  f+ ( Ji ) • 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)

  20. J2 J1 ( should wait for J2) r2 D1 r1 D2 J3 J1 ( should begin J1) r3 D1 and D3 r1 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

  21. Clock-Driven Scheduling • Assumption: • system must be deterministic (with few aperiodic or sporadic jobs) • periodic tasks ( I , pi, ei, Di ) • Cyclic schedule: ( tk, T(tk) ) -- at instancetk, run task set T(tk) or idle • Scheduler: • Need a major cycle • A table with entries for all tk in major cycle • Timer interrupts at tk. • An example: • T1 =(4,1), T2 = (5,1.8), T3 = (20,1), T4 = (20,2) • hyperperiod (major cycle) = 20 T1 T3 T2 T1 T4 T2 T1 T2 T1 T1 T2

  22. 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 0 10 20 30 40 50 60

  23. t+2f t’+D t’ t+f t Determination of Minor Cycle (frame) • Major cycle: H= LCM ( pi ) • Frame: f devides H • Tasks can be done within one minor cycle --- f  ei • 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, pi ), we have a sufficient condition 2f - gcd ( f, pi )  Di

  24. T1 T2 T3,,1 T1 T3,2 T1 T2 T3,3 T1 T2 T1 T2 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

  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

  26. 0.5ms 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

  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 A2A2 A1_1 A2 A1_2 A2 A2

  28. Algorithm to Find Major/Minor Cyclic Schedule • Assume tasks can be sliced (or preemptable) • choose f that divides H and 2f - gcd ( f, pi )  Di • For each f, construct a network flow diagram • a source and a sink • a vertex for each job Ji,j(task instance) and an edge from the source with a capacity ei • a vertex for each frame fk and an edge from each frame to the sink with a capacity f • if Ji,jcan be scheduled in fk, 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

  29. J1,1 f1 sink source Example • Three tasks (4, 1) (5, 2, 7) and (20, 5) • H=20, f = 2 or 4

  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, ek is allocated to periodic tasks • slack time: s= f - ek • at the beginning of frame k, find a aperiodic task j with an execution time ej that is less than s • try to run the other aperiodic task with a slack time: s=s - ej • Do slack stealing at the beginning of each frame and then examine the queue when idle

  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

More Related