Re: Linux-kernel examples for LKMM recipes

From: Paul E. McKenney
Date: Tue Oct 17 2017 - 16:19:01 EST


On Thu, Oct 12, 2017 at 03:27:44PM +0200, Andrea Parri wrote:
> Hi Paul,
>
> On Wed, Oct 11, 2017 at 03:32:30PM -0700, Paul E. McKenney wrote:
> > Hello!
> >
> > At Linux Plumbers Conference, we got requests for a recipes document,
> > and a further request to point to actual code in the Linux kernel.
> > I have pulled together some examples for various litmus-test families,
> > as shown below. The decoder ring for the abbreviations (ISA2, LB, SB,
> > MP, ...) is here:
> >
> > https://www.cl.cam.ac.uk/~pes20/ppc-supplemental/test6.pdf
> >
> > This document is also checked into the memory-models git archive:
> >
> > https://github.com/aparri/memory-model.git
> >
> > I would be especially interested in simpler examples in general, and
> > of course any example at all for the cases where I was unable to find
> > any. Thoughts?
>
> Below are some examples we did discuss (at some point):
>
> The comment in kernel/events/ring_buffer.c:perf_output_put_handle()
> describes instances of MP+wmb+rmb and LB+ctrl+mb.

I added this as an alternative for MP and as the example for LB.

> The comments in kernel/sched/core.c:try_to_wake_up() describes more
> instances of MP ("plus locking") and LB (see finish_lock_switch()).

This one looks a bit more messy, so I will set it aside, for the moment,
anyway.

> The comment in kernel/sched/core.c:task_rq_lock() describes an ins-
> tance of MP+wmb+addr-acqpo.

This one also looks a bit messy, so I am setting it aside as well.

> The comment in include/linux/wait.h:waitqueue_active() describes an
> instance of SB+mb+mb.

Very good, I took this as the generic pattern for the current pair
of SB examples.

> 63cae12bce986 ("perf/core: Fix sys_perf_event_open() vs. hotplug")
> describes an instance of W+RWC+porel+mb+mb.

Well, this one certainly is of historical interest. After all, it might
well be the first Linux-kernel commit containing a litmus test. ;-)

I put it in recipes-LKcode-63cae12bce986.txt and reference it from
recipes-LKcode.txt.

> [...]
>
> I wish we could say "any barrier (explicit or implicit) in sources
> is accompanied by a comment mentioning the interested pattern...",
> but life is not always this simple. ;-)

Well, at least scripts/checkpatch.pl now complains if you try to add
a new comment-free barrier. Not that these complaints are always
paid attention to...

Thanx, Paul