I'm looking for the value of the time slice (or quantum) of my Linux kernel.
Is there a /proc
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.
I googled this tickets about same doubt of time slice of SCHED_RR in Linux. But I cannot get clear answer both from here and kernel source code. After further check, I found the key point is "RR_TIMESLICE" is the default time slice in jiffies, not millisecond! So, the default time slice of SCHED_RR is always 100ms, no matter what HZ you configured.
Same as the value of "/proc/sys/kernel/sched_rr_timeslice_ms", which input value in millisecond, but it store and output in jiffies! So, when your CONFIG_HZ=100, you will find that:
It's little bit confused. Hope this can help you to understand it!
The quantum allocated for a particular process may vary:
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.You can use
sched_rr_get_interval()
to get the SCHED_RR interval for a specific SCHED_RR process.CFS (which is default scheduler for processes) has no fixed timeslice, it is calculated at runtime depending of targeted latency (
sysctl_sched_latency
) and number of running processes. Timeslice could never be less than minimum granularity (sysctl_sched_min_granularity
).Timeslice will be always between
sysctl_sched_min_granularity
andsysctl_sched_latency
, which are defaults to 0.75 ms and 6 ms respectively and defined in kernel/sched/fair.c.But actual timeslice isn't exported to user-space.
There is some confusion in the accepted answer between
SCHED_OTHER
processes (i.e., those operating under the (default) non-realtime round-robin timesharing policy) andSCHED_RR
processes.The
sched_latency_ns
andsched_min_granularity_ns
files (which are intended for debugging purposes, and visible only if the kernel is configured withCONFIG_SCHED_DEBUG
) affect the scheduling ofSCHED_OTHER
processes. As noted in Alexey Shmalko's answer, the time slice under CFS is not fixed (and not exported to user space), and will depend on kernel parameters and factors such as the process's nice value.sched_rr_get_interval() returns a fixed value which is the quantum that a
SCHED_RR
process is guaranteed to get, unless it is preempted or blocks. On traditional Linux, theSCHED_RR
quantum is 0.1 seconds. Since Linux 3.9, the limit is adjustable via the/proc/sys/kernel/sched_rr_timeslice_ms
file, where the quantum is expressed as a millisecond value whose default is 100.