Realtime API¶
Scheduling Policies¶
Scheduling policies determine the scheduler’s way of assigning CPUs …
SCHED_OTHER
: the fair world (runnable processes are only added to pool of all runnables)SCHED_FIFO
(First-in first-out)Process gets CPU immediately assigned
Remains on CPU until he relinquishes
… or a higher prio process wants CPU
SCHED_RR
(Round Robin)Like
SCHED_FIFO
Equal prio processes: short timeslices in round robin order
Scheduling Priorities¶
0 … Reserved for good old fair processes (
SCHED_OTHER
)1 … lowest realtime priority
…
99 … highest realtime priority
What’s Runnning On A System?¶
Scheduling: System Calls¶
Manipulating scheduling attributes of a process:
-
int sched_setscheduler(pid_t pid, int policy, const struct sched_param *param); int sched_getscheduler(pid_t pid); struct sched_param { int sched_priority; };
Scheduling: Threads (1)¶
Manipulating scheduling attributes of an existing thread:
-
pthread_setschedparam( pthread_t thread, int policy, const struct sched_param *param); pthread_getschedparam( pthread_t thread, int *policy, struct sched_param *param);
Scheduling: Threads (2)¶
Start a new thread with predefinied scheduling attributes:
man 3 pthread_attr_setschedparam
int pthread_attr_setschedparam( pthread_attr_t *attr, const struct sched_param *param);
man 3 pthread_attr_setschedpolicy
int pthread_attr_setschedpolicy( pthread_attr_t *attr, int policy);
Priority Inversion¶
Priority Inversion: Mutex Protocols (1)¶
Solution, in spoken words: at the time that C wants the mutex, A has to carry on ⟶ protocol between both, communicated via the mutex
⟶ Mutex Attribute
man 3 pthread_mutexattr_setprotocol
int pthread_mutexattr_setprotocol( pthread_mutexattr_t *attr, int protocol);
Protocols
PTHREAD_PRIO_INHERIT
: A’s priority is temporarily* (until mutex is acquired) boosted to B’sPTHREAD_PRIO_PROTECT
: A’s priority is temporarily risen to a fixed limit ⟶ man 3 pthread_mutexattr_setprioceiling