Re: [PATCH 2/2] allow printk delay after multi lines

From: Dave Young
Date: Mon Feb 08 2010 - 21:35:35 EST


On Tue, Feb 9, 2010 at 6:01 AM, Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> wrote:
> On Mon, 8 Feb 2010 13:56:54 -0800
> Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> wrote:
>
>> On Sat, 6 Feb 2010 21:40:56 +0800
>> Dave Young <hidave.darkstar@xxxxxxxxx> wrote:
>>
>> > printk delay help us to capture printk messages on some unconvenient senarios,
>> > but it is still not easy to read.
>> >
>> > Add another sysctl variable printk_delay_per_lines to make it more readable.
>> > We can set the lines according to screen height, then take pictures by camera.
>> >
>> > kmesg will delay printk_delay_per_lines * printk_delay_msecs milliseconds
>> > after every printk_delay_per_lines lines when printk_delay is enabled.
>> >
>> > Setting the lines by proc/sysctl interface:
>> > /proc/sys/kernel/printk_delay_per_lines
>> >
>> > Andrew, sorry, I have not find time to cleanup the kernel.h sysctl variables.
>> > If I'm free I will try to do it.
>> >
>> > The value range from 1 - 100, default value is 1
>> >
>> > ...
>> >
>> > --- linux-2.6.orig/include/linux/kernel.h  2010-02-02 13:38:09.537495564 +0800
>> > +++ linux-2.6/include/linux/kernel.h    Â2010-02-02 13:40:47.657480122 +0800
>> > @@ -246,6 +246,7 @@ extern bool printk_timed_ratelimit(unsig
>> > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âunsigned int interval_msec);
>> >
>> > Âextern int printk_delay_msec;
>> > +extern int printk_delay_per_lines;
>> >
>> > Â/*
>> > Â * Print a one-time message (analogous to WARN_ONCE() et al):
>> > --- linux-2.6.orig/kernel/printk.c Â2010-02-02 13:39:19.446657319 +0800
>> > +++ linux-2.6/kernel/printk.c    2010-02-02 13:40:47.660813615 +0800
>> > @@ -656,16 +656,26 @@ static int new_text_line = 1;
>> > Âstatic char printk_buf[1024];
>> >
>> > Âint printk_delay_msec __read_mostly;
>> > +int printk_delay_per_lines __read_mostly;
>> >
>> > Âstatic inline void printk_delay(void)
>> > Â{
>> > Â Â if (unlikely(printk_delay_msec)) {
>> > - Â Â Â Â Â int m = printk_delay_msec;
>> > + Â Â Â Â Â static int m, l;
>> >
>> > + Â Â Â Â Â if (!l)
>> > + Â Â Â Â Â Â Â Â Â l = printk_delay_per_lines;
>> > +
>> > + Â Â Â Â Â if (--l) {
>> > + Â Â Â Â Â Â Â Â Â m += printk_delay_msec;
>> > + Â Â Â Â Â Â Â Â Â return;
>> > + Â Â Â Â Â }
>> > + Â Â Â Â Â m += printk_delay_msec;
>> > Â Â Â Â Â Â while (m--) {
>> > Â Â Â Â Â Â Â Â Â Â mdelay(1);
>> > Â Â Â Â Â Â Â Â Â Â touch_nmi_watchdog();
>> > Â Â Â Â Â Â }
>> > + Â Â Â Â Â m = 0;
>> > Â Â }
>> > Â}
>>
>
> Also...
>
> - The above code is racy: if multiple CPUs run printk_delay()
> Âconcurrently, `m' and `l' will get mucked up.
>
> ÂWe should verify that the effects of this race are benign. ÂThis
> Âwill be hard.
>
> ÂOr we fix the race. ÂOne could add locking (irq-safe locking), but
> ÂI suspect a better approach would be to use atomic ops.
>

will change to use atomic ops

--
Regards
dave
--
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/