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:

  • man 2 sched_setscheduler

    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:

  • man 3 pthread_setschedparam

        pthread_t thread, int policy,
        const struct sched_param *param);
        pthread_t thread, int *policy,
        struct sched_param *param);

Scheduling: Threads (2)

Start a new thread with predefinied scheduling attributes:

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


  • PTHREAD_PRIO_INHERIT: A’s priority is temporarily* (until mutex is acquired) boosted to B’s

  • PTHREAD_PRIO_PROTECT: A’s priority is temporarily risen to a fixed limit ⟶ man 3 pthread_mutexattr_setprioceiling