From: Will Deacon <will.deacon@arm.com>
To: Boqun Feng <boqun.feng@gmail.com>
Cc: Andrea Parri <parri.andrea@gmail.com>,
Waiman Long <longman@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Pan Xinhui <xinhui@linux.vnet.ibm.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] locking/pvqspinlock: Relax cmpxchg's to improve performance on some archs
Date: Tue, 21 Feb 2017 13:04:00 +0000 [thread overview]
Message-ID: <20170221130400.GG300@arm.com> (raw)
In-Reply-To: <20170220045839.GJ9178@tardis.cn.ibm.com>
On Mon, Feb 20, 2017 at 12:58:39PM +0800, Boqun Feng wrote:
> > So Waiman, the fact is that in this case, we want the following code
> > sequence:
> >
> > CPU 0 CPU 1
> > ================= ====================
> > {pn->state = vcpu_running, node->locked = 0}
> >
> > smp_store_smb(&pn->state, vcpu_halted):
> > WRITE_ONCE(pn->state, vcpu_halted);
> > smp_mb();
> > r1 = READ_ONCE(node->locked);
> > arch_mcs_spin_unlock_contented();
> > WRITE_ONCE(node->locked, 1)
> >
> > cmpxchg(&pn->state, vcpu_halted, vcpu_hashed);
> >
> > never ends up in:
> >
> > r1 == 0 && cmpxchg fail(i.e. the read part of cmpxchg reads the
> > value vcpu_running).
> >
> > We can have such a guarantee if cmpxchg has a smp_mb() before its load
> > part, which is true for PPC. But semantically, cmpxchg() doesn't provide
> > any order guarantee if it fails, which is true on ARM64, IIUC. (Add Will
> > in Cc for his insight ;-)).
I think you're right. The write to node->locked on CPU1 is not required
to be ordered before the load part of the failing cmpxchg.
> > So a possible "fix"(in case ARM64 will use qspinlock some day), would be
> > replace cmpxchg() with smp_mb() + cmpxchg_relaxed().
Peversely, we could actually get away with cmpxchg_acquire on arm64 because
arch_mcs_spin_unlock_contended is smp_store_release and we order release ->
acquire in the architecture. But that just brings up the age old unlock/lock
discussion again...
Will
next prev parent reply other threads:[~2017-02-21 13:04 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-17 20:43 [PATCH v3] locking/pvqspinlock: Relax cmpxchg's to improve performance on some archs Waiman Long
2017-02-20 4:20 ` Andrea Parri
2017-02-20 4:53 ` Boqun Feng
2017-02-20 4:58 ` Boqun Feng
2017-02-21 13:04 ` Will Deacon [this message]
2017-02-20 15:58 ` Waiman Long
2017-02-20 11:00 ` Peter Zijlstra
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=20170221130400.GG300@arm.com \
--to=will.deacon@arm.com \
--cc=boqun.feng@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mingo@redhat.com \
--cc=parri.andrea@gmail.com \
--cc=peterz@infradead.org \
--cc=xinhui@linux.vnet.ibm.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