Skip to contentSkip to conversation

sched/core: Fix arch_scale_freq_tick() on tickless systems

PATCH Applied Yair Podemsky 4 participants 5 messages Nov 30, 2022 – Jan 7, 2023 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched/core: Fix arch_scale_freq_tick() on tickless systems

In order for the scheduler to be frequency invariant we measure the ratio between the maximum cpu frequency and the actual cpu frequency. During long tickless periods of time the calculations that keep track of that might overflow, in the function scale_freq_tick():

if (check_shl_overflow(acnt, 2*SCHED_CAPACITY_SHIFT, &acnt))
» goto error;

eventually forcing the kernel to disable the feature for all cpus, and show the warning message
"Scheduler frequency invariance went wobbly, disabling!". Let's avoid that by limiting the frequency invariant calculations to cpus with regular tick.

Fixes e2b0d619b400 ("x86, sched: check for counters overflow in frequency invariant accounting")

---
V1 -> V2: solution approach was changed from detecting long tickless periods to frequency invariant measurements on housekeeping cpus only.
Link: [email protected]

---
 kernel/sched/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/sched/core.c +3 -1
index daff72f00385..1bb0a840c817 100644
@@ -5469,7 +5469,9 @@ void scheduler_tick(void)
 	unsigned long thermal_pressure;
 	u64 resched_latency;
 
-	arch_scale_freq_tick();
+	if (housekeeping_cpu(cpu, HK_TYPE_TICK))
+		arch_scale_freq_tick();
+
 	sched_clock_tick();
 
 	rq_lock(rq, &rf);
Signature · 1 line
2.31.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Yair Podemsky

In order for the scheduler to be frequency invariant we measure the ratio between the maximum cpu frequency and the actual cpu frequency. During long tickless periods of time the calculations that keep track of that might overflow, in the function scale_freq_tick():

if (check_shl_overflow(acnt, 2*SCHED_CAPACITY_SHIFT, &acnt))
» goto error;

eventually forcing the kernel to disable the feature for all cpus, and show the warning message
"Scheduler frequency invariance went wobbly, disabling!". Let's avoid that by limiting the frequency invariant calculations to cpus with regular tick.

Quoted 3 lines
Fixes e2b0d619b400 ("x86, sched: check for counters overflow in frequency invariant accounting")
Quoted 25 lines

---
V1 -> V2: solution approach was changed from detecting long tickless periods to frequency invariant measurements on housekeeping cpus only.
Link: [email protected]

---
 kernel/sched/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/sched/core.c +3 -2
index daff72f00385..1bb0a840c817 100644
@@ -5469,7 +5469,9 @@ void scheduler_tick(void)
      unsigned long thermal_pressure;
      u64 resched_latency;
 
-	arch_scale_freq_tick();
+	if (housekeeping_cpu(cpu, HK_TYPE_TICK))
+		arch_scale_freq_tick();
+
      sched_clock_tick();
 
      rq_lock(rq, &rf);
--

2.31.1

Acked-by on v1 1/1
#2 lore raw
In reply to Yair Podemsky
Quoted 14 lines · Yair Podemsky

In order for the scheduler to be frequency invariant we measure the ratio between the maximum cpu frequency and the actual cpu frequency. During long tickless periods of time the calculations that keep track of that might overflow, in the function scale_freq_tick():

if (check_shl_overflow(acnt, 2*SCHED_CAPACITY_SHIFT, &acnt))
» goto error;

eventually forcing the kernel to disable the feature for all cpus, and show the warning message
"Scheduler frequency invariance went wobbly, disabling!". Let's avoid that by limiting the frequency invariant calculations to cpus with regular tick.

Quoted 3 lines
Fixes e2b0d619b400 ("x86, sched: check for counters overflow in frequency invariant accounting")
Quoted 23 lines

---
V1 -> V2: solution approach was changed from detecting long tickless periods to frequency invariant measurements on housekeeping cpus only.
Link: [email protected]

---
 kernel/sched/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/sched/core.c +3 -1
index daff72f00385..1bb0a840c817 100644
@@ -5469,7 +5469,9 @@ void scheduler_tick(void)
 	unsigned long thermal_pressure;
 	u64 resched_latency;
 
-	arch_scale_freq_tick();
+	if (housekeeping_cpu(cpu, HK_TYPE_TICK))
+		arch_scale_freq_tick();
+
 	sched_clock_tick();
 
 	rq_lock(rq, &rf);
#3 lore raw

Friendly ping

Quoted 48 lines · Giovanni Gherdovich
Quoted 16 lines · Yair Podemsky

In order for the scheduler to be frequency invariant we measure the ratio between the maximum cpu frequency and the actual cpu frequency.
During long tickless periods of time the calculations that keep track
of that might overflow, in the function scale_freq_tick():

if (check_shl_overflow(acnt, 2*SCHED_CAPACITY_SHIFT, &acnt))
» goto error;

eventually forcing the kernel to disable the feature for all cpus, and show the warning message
"Scheduler frequency invariance went wobbly, disabling!". Let's avoid that by limiting the frequency invariant calculations to cpus with regular tick.

Quoted 4 lines
Fixes e2b0d619b400 ("x86, sched: check for counters overflow in

frequency invariant accounting")

Quoted 24 lines

---
V1 -> V2: solution approach was changed from detecting long tickless periods
to frequency invariant measurements on housekeeping cpus only.
Link: [email protected]

---
 kernel/sched/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/sched/core.c +3 -1
index daff72f00385..1bb0a840c817 100644
@@ -5469,7 +5469,9 @@ void scheduler_tick(void)
 	unsigned long thermal_pressure;
 	u64 resched_latency;
 
-	arch_scale_freq_tick();
+	if (housekeeping_cpu(cpu, HK_TYPE_TICK))
+		arch_scale_freq_tick();
+
 	sched_clock_tick();
 
 	rq_lock(rq, &rf);
merge bot Applied
#4 lore raw
In reply to Yair Podemsky
The following commit has been merged into the sched/urgent branch of tip:

The following commit has been merged into the sched/urgent branch of tip:

Commit-ID:     7fb3ff22ad8772bbf0e3ce1ef3eb7b09f431807f
Gitweb:        https://git.kernel.org/tip/7fb3ff22ad8772bbf0e3ce1ef3eb7b09f431807f
Author:        Yair Podemsky <[email protected]>
AuthorDate:    Wed, 30 Nov 2022 14:51:21 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Sat, 07 Jan 2023 12:25:50 +01:00

sched/core: Fix arch_scale_freq_tick() on tickless systems

In order for the scheduler to be frequency invariant we measure the ratio between the maximum CPU frequency and the actual CPU frequency.

During long tickless periods of time the calculations that keep track of that might overflow, in the function scale_freq_tick():

if (check_shl_overflow(acnt, 2*SCHED_CAPACITY_SHIFT, &acnt))

          goto error;

eventually forcing the kernel to disable the feature for all CPUs, and show the warning message:

"Scheduler frequency invariance went wobbly, disabling!".

Let's avoid that by limiting the frequency invariant calculations to CPUs with regular tick.

Fixes e2b0d619b400 ("x86, sched: check for counters overflow in frequency invariant accounting")
---
 kernel/sched/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/sched/core.c +3 -1
index 25b582b..965d813 100644
@@ -5504,7 +5504,9 @@ void scheduler_tick(void)
 	unsigned long thermal_pressure;
 	u64 resched_latency;
 
-	arch_scale_freq_tick();
+	if (housekeeping_cpu(cpu, HK_TYPE_TICK))
+		arch_scale_freq_tick();
+
 	sched_clock_tick();
 
 	rq_lock(rq, &rf);