lkml.org 
[lkml]   [2017]   [Oct]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 3/3] early_printk: Add simple serialization to early_vprintk()
On Tue, Oct 03, 2017 at 06:24:22PM -0400, Steven Rostedt wrote:
> On Thu, 28 Sep 2017 14:18:26 +0200
> Peter Zijlstra <peterz@infradead.org> wrote:
> > static int early_vprintk(const char *fmt, va_list args)
> > {
> > + int n, cpu, old;
> > char buf[512];
> > +
> > + cpu = get_cpu();
> > + /*
> > + * Test-and-Set inter-cpu spinlock with recursion.
> > + */
> > + for (;;) {
> > + /*
> > + * c-cas to avoid the exclusive bouncing on spin.
> > + * Depends on the memory barrier implied by cmpxchg
> > + * for ACQUIRE semantics.
> > + */
> > + old = READ_ONCE(early_printk_cpu);
> > + if (old == -1) {
>
> If old != -1 and old != cpu, is it possible that the CPU could have
> fetched an old value, and never try to fetch it again?

What? If old != -1 and old != cpu, we'll hit the cpu_relax() and do the
READ_ONCE() again. The READ_ONCE() guarantees we'll do the load again,
as does the barrier() implied by cpu_relax().

> The cmpxchg memory barrier only happens when old == -1.

Yeah, so?

> > + old = cmpxchg(&early_printk_cpu, -1, cpu);
> > + if (old == -1)
> > + break;
> > + }
> > + /*
> > + * Allow recursion for interrupts and the like.
> > + */
> > + if (old == cpu)
> > + break;
> > +
> > + cpu_relax();
> > + }
> >
> > n = vscnprintf(buf, sizeof(buf), fmt, args);
> > early_console->write(early_console, buf, n);
> >
> > + /*
> > + * Unlock -- in case @old == @cpu, this is a no-op.
> > + */
> > + smp_store_release(&early_printk_cpu, old);
> > + put_cpu();
> > +
> > return n;
> > }

\
 
 \ /
  Last update: 2017-10-04 11:09    [W:0.103 / U:0.008 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site