All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Andrea Parri <parri.andrea@gmail.com>,
	Will Deacon <will.deacon@arm.com>,
	peterz@infradead.org, boqun.feng@gmail.com, npiggin@gmail.com,
	dhowells@redhat.com, Jade Alglave <j.alglave@ucl.ac.uk>,
	Luc Maranget <luc.maranget@inria.fr>,
	Kernel development list <linux-kernel@vger.kernel.org>
Subject: Re: Linux-kernel examples for LKMM recipes
Date: Fri, 13 Oct 2017 13:00:33 -0700	[thread overview]
Message-ID: <20171013200033.GI3521@linux.vnet.ibm.com> (raw)
In-Reply-To: <Pine.LNX.4.44L0.1710131523470.1364-100000@iolanthe.rowland.org>

On Fri, Oct 13, 2017 at 03:44:07PM -0400, Alan Stern wrote:
> On Wed, 11 Oct 2017, Paul E. McKenney wrote:
> 
> > This document lists the litmus-test patterns that we have been discussing,
> > along with examples from the Linux kernel.  This is intended to feed into
> > the recipes document.  All examples are from v4.13.
> > 
> > 0.	Single-variable SC.
> > 
> > 	a.	Within a single CPU, the use of the ->dynticks_nmi_nesting
> > 		counter by rcu_nmi_enter() and rcu_nmi_exit() qualifies
> > 		(see kernel/rcu/tree.c).  The counter is accessed by
> > 		interrupts and NMIs as well as by process-level code.
> > 		This counter can be accessed by other CPUs, but only
> > 		for debug output.
> 
> I'm not sure that single-variable SC can really be represented by an 
> example.  It gets used literally all over the kernel -- it's such a 
> large part of the way we think about computer programs that we rely on 
> it unconsciously.
> 
> For example, the very first function in the very first C source file 
> in the kernel/ directory (namely, check_free_space() in kernel/acct.c) 
> includes this code:
> 
>         if (acct->active) {
>                 u64 suspend = sbuf.f_blocks * SUSPEND;
>                 do_div(suspend, 100);
> 
> How do we know that the value which gets divided by 100 is
> sbuf.f_blocks * SUSPEND and not the random garbage which was stored in
> suspend's memory location before it was initialized?  Answer:
> per-variable SC.
> 
> Okay, maybe that's not really applicable, since it doesn't involve
> accesses to shared memory.  Here's an example that does.  
> get_futex_key() in kernel/futex.c calls READ_ONCE(page->mapping) twice.  
> How do we know that the value retrieved by the second call was not
> stored _earlier_ than the value retrieved by the first call?  
> Per-variable SC.
> 
> > 	b.	Between CPUs, I would put forward the ->dflags
> > 		updates, but this is anything but simple.  But maybe
> > 		OK for an illustration?
> 
> Pretty much any code that accesses the same shared variable twice on
> the same CPU could be an example of per-variable SC.  But I don't think 
> people would learn much by studying such examples.

Perhaps the recipes document should just baldly state that any execution
having only one thread and/or having only one variable will be fully
ordered?

							Thanx, Paul

  reply	other threads:[~2017-10-13 20:00 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
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 [this message]
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=20171013200033.GI3521@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.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=peterz@infradead.org \
    --cc=stern@rowland.harvard.edu \
    --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.