mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH][2.5][14/14] smp_call_function_on_cpu - x86_64
@ 2003-02-14  9:33 Zwane Mwaikambo
  2003-02-14 12:52 ` Zwane Mwaikambo
  0 siblings, 1 reply; 4+ messages in thread
From: Zwane Mwaikambo @ 2003-02-14  9:33 UTC (permalink / raw)
  To: Linux Kernel; +Cc: Linus Torvalds, Andi Kleen

 smp.c |   48 ++++++++++++++++++++++++++++++++----------------
 1 files changed, 32 insertions(+), 16 deletions(-)

Index: linux-2.5.60/arch/x86_64/kernel/smp.c
===================================================================
RCS file: /build/cvsroot/linux-2.5.60/arch/x86_64/kernel/smp.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 smp.c
--- linux-2.5.60/arch/x86_64/kernel/smp.c	10 Feb 2003 22:15:09 -0000	1.1.1.1
+++ linux-2.5.60/arch/x86_64/kernel/smp.c	14 Feb 2003 05:47:57 -0000
@@ -385,26 +385,35 @@
  * in the system.
  */
 
-int smp_call_function (void (*func) (void *info), void *info, int nonatomic,
-			int wait)
 /*
- * [SUMMARY] Run a function on all other CPUs.
- * <func> The function to run. This must be fast and non-blocking.
- * <info> An arbitrary pointer to pass to the function.
- * <nonatomic> currently unused.
- * <wait> If true, wait (atomically) until function has completed on other CPUs.
- * [RETURNS] 0 on success, else a negative status code. Does not return until
- * remote CPUs are nearly ready to execute <<func>> or are or have executed.
+ * smp_call_function_on_cpu - Runs func on all processors in the mask
+ *
+ * @func: The function to run. This must be fast and non-blocking.
+ * @info: An arbitrary pointer to pass to the function.
+ * @wait: If true, wait (atomically) until function has completed on other CPUs.
+ * @mask: The bitmask of CPUs to call the function
+ * 
+ * Returns 0 on success, else a negative status code. Does not return until
+ * remote CPUs are nearly ready to execute func or have executed it.
  *
  * You must not call this function with disabled interrupts or from a
  * hardware interrupt handler or from a bottom half handler.
  */
+
+int smp_call_function_on_cpu (void (*func) (void *info), void *info, int wait,
+				unsigned long mask)
 {
 	struct call_data_struct data;
-	int cpus = num_online_cpus()-1;
+	int i, cpu, num_cpus;
+
 
-	if (!cpus)
-		return 0;
+	cpu = get_cpu();
+	mask &= ~(1UL << cpu);
+	num_cpus = hweight64(mask);
+	if (num_cpus == 0) {
+		put_cpu_no_resched();
+		return -EINVAL;
+	}
 
 	data.func = func;
 	data.info = info;
@@ -416,19 +425,26 @@
 	spin_lock(&call_lock);
 	call_data = &data;
 	wmb();
+
 	/* Send a message to all other CPUs and wait for them to respond */
-	send_IPI_allbutself(CALL_FUNCTION_VECTOR);
+	send_IPI_mask(mask, CALL_FUNCTION_VECTOR);
 
 	/* Wait for response */
-	while (atomic_read(&data.started) != cpus)
+	while (atomic_read(&data.started) != num_cpus)
 		barrier();
 
 	if (wait)
-		while (atomic_read(&data.finished) != cpus)
+		while (atomic_read(&data.finished) != num_cpus)
 			barrier();
 	spin_unlock(&call_lock);
-
+	put_cpu_no_resched();
 	return 0;
+}
+
+int smp_call_function (void (*func) (void *info), void *info, int nonatomic,
+			int wait)
+{
+	return smp_call_function_on_cpu(func, info, wait, cpu_online_map);
 }
 
 static void stop_this_cpu (void * dummy)

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

* Re: [PATCH][2.5][14/14] smp_call_function_on_cpu - x86_64
  2003-02-14  9:33 [PATCH][2.5][14/14] smp_call_function_on_cpu - x86_64 Zwane Mwaikambo
@ 2003-02-14 12:52 ` Zwane Mwaikambo
  2003-02-14 14:47   ` Andi Kleen
  0 siblings, 1 reply; 4+ messages in thread
From: Zwane Mwaikambo @ 2003-02-14 12:52 UTC (permalink / raw)
  To: Linux Kernel; +Cc: Linus Torvalds, Andi Kleen

One liner to fix num_cpus == 0 on SMP kernel w/ UP box

Index: linux-2.5.60/arch/x86_64/kernel/smp.c
===================================================================
RCS file: /build/cvsroot/linux-2.5.60/arch/x86_64/kernel/smp.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 smp.c
--- linux-2.5.60/arch/x86_64/kernel/smp.c	10 Feb 2003 22:15:09 -0000	1.1.1.1
+++ linux-2.5.60/arch/x86_64/kernel/smp.c	14 Feb 2003 12:17:24 -0000
@@ -385,26 +385,35 @@
  * in the system.
  */
 
-int smp_call_function (void (*func) (void *info), void *info, int nonatomic,
-			int wait)
 /*
- * [SUMMARY] Run a function on all other CPUs.
- * <func> The function to run. This must be fast and non-blocking.
- * <info> An arbitrary pointer to pass to the function.
- * <nonatomic> currently unused.
- * <wait> If true, wait (atomically) until function has completed on other CPUs.
- * [RETURNS] 0 on success, else a negative status code. Does not return until
- * remote CPUs are nearly ready to execute <<func>> or are or have executed.
+ * smp_call_function_on_cpu - Runs func on all processors in the mask
+ *
+ * @func: The function to run. This must be fast and non-blocking.
+ * @info: An arbitrary pointer to pass to the function.
+ * @wait: If true, wait (atomically) until function has completed on other CPUs.
+ * @mask: The bitmask of CPUs to call the function
+ * 
+ * Returns 0 on success, else a negative status code. Does not return until
+ * remote CPUs are nearly ready to execute func or have executed it.
  *
  * You must not call this function with disabled interrupts or from a
  * hardware interrupt handler or from a bottom half handler.
  */
+
+int smp_call_function_on_cpu (void (*func) (void *info), void *info, int wait,
+				unsigned long mask)
 {
 	struct call_data_struct data;
-	int cpus = num_online_cpus()-1;
+	int i, cpu, num_cpus;
+
 
-	if (!cpus)
+	cpu = get_cpu();
+	mask &= ~(1UL << cpu);
+	num_cpus = hweight64(mask);
+	if (num_cpus == 0) {
+		put_cpu_no_resched();
 		return 0;
+	}
 
 	data.func = func;
 	data.info = info;
@@ -416,19 +425,26 @@
 	spin_lock(&call_lock);
 	call_data = &data;
 	wmb();
+
 	/* Send a message to all other CPUs and wait for them to respond */
-	send_IPI_allbutself(CALL_FUNCTION_VECTOR);
+	send_IPI_mask(mask, CALL_FUNCTION_VECTOR);
 
 	/* Wait for response */
-	while (atomic_read(&data.started) != cpus)
+	while (atomic_read(&data.started) != num_cpus)
 		barrier();
 
 	if (wait)
-		while (atomic_read(&data.finished) != cpus)
+		while (atomic_read(&data.finished) != num_cpus)
 			barrier();
 	spin_unlock(&call_lock);
-
+	put_cpu_no_resched();
 	return 0;
+}
+
+int smp_call_function (void (*func) (void *info), void *info, int nonatomic,
+			int wait)
+{
+	return smp_call_function_on_cpu(func, info, wait, cpu_online_map);
 }
 
 static void stop_this_cpu (void * dummy)

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

* Re: [PATCH][2.5][14/14] smp_call_function_on_cpu - x86_64
  2003-02-14 12:52 ` Zwane Mwaikambo
@ 2003-02-14 14:47   ` Andi Kleen
  2003-02-14 17:09     ` Zwane Mwaikambo
  0 siblings, 1 reply; 4+ messages in thread
From: Andi Kleen @ 2003-02-14 14:47 UTC (permalink / raw)
  To: Zwane Mwaikambo; +Cc: Linux Kernel, Linus Torvalds, Andi Kleen

On Fri, Feb 14, 2003 at 07:52:15AM -0500, Zwane Mwaikambo wrote:
> One liner to fix num_cpus == 0 on SMP kernel w/ UP box

Shouldn't num_cpus be 1 in that case ?

-Andi

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

* Re: [PATCH][2.5][14/14] smp_call_function_on_cpu - x86_64
  2003-02-14 14:47   ` Andi Kleen
@ 2003-02-14 17:09     ` Zwane Mwaikambo
  0 siblings, 0 replies; 4+ messages in thread
From: Zwane Mwaikambo @ 2003-02-14 17:09 UTC (permalink / raw)
  To: Andi Kleen; +Cc: Linux Kernel, Linus Torvalds

On Fri, 14 Feb 2003, Andi Kleen wrote:

> On Fri, Feb 14, 2003 at 07:52:15AM -0500, Zwane Mwaikambo wrote:
> > One liner to fix num_cpus == 0 on SMP kernel w/ UP box
> 
> Shouldn't num_cpus be 1 in that case ?

We mask out current cpu first like so;

mask &= ~(1UL << smp_processor_id());
num_cpus = hweight(mask);
if (num_cpus == )
	return 0;

So really it's number of eligible IPI cpus

	Zwane
-- 
function.linuxpower.ca

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

end of thread, other threads:[~2003-02-14 17:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-14  9:33 [PATCH][2.5][14/14] smp_call_function_on_cpu - x86_64 Zwane Mwaikambo
2003-02-14 12:52 ` Zwane Mwaikambo
2003-02-14 14:47   ` Andi Kleen
2003-02-14 17:09     ` Zwane Mwaikambo

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®