CFSの話 - __sched_period()で算出されるperiodの値
/* * The idea is to set a period in which each task runs once. * * When there are too many tasks (sysctl_sched_nr_latency) we have to stretch * this period because otherwise the slices get too small. * * p = (nr <= nl) ? l : l*nr/nl */ static u64 __sched_period(unsigned long nr_running) { u64 period = sysctl_sched_latency; unsigned long nr_latency = sched_nr_latency; if (unlikely(nr_running > nr_latency)) { period = sysctl_sched_min_granularity; period *= nr_running; } return period; }
if文の条件は実行中プロセス数 > sched_nr_latencyで、
* is kept at sysctl_sched_latency / sysctl_sched_min_granularity */ static unsigned int sched_nr_latency = 5;
と定義されてるから実行プロセス数が5を超えていなければsysctl_sched_latencyがreturnされるはず。
sysctl_sched_latencyの定義をみると
/* * Targeted preemption latency for CPU-bound tasks: * (default: 20ms * (1 + ilog(ncpus)), units: nanoseconds) * * NOTE: this latency value is not the same as the concept of * 'timeslice length' - timeslices in CFS are of variable length * and have no persistent notion like in traditional, time-slice * based scheduling concepts. * * (to see the precise effective timeslice length of your workload, * run vmstat and monitor the context-switches (cs) field) */ unsigned int sysctl_sched_latency = 20000000ULL;
と書いてあるので、返り値は20ms * (1 + ilog(ncpus))なのだろう。
デフォルトで代入されているのはncpusが1の時の値か。
一方、実行プロセス数が5を超えてる場合はsysctl_sched_min_granularity * nr_runningがreturnされるようだ。
sysctl_sched_min_granularityは
/* * Minimal preemption granularity for CPU-bound tasks: * (default: 4 msec * (1 + ilog(ncpus)), units: nanoseconds) */ unsigned int sysctl_sched_min_granularity = 4000000ULL;
なので、返り値は 4ms * (1 + ilog(ncpus)) * nr_runningなのだろう。
これもデフォルトはncpusが1の時か。