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 →| Name | What it does |
|---|---|
| SCHED_DEADLINE | Earliest-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_FORK | Children revert to SCHED_OTHER. Without it, fork(2) from a SCHED_DEADLINE thread fails with EAGAIN. |
| SCHED_FLAG_RECLAIM | Let a deadline task reclaim bandwidth other deadline tasks reserved but did not use. |
| SCHED_FLAG_DL_OVERRUN | Deliver SIGXCPU when the task overruns its runtime. |
Errors you will actually hit
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
Version numbers are read off the cited man pages, not memory. Spot one that's wrong? Tell Rod.
