backlash backlash - 5 months ago 49
Linux Question

How to know linux scheduler time slice?

I'm looking for the value of the time slice (or quantum) of my Linux kernel.

Is there a

file which expose such an information ?

(Or) Is it well-defined in the Linux header of my distributions ?

(Or) Is there a C function of the Linux API (maybe sysinfo) that expose this value ?

Thanks in advance.

Answer Source

The default Linux timeslice for realtime processes 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)

Note that the actual quantum allocated for a particular process may be different than this value:

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.

However, you can use sched_rr_get_interval() to get the SCHED_RR interval for a given realtime process.