Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCI1600: Embedded and Real Time Software Lecture 23: Real Time Scheduling I Steven Reiss, Fall 2015.

Similar presentations


Presentation on theme: "CSCI1600: Embedded and Real Time Software Lecture 23: Real Time Scheduling I Steven Reiss, Fall 2015."— Presentation transcript:

1 CSCI1600: Embedded and Real Time Software Lecture 23: Real Time Scheduling I Steven Reiss, Fall 2015

2 Scheduling Problem  Arduino Main Loop  Round-robin scheduler (with interrupts)  No preemption  Assuming not that much is time critical  Possibly one interrupt routine  What happens in a more complex system  We first must understand the components

3 Periodic Tasks  Execution time (e units) : max execution time  Release time (t – when it becomes available to run)  Period p: the time between releases  Deadline (d – relative to release time)  How quickly it needs to be processed  Default = period  P(p,e,d) : representation of a job  P(p,e) = P(p,e,p)  Goal: ensure all deadlines are met

4 Aperiodic Tasks  Background tasks that run occassionally  Arise at random (possibly with a distribution)  Soft deadlines  Can have priorities  Again have release time, deadline, execution time  GOAL: Execute these jobs as fast as possible  Average or worst case time

5 Sporadic Tasks  Response to interrupts or unusual events  Arise randomly (possibly with a distribution)  Hard deadlines  Again have release time, deadline, execution time  GOAL: ensure these can be serviced correctly  Accept or reject the job

6 Simplifying Assumptions  All jobs are preemptible at any time  Relaxations:  Not preemptible until non-runnable  Preempt at “safe” times (calling OS, acquiring synchronization)  Switching overhead is 0  No resource contention between jobs (no blocking)  Jobs don’t suspend voluntarily  Job execution time (max) is known  Simple processor  All of these can be taken into account, but things are more complex

7 Scheduling Problem  Given a set of periodic tasks, can they be scheduled  Can aperiodic tasks at a given rate be handled  Can all sporadic tasks be handled  Can we accept/reject a sporadic task when it arises  We first need to decide what type of solution we want

8 Solution Models: Fixed Schedule  Also call clock-based  Single schedule  Schedule is precomputed, stored in a table  Time allocated for aperiodic and sporadic tasks  Can be fully static (all decisions made in advance)  Can be static order  Order precomputed  When to run decided at run time

9 Solution Models: Fixed Priority  Assign priority to jobs as they arise  Priorities don’t change once they are assigned  Low numbers are higher priority  Highest priority job runs  Schedule reexamined as new jobs come in  Aperiodic and sporadic jobs are accommodated  Either directly by priority  Or by creating a periodic job for them

10 Solution Models: Dynamic Priority  Jobs are assigned priorities as they arise  But job priorities can be changed over time  Highest priority job runs  Schedule reexamined periodically & as new jobs arise  Accommodate aperiodic and sporadic jobs

11 Solution Models: Advanced  Multiple threads/cores/processors  Handling aperiodic and sporadic tasks  Relaxing assumptions  Resource scheduling

12 Example  Consider three jobs  P1(4,2), P2(6,2), P3(12,2)  Can we schedule these  How many time units do we have to consider

13 Schedule Representations  P1(4,2), P2(6,2), P3(12,2)

14 Schedule Representations  P1(4,2), P2(6,2), P3(12,2) P1 P2 P3

15 Scheduling Example  P1(4,1), P2(6,2), P3(12,3)

16 Schedule Representations  P1(4,1), P2(6,2), P3(12,3)

17 Scheduling Example  P1(4,2), P2(6,3), P3(12,1)

18 Clock-Based Scheduling  Set up fixed schedule in advance  Problem is NP-complete but can be solved  Done once off-line  Still need to handle aperiodic and sporadic tasks  Need to leave slack in schedule  We’ll get back to this  Pros and Cons  Simple to implement  Can use an optimal schedule  Assumes release times are fixed (no jitter)  Everything must be known in advance  Changing anything can be messy

19 Fixed Priority Scheduling  Basic Idea  Assign a priority to a job as it arrives  Not necessarily based on its a priori priority  Based on scheduling requirements  Job with highest priority is run  If a new job gets higher priority, it preempts running job  Implementaiton  Maintain a priority queue of jobs  New jobs are inserted into the queue  And may cause preemption

20 Fixed Priority Assignment  Problem: how to assign priorities  Rate Monotonic (RM) priority assignment  Priority is the period  Shortest task gets the highest priority  Deadline Monotonic (DM) priority assignment  Priority is the deadline  Jobs with shortest relative deadline gets highest priority  If deadline = period, these are the same

21 Rate Monotonic Example  P1(4,1), P2(5,2), P3(20,5)

22 Feasibility Analysis  How good is a RM/DM schedule?  What do you want to measure?  Utilization of the CPU  Does the algorithm produce a feasible schedule  If the jobs are schedulable  Under what circumstances  Necessary and Sufficient Schedule  All cycles are needed to service jobs and there are enough cycles to service jobs  Achieving this is NP-hard. Settle for sufficient (enough cycles)

23 Critical Instant Theorem  The critical instant for a job is the worst time to start it  The release time for which response is maximized  Theorem: The critical instant occurs (for periodic tasks with fixed priorities) when all higher priority jobs share the release time with the job in question  This is fairly robust : stays true even if we remove simplifying assumptions

24 Checking a Schedule  Notation  τ i – the ith task or the i th execution of task τ  D i – the relative deadline for the i th task  P i – the period of the i th task  e i – the execution time of the i th task

25 Checking a Schedule  Simple necessary and sufficient test of feasibility  Assuming synchronous release  Release jobs from all tasks at time t  Simulate until lowest priority job completes or misses  Only on deadline and release points

26 RM Priority Assigment  If a task set can be scheduled at all by a fixed priority schedule  It can be scheduled with a RM policy  Hence RM (or DM) is optimal in some sense  Define the utility of a task u i = e i /P i  The utility of a set of tasks is their sum  If Sum > 1 then the jobs can’t be scheduled  If Sum = 1 and tasks can be scheduled, algorithm is optimal  What can be done using RM/DM scheduling?

27 RM Scheduling

28 RM and DM Can Be Optimal  Simply Periodic  For every pair of tasks A and B with Pa < Pb, Pb is an integral multiple of Pa  Then we can schedule the jobs if Utilization <= 1  Can we do better in the general case?

29 Rate (Deadline) Monotonic  Jobs come in, are assigned a priority, highest runs  Consider (8,3), (9,3), (15,3)  Is this guaranteed to be schedulable?

30 Rate Monotonic Scheduling  Consider (10,2), (12,5), (15,4)  Utilization = 0.2 + 0.417 + 0.27 = 0.887  But RM fails: (WHY)

31 Rate Monotonic Scheduling  Consider (8,4), (10,2), (12,3)  Utilization = 0.5 + 0.2 + 0.25 = 0.95  RM fails: (WHY)

32 Dynamic Priority Scheduling  Priorities are changed dynamically for different tasks  Otherwise same simplifying assumptions  Approaches to assigning priorities  Basic idea: give priority to the job that needs it the most  Least laxity (least slack) first  Earliest deadline first

33 Homework  Read 12.3-12.4


Download ppt "CSCI1600: Embedded and Real Time Software Lecture 23: Real Time Scheduling I Steven Reiss, Fall 2015."

Similar presentations


Ads by Google