mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] x86/aperfmperf: erase stale arch_freq_scale values when disabling frequency invariance readings
@ 2023-01-10 16:02 Yair Podemsky
  2023-01-16  9:28 ` [tip: sched/urgent] x86/aperfmperf: Erase " tip-bot2 for Yair Podemsky
  0 siblings, 1 reply; 2+ messages in thread
From: Yair Podemsky @ 2023-01-10 16:02 UTC (permalink / raw)
  To: tglx, mingo, bp, dave.hansen, x86, hpa, peterz, rafael.j.wysocki,
	paulmck, frederic, linux-kernel
  Cc: ypodemsk

Once disable_freq_invariance_work is called the scale_freq_tick function
will not compute or update the arch_freq_scale values.
However the scheduler will still read these values and use them.
The result is that the scheduler might perform unfair decisions based on stale
values.

This patch adds the step of setting the arch_freq_scale values for all
cpus to the default (max) value SCHED_CAPACITY_SCALE, Once all cpus
have the same arch_freq_scale value the scaling is meaningless.

Signed-off-by: Yair Podemsky <ypodemsk@redhat.com>
---
 arch/x86/kernel/cpu/aperfmperf.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/arch/x86/kernel/cpu/aperfmperf.c b/arch/x86/kernel/cpu/aperfmperf.c
index 1f60a2b27936..fdbb5f07448f 100644
--- a/arch/x86/kernel/cpu/aperfmperf.c
+++ b/arch/x86/kernel/cpu/aperfmperf.c
@@ -330,7 +330,16 @@ static void __init bp_init_freq_invariance(void)
 
 static void disable_freq_invariance_workfn(struct work_struct *work)
 {
+	int cpu;
+
 	static_branch_disable(&arch_scale_freq_key);
+
+	/*
+	 * Set arch_freq_scale to a default value on all cpus
+	 * This negates the effect of scaling
+	 */
+	for_each_possible_cpu(cpu)
+		per_cpu(arch_freq_scale, cpu) = SCHED_CAPACITY_SCALE;
 }
 
 static DECLARE_WORK(disable_freq_invariance_work,
-- 
2.31.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [tip: sched/urgent] x86/aperfmperf: Erase stale arch_freq_scale values when disabling frequency invariance readings
  2023-01-10 16:02 [PATCH] x86/aperfmperf: erase stale arch_freq_scale values when disabling frequency invariance readings Yair Podemsky
@ 2023-01-16  9:28 ` tip-bot2 for Yair Podemsky
  0 siblings, 0 replies; 2+ messages in thread
From: tip-bot2 for Yair Podemsky @ 2023-01-16  9:28 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Yair Podemsky, Ingo Molnar, Peter Zijlstra, x86, linux-kernel

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

Commit-ID:     5f5cc9ed992cbab6361f198966f0edba5fc52688
Gitweb:        https://git.kernel.org/tip/5f5cc9ed992cbab6361f198966f0edba5fc52688
Author:        Yair Podemsky <ypodemsk@redhat.com>
AuthorDate:    Tue, 10 Jan 2023 18:02:06 +02:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Mon, 16 Jan 2023 10:19:15 +01:00

x86/aperfmperf: Erase stale arch_freq_scale values when disabling frequency invariance readings

Once disable_freq_invariance_work is called the scale_freq_tick function
will not compute or update the arch_freq_scale values.
However the scheduler will still read these values and use them.
The result is that the scheduler might perform unfair decisions based on stale
values.

This patch adds the step of setting the arch_freq_scale values for all
cpus to the default (max) value SCHED_CAPACITY_SCALE, Once all cpus
have the same arch_freq_scale value the scaling is meaningless.

Signed-off-by: Yair Podemsky <ypodemsk@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20230110160206.75912-1-ypodemsk@redhat.com
---
 arch/x86/kernel/cpu/aperfmperf.c |  9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/arch/x86/kernel/cpu/aperfmperf.c b/arch/x86/kernel/cpu/aperfmperf.c
index 1f60a2b..fdbb5f0 100644
--- a/arch/x86/kernel/cpu/aperfmperf.c
+++ b/arch/x86/kernel/cpu/aperfmperf.c
@@ -330,7 +330,16 @@ static void __init bp_init_freq_invariance(void)
 
 static void disable_freq_invariance_workfn(struct work_struct *work)
 {
+	int cpu;
+
 	static_branch_disable(&arch_scale_freq_key);
+
+	/*
+	 * Set arch_freq_scale to a default value on all cpus
+	 * This negates the effect of scaling
+	 */
+	for_each_possible_cpu(cpu)
+		per_cpu(arch_freq_scale, cpu) = SCHED_CAPACITY_SCALE;
 }
 
 static DECLARE_WORK(disable_freq_invariance_work,

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-01-16  9:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-10 16:02 [PATCH] x86/aperfmperf: erase stale arch_freq_scale values when disabling frequency invariance readings Yair Podemsky
2023-01-16  9:28 ` [tip: sched/urgent] x86/aperfmperf: Erase " tip-bot2 for Yair Podemsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®