public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: pwatkins@sicortex.com
To: eranian@hpl.hp.com, heiko.carstens@de.ibm.com
Cc: pwatkins@sicortex.com, mucci@cs.utk.edu, ralf@linux-mips.org,
	linux-kernel@vger.kernel.org, linux-mips@linux-mips.org,
	ak@suse.de, akpm@linux-foundation.org, tony.luck@intel.com,
	avi@qumranet.com
Subject: Re: [PATCH] MIPS: Add smp_call_function_single()
Date: Mon, 30 Jul 2007 18:01:29 -0400	[thread overview]
Message-ID: <11858328891389-git-send-email-pwatkins@sicortex.com> (raw)

How about this to handle the "call yourself" semantic?

In the other archs, there is more factoring of smp call code, and more care in
the use of get_cpu(). That can be a follow-up MIPS patch.

Signed-off-by: Peter Watkins <pwatkins@sicortex.com>

---
diff --git a/arch/mips/kernel/smp.c b/arch/mips/kernel/smp.c
index 67edfa7..33712ff 100644
--- a/arch/mips/kernel/smp.c
+++ b/arch/mips/kernel/smp.c
@@ -203,6 +203,61 @@ 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;
+
+	/*
+	 * Can die spectacularly if this CPU isn't yet marked online
+	 */
+	if (!cpu_online(cpu))
+		return 0;
+
+	me = get_cpu();
+	BUG_ON(!cpu_online(me));
+
+	if (cpu == me) {
+		local_irq_disable()
+		func(info);
+		local_irq_enable();
+		put_cpu();
+		return 0;
+	}
+
+	/* 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;
+	smp_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);
+
+	put_cpu();
+	return 0;
+}
+
 static void stop_this_cpu(void *dummy)
 {
 	/*

             reply	other threads:[~2007-07-30 22:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-30 22:01 pwatkins [this message]
  -- strict thread matches above, loose matches on Subject: below --
2007-07-27 12:44 [PATCH] MIPS: add smp_call_function_single() Stephane Eranian
2007-07-27 12:55 ` Ralf Baechle
2007-07-27 13:53   ` Stephane Eranian
2007-07-28  9:19     ` Heiko Carstens
2007-07-29  7:33       ` Avi Kivity
2007-07-30  9:18       ` Stephane Eranian

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11858328891389-git-send-email-pwatkins@sicortex.com \
    --to=pwatkins@sicortex.com \
    --cc=ak@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=avi@qumranet.com \
    --cc=eranian@hpl.hp.com \
    --cc=heiko.carstens@de.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@linux-mips.org \
    --cc=mucci@cs.utk.edu \
    --cc=ralf@linux-mips.org \
    --cc=tony.luck@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox