diff mbox series

[RFC] x86,lib: Add wbinvd_on_many_cpus helpers

Message ID 20240409042056.51757-1-lirongqing@baidu.com (mailing list archive)
State New
Headers show
Series [RFC] x86,lib: Add wbinvd_on_many_cpus helpers | expand

Commit Message

Li,Rongqing April 9, 2024, 4:20 a.m. UTC
wbinvd_on_many_cpus will call smp_call_function_many(), which should
be more efficient that iterating cpus since it would run wbinvd()
concurrently locally and remotely

it can be used by the below patch
https://patchwork.kernel.org/project/kvm/patch/1860502863.219296.1710395908135.JavaMail.zimbra@sjtu.edu.cn/

Cc: Zheyun Shen <szy0127@sjtu.edu.cn>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
 arch/x86/include/asm/smp.h | 7 +++++++
 arch/x86/lib/cache-smp.c   | 7 +++++++
 2 files changed, 14 insertions(+)

Comments

Ingo Molnar April 9, 2024, 7:45 a.m. UTC | #1
* Li RongQing <lirongqing@baidu.com> wrote:

> wbinvd_on_many_cpus will call smp_call_function_many(), which should
> be more efficient that iterating cpus since it would run wbinvd()
> concurrently locally and remotely
> 
> it can be used by the below patch
> https://patchwork.kernel.org/project/kvm/patch/1860502863.219296.1710395908135.JavaMail.zimbra@sjtu.edu.cn/
> 
> Cc: Zheyun Shen <szy0127@sjtu.edu.cn>
> Cc: Tom Lendacky <thomas.lendacky@amd.com>
> Signed-off-by: Li RongQing <lirongqing@baidu.com>
> ---
>  arch/x86/include/asm/smp.h | 7 +++++++
>  arch/x86/lib/cache-smp.c   | 7 +++++++
>  2 files changed, 14 insertions(+)

The two patches should be submitted together within the same series.

Thanks,

	Ingo
diff mbox series

Patch

diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
index a35936b..70973de 100644
--- a/arch/x86/include/asm/smp.h
+++ b/arch/x86/include/asm/smp.h
@@ -111,6 +111,7 @@  void native_play_dead(void);
 void play_dead_common(void);
 void wbinvd_on_cpu(int cpu);
 int wbinvd_on_all_cpus(void);
+int wbinvd_on_many_cpus(const struct cpumask *mask);
 
 void smp_kick_mwait_play_dead(void);
 
@@ -159,6 +160,12 @@  static inline int wbinvd_on_all_cpus(void)
 	return 0;
 }
 
+static inline int wbinvd_on_many_cpus(const struct cpumask *mask)
+{
+	wbinvd();
+	return 0;
+}
+
 static inline struct cpumask *cpu_llc_shared_mask(int cpu)
 {
 	return (struct cpumask *)cpumask_of(0);
diff --git a/arch/x86/lib/cache-smp.c b/arch/x86/lib/cache-smp.c
index 7af743b..5950d1b 100644
--- a/arch/x86/lib/cache-smp.c
+++ b/arch/x86/lib/cache-smp.c
@@ -20,3 +20,10 @@  int wbinvd_on_all_cpus(void)
 	return 0;
 }
 EXPORT_SYMBOL(wbinvd_on_all_cpus);
+
+int wbinvd_on_many_cpus(const struct cpumask *mask)
+{
+	smp_call_function_many(mask, __wbinvd, NULL, 1);
+	return 0;
+}
+EXPORT_SYMBOL(wbinvd_on_many_cpus);