linux-yocto/kernel/sched
zihan zhou e9bed533ec sched: Reduce the default slice to avoid tasks getting an extra tick
[ Upstream commit 2ae891b826 ]

The old default value for slice is 0.75 msec * (1 + ilog(ncpus)) which
means that we have a default slice of:

  0.75 for 1 cpu
  1.50 up to 3 cpus
  2.25 up to 7 cpus
  3.00 for 8 cpus and above.

For HZ=250 and HZ=100, because of the tick accuracy, the runtime of
tasks is far higher than their slice.

For HZ=1000 with 8 cpus or more, the accuracy of tick is already
satisfactory, but there is still an issue that tasks will get an extra
tick because the tick often arrives a little faster than expected. In
this case, the task can only wait until the next tick to consider that it
has reached its deadline, and will run 1ms longer.

vruntime + sysctl_sched_base_slice =     deadline
        |-----------|-----------|-----------|-----------|
             1ms          1ms         1ms         1ms
                   ^           ^           ^           ^
                 tick1       tick2       tick3       tick4(nearly 4ms)

There are two reasons for tick error: clockevent precision and the
CONFIG_IRQ_TIME_ACCOUNTING/CONFIG_PARAVIRT_TIME_ACCOUNTING. with
CONFIG_IRQ_TIME_ACCOUNTING every tick will be less than 1ms, but even
without it, because of clockevent precision, tick still often less than
1ms.

In order to make scheduling more precise, we changed 0.75 to 0.70,
Using 0.70 instead of 0.75 should not change much for other configs
and would fix this issue:

  0.70 for 1 cpu
  1.40 up to 3 cpus
  2.10 up to 7 cpus
  2.8 for 8 cpus and above.

This does not guarantee that tasks can run the slice time accurately
every time, but occasionally running an extra tick has little impact.

Signed-off-by: zihan zhou <15645113830zzh@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org>
Link: https://lkml.kernel.org/r/20250208075322.13139-1-15645113830zzh@gmail.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2025-06-04 14:42:09 +02:00
..
autogroup.c
autogroup.h
build_policy.c
build_utility.c
clock.c Locking changes for v6.5: 2023-06-27 14:14:30 -07:00
completion.c sched: add a few helpers to wake up tasks on the current cpu 2023-07-17 16:08:08 -07:00
core_sched.c
core.c sched/cpufreq: Rework schedutil governor performance estimation 2025-05-02 07:50:41 +02:00
cpuacct.c
cpudeadline.c sched/topology: Consolidate and clean up access to a CPU's max compute capacity 2025-05-02 07:50:41 +02:00
cpudeadline.h
cpufreq_schedutil.c cpufreq/sched: Explicitly synchronize limits_changed flag handling 2025-05-02 07:50:41 +02:00
cpufreq.c
cpupri.c sched/rt: Fix live lock between select_fallback_rq() and RT push 2023-09-28 22:58:13 +02:00
cpupri.h
cputime.c sched/cputime: Fix mul_u64_u64_div_u64() precision for cputime 2024-08-14 13:58:47 +02:00
deadline.c sched/topology: Consolidate and clean up access to a CPU's max compute capacity 2025-05-02 07:50:41 +02:00
debug.c sched/debug: Provide slice length for fair tasks 2025-03-22 12:50:40 -07:00
fair.c sched: Reduce the default slice to avoid tasks getting an extra tick 2025-06-04 14:42:09 +02:00
features.h sched/eevdf: Curb wakeup-preemption 2023-08-17 17:07:07 +02:00
idle.c sched/fair: Rename check_preempt_curr() to wakeup_preempt() 2024-12-14 20:00:18 +01:00
isolation.c sched/isolation: Fix boot crash when maxcpus < first housekeeping CPU 2024-06-12 11:11:24 +02:00
loadavg.c
Makefile
membarrier.c sched/membarrier: reduce the ability to hammer on sys_membarrier 2024-02-23 09:25:27 +01:00
pelt.c
pelt.h
psi.c sched: psi: fix bogus pressure spikes from aggregation race 2024-10-10 11:58:03 +02:00
rt.c sched/topology: Consolidate and clean up access to a CPU's max compute capacity 2025-05-02 07:50:41 +02:00
sched-pelt.h
sched.h sched/cpufreq: Rework schedutil governor performance estimation 2025-05-02 07:50:41 +02:00
smp.h
stats.c profiling: remove profile=sleep support 2024-08-14 13:58:47 +02:00
stats.h sched: Move psi_account_irqtime() out of update_rq_clock_task() hotpath 2024-07-18 13:21:25 +02:00
stop_task.c sched: Unify runtime accounting across classes 2024-12-14 20:00:19 +01:00
swait.c sched: add a few helpers to wake up tasks on the current cpu 2023-07-17 16:08:08 -07:00
topology.c sched/topology: Consolidate and clean up access to a CPU's max compute capacity 2025-05-02 07:50:41 +02:00
wait_bit.c
wait.c sched: add a few helpers to wake up tasks on the current cpu 2023-07-17 16:08:08 -07:00