Re: [PATCH 5/5] ring-buffer: fix printk output

Andrew Morton
2009-04-29T15:13:20Z

On Wed, 29 Apr 2009 11:56:25 +0200 Ingo Molnar <mingo@elte.hu> wrote:

>
> > > My larger point remains, about possibly embedding linux-next
> > > into lkml. I couldnt think of a single linux-next mail that isnt
> > > relevant to lkml. It's all about commits that are destined for
> > > upstream in 0-2.5 months.
> >
> > Sure, I'd be OK with zapping the linux-next list.
>
> Another, less drastic solution would be to keep it as an _alias_
> list. All mails posted to it also go to lkml, but it would still be
> subscribe-able separately.

That would work, although I wonder about the potential for duplicates
turning up somewhere.

> ( This has come up before and this would be useful for a number of
> other things - such as tracing/instrumentation. Someone who is
> only interested in instrumentation related discussions could
> subscribe to that list. )
>
> > > > printk_once() is racy on smp and preempt btw ;)
> > >
> > > Like WARN_ONCE() and WARN_ON_ONCE(). It's really an "oh crap"
> > > facility, not for normal kernel messages.
> > >
> > > Do we want to complicate them with locking and preemption - or
> > > should we just concentrate on getting the "oh crap" message out
> > > to the syslog (before it's possibly too late to get anything
> > > out)?
> > >
> > > I have no strong opinion about it - but i tend to like the
> > > simpler method most. printk + stack dumps themselves arent
> > > atomic to begin with.
> >
> > Well, it's hardly likely to be a problem. otoh, if two CPUs _do_
> > hit the thing at the same time, the resulting output will be all
> > messed up and we'd really like to see it.
> >
> > Easily fixed with test_and_set_bit()?
>
> but if two CPUs hit it at once then the printk+stack-dump itself is
> already mixed up. So if we do any atomicity it should be done for
> all the print-once APIs. (note, lockdep does such message-atomicity
> already, in its own facility)

Confused.

<gets distracted by FW_BUG and friends. ytf are they in kernel.h?>

#define printk_once(x...) ({ \
static unsigned long __print_once; \
\
if (!test_and_set_bit(0, &__print_once)) \
printk(x); \
})

How can two CPUs do the printk(x)?