$RodHat_/search
Syscall reference · Scheduling

sched_setattr(2)

Set scheduling policy and attributes for a thread, including SCHED_DEADLINE runtime/deadline/period reservations.

Since
Linux 3.14check your kernel →
glibc
none (use syscall(2))
System
Linux
Man page
sched_setattr(2)

Synopsis

#include <linux/sched/types.h>
#include <sys/syscall.h>
#include <unistd.h>

long syscall(SYS_sched_setattr, pid_t pid, struct sched_attr *attr,
             unsigned int flags);

Rod's take

SCHED_FIFO makes you pick a priority and pray nothing else needs the CPU. SCHED_DEADLINE makes you state a budget (runtime every period) and the kernel either guarantees it or says no up front with EBUSY. That refusal is the feature. Mind the traps: it needs CAP_SYS_NICE, children can't inherit it without RESET_ON_FORK, and a task that overruns its runtime is throttled until the next period, so size the runtime from measured worst case, not the average.

Flags and arguments that matter

Browse flag index →
NameWhat it does
SCHED_DEADLINEEarliest-deadline-first policy. sched_runtime, sched_deadline and sched_period (nanoseconds) must satisfy runtime <= deadline <= period. Admission control rejects reservations the CPUs cannot honor.
SCHED_FLAG_RESET_ON_FORKChildren revert to SCHED_OTHER. Without it, fork(2) from a SCHED_DEADLINE thread fails with EAGAIN.
SCHED_FLAG_RECLAIMLet a deadline task reclaim bandwidth other deadline tasks reserved but did not use.
SCHED_FLAG_DL_OVERRUNDeliver SIGXCPU when the task overruns its runtime.

Errors you will actually hit

errnoMeaning
EBUSYSCHED_DEADLINE admission control failed: the requested bandwidth does not fit.
EPERMCaller lacks CAP_SYS_NICE (or the RLIMIT_RTPRIO equivalent for RT policies).
EINVALBad attr: size, or runtime/deadline/period ordering violated.

Example

# 5ms of CPU every 10ms, deadline 10ms (values in nanoseconds)
chrt -d --sched-runtime 5000000 --sched-deadline 10000000 --sched-period 10000000 0 ./rt-worker

# inspect
chrt -p "$pid"

Trimmed from the full walkthrough in SCHED_DEADLINE: ask the kernel for a CPU budget and get told no.

BSD equivalent

No SCHED_DEADLINE. FreeBSD has rtprio(2) and POSIX SCHED_FIFO/SCHED_RR via sched_setscheduler(2); there is no admission-controlled reservation scheduler.

The long version, from the console

Sources

  1. sched_setattr(2), man7.org
  2. sched(7), man7.org
  3. chrt(1), man7.org

Version numbers are read off the cited man pages, not memory. Spot one that's wrong? Tell Rod.