From: Will Deacon <will.deacon@arm.com>
To: Boqun Feng <boqun.feng@gmail.com>
Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
stern@rowland.harvard.edu, parri.andrea@gmail.com,
peterz@infradead.org, npiggin@gmail.com, dhowells@redhat.com,
j.alglave@ucl.ac.uk, luc.maranget@inria.fr,
linux-kernel@vger.kernel.org
Subject: Re: Linux-kernel examples for LKMM recipes
Date: Thu, 12 Oct 2017 12:27:19 +0100 [thread overview]
Message-ID: <20171012112718.GA31036@arm.com> (raw)
In-Reply-To: <20171012012359.yrz5dhqmfp7nyq37@tardis>
On Thu, Oct 12, 2017 at 09:23:59AM +0800, Boqun Feng wrote:
> On Wed, Oct 11, 2017 at 10:32:30PM +0000, Paul E. McKenney wrote:
> > I am not aware of any three-CPU release-acquire chains in the
> > Linux kernel. There are three-CPU lock-based chains in RCU,
> > but these are not at all simple, either.
> >
>
> The "Program-Order guarantees" case in scheduler? See the comments
> written by Peter above try_to_wake_up():
>
> * The basic program-order guarantee on SMP systems is that when a task [t]
> * migrates, all its activity on its old CPU [c0] happens-before any subsequent
> * execution on its new CPU [c1].
> ...
> * For blocking we (obviously) need to provide the same guarantee as for
> * migration. However the means are completely different as there is no lock
> * chain to provide order. Instead we do:
> *
> * 1) smp_store_release(X->on_cpu, 0)
> * 2) smp_cond_load_acquire(!X->on_cpu)
> *
> * Example:
> *
> * CPU0 (schedule) CPU1 (try_to_wake_up) CPU2 (schedule)
> *
> * LOCK rq(0)->lock LOCK X->pi_lock
> * dequeue X
> * sched-out X
> * smp_store_release(X->on_cpu, 0);
> *
> * smp_cond_load_acquire(&X->on_cpu, !VAL);
> * X->state = WAKING
> * set_task_cpu(X,2)
> *
> * LOCK rq(2)->lock
> * enqueue X
> * X->state = RUNNING
> * UNLOCK rq(2)->lock
> *
> * LOCK rq(2)->lock // orders against CPU1
> * sched-out Z
> * sched-in X
> * UNLOCK rq(2)->lock
> *
> * UNLOCK X->pi_lock
> * UNLOCK rq(0)->lock
>
> This is a chain mixed with lock and acquire-release(maybe even better?).
>
>
> And another example would be osq_{lock,unlock}() on multiple(more than
> three) CPUs.
I think the qrwlock also has something similar with the writer fairness
issue fixed:
CPU0: (writer doing an unlock)
smp_store_release(&lock->wlocked, 0); // Bottom byte of lock->cnts
CPU1: (waiting writer on slowpath)
atomic_cond_read_acquire(&lock->cnts, VAL == _QW_WAITING);
...
arch_spin_unlock(&lock->wait_lock);
CPU2: (reader on slowpath)
arch_spin_lock(&lock->wait_lock);
and there's mixed-size accesses here too. Fun stuff!
Will
next prev parent reply other threads:[~2017-10-12 11:27 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-11 22:32 Linux-kernel examples for LKMM recipes Paul E. McKenney
2017-10-12 1:23 ` Boqun Feng
2017-10-12 11:27 ` Will Deacon [this message]
2017-10-17 20:37 ` Paul E. McKenney
2017-10-17 20:56 ` Paul E. McKenney
2017-10-12 13:27 ` Andrea Parri
2017-10-17 20:18 ` Paul E. McKenney
2017-10-13 19:44 ` Alan Stern
2017-10-13 20:00 ` Paul E. McKenney
2017-10-13 20:09 ` Alan Stern
2017-10-17 18:56 ` Paul E. McKenney
2017-10-17 19:38 ` Alan Stern
2017-10-17 20:33 ` Paul E. McKenney
2017-10-17 21:03 ` Alan Stern
2017-10-17 21:55 ` Paul E. McKenney
2017-10-18 14:43 ` Alan Stern
2017-10-18 20:28 ` Paul E. McKenney
2017-10-18 21:18 ` Alan Stern
2017-10-18 22:57 ` Paul E. McKenney
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=20171012112718.GA31036@arm.com \
--to=will.deacon@arm.com \
--cc=boqun.feng@gmail.com \
--cc=dhowells@redhat.com \
--cc=j.alglave@ucl.ac.uk \
--cc=linux-kernel@vger.kernel.org \
--cc=luc.maranget@inria.fr \
--cc=npiggin@gmail.com \
--cc=parri.andrea@gmail.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=stern@rowland.harvard.edu \
/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