1

Does Linux 3.10 CFS have "timeslices"?

I am confused, because sched-design-CFS.txt clearly states:

CFS uses nanosecond granularity accounting and does not rely on any jiffies or other HZ detail. Thus the CFS scheduler has no notion of "timeslices" in the way the previous scheduler had, and has no heuristics whatsoever. There is only one central tunable (you have to switch on CONFIG_SCHED_DEBUG):

/proc/sys/kernel/sched_min_granularity_ns

which can be used to tune the scheduler from "desktop" (i.e., low latencies) to "server" (i.e., good batching) workloads.

But then multiple task scheduler tuning guides suggest two different formulas of calculating a "timeslice". (Depending on the number of runnable tasks.) For example this OpenSUSE guide.

I am running only SCHED_FIFO threads on isolated CPUs.

1 Answer 1

7

CFS doesn't have timeslices "in the way the previous scheduler had".

In CFS a timeslice is basically the duration between consecutive switches to grant CPU execution time to the same thread. This gives you two options:

  • All of your threads have enough time to execute for at least min_granularity_ns within one latency_ns. Then, your timeslice = scheduling period * (task's weight/total weight of tasks in the run queue)

  • There are too many threads to fit in the latency_ns, so your timeslices get bigger to accommodate more threads that want to run according to timeslice = number_of_running_tasks * sched_min_granularity_ns

This is why CFS stands for a Completely Fair Scheduler, as is doesn't exclude threads with lower priorities but rather indiscriminately extends the timeslices for everyone.

3
  • aha, excellent! Thank you. So seems that I only had trouble understanding the "doesn't have timeslices in the way the previous scheduler had". :) Thanks a lot!! Commented Jun 27, 2018 at 13:16
  • mind accepting the answer, then? ;) @VäinöErtanen Commented Jun 27, 2018 at 13:30
  • What about cgroups' CPU shares? How it affects the timeslice? Commented Mar 29, 2020 at 22:26

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.