public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kvm: external module: backward compatibility for smp_call_function_mask()
@ 2007-10-23  9:06 Laurent Vivier
       [not found] ` <1193130386915-git-send-email-Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: Laurent Vivier @ 2007-10-23  9:06 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f; +Cc: Laurent Vivier

Before kernel 2.6.24, smp_call_function_mask() is not defined for architecture
x86_64 and not for architecture i386.

This patch defines it in external-module-compat.h to emulate it for older
kernel, it uses codes from arch/x86/kernel/smp_64.c modified to call 
smp_call_single_function() (like in previous version of KVM) instead of 
send_IPI_mask().

Signed-off-by: Laurent Vivier <Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
---
 kernel/external-module-compat.h |   75 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 75 insertions(+), 0 deletions(-)

diff --git a/kernel/external-module-compat.h b/kernel/external-module-compat.h
index bd637db..adc5cd4 100644
--- a/kernel/external-module-compat.h
+++ b/kernel/external-module-compat.h
@@ -421,3 +421,78 @@ typedef _Bool bool;
 #ifndef PF_VCPU
 #define PF_VCPU 0
 #endif
+
+/* 
+ * smp_call_function_mask() is not defined/exported below 2.6.24
+ */
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
+struct kvm_call_data_struct {
+	void (*func) (void *info);
+	void *info;
+	atomic_t started;
+	atomic_t finished;
+	int wait;
+};
+
+static void kvm_ack_smp_call(void *_data)
+{
+	struct kvm_call_data_struct *data = _data;
+	/* if wait == 0, data can be out of scope
+	 * after atomic_inc(info->started)
+	 */
+	void (*func) (void *info) = data->func;
+	void *info = data->info;
+	int wait = data->wait;
+
+	smp_mb();
+	atomic_inc(&data->started);
+	(*func)(info);
+	if (wait) {
+		smp_mb();
+		atomic_inc(&data->finished);
+	}
+}
+
+static inline int smp_call_function_mask(cpumask_t mask, 
+	void (*func) (void *info), void *info, int wait)
+{
+	struct kvm_call_data_struct data;
+	cpumask_t allbutself;
+	int cpus;
+	int cpu;
+
+	allbutself = cpu_online_map;
+	cpu_clear(smp_processor_id(), allbutself);
+
+	cpus_and(mask, mask, allbutself);
+	cpus = cpus_weight(mask);
+
+	if (!cpus)
+		return 0;
+
+	data.func = func;
+	data.info = info;
+	atomic_set(&data.started, 0);
+	data.wait = wait;
+	if (wait)
+		atomic_set(&data.finished, 0);
+
+	for (cpu = first_cpu(mask); cpu != NR_CPUS; cpu = next_cpu(cpu, mask))
+		smp_call_function_single(cpu, kvm_ack_smp_call, &data, 1, 0);
+
+	while (atomic_read(&data.started) != cpus) {
+		cpu_relax();
+		barrier();
+	}
+
+	if (!wait)
+		return 0;
+
+	while (atomic_read(&data.finished) != cpus) {
+		cpu_relax();
+		barrier();
+	}
+	return 0;
+}
+#endif
-- 
1.5.2.4


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

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

end of thread, other threads:[~2007-10-23 10:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-23  9:06 [PATCH] kvm: external module: backward compatibility for smp_call_function_mask() Laurent Vivier
     [not found] ` <1193130386915-git-send-email-Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
2007-10-23 10:02   ` Avi Kivity

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