TuToR 2017 Luca Abeni – 1 / 33
SCHED DEADLINE: a real-time CPU scheduler for Linux
Luca Abeni
luca.abeni@santannapisa.it
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
TuToR 2017 Luca Abeni – 1 / 33
luca.abeni@santannapisa.it
Introduction Real-Time Scheduling in Linux Setting the Scheduling Policy The Constant Bandwidth Server SCHED DEADLINE Using SCHED DEADLINE
TuToR 2017 Luca Abeni – 2 / 33
fj cj rj dj fj+1 cj+1 rj+1 dj+1
Γ = {τ0, ...τN−1}
OS?
reservations + EDF
Introduction Real-Time Scheduling in Linux Setting the Scheduling Policy The Constant Bandwidth Server SCHED DEADLINE Using SCHED DEADLINE
TuToR 2017 Luca Abeni – 3 / 33
them!)
Introduction Real-Time Scheduling in Linux Setting the Scheduling Policy The Constant Bandwidth Server SCHED DEADLINE Using SCHED DEADLINE
TuToR 2017 Luca Abeni – 4 / 33
implement RM and DM
(SCHED OTHER) tasks
when more tasks have the same priority
tasks with the same priority
Introduction Real-Time Scheduling in Linux Setting the Scheduling Policy The Constant Bandwidth Server SCHED DEADLINE Using SCHED DEADLINE
TuToR 2017 Luca Abeni – 5 / 33
int sched_get_priority_max (int policy ); int sched_get_priority_min (int policy ); int sched_setscheduler (pid_t pid , int policy , const struct sched_param *param ); int sched_setparam(pid_t pid , const struct sched_param *param );
task are changed
is sched priority
Introduction Real-Time Scheduling in Linux Setting the Scheduling Policy The Constant Bandwidth Server SCHED DEADLINE Using SCHED DEADLINE
TuToR 2017 Luca Abeni – 6 / 33
arrive (in an unpredictable way)
/ ...
tasks
Introduction Real-Time Scheduling in Linux Setting the Scheduling Policy The Constant Bandwidth Server SCHED DEADLINE Using SCHED DEADLINE
TuToR 2017 Luca Abeni – 7 / 33
scheduled in background respect to real-time ones
priority can make a CPU / core unusable void bad bad task ( )
{
while ( 1 ) ;
}
Introduction Real-Time Scheduling in Linux Setting the Scheduling Policy The Constant Bandwidth Server SCHED DEADLINE Using SCHED DEADLINE
TuToR 2017 Luca Abeni – 8 / 33
real-time priorities only when really needed!)
priorities requires root privileges (or part of them!)
Introduction Real-Time Scheduling in Linux Setting the Scheduling Policy The Constant Bandwidth Server SCHED DEADLINE Using SCHED DEADLINE
TuToR 2017 Luca Abeni – 9 / 33
unusable...
to address this problem
real-time guarantees?
guaranteed all the deadlines if no throttling mechanism is used...
founded” might be needed...
Introduction Real-Time Scheduling in Linux Setting the Scheduling Policy The Constant Bandwidth Server SCHED DEADLINE Using SCHED DEADLINE
TuToR 2017 Luca Abeni – 10 / 33
reservations
Linux?
deadlines...
the tasks!
Introduction Real-Time Scheduling in Linux Setting the Scheduling Policy The Constant Bandwidth Server SCHED DEADLINE Using SCHED DEADLINE
TuToR 2017 Luca Abeni – 11 / 33
deadlines
needed...
task...
too
Introduction Real-Time Scheduling in Linux Setting the Scheduling Policy The Constant Bandwidth Server SCHED DEADLINE Using SCHED DEADLINE
TuToR 2017 Luca Abeni – 12 / 33
beginning / end of a job (some kind of
startjob() / endjob() system call)...
arrives each time a task wakes up!
dynamic scheduling deadlines to tasks
Introduction Real-Time Scheduling in Linux Setting the Scheduling Policy The Constant Bandwidth Server SCHED DEADLINE Using SCHED DEADLINE
TuToR 2017 Luca Abeni – 13 / 33
to task τ
absolute deadline dj of a job, then the scheduler can respect dj!!!
Introduction Real-Time Scheduling in Linux Setting the Scheduling Policy The Constant Bandwidth Server SCHED DEADLINE Using SCHED DEADLINE
TuToR 2017 Luca Abeni – 14 / 33
assign a dynamic scheduling deadline ds to a task τ
runtime Q every reservation period P
depend on the other tasks running in the system...
reserved time
Introduction Real-Time Scheduling in Linux Setting the Scheduling Policy The Constant Bandwidth Server SCHED DEADLINE Using SCHED DEADLINE
TuToR 2017 Luca Abeni – 15 / 33
too much execution time
algorithm decreases its priority, or throttles it
consumed by a periodic task with WCET Q and period P
Introduction Real-Time Scheduling in Linux Setting the Scheduling Policy The Constant Bandwidth Server SCHED DEADLINE Using SCHED DEADLINE
TuToR 2017 Luca Abeni – 16 / 33
UP!)
assigned by the CBS), then τi is guaranteed to receive Qi time units every Pi if
j Qj/Pj ≤ 1!!!
receive Qi every Pi with a maximum delay
Introduction Real-Time Scheduling in Linux Setting the Scheduling Policy The Constant Bandwidth Server SCHED DEADLINE Using SCHED DEADLINE
TuToR 2017 Luca Abeni – 17 / 33
problems with aperiodic job arrivals - due to the (in)famous “deferrable server problem”
(see the rule for assigning deadlines when a task wakes up)
model
terminations
Introduction Real-Time Scheduling in Linux Setting the Scheduling Policy The Constant Bandwidth Server SCHED DEADLINE Using SCHED DEADLINE
TuToR 2017 Luca Abeni – 18 / 33
and a current runtime q
activation
deadline can be used (ds > t and
q/(ds − t) < Q/P )
ds ds = ds + P q = q + Q
Introduction Real-Time Scheduling in Linux Setting the Scheduling Policy The Constant Bandwidth Server SCHED DEADLINE Using SCHED DEADLINE
TuToR 2017 Luca Abeni – 19 / 33
Introduction Real-Time Scheduling in Linux Setting the Scheduling Policy The Constant Bandwidth Server SCHED DEADLINE Using SCHED DEADLINE
TuToR 2017 Luca Abeni – 20 / 33
SCHED DEADLINE tasks
(reservation) period P to SCHED DEADLINE tasks
be used” rule is used at task wake-up
possible
Introduction Real-Time Scheduling in Linux Setting the Scheduling Policy The Constant Bandwidth Server SCHED DEADLINE Using SCHED DEADLINE
TuToR 2017 Luca Abeni – 21 / 33
Qj Pj ≤ U L
partitioned scheduling
Introduction Real-Time Scheduling in Linux Setting the Scheduling Policy The Constant Bandwidth Server SCHED DEADLINE Using SCHED DEADLINE
TuToR 2017 Luca Abeni – 22 / 33
structures added to be extensible)
int sched_setattr(pid_t pid , const struct sched_attr *attr , unsigned int flags ); int sched_getattr(pid_t pid , struct sched_attr *attr , unsigned int size , unsigned int flags ); struct sched_attr { __u32 size; __u32 sched_policy; __u64 sched_flags; ... __u64 sched_runtime; __u64 sched_deadline; __u64 sched_period; };
Introduction Real-Time Scheduling in Linux Setting the Scheduling Policy The Constant Bandwidth Server SCHED DEADLINE Using SCHED DEADLINE
TuToR 2017 Luca Abeni – 23 / 33
sched attr)
Introduction Real-Time Scheduling in Linux Setting the Scheduling Policy The Constant Bandwidth Server SCHED DEADLINE Using SCHED DEADLINE
TuToR 2017 Luca Abeni – 24 / 33
programs?
3.14...
many Linux distributions
sched attr, etc...
sched *attr() system calls and related data
structures
Introduction Real-Time Scheduling in Linux Setting the Scheduling Policy The Constant Bandwidth Server SCHED DEADLINE Using SCHED DEADLINE
TuToR 2017 Luca Abeni – 25 / 33
#include "libdl/dl_syscalls.h" ... struct sched_attr attr; attr.size = sizeof(struct attr ); attr.sched_policy = SCHED_DEADLINE; attr.sched_runtime = 30000000; attr.sched_period = 100000000; attr.sched_deadline = 100000000; ... res = sched_setattr (0, &attr , 0); if (res < 0) perror (" sched_setattr ()"); ...
Introduction Real-Time Scheduling in Linux Setting the Scheduling Policy The Constant Bandwidth Server SCHED DEADLINE Using SCHED DEADLINE
TuToR 2017 Luca Abeni – 26 / 33
fails
Qj Pj ≤ M guarantees bounded tardiness for
global scheduling!
Introduction Real-Time Scheduling in Linux Setting the Scheduling Policy The Constant Bandwidth Server SCHED DEADLINE Using SCHED DEADLINE
TuToR 2017 Luca Abeni – 27 / 33
a set of tasks
cpusets can bee used to create isolated domains
mount -t tmpfs cgroup_root /sys/fs/cgroup mkdir /sys/fs/cgroup/cpuset mount -t cgroup
cpuset /sys/fs/cgroup/cpuset mkdir /sys/fs/cgroup/cpuset/Set1 echo 3 > /sys/fs/cgroup/cpuset/Set1/cpuset.cpus echo 0 > /sys/fs/cgroup/cpuset/Set1/cpuset.mems echo 0 > cpuset. sched_load_balance echo 1 > /sys/fs/cgroup/cpuset/Set1/cpuset. cpu_exclusive echo $PID > /sys/fs/cgroup/cpuset/Set1/tasks
Introduction Real-Time Scheduling in Linux Setting the Scheduling Policy The Constant Bandwidth Server SCHED DEADLINE Using SCHED DEADLINE
TuToR 2017 Luca Abeni – 28 / 33
tasks can fail
something different from global scheduling
inherited?
nanoseconds (not microseconds)
Introduction Real-Time Scheduling in Linux Setting the Scheduling Policy The Constant Bandwidth Server SCHED DEADLINE Using SCHED DEADLINE
TuToR 2017 Luca Abeni – 29 / 33
deadline D
Qj Pj ≤ M
Introduction Real-Time Scheduling in Linux Setting the Scheduling Policy The Constant Bandwidth Server SCHED DEADLINE Using SCHED DEADLINE
TuToR 2017 Luca Abeni – 30 / 33
the others
runtime larger than WCET, and server period smaller than task period)...
jobs’ deadlines!!!
UP / partitioned systems), or an upper bound for the tardiness is provided (if global scheduling is used)!!!
Introduction Real-Time Scheduling in Linux Setting the Scheduling Policy The Constant Bandwidth Server SCHED DEADLINE Using SCHED DEADLINE
TuToR 2017 Luca Abeni – 31 / 33
P must be larger than the ratio between average
execution time ci and average inter-arrival time
ti...
i → ∞ and there will be no
control on the task’s response times
(Markov chains, etc...)
Introduction Real-Time Scheduling in Linux Setting the Scheduling Policy The Constant Bandwidth Server SCHED DEADLINE Using SCHED DEADLINE
TuToR 2017 Luca Abeni – 32 / 33
can change during the tasks lifetime... So, how to dimension Q and P ?
(GRUB, ...)
try to reuse the residual
user-space daemon
s
Introduction Real-Time Scheduling in Linux Setting the Scheduling Policy The Constant Bandwidth Server SCHED DEADLINE Using SCHED DEADLINE
TuToR 2017 Luca Abeni – 33 / 33
tolerate short-term variations in the execution times...
added to SCHED DEADLINE!
reclaiming of unused CPU time
SCHED FLAG RECLAIM (2)