1 / 28

Process Scheduling for RTS

Process Scheduling for RTS. RTS Scheduling Approach. RTS typically control multiple parameters concurrently Eg. Flight Control System Speed, altitude, inclination etc.. Options Use a single process Simple/limited approach but can be dangerous No OS required Use multiple processes

Télécharger la présentation

Process Scheduling for RTS

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. Process Scheduling for RTS Dr. Hugh Melvin, Dept. of IT, NUI,G

  2. RTS Scheduling Approach • RTS typically control multiple parameters concurrently • Eg. Flight Control System • Speed, altitude, inclination etc.. • Options • Use a single process • Simple/limited approach but can be dangerous • No OS required • Use multiple processes • More complex but more robust • Use threads • Light weight relative to processes Dr. Hugh Melvin, Dept. of IT, NUI,G

  3. Cyclic Executive Approach • Single Process while(1){ Task 1; Task 2; .. .. Task n; } • Encapsulate all tasks within single infinite loop Dr. Hugh Melvin, Dept. of IT, NUI,G

  4. Cyclic Executive • Ok for very well defined / periodic tasks with bounded execution times • Need to ensure that tasks cannot block and halt all others • May need to slow it down to meet particular task reqds • Eg. Above example will run as fast as processor can handle tasks • Possible Strategy • Run as fast as required by highest freq task • Use lower harmonics for remaining tasks • Eg. Highest freq Task is 100 Hz • Other tasks at 50Hz, 25 Hz etc • Possible use counters to control sequence • Possible use of timers to sleep • Limited scope for aperiodic tasks eg. Interrupts • Hardware specificvery limited portability Dr. Hugh Melvin, Dept. of IT, NUI,G

  5. Cyclic Executive • AS Example • Cyclic executive approach • Each AS station handles well defined tasks • Execution time of each task precisely known • Task schedule customised s.t.total task runtime will facilitate/meet response time • Slack time in each cycle built in for interrupt processing • If total task time exceeded repeatedly, timeout fault Dr. Hugh Melvin, Dept. of IT, NUI,G

  6. Multiple Process Approach • Each process is much more simple as handling a small subset of overall system • Overall system • More robust and reliable • More scalable • Can run on multiprocessor machine • Modular • Process code more portable • Protected • Each process operates in isolation with dedicated memory  less risk of overall system failure • Downside • Requires an OS to schedule multiple processes • More memory reqd for process overhead • Communication between processes has to be explicitly done (advantage!) Dr. Hugh Melvin, Dept. of IT, NUI,G

  7. Multiple Process • Generic Process States • Dormant : Process created but not eligible to execute • Ready: Process released and eligible to execute but not doing so • May be preempted • May have been blocked for resources  move to ready • May have reached end of timeslice • Executing: Process being executed • Suspended (Blocked): Process waiting for resource to be freed or self-suspended • Terminated: Process finished execution Dr. Hugh Melvin, Dept. of IT, NUI,G

  8. Process State Diagram Pre-empt or Timeslice allocated Executing Blocked/ Self suspended Resource freed Blocked Preempted, timeslice up Ready Resource freed Process terminated Schedule Task Terminated Dormant Dr. Hugh Melvin, Dept. of IT, NUI,G

  9. Scheduling for RTS • Fundamental OS function • More critical for RTS • Allocating resources and scheduling tasks to ensure that deadlines are met • Schedule is feasible iff all the tasks start after their release time and complete before their deadlines • Scheduling Policy may be determined • Pre-run-time • Schedule created offline • Not unlike Cyclic Executive approach • Run-time • Schedule determined online as tasks arrive • Needs to be done quickly! Dr. Hugh Melvin, Dept. of IT, NUI,G

  10. Scheduling for RTS • Static versus Dynamic Priority • Static Priority Scheduling Alg. • Task priority does not change • Rate Monotonic Alg. • Dynamic Priority Scheduling Alg. • Priority can change over time • Earliest Deadline First (EDF) • Preemptive versus non-preemptive • Preemptive Schedule • Task can be preempted by other tasks • Penalty of context switches • Non preemptive • Task runs to completion unless blocked over resource Dr. Hugh Melvin, Dept. of IT, NUI,G

  11. Task Characteristics Ti • Precedence Constraints • Other tasks reqd before task Ti can run • Release Time of task Ti = ri • PhaseΦi of task Ti = release time of 1st instance of task Ti • Execution time ei of task Ti = time (worst case) for task to complete • Period pi = interval between consecutive instances of task Ti (presuming periodic) • Absolute Deadline Di = instant by which task must be complete • Relative Deadline di .. Relative to release time ri Dr. Hugh Melvin, Dept. of IT, NUI,G

  12. Task Characteristics Ti pi di ei Di ri Φi Dr. Hugh Melvin, Dept. of IT, NUI,G

  13. Simplifications • All tasks are periodic • Relative deadline is equal to period • No precedence constraints • No task has any non-preemptible sections • Cost of preemption is zero • Non CPU resources are infinite eg. Memory / I/O •  limited use in the real world! Dr. Hugh Melvin, Dept. of IT, NUI,G

  14. Rate Monotonic Scheduling • Run time scheduling, Static priority and Preemptive • Priority inversely related to period • Eg. Given task Ti and Tj where pi < pj • Priority of task Ti greater than Tj • Scheduling decision made when • Current task execution complete • New task released • Recall: In real world, RTS tasks with higher freq typically require shortest response times and are the most critical • Recall task Ti utilisation ui = ei / pi • Overall CPU Utilisation U = Dr. Hugh Melvin, Dept. of IT, NUI,G

  15. RM Example All Tasks released at time 0 Priority T1 > T2 > T3 Overall U = 0.9 Sequence 1st inst Task 1 runs to completion 1st inst Task 2 runs to completion 1st inst Task 3 runs for 1 unit ..at Eu=4, Task 1 released  preempts Task 3 2nd inst Task 1 runs to completion ..at Eu =5, Task 2 released 2nd inst Task 2 runs to completion 1st inst Task 3 runs for 1 unit .. At Eu = 8, Task 1 released  preempts Task3 3rd inst Task 1 runs to completion 1st inst Task 3 runs for 1 unit .. At Eu = 10, 3rd inst of Task 2 released  preempts 3 .. At Eu = 15, 1st inst Task 3 completes.. CPU idle Eu 18-20 At Eu = 20, all 3 tasks released .. Cycle repeats 1 2 2 3 1 2 2 3 1 3 2 2 1 3 3 2 1 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Execution Units Eu Dr. Hugh Melvin, Dept. of IT, NUI,G

  16. RM Scheduling • General schedulability test • If overall CPU utilisation U <= n(21/n -1) • where n = no of tasks • RM will definitely produce feasible schedule • However • RM may produce feasible schedule where • U > n(21/n -1) • i.e. Sufficient but not necessary condition • Recall Example: CPU U = 0.9 but still schedulable • Depends on particular task characteristics • May need to perform further schedulability analysis • As Task no increases, bound  69% Dr. Hugh Melvin, Dept. of IT, NUI,G

  17. Utilisation Bound for RM Alg. 1 0.83 0.78 0.69 0.73 Bound ∞ 1 2 3 4 5 6 10 No of Tasks Dr. Hugh Melvin, Dept. of IT, NUI,G

  18. Earliest Deadline First (EDF) • Dynamic priority and preemptable • Ready task whose absolute deadline is the earliest given highest priority • Task priorities are reevaluated when tasks released/completed • EDF is an optimal uniprocessor sched alg • If all tasks are periodic • Task 1…n ; CPU U = • If U <=1, then task set is EDF schedulable Dr. Hugh Melvin, Dept. of IT, NUI,G

  19. EDF Example All Tasks released at time 0 Overall U = 0.9 Sequence 1st inst Task 1 runs 1st as earliest deadline of 4 1st inst Task 2 runs to completion 1st inst Task 3 runs for 1 unit ..note: Deadline is 20 ..at Eu=4, Task 1 rel.  preempy Task 3 as deadline is 8 2nd inst Task 1 runs to completion ..at Eu =5, Task 2 released 2nd inst Task 2 runs to completion as deadline is 10 1st inst Task 3 runs for 1 unit .. At Eu = 8, Task 1 released  preempts Task3 3rd inst Task 1 runs to completion 1st inst Task 3 runs for 1 unit .. At Eu =10, Task 2 rel.. Preempts task 3 as deadline is 15 .. At Eu =12, Task 1 runs as deadline 16 < 20 At Eu =15 Task 2 released and runs with deadline 20 At Eu =16 Task 1 rel with deadline 20  no preemption 1 2 2 3 1 2 2 3 1 3 2 2 1 3 3 2 2 1 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Execution Units Eu Dr. Hugh Melvin, Dept. of IT, NUI,G

  20. EDF Example All Tasks released at time 0 Overall U = 0.93 Sequence 1st inst Task 1 runs 1st as earliest deadline of 3 1st inst Task 2 runs to completion .. At Eu=3, 2nd inst Task 1 rel & runs as deadline is 6 1st inst Task 3 runs ..at Eu=5, Task 2 rel.  doesn’t preempt Task 3 as deadline is also 10 .. Task 3 completes .. At Eu = 6, Task 1 released deadline 9 runs .. At Eu = 7 Task 2 runs to completion .. At Eu =9, Task 1 rel  deadline 12 ..runs .. At Eu =10, Task 3 rel. deadline 20, Task 2 also rel with deadline 15 Task 2 runs .. At Eu =15, Task 1 and 2 released with deadlines 16,20  Task 1 runs .. At Eu=16, Task 2 runs .. At Eu = 18 Task 1 rel with deadline 21 but Task 3 has deadline 20  Task 3 runs 1 2 2 1 3 3 1 2 2 1 2 2 1 3 3 1 2 2 3 3 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Execution Units Eu Dr. Hugh Melvin, Dept. of IT, NUI,G

  21. EDF vs RM • With RM, priorities fixed • Lowest period tasks guaranteed proc time • Only higher period tasks will miss deadlines • In overload conditions, same lower priority tasks lose out • Bound on CPU utilisation must be considered • EDF, dynamic priority • More flexible.. Less predictable • All tasks may miss deadlines • Schedulable if CPU U <=1 • May react poorly to overload condition Dr. Hugh Melvin, Dept. of IT, NUI,G

  22. Conventional OS Scheduling • Time Sharing Emphasis • Balance needs of interactive and CPU intensive traffic • Complex alg • Constantly adjust process priority • CPU intensive processes lose priority as they run • As a process waits, priority is increased  will get CPU slot sooner • Unix command nice • nice -20 process_high_priority • nice +20 process_low_priority • nice will work but underlying sched alg unchanged • Windows RealTime Threads • Somewhat equivalent Dr. Hugh Melvin, Dept. of IT, NUI,G

  23. POSIX.4 RT Scheduling • Defines two main scheduling policies • SCHED_FIFO and SCHED_RR • Each have attributes • Also have SCHED_OTHER • Currently a single attribute = priority struct sched_param{ int sched_priority; } • Eg. Could implement EDF by extending structure to include • struct timespec sched_deadline; • struct timespec sched_timerequired; Dr. Hugh Melvin, Dept. of IT, NUI,G

  24. POSIX.4 RT Scheduling • SCHED_FIFO • Simple priority based preemptive scheduler • Most common in RTS • FIFO used to schedule processes within each priority level • If no other process exists at higher priority, process runs until complete • Next process at that priority (if present) then allocated CPU • Highest priority process guaranteed processor time Dr. Hugh Melvin, Dept. of IT, NUI,G

  25. POSIX.4 RT Scheduling • SCHED_RR • Round robin used to timeslice among processes at same priority level • System provided timeslice • Use for lower priority tasks Dr. Hugh Melvin, Dept. of IT, NUI,G

  26. POSIX.4 RT Scheduling • Setting scheduling policy and attribute #include <sched.h> struct sched_param scheduling_parameters; int scheduling_policy; int i; scheduling_parameters.sched_priority=17; i=sched_setscheduler(getpid( ),SCHED_FIFO, &scheduling_parameters); • getpid( ) used to determine process ID • Process set to FIFO, priority 17 Dr. Hugh Melvin, Dept. of IT, NUI,G

  27. POSIX.4 RT Scheduling • Process priority ranges differ among OS • Need this info before setting priority level int sched_rr_min, sched_rr_max; int sched_fifo_min, sched_fifo_max; sched_rr_min=sched_get_priority_min(SCHED_RR); sched_rr_max=sched_get_priority_max(SCHED_RR); sched_fifo_min=sched_get_priority_min(SCHED_FIFO); sched_fifo_max=sched_get_priority_max(SCHED_FIFO); • Eg. 256 priority levels • FIFO range 128-255 • RR range 0-127 Dr. Hugh Melvin, Dept. of IT, NUI,G

  28. POSIX.4 RT Scheduling Eg. #include<sched.h> int i; struct sched_param my_sched_params; // determine max FIFO priority level my_sched_params.sched_priority= sched_get_priority_max(SCHED_FIFO); // Set priority i=sched_setparam(getpid (),&my_sched_params); Dr. Hugh Melvin, Dept. of IT, NUI,G

More Related