Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1576309
| Path | csiph.com!news.redatomik.org!aioe.org!bofh.it!news.nic.it!robomod |
|---|---|
| From | Boqun Feng <boqun.feng@gmail.com> |
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH v2] locking/pvqspinlock: Relax cmpxchg's to improve performance on some archs |
| Date | Wed, 08 Feb 2017 08:20:01 +0100 |
| Message-ID | <t8uHL-5In-5@gated-at.bofh.it> (permalink) |
| References | <sSnAB-2cx-11@gated-at.bofh.it> <t8rTz-3KA-13@gated-at.bofh.it> <t8rTz-3KA-11@gated-at.bofh.it> <t8tC1-4YS-1@gated-at.bofh.it> <t8uy6-5F3-23@gated-at.bofh.it> |
| X-Original-To | Pan Xinhui <xinhui@linux.vnet.ibm.com> |
| Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=zP8b81iQlfjvLp/Htur9mgglLyEI6vxMc6zTSelsENE=; b=EuAkGQ+hY/1nGUZTiq9KH5ts4RUDRNg7ct3TeSvIMniRGZN5nxyJRt2l8Bd80ZzrcI P325MlX6Bo07pZFMNg92a0MosN0MFVJ3LFMDdjJDeOZ13K97KSKM69fW3n/xSQaalC5U NQHxduE3WIbyChhFgfytuh4SleyW60pEIKtsccwAwaQbNDq6oOg1n1IenL60xKZrKvzN tUp9hMxb91fXbL4AitTllUM7/F1ZWxvWntWNPXJfeVabDGd50fUALNmmSvd+g3vcAWp7 spZtQS1rbwSTwBiT5sgn2hbzQa10nskXsv3yoQ/SZjhgaRZpNijxXdTCIOLClq/ghy87 VBqA== |
| X-Google-Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=zP8b81iQlfjvLp/Htur9mgglLyEI6vxMc6zTSelsENE=; b=s0BrzM53Bitkrw7WKphJQFVuX9nt1RAqpDEhL+tiKXAV4+j1edB+1RYrq2miLq1W9h iAqoXujWOHtqOZLoVWxh+hM+iKbAqj2J16bMBfPNWYJTR/mVq3kaGtHZI43JJJkxUTdY 9SjJUeVucpO825YA60brOSxZVI9DT5fp1ZK2Die+gi7gpTBjC/p1+N5j5mrhlMqxBY6I /ZU6kTskeYCEAZOO5DHBCYgoG7Tv4yZmFpvT3dMydO20GJpWGwqG2d/tAW8+LxBRo3kB fCkC15pF93HPCQMOW5WezM6ySydQ3F45gV5yQv8t1czLe+bhjW/ygtVJaQS0NMhr5VRr azfA== |
| X-Gm-Message-State | AIkVDXIBYO/gcN6L7sfDMPXVh56jlZgJ+CgzQnV8omou+6X/eTEh2ojBBD0nQ8CuXlmuhQ== |
| X-Received | by 10.99.149.27 with SMTP id p27mr25426263pgd.21.1486538044559; Tue, 07 Feb 2017 23:14:04 -0800 (PST) |
| MIME-Version | 1.0 |
| Content-Type | multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="IMjqdzrDRly81ofr" |
| Content-Disposition | inline |
| User-Agent | Mutt/1.7.2 (2016-11-26) |
| Sender | robomod@news.nic.it |
| List-ID | <linux-kernel.vger.kernel.org> |
| X-Mailing-List | linux-kernel@vger.kernel.org |
| Approved | robomod@news.nic.it |
| Lines | 153 |
| Organization | linux.* mail to news gateway |
| X-Original-Cc | Xinhui Pan <mnipxh@gmail.com>, Waiman Long <longman@redhat.com>, Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@redhat.com>, linux-kernel@vger.kernel.org |
| X-Original-Date | Wed, 8 Feb 2017 15:15:22 +0800 |
| X-Original-Message-ID | <20170208071522.GD9178@tardis.cn.ibm.com> |
| X-Original-References | <1482697561-23848-1-git-send-email-longman@redhat.com> <CAH4ORazqsCBA4G5paHtsp8PMfM=J3P6rvyR-53-ZLjn=7U6J0g@mail.gmail.com> <20170208040540.GB9178@tardis.cn.ibm.com> <20170208060939.GC9178@tardis.cn.ibm.com> <9c22e27d-e80e-81f9-d7a0-992e80425f44@linux.vnet.ibm.com> |
| X-Original-Sender | linux-kernel-owner@vger.kernel.org |
| Xref | csiph.com linux.kernel:1576309 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
On Wed, Feb 08, 2017 at 03:09:33PM +0800, Pan Xinhui wrote: > > > 在 2017/2/8 14:09, Boqun Feng 写道: > > On Wed, Feb 08, 2017 at 12:05:40PM +0800, Boqun Feng wrote: > > > On Wed, Feb 08, 2017 at 11:39:10AM +0800, Xinhui Pan wrote: > > > > 2016-12-26 4:26 GMT+08:00 Waiman Long <longman@redhat.com>: > > > > > > > > > A number of cmpxchg calls in qspinlock_paravirt.h were replaced by more > > > > > relaxed versions to improve performance on architectures that use LL/SC. > > > > > > > > > > All the locking related cmpxchg's are replaced with the _acquire > > > > > variants: > > > > > - pv_queued_spin_steal_lock() > > > > > - trylock_clear_pending() > > > > > > > > > > The cmpxchg's related to hashing are replaced by either by the _release > > > > > or the _relaxed variants. See the inline comment for details. > > > > > > > > > > Signed-off-by: Waiman Long <longman@redhat.com> > > > > > > > > > > v1->v2: > > > > > - Add comments in changelog and code for the rationale of the change. > > > > > > > > > > --- > > > > > kernel/locking/qspinlock_paravirt.h | 50 ++++++++++++++++++++++++------ > > > > > ------- > > > > > 1 file changed, 33 insertions(+), 17 deletions(-) > > > > > > > > > > > > > > > @@ -323,8 +329,14 @@ static void pv_wait_node(struct mcs_spinlock *node, > > > > > struct mcs_spinlock *prev) > > > > > * If pv_kick_node() changed us to vcpu_hashed, retain that > > > > > * value so that pv_wait_head_or_lock() knows to not also > > > > > try > > > > > * to hash this lock. > > > > > + * > > > > > + * The smp_store_mb() and control dependency above will > > > > > ensure > > > > > + * that state change won't happen before that. > > > > > Synchronizing > > > > > + * with pv_kick_node() wrt hashing by this waiter or by the > > > > > + * lock holder is done solely by the state variable. There > > > > > is > > > > > + * no other ordering requirement. > > > > > */ > > > > > - cmpxchg(&pn->state, vcpu_halted, vcpu_running); > > > > > + cmpxchg_relaxed(&pn->state, vcpu_halted, vcpu_running); > > > > > > > > > > /* > > > > > * If the locked flag is still not set after wakeup, it is > > > > > a > > > > > @@ -360,9 +372,12 @@ static void pv_kick_node(struct qspinlock *lock, > > > > > struct mcs_spinlock *node) > > > > > * pv_wait_node(). If OTOH this fails, the vCPU was running and > > > > > will > > > > > * observe its next->locked value and advance itself. > > > > > * > > > > > - * Matches with smp_store_mb() and cmpxchg() in pv_wait_node() > > > > > + * Matches with smp_store_mb() and cmpxchg_relaxed() in > > > > > pv_wait_node(). > > > > > + * A release barrier is used here to ensure that node->locked is > > > > > + * always set before changing the state. See comment in > > > > > pv_wait_node(). > > > > > */ > > > > > - if (cmpxchg(&pn->state, vcpu_halted, vcpu_hashed) != vcpu_halted) > > > > > + if (cmpxchg_release(&pn->state, vcpu_halted, vcpu_hashed) > > > > > + != vcpu_halted) > > > > > return; > > > > > > > > > > hi, Waiman > > > > We can't use _release here, a full barrier is needed. > > > > > > > > There is pv_kick_node vs pv_wait_head_or_lock > > > > > > > > [w] l->locked = _Q_SLOW_VAL //reordered here > > > > > > > > if (READ_ONCE(pn->state) == vcpu_hashed) //False. > > > > > > > > lp = (struct qspinlock **)1; > > > > > > > > [STORE] pn->state = vcpu_hashed lp = pv_hash(lock, > > > > pn); > > > > pv_hash() if > > > > (xchg(&l->locked, _Q_SLOW_VAL) == 0) // fasle, not unhashed. > > > > > > > > > > This analysis is correct, but.. > > > > > > > Hmm.. look at this again, I don't think this analysis is meaningful, > > let's say the reordering didn't happen, we still got(similar to your > > case): > > > but there is > cmpxchg_relaxed(&pn->state, vcpu_halted, vcpu_running); > > > if (READ_ONCE(pn->state) == vcpu_hashed) // false. > > lp = (struct qspinlock **)1; > > > > cmpxchg(pn->state, vcpu_halted, vcpu_hashed); > this cmpxchg will observe the cmpxchg_relaxed above, so this cmpxchg will fail as pn->state is vcpu_running. > No bug here.. > And we got the same guarantee if we use cmpxchg_release(), no? Regards, Boqun
Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread
Re: [PATCH v2] locking/pvqspinlock: Relax cmpxchg's to improve performance on some archs Boqun Feng <boqun.feng@gmail.com> - 2017-02-08 05:20 +0100
Re: [PATCH v2] locking/pvqspinlock: Relax cmpxchg's to improve performance on some archs Boqun Feng <boqun.feng@gmail.com> - 2017-02-08 07:10 +0100
Re: [PATCH v2] locking/pvqspinlock: Relax cmpxchg's to improve performance on some archs Pan Xinhui <xinhui@linux.vnet.ibm.com> - 2017-02-08 07:50 +0100
Re: [PATCH v2] locking/pvqspinlock: Relax cmpxchg's to improve performance on some archs Pan Xinhui <xinhui@linux.vnet.ibm.com> - 2017-02-08 07:50 +0100
Re: [PATCH v2] locking/pvqspinlock: Relax cmpxchg's to improve performance on some archs Pan Xinhui <xinhui@linux.vnet.ibm.com> - 2017-02-08 08:10 +0100
Re: [PATCH v2] locking/pvqspinlock: Relax cmpxchg's to improve performance on some archs Boqun Feng <boqun.feng@gmail.com> - 2017-02-08 08:20 +0100
csiph-web