Skip to contentSkip to conversation

MIPS: add smp_call_function_single()

PATCH In review Stephane Eranian 4 participants 6 messages Jul 27, 2007 – Jul 30, 2007 MIPS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 MIPS: add smp_call_function_single()

[MIPS] add smp_call_function_single()

arch/mips/kernel/smp.c +47 -0
index be7362b..9e376e2 100644
@@ -193,6 +193,53 @@ void smp_call_function_interrupt(void)
 	}
 }
 
+int smp_call_function_single(int cpu, void (*func) (void *info), void *info, int retry,
+			     int wait)
+{
+  struct call_data_struct data;
+  int me = smp_processor_id();
+
+  /*
+     * Can die spectacularly if this CPU isn't yet marked online
+      */
+  BUG_ON(!cpu_online(me));
+  if (cpu == me) {
+    WARN_ON(1);
+    return -EBUSY;
+    }
+
+  /* Can deadlock when called with interrupts disabled */
+  WARN_ON(irqs_disabled());
+
+  data.func = func;
+  data.info = info;
+  atomic_set(&data.started, 0);
+  data.wait = wait;
+  if (wait)
+    atomic_set(&data.finished, 0);
+
+  spin_lock(&smp_call_lock);
+  call_data = &data;
+  mb();
+
+  /* Send a message to the other CPU */
+  core_send_ipi(cpu, SMP_CALL_FUNCTION);
+
+  /* Wait for response */
+  /* FIXME: lock-up detection, backtrace on lock-up */
+  while (atomic_read(&data.started) != 1)
+    barrier();
+
+  if (wait)
+    while (atomic_read(&data.finished) != 1)
+      barrier();
+  call_data = NULL;
+  spin_unlock(&smp_call_lock);
+
+  return 0;
+}
+EXPORT_SYMBOL(smp_call_function_single);
+
 static void stop_this_cpu(void *dummy)
 {
 	/*
include/asm-mips/smp.h +2 -0
index 13aef6a..5acbf38 100644
@@ -102,6 +102,8 @@ static inline void smp_send_reschedule(int cpu)
 	core_send_ipi(cpu, SMP_RESCHEDULE_YOURSELF);
 }
 
+extern int smp_call_function_single(int cpuid, void (*func) (void *info),
+				void *info, int retry, int wait);
 extern asmlinkage void smp_call_function_interrupt(void);
 
 #endif /* CONFIG_SMP */
#1 lore raw
Quoted 44 lines · Stephane Eranian
arch/mips/kernel/smp.c +36 -0
index be7362b..9e376e2 100644
@@ -193,6 +193,53 @@ void smp_call_function_interrupt(void)
 	}
 }
 
+int smp_call_function_single(int cpu, void (*func) (void *info), void *info, int retry,
+			     int wait)
+{
+  struct call_data_struct data;
+  int me = smp_processor_id();
+
+  /*
+     * Can die spectacularly if this CPU isn't yet marked online
+      */
+  BUG_ON(!cpu_online(me));
+  if (cpu == me) {
+    WARN_ON(1);
+    return -EBUSY;
+    }
+
+  /* Can deadlock when called with interrupts disabled */
+  WARN_ON(irqs_disabled());
+
+  data.func = func;
+  data.info = info;
+  atomic_set(&data.started, 0);
+  data.wait = wait;
+  if (wait)
+    atomic_set(&data.finished, 0);
+
+  spin_lock(&smp_call_lock);
+  call_data = &data;
+  mb();
+
+  /* Send a message to the other CPU */
+  core_send_ipi(cpu, SMP_CALL_FUNCTION);
+
+  /* Wait for response */
+  /* FIXME: lock-up detection, backtrace on lock-up */
+  while (atomic_read(&data.started) != 1)
+    barrier();

arch/mips/kernel/smp.c void smp_call_function_interrupt(void) · line 241

Quoted 10 lines
arch/mips/kernel/smp.c +10 -0
+
+  if (wait)
+    while (atomic_read(&data.finished) != 1)
+      barrier();
+  call_data = NULL;
+  spin_unlock(&smp_call_lock);
+
+  return 0;
+}
+EXPORT_SYMBOL(smp_call_function_single);

Please fix the indentation to use tabs as per Documentation/CodingStyle.

include/asm-mips/smp.h static inline void smp_send_reschedule(int cpu) · line 106

Quoted 13 lines
arch/mips/kernel/smp.c +0 -0
 static void stop_this_cpu(void *dummy)
 {
 	/*
include/asm-mips/smp.h +2 -0
index 13aef6a..5acbf38 100644
@@ -102,6 +102,8 @@ static inline void smp_send_reschedule(int cpu)
 	core_send_ipi(cpu, SMP_RESCHEDULE_YOURSELF);
 }
 
+extern int smp_call_function_single(int cpuid, void (*func) (void *info),
+				void *info, int retry, int wait);

The function is already declared in include/linux/smp.h so this segment is unecessary.

Ralf

#2 lore raw

Ralf,

Here is take 2.

[MIPS] add smp_call_function_single (take 2)

arch/mips/kernel/smp.c +47 -0
index be7362b..d47234c 100644
@@ -193,6 +193,53 @@ void smp_call_function_interrupt(void)
 	}
 }
 
+int smp_call_function_single(int cpu, void (*func) (void *info), void *info, int retry,
+			     int wait)
+{
+	struct call_data_struct data;
+	int me = smp_processor_id();
+
+	/*
+	 * Can die spectacularly if this CPU isn't yet marked online
+	 */
+	BUG_ON(!cpu_online(me));
+	if (cpu == me) {
+		WARN_ON(1);
+		return -EBUSY;
+	}
+
+	/* Can deadlock when called with interrupts disabled */
+	WARN_ON(irqs_disabled());
+
+	data.func = func;
+	data.info = info;
+	atomic_set(&data.started, 0);
+	data.wait = wait;
+	if (wait)
+		atomic_set(&data.finished, 0);
+
+	spin_lock(&smp_call_lock);
+	call_data = &data;
+	mb();
+
+	/* Send a message to the other CPU */
+	core_send_ipi(cpu, SMP_CALL_FUNCTION);
+
+	/* Wait for response */
+	/* FIXME: lock-up detection, backtrace on lock-up */
+	while (atomic_read(&data.started) != 1)
+		barrier();
+
+	if (wait)
+		while (atomic_read(&data.finished) != 1)
+			barrier();
+	call_data = NULL;
+	spin_unlock(&smp_call_lock);
+
+	return 0;
+}
+EXPORT_SYMBOL(smp_call_function_single);
+
 static void stop_this_cpu(void *dummy)
 {
 	/*
#3 lore raw
Quoted 56 lines · Stephane Eranian

Ralf,

Here is take 2.

[MIPS] add smp_call_function_single (take 2)

arch/mips/kernel/smp.c +39 -0
index be7362b..d47234c 100644
@@ -193,6 +193,53 @@ void smp_call_function_interrupt(void)
 	}
 }
 
+int smp_call_function_single(int cpu, void (*func) (void *info), void *info, int retry,
+			     int wait)
+{
+	struct call_data_struct data;
+	int me = smp_processor_id();
+
+	/*
+	 * Can die spectacularly if this CPU isn't yet marked online
+	 */
+	BUG_ON(!cpu_online(me));
+	if (cpu == me) {
+		WARN_ON(1);
+		return -EBUSY;
+	}
+
+	/* Can deadlock when called with interrupts disabled */
+	WARN_ON(irqs_disabled());
+
+	data.func = func;
+	data.info = info;
+	atomic_set(&data.started, 0);
+	data.wait = wait;
+	if (wait)
+		atomic_set(&data.finished, 0);
+
+	spin_lock(&smp_call_lock);
+	call_data = &data;
+	mb();
+
+	/* Send a message to the other CPU */
+	core_send_ipi(cpu, SMP_CALL_FUNCTION);
+
+	/* Wait for response */
+	/* FIXME: lock-up detection, backtrace on lock-up */
+	while (atomic_read(&data.started) != 1)
+		barrier();
+
+	if (wait)
+		while (atomic_read(&data.finished) != 1)

arch/mips/kernel/smp.c void smp_call_function_interrupt(void) · line 244

Quoted 10 lines
arch/mips/kernel/smp.c +8 -0
+			barrier();
+	call_data = NULL;
+	spin_unlock(&smp_call_lock);
+
+	return 0;
+}
+EXPORT_SYMBOL(smp_call_function_single);
+
 static void stop_this_cpu(void *dummy)
 {

This will not do the right thing. Semantics of smp_call_function_single() changed recently. It now is supposed to call func() locally with irqs disabled if cpu == smp_processor_id(). See i386/x86_64 and powerpc. Unfortunately ia64 hasn't been changed yet, so it will behave differently.

#4 lore raw
Quoted 5 lines · Heiko Carstens

This will not do the right thing. Semantics of smp_call_function_single() changed recently. It now is supposed to call func() locally with irqs disabled if cpu == smp_processor_id(). See i386/x86_64 and powerpc. Unfortunately ia64 hasn't been changed yet, so it will behave differently.

A patch for ia64 has been submitted, presumably it's somewhere in the pipeline.

Signature · 1 line
error compiling committee.c: too many arguments to function
#5 lore raw
In reply to Heiko Carstens

Hello,

Thanks for catching this. We will resubmit an updated version.

PHil, Peter, would you be able/willing to do this?

thanks.

Quoted 72 lines · Heiko Carstens
Quoted 56 lines · Stephane Eranian

Ralf,

Here is take 2.

[MIPS] add smp_call_function_single (take 2)

arch/mips/kernel/smp.c +39 -0
index be7362b..d47234c 100644
@@ -193,6 +193,53 @@ void smp_call_function_interrupt(void)
 	}
 }
 
+int smp_call_function_single(int cpu, void (*func) (void *info), void *info, int retry,
+			     int wait)
+{
+	struct call_data_struct data;
+	int me = smp_processor_id();
+
+	/*
+	 * Can die spectacularly if this CPU isn't yet marked online
+	 */
+	BUG_ON(!cpu_online(me));
+	if (cpu == me) {
+		WARN_ON(1);
+		return -EBUSY;
+	}
+
+	/* Can deadlock when called with interrupts disabled */
+	WARN_ON(irqs_disabled());
+
+	data.func = func;
+	data.info = info;
+	atomic_set(&data.started, 0);
+	data.wait = wait;
+	if (wait)
+		atomic_set(&data.finished, 0);
+
+	spin_lock(&smp_call_lock);
+	call_data = &data;
+	mb();
+
+	/* Send a message to the other CPU */
+	core_send_ipi(cpu, SMP_CALL_FUNCTION);
+
+	/* Wait for response */
+	/* FIXME: lock-up detection, backtrace on lock-up */
+	while (atomic_read(&data.started) != 1)
+		barrier();
+
+	if (wait)
+		while (atomic_read(&data.finished) != 1)

arch/mips/kernel/smp.c void smp_call_function_interrupt(void) · line 244

Quoted 10 lines
arch/mips/kernel/smp.c +8 -0
+			barrier();
+	call_data = NULL;
+	spin_unlock(&smp_call_lock);
+
+	return 0;
+}
+EXPORT_SYMBOL(smp_call_function_single);
+
 static void stop_this_cpu(void *dummy)
 {

This will not do the right thing. Semantics of smp_call_function_single() changed recently. It now is supposed to call func() locally with irqs disabled if cpu == smp_processor_id(). See i386/x86_64 and powerpc. Unfortunately ia64 hasn't been changed yet, so it will behave differently.

Signature · 1 line
-Stephane