sched deadline a real time cpu scheduler for linux
play

SCHED DEADLINE: a real-time CPU scheduler for Linux Luca Abeni - PowerPoint PPT Presentation

SCHED DEADLINE: a real-time CPU scheduler for Linux Luca Abeni luca.abeni@santannapisa.it TuToR 2017 Luca Abeni 1 / 33 Scheduling Real-Time Tasks Introduction c j c j+1 Real-Time Scheduling in d j d j+1 f j f j+1 Linux r j r j+1


  1. SCHED DEADLINE: a real-time CPU scheduler for Linux Luca Abeni luca.abeni@santannapisa.it TuToR 2017 Luca Abeni – 1 / 33

  2. Scheduling Real-Time Tasks Introduction c j c j+1 Real-Time Scheduling in d j d j+1 f j f j+1 Linux r j r j+1 Setting the Scheduling Policy Consider a set of N real-time tasks The Constant � Bandwidth Server Γ = { τ 0 , ...τ N − 1 } SCHED DEADLINE Using SCHED DEADLINE Scheduled on M CPUs � Real-Time theory → lot of scheduling algorithms... � ...But which ones are available on a commonly used � OS? POSIX: fixed priorities � Can be used to do RM, DM, etc... � Multiple processors: DkC, etc... � Linux also provides SCHED DEADLINE : resource � reservations + EDF TuToR 2017 Luca Abeni – 2 / 33

  3. Definitions Introduction Real-time task τ : sequence of jobs J i = ( r i , c i , d i ) � Real-Time Scheduling in Linux Finishing time f i Setting the Scheduling � Policy The Constant Goal: f i ≤ d i � Bandwidth Server SCHED DEADLINE ∀ J i , or control the amount of missed deadlines � Using SCHED DEADLINE Schedule on multiple CPUS: partitioned or global � Schedule in a general-purpose OS � Open System (with online admission control) � Presence of non real-time tasks (do not starve � them!) TuToR 2017 Luca Abeni – 3 / 33

  4. Using Fixed Priorities with POSIX SCHED FIFO and SCHED RR use fixed priorities Introduction � Real-Time Scheduling in Linux They can be used for real-time tasks, to Setting the Scheduling � Policy The Constant implement RM and DM Bandwidth Server SCHED DEADLINE Real-time tasks have priority over non real-time � Using SCHED DEADLINE ( SCHED OTHER ) tasks The difference between the two policies is visible � when more tasks have the same priority In real-time applications, try to avoid multiple � tasks with the same priority TuToR 2017 Luca Abeni – 4 / 33

  5. Setting the Scheduling Policy Introduction int sched_get_priority_max (int policy ); Real-Time Scheduling in Linux int sched_get_priority_min (int policy ); Setting the Scheduling Policy int sched_setscheduler (pid_t pid , int policy , The Constant const struct sched_param *param ); Bandwidth Server int sched_setparam(pid_t pid , SCHED DEADLINE Using const struct sched_param *param ); SCHED DEADLINE If pid == 0 , then the parameters of the running � task are changed The only meaningful field of struct sched param � is sched priority TuToR 2017 Luca Abeni – 5 / 33

  6. Issues with Real-Time Priorities Open Systems → real-time tasks can dynamically Introduction � Real-Time Scheduling in Linux arrive (in an unpredictable way) Setting the Scheduling Policy The Constant Need to re-arrange priorities to respect RM / DM � Bandwidth Server SCHED DEADLINE / ... Using SCHED DEADLINE Interactions with non real-time tasks? � Scheduled in background respect to real-time � tasks Suboptimal utilization? � TuToR 2017 Luca Abeni – 6 / 33

  7. Real-Time Priorities vs “Regular Tasks” In general, “regular” ( SCHED OTHER ) tasks are Introduction � Real-Time Scheduling in Linux scheduled in background respect to real-time ones Setting the Scheduling Policy Real-time tasks can starve other applications � The Constant Bandwidth Server Example: the following task scheduled at high � SCHED DEADLINE Using priority can make a CPU / core unusable SCHED DEADLINE void bad bad task ( ) { while ( 1 ) ; } TuToR 2017 Luca Abeni – 7 / 33

  8. Starvation of Non Real-Time Tasks Introduction Starvation of non real-time tasks � Real-Time Scheduling in Linux Real-time computation have to be limited (use Setting the Scheduling � Policy The Constant real-time priorities only when really needed !) Bandwidth Server SCHED DEADLINE On sane systems, running applications with real-time � Using SCHED DEADLINE priorities requires root privileges (or part of them!) Not usable by everyone � TuToR 2017 Luca Abeni – 8 / 33

  9. Real-Time Throttling Introduction A “bad” high-priority task can make a CPU / core � Real-Time Scheduling in Linux unusable... Setting the Scheduling Policy ...Linux provides the real-time throttling mechanism � The Constant Bandwidth Server to address this problem SCHED DEADLINE Using SCHED DEADLINE How does real-time throttling interfere with � real-time guarantees? Given a priority assignment, a taskset is � guaranteed all the deadlines if no throttling mechanism is used... ...But, what happens in case of throttling? � Very useful idea, but something more “theoretically � founded” might be needed... TuToR 2017 Luca Abeni – 9 / 33

  10. Can We Do Better? Introduction Avoid starvation issues by using resource � Real-Time Scheduling in Linux reservations Setting the Scheduling Policy Use EDF instead of fixed priorities � The Constant Bandwidth Server CPU Reservations + EDF = SCHED DEADLINE !!! SCHED DEADLINE � Using SCHED DEADLINE So, how to implement EDF (or something similar) in � Linux? Issue: the kernel is (was?) not aware of tasks � deadlines... ...But deadlines are needed in order to schedule � the tasks! TuToR 2017 Luca Abeni – 10 / 33

  11. EDF in the Linux Kernel Introduction EDF assigns dynamic priorities based on absolute � Real-Time Scheduling in Linux deadlines Setting the Scheduling Policy So, a more advanced API for the scheduler is � The Constant Bandwidth Server needed... SCHED DEADLINE Using SCHED DEADLINE Assign at least a relative deadline D to the � task... We will see that we need a runtime and a period � too Moreover, d j = r j + D ... � ...However, how can the scheduler know r j ? � The scheduler is not aware of jobs... � TuToR 2017 Luca Abeni – 11 / 33

  12. Tasks, and Jobs... EDF → need to know when a job starts / finishes Introduction � Real-Time Scheduling in Linux Applications must be modified to signal the Setting the Scheduling � Policy The Constant beginning / end of a job (some kind of Bandwidth Server startjob() / endjob() system call)... SCHED DEADLINE Using SCHED DEADLINE ...Or the scheduler can assume that a new job � arrives each time a task wakes up! Or, some other algorithm can be used to assign � dynamic scheduling deadlines to tasks TuToR 2017 Luca Abeni – 12 / 33

  13. ...And Scheduling Deadlines! Introduction The scheduler does EDF on scheduling deadlines � Real-Time Scheduling in Linux Scheduling deadline d s : assigned by the kernel Setting the Scheduling � Policy to task τ The Constant Bandwidth Server SCHED DEADLINE But the task cares about its absolute deadlines � Using SCHED DEADLINE If the scheduling deadline d s matches the � absolute deadline d j of a job, then the scheduler can respect d j !!! TuToR 2017 Luca Abeni – 13 / 33

  14. CBS: The Basic Idea Introduction Constant Bandwidth Server (CBS): algorithm used to � Real-Time Scheduling in assign a dynamic scheduling deadline d s to a task τ Linux Setting the Scheduling Policy Based on the Resource Reservation paradigm � The Constant Bandwidth Server Task τ is periodically reserved a maximum SCHED DEADLINE � Using SCHED DEADLINE runtime Q every reservation period P Temporal isolation between tasks � The worst case finishing time for a task does not � depend on the other tasks running in the system... ...Because the task is guaranteed to receive its � reserved time TuToR 2017 Luca Abeni – 14 / 33

  15. CBS: Some More Details Introduction Solves the issue with “bad tasks” trying to consume � Real-Time Scheduling in Linux too much execution time Setting the Scheduling Policy Based on CPU reservations ( Q, P ) � The Constant Bandwidth Server If τ tries to execute for more than Q every P , the SCHED DEADLINE � Using SCHED DEADLINE algorithm decreases its priority, or throttles it τ consumes the same amount of CPU time � consumed by a periodic task with WCET Q and period P Q/P : fraction of CPU time reserved to τ � TuToR 2017 Luca Abeni – 15 / 33

  16. CBS: Admission Control Introduction The CBS is based on EDF � Real-Time Scheduling in Linux Assigns scheduling deadlines d s Setting the Scheduling � Policy EDF on d s ⇒ good CPU utilization (optimal on The Constant � Bandwidth Server SCHED DEADLINE UP!) Using SCHED DEADLINE If EDF is used (based on the scheduling deadlines � assigned by the CBS), then τ i is guaranteed to receive Q i time units every P i if � j Q j /P j ≤ 1 !!! Only on uni-processor / partitioned systems... � M CPUs / cores with global scheduling: if � � j Q j /P j ≤ M each task is guaranteed to receive Q i every P i with a maximum delay TuToR 2017 Luca Abeni – 16 / 33

  17. CBS vs Other Reservation Algorithms Introduction The CBS allows to serve non periodic tasks � Real-Time Scheduling in Linux Some reservation-based schedulers have Setting the Scheduling � Policy The Constant problems with aperiodic job arrivals - due to the Bandwidth Server SCHED DEADLINE (in)famous “deferrable server problem” Using SCHED DEADLINE The CBS explicitly supports aperiodic arrivals � (see the rule for assigning deadlines when a task wakes up) Allows to support “self-suspending” tasks � No need to strictly respect the Liu&Layland task � model No need to explicitly signal job arrivals / � terminations TuToR 2017 Luca Abeni – 17 / 33

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend