sched/core: Bypass arch_scale_freq_tick() on nohz_full CPUs
PATCH 1/1 sched/core: Bypass arch_scale_freq_tick() on nohz_full CPUs
arch_scale_freq_tick() calculations generally track the increment of frequency performance counters in between scheduler ticks to provide estimations on how DVFS swayed frequency on that CPU. This information eventually allows for more precise scheduling decisions. It's all fine and good, but nohz_full CPUs are capable of disabling the tick indefinitely and potentially trigger overflows in arch_scale_freq_tick()'s calculations once it's eventually re-enabled.
This will happen for both users of this interface: x86 and arm64. And it's also relevant that the heuristic on what to do in case of operations overflowing varies depending on the implementation. It goes from fully disabling frequency invariance scaling on all CPUS, to ignoring this is a possibility.
It's arguable that nohz_full CPUs are unlikely to benefit much from this feature, since their aim is to allow for uninterrupted execution of a single task, effectively getting the scheduler out of the way. Also, DVFS itself is also unlikely be used on most nohz_full systems, given its effects on latency.
So get around this by not calling arch_scale_freq_tick() on nohz_full CPUs.
Note that tick_nohz_full_cpu() relies on a static branch, which avoids degrading performance on the rest of systems.
--- kernel/sched/core.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
kernel/sched/core.c +7 -1
@@ -5016,7 +5016,13 @@ void scheduler_tick(void)unsigned long thermal_pressure;u64 resched_latency; -arch_scale_freq_tick (); +/* +* nohz_full CPUs are capable of disabling the scheduler tick +* indefinitely, potentially overflowing arch_scale_freq_tick() +* calculations once it's re-enabled. +*/ +if (!tick_nohz_full_cpu (smp_processor_id ())) +arch_scale_freq_tick ();sched_clock_tick ();rq_lock (rq, &rf);
Signature · 1 line
2.31.1
Peter Zijlstra
maintainerQuoted 40 lines · Nicolas Saenz Julienne
arch_scale_freq_tick()calculations generally track the increment of frequency performance counters in between scheduler ticks to provide estimations on how DVFS swayed frequency on that CPU. This information eventually allows for more precise scheduling decisions. It's all fine and good, butnohz_fullCPUs are capable of disabling the tick indefinitely and potentially trigger overflows in arch_scale_freq_tick()'s calculations once it's eventually re-enabled.This will happen for both users of this interface: x86 and arm64. And it's also relevant that the heuristic on what to do in case of operations overflowing varies depending on the implementation. It goes from fully disabling frequency invariance scaling on all CPUS, to ignoring this is a possibility.
It's arguable that
nohz_fullCPUs are unlikely to benefit much from this feature, since their aim is to allow for uninterrupted execution of a single task, effectively getting the scheduler out of the way. Also, DVFS itself is also unlikely be used on mostnohz_fullsystems, given its effects on latency.So get around this by not calling
arch_scale_freq_tick()onnohz_fullCPUs.Note that
tick_nohz_full_cpu()relies on a static branch, which avoids degrading performance on the rest of systems.Signed-off-by Nicolas Saenz Julienne <[email protected]>--- kernel/sched/core.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)kernel/sched/core.c +0
-1@@ -5016,7 +5016,13 @@ void scheduler_tick(void)unsigned long thermal_pressure;u64 resched_latency; -arch_scale_freq_tick ();
kernel/sched/core.c void scheduler_tick(void) · line 5028
Quoted 10 lines
kernel/sched/core.c +7
-0+/* +* nohz_full CPUs are capable of disabling the scheduler tick +* indefinitely, potentially overflowing arch_scale_freq_tick() +* calculations once it's re-enabled. +*/ +if (!tick_nohz_full_cpu (smp_processor_id ())) +arch_scale_freq_tick ();sched_clock_tick ();rq_lock (rq, &rf);
Hurmph,.. I'm not too happy with this.. Fundamentally the whole NOHZ_FULL state should be dynamic, it currently isn't but that's arguably a bug of the current implementation.
As such the above doesn't really dtrt, since a CPU disabling NOHZ_FULL will then still suffer all them overflows you mentioned.
Frederic, how should this be done right? Is there a place where upon entering/exiting NOHZ_FULL we can do fixups?