How to know linux scheduler time slice?

The quantum allocated for a particular process may vary:

You can tune “slice” by adjusting sched_latency_ns and
sched_min_granularity_ns, but note that “slice” is not a fixed
quantum. Also note that CFS preemption decisions are based upon
instantaneous state. A task may have received a full (variable)
“slice” of CPU time, but preemption will be triggered only if a more
deserving task is available, so a “slice” is not the “max
uninterrupted CPU time” that you may expect it to be.. but it is
somewhat similar.

This is because the Completely Fair Scheduler, the default Linux scheduler, assigns a proportion of the processor to a process rather than a fixed timeslice. That means the timeslice for each process is proportional to the current load and weighted by the process’ priority value.

For special-purpose realtime processes which use SCHED_RR, the default timeslice is defined in the Linux kernel as RR_TIMESLICE in include/linux/sched/rt.h.

/*
 * default timeslice is 100 msecs (used only for SCHED_RR tasks).
 * Timeslices get refilled after they expire.
 */
#define RR_TIMESLICE            (100 * HZ / 1000)

You can use sched_rr_get_interval() to get the SCHED_RR interval for a specific SCHED_RR process.

Leave a Comment