All of lore.kernel.org
 help / color / mirror / Atom feed
From: Boqun Feng <boqun.feng@gmail.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Davidlohr Bueso <dave@stgolabs.net>,
	Manfred Spraul <manfred@colorfullife.com>,
	Waiman Long <Waiman.Long@hpe.com>, Ingo Molnar <mingo@kernel.org>,
	ggherdovich@suse.com, Mel Gorman <mgorman@techsingularity.net>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Paul McKenney <paulmck@linux.vnet.ibm.com>,
	Will Deacon <will.deacon@arm.com>
Subject: Re: sem_lock() vs qspinlocks
Date: Wed, 25 May 2016 14:37:37 +0800	[thread overview]
Message-ID: <20160525063737.GD21433@insomnia> (raw)
In-Reply-To: <CA+55aFyHVYh8VP9r1kohMomw=ed7y_=uQHDxtMsDCEcHKm+tFQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2673 bytes --]

On Mon, May 23, 2016 at 10:52:09AM -0700, Linus Torvalds wrote:
> On Mon, May 23, 2016 at 5:25 AM, Peter Zijlstra <peterz@infradead.org> wrote:
> >
> > Paul has smp_mb__after_unlock_lock() for the RCpc 'upgrade'. How about
> > something like:
> >
> >         smp_mb__after_lock()
> 
> I'd much rather make the naming be higher level. It's not necessarily

Speak of higher level, I realize that problem here is similar to the
problem we discussed last year:

http://lkml.kernel.org/r/20151112070915.GC6314@fixme-laptop.cn.ibm.com

the problem here is about synchronization between two spinlocks and that
problem is about synchronization between a spinlock and ordinary
variables.

(One result of this similarity is that qspinlock on x86 may be also
broken in the do_exit() code as spinlocks on AARCH64 and PPC. Because
a variable LOAD inside a qspinlock critical section could be reordered
before the STORE part of a qspinlock acquisition.)


For the problem we found last year, the current solution for AARCH64 and
PPC is to have a little heavy weight spin_unlock_wait() to pair with
spin_lock():

AARCH64: http://lkml.kernel.org/r/1448624646-15863-1-git-send-email-will.deacon@arm.com
PPC: http://lkml.kernel.org/r/1461130033-70898-1-git-send-email-boqun.feng@gmail.com (not merged yet)

Another solution works on PPC is what Paul Mckenney suggested, using
smp_mb__after_unlock_lock():

http://lkml.kernel.org/r/20151112144004.GU3972@linux.vnet.ibm.com

, which is petty much the same as the spinlock synchronization
primitive we are discussing about here.


So I'm thinking, if we are going to introduce some primitives for
synchronizing two spinlocks (or even a spinlock and a mutex) anyway,
could we be a little more higher level, to reuse/invent primitives to
solve the synchronzing problem we have between
spinlocks(spin_unlock_wait()) and normal variables?

One benefit of this is that we could drop the complex implementations of
spin_unlock_wait() on AARCH64 and PPC.

Thoughts?

Regards,
Boqun

> going to be a "mb", and while the problem is about smp, the primitives
> it is synchronizing aren't actually smp-specific (ie you're
> synchronizing a lock that is relevant on UP too).
> 
> So I'd just call it something like
> 
>         spin_lock_sync_after_lock();
> 
> because different locks might have different levels of serialization
> (ie maybe a spinlock needs one thing, and a mutex needs another - if
> we start worrying about ordering between spin_lock and
> mutex_is_locked(), for example, or between mutex_lock() and
> spin_is_locked()).
> 
> Hmm?
> 
>                      Linus

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

  reply	other threads:[~2016-05-25  6:33 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-20  5:39 sem_lock() vs qspinlocks Davidlohr Bueso
2016-05-20  7:49 ` Peter Zijlstra
2016-05-20 15:00   ` Davidlohr Bueso
2016-05-20 15:05     ` Peter Zijlstra
2016-05-20 15:25       ` Davidlohr Bueso
2016-05-20 15:28       ` Peter Zijlstra
2016-05-20 20:47     ` Waiman Long
2016-05-20 20:52       ` Peter Zijlstra
2016-05-21  0:59         ` Davidlohr Bueso
2016-05-21  4:01           ` Waiman Long
2016-05-21  7:40             ` Peter Zijlstra
2016-05-20  7:53 ` Peter Zijlstra
2016-05-20  8:13 ` Peter Zijlstra
2016-05-20  8:18   ` Peter Zijlstra
2016-05-20  9:07     ` Giovanni Gherdovich
2016-05-20  9:34       ` Peter Zijlstra
2016-05-20  8:30 ` Peter Zijlstra
2016-05-20  9:00   ` Peter Zijlstra
2016-05-20 10:09     ` Ingo Molnar
2016-05-20 10:45       ` Mel Gorman
2016-05-20 11:58 ` Peter Zijlstra
2016-05-20 14:05   ` Boqun Feng
2016-05-20 15:21     ` Peter Zijlstra
2016-05-20 16:04       ` Peter Zijlstra
2016-05-20 17:00         ` Linus Torvalds
2016-05-20 21:06           ` Peter Zijlstra
2016-05-20 21:44             ` Linus Torvalds
2016-05-21  0:48               ` Davidlohr Bueso
2016-05-21  2:30                 ` Linus Torvalds
2016-05-21  7:37                 ` Peter Zijlstra
2016-05-21 13:49                   ` Manfred Spraul
2016-05-24 10:57                     ` Peter Zijlstra
2016-05-21 17:14                   ` Davidlohr Bueso
2016-05-23 12:25           ` Peter Zijlstra
2016-05-23 17:52             ` Linus Torvalds
2016-05-25  6:37               ` Boqun Feng [this message]
2016-05-22  8:43         ` Manfred Spraul
2016-05-22  9:38           ` Peter Zijlstra
2016-05-20 16:20   ` Davidlohr Bueso
2016-05-20 20:44   ` Waiman Long
2016-05-20 20:53     ` 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=20160525063737.GD21433@insomnia \
    --to=boqun.feng@gmail.com \
    --cc=Waiman.Long@hpe.com \
    --cc=dave@stgolabs.net \
    --cc=ggherdovich@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=manfred@colorfullife.com \
    --cc=mgorman@techsingularity.net \
    --cc=mingo@kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=torvalds@linux-foundation.org \
    --cc=will.deacon@arm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.