Skip to contentSkip to conversation

arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c: avoid cross-CPU interrupts by using smp_call_function_any()

PATCH Applied [email protected] 3 participants 4 messages Sep 18, 2009 – Sep 22, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 2/8 arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c: avoid cross-CPU interrupts by using smp_call_function_any()

From: Andrew Morton <[email protected]>

Presently acpi-cpufreq will perform the MSR read on the first CPU in the mask. That's inefficient if that CPU differs from the current CPU. Because we have to perform a cross-CPU call, but we could have run the rdmsr on the current CPU.

So switch to using the new smp_call_function_any(), whcih will perform the call on the current CPU if that CPU is present in the mask (it is).

Cc "Zhang, Yanmin" <[email protected]>
Cc Dave Jones <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Jaswinder Singh Rajput <[email protected]>
Cc Len Brown <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Rusty Russell <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Venkatesh Pallipadi <[email protected]>
Cc Zhao Yakui <[email protected]>

---

 arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c renamed from arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c~arch-x86-kernel-cpu-cpufreq-acpi-cpufreqc-avoid-cross-cpu-interrupts-by-using-smp_call_function_any +3 -1
diff -puN arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c~arch-x86-kernel-cpu-cpufreq-acpi-cpufreqc-avoid-cross-cpu-interrupts-by-using-smp_call_function_any arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c
@@ -192,9 +192,11 @@ static void do_drv_write(void *_cmd)
 
 static void drv_read(struct drv_cmd *cmd)
 {
+	int err;
 	cmd->val = 0;
 
-	smp_call_function_single(cpumask_any(cmd->mask), do_drv_read, cmd, 1);
+	err = smp_call_function_any(cmd->mask, do_drv_read, cmd, 1);
+	WARN_ON_ONCE(err);	/* smp_call_function_any() was buggy? */
 }
 
 static void drv_write(struct drv_cmd *cmd)

_

#1 lore raw
Quoted 6 lines · Andrew Morton

diff -puN arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c~arch-x86-kernel-cpu-cpufreq-acpi-cpufreqc-avoid-cross-cpu-interrupts-by-using-smp_call_function_any arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c

arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c renamed from arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c~arch-x86-kernel-cpu-cpufreq-acpi-cpufreqc-avoid-cross-cpu-interrupts-by-using-smp_call_function_any +0 -0
@@ -192,9 +192,11 @@ static void do_drv_write(void *_cmd)
 
 static void drv_read(struct drv_cmd *cmd)

arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c static void do_drv_write(void *_cmd) · line 202

Quoted 10 lines
arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c renamed from arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c~arch-x86-kernel-cpu-cpufreq-acpi-cpufreqc-avoid-cross-cpu-interrupts-by-using-smp_call_function_any +3 -1
 {
+	int err;
 	cmd->val = 0;
 
-	smp_call_function_single(cpumask_any(cmd->mask), do_drv_read, cmd, 1);
+	err = smp_call_function_any(cmd->mask, do_drv_read, cmd, 1);
+	WARN_ON_ONCE(err);	/* smp_call_function_any() was buggy? */
 }
 
 static void drv_write(struct drv_cmd *cmd)

I'm ok with this going in, but I still wonder if we could have done it all a lot easier, by making cpumask_any pick the current cpu if it was in the mask instead of introducing yet another variant to an already enormous api.

Dave

#2 lore raw
Quoted 17 lines · On Fri, 18 Sep 2009 15:59:53 -0400 Dave Jones <[email protected]> wrote:
Quoted 15 lines · Andrew Morton

diff -puN arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c~arch-x86-kernel-cpu-cpufreq-acpi-cpufreqc-avoid-cross-cpu-interrupts-by-using-smp_call_function_any arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c

arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c renamed from arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c~arch-x86-kernel-cpu-cpufreq-acpi-cpufreqc-avoid-cross-cpu-interrupts-by-using-smp_call_function_any +3 -1
@@ -192,9 +192,11 @@ static void do_drv_write(void *_cmd)
 
 static void drv_read(struct drv_cmd *cmd)
 {
+	int err;
 	cmd->val = 0;
 
-	smp_call_function_single(cpumask_any(cmd->mask), do_drv_read, cmd, 1);
+	err = smp_call_function_any(cmd->mask, do_drv_read, cmd, 1);
+	WARN_ON_ONCE(err);	/* smp_call_function_any() was buggy? */
 }
 
Quoted 7 lines

arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c static void do_drv_write(void *_cmd) · line 202

Quoted 1 line
arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c renamed from arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c~arch-x86-kernel-cpu-cpufreq-acpi-cpufreqc-avoid-cross-cpu-interrupts-by-using-smp_call_function_any +0 -0
 static void drv_write(struct drv_cmd *cmd)

I'm ok with this going in, but I still wonder if we could have done it all a lot easier, by making cpumask_any pick the current cpu if it was in the mask instead of introducing yet another variant to an already enormous api.

Yeah, I wondered about that. But iirc Rusty had a good-sounding reason for adding a new function but that reason didn't get into the changelog so it's lost.

#3 lore raw
In reply to Dave Jones
Quoted 4 lines · Dave Jones

I'm ok with this going in, but I still wonder if we could have done it all a lot easier, by making cpumask_any pick the current cpu if it was in the mask instead of introducing yet another variant to an already enormous api.

That was the initial proposal, but I'm uncomfortable with that, too. "any" really implies "doesn't matter"; if we overload it to have a preference, it becomes really hard to tell which ones really care and which ones don't.

Then refactoring becomes harder (performance regression when you alter code).

So yeah, not ideal, but this seemed like the minimal API extension.

Cheers,
Rusty.