From: Peter Zijlstra <peterz@infradead.org>
To: Vineet Gupta <Vineet.Gupta1@synopsys.com>
Cc: "linux-arch@vger.kernel.org" <linux-arch@vger.kernel.org>,
Gilad Ben-Yossef <gilad@benyossef.com>,
Noam Camus <noamc@ezchip.com>,
David Daney <david.daney@cavium.com>,
James Hogan <james.hogan@imgtec.com>,
thomas Gleixner <tglx@linutronix.de>,
lkml <linux-kernel@vger.kernel.org>,
Richard Kuo <rkuo@codeaurora.org>
Subject: Re: Preventing IPI sending races in arch code
Date: Mon, 25 Nov 2013 14:57:25 +0100 [thread overview]
Message-ID: <20131125135725.GA10022@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <C2D7FE5348E1B147BCA15975FBA2307515715C@IN01WEMBXA.internal.synopsys.com>
On Mon, Nov 25, 2013 at 01:35:38PM +0000, Vineet Gupta wrote:
> On 11/25/2013 05:57 PM, Peter Zijlstra wrote:
> > So sure, then someone can again assert the interrupt, but given we just
> > established a protocol for raising the thing; namely something like
> > this:
> >
> > void arch_send_ipi(int cpu, int type)
> > {
> > u32 *pending_ptr = per_cpu_ptr(ipi_bits, cpu);
> > u32 new, old;
> >
> > do {
> > new = old = *pending_ptr;
> > new |= 1U << type;
> > } while (cmpxchg(pending_ptr, old, new) != old)
> >
> > if (!old) /* only raise the actual IPI if we set the first bit */
> > raise_ipi(cpu);
> > }
> >
> > Who would re-assert it if we have !0 pending?
>
> I see your point. So in receiver, it is OK to de-assert the IPI before processing
> the msg itself.
>
> Actually your code seems to be optimizing away asserting an IPI, if sender already
> had a pending msg (assuming we retain the xchg loop in receiver). Was that an
> intended optimization - or just a side effect of your code ;-)
No, full intention. As you mentioned you wanted to avoid sending IPIs
where none were needed.
> >> IMO the while loop is
> >> completely useless specially if IPIs are not coalesced in h/w.
> > Agreed, the while loops seems superfluous.
>
> Not with your version of sender, since we need it as described above.
No, even with my code; the receiving end should look like:
void handle_ipi(struct pt_regs *regs)
{
u32 pending;
ipi_clear(irq);
pending = xchg(this_cpu_ptr(ipi_bits), 0);
while (pending) {
bit = ffs(pending);
/* handle bit */
pending &= ~(1U << bit);
}
}
So while it does have a while() loop, it only does a single xchg().
The version you showed before had the xchg() in the loop, that is not
required.
next prev parent reply other threads:[~2013-11-25 13:57 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-25 10:52 Preventing IPI sending races in arch code Vineet Gupta
2013-11-25 11:00 ` Peter Zijlstra
2013-11-25 11:30 ` Vineet Gupta
2013-11-25 12:27 ` Peter Zijlstra
2013-11-25 13:35 ` Vineet Gupta
2013-11-25 13:57 ` Peter Zijlstra [this message]
2013-11-25 13:57 ` Peter Zijlstra
2013-11-25 19:51 ` Benjamin Herrenschmidt
2013-11-26 4:47 ` Vineet Gupta
2013-11-26 5:11 ` Benjamin Herrenschmidt
2013-11-26 6:35 ` Vineet Gupta
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=20131125135725.GA10022@twins.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=Vineet.Gupta1@synopsys.com \
--cc=david.daney@cavium.com \
--cc=gilad@benyossef.com \
--cc=james.hogan@imgtec.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=noamc@ezchip.com \
--cc=rkuo@codeaurora.org \
--cc=tglx@linutronix.de \
/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