Re: [RFC PATCH] printk: Use ACCESS_ONCE() instead of a volatile type

From: Steven Rostedt
Date: Thu Nov 13 2014 - 23:57:52 EST


On Thu, 13 Nov 2014 22:48:33 -0600
Alex Elder <elder@xxxxxxxxxx> wrote:

> > diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> > index e748971..4790191 100644
> > --- a/kernel/printk/printk.c
> > +++ b/kernel/printk/printk.c
> > @@ -1624,7 +1624,7 @@ asmlinkage int vprintk_emit(int facility, int level,
> > int printed_len = 0;
> > bool in_sched = false;
> > /* cpu currently holding logbuf_lock in this function */
> > - static volatile unsigned int logbuf_cpu = UINT_MAX;
> > + static unsigned int logbuf_cpu = UINT_MAX;
>
> If this is not volatile, can the compiler assume that it
> can't change before the first access? Put another way,
> does this assignment need to be done more like this?
>
> static unsigned int ACCESS_ONCE(logbuf_cpu) = UINT_MAX;
>
> (I haven't checked, but I don't believe that expands to valid code.)
>

I can bet you that it doesn't compile.

That assignment is what it is initialized to at boot up. I can't see
any optimization that would cause gcc to modify that. Especially since
we are hiding its accesses within the ACCESS_ONCE(). That alone should
confuse gcc enough to leave it a hell alone J.

-- Steve
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/