Re: [PATCH printk 18/18] printk: Handle dropped message smarter
From: Petr Mladek
Date: Mon Oct 10 2022 - 12:07:29 EST
On Mon 2022-09-26 10:00:36, John Ogness wrote:
> On 2022-09-26, Sergey Senozhatsky <senozhatsky@xxxxxxxxxxxx> wrote:
> > On (22/09/24 02:10), John Ogness wrote:
> >> +/**
> >> + * cons_print_dropped - Print 'dropped' message if required
> >> + * @desc: Pointer to the output descriptor
> >> + *
> >> + * Prints the 'dropped' message info the output buffer if @desc->dropped is
> >> + * not 0 and the regular format is requested. Extended format does not
> >> + * need this message because it prints the sequence numbers.
> >> + *
> >> + * In regular format the extended message buffer is not in use.
> >> + * So print into it at the beginning and move the resulting string
> >> + * just in front of the regular text buffer so that the message can
> >> + * be printed in one go.
> >> + *
> >> + * In case of a message this returns with @desc->outbuf and @desc->len
> >> + * updated. If no message is required then @desc is not modified.
> >> + */
> >> +static void cons_print_dropped(struct cons_outbuf_desc *desc)
> >> +{
> >> + struct cons_text_buf *txtbuf = desc->txtbuf;
> >> + size_t len;
> >> +
> >> + if (!desc->dropped || desc->extmsg)
> >> + return;
> >> +
> >> + if (WARN_ON_ONCE(desc->outbuf != txtbuf->text))
> >> + return;
> >> +
> >> + /* Print it into ext_text which is unused */
> >> + len = snprintf(txtbuf->ext_text, DROPPED_TEXT_MAX,
> >> + "** %lu printk messages dropped **\n", desc->dropped);
> >> + desc->dropped = 0;
> >> +
> >> + /* Copy it just below text so it goes out with one write */
> >> + memcpy(txtbuf->text - len, txtbuf->ext_text, len);
> >> +
> >> + /* Update the descriptor */
> >> + desc->len += len;
> >> + desc->outbuf -= len;
> >
> > Oh, hmm. This does not look to me as a simplification. Quite
> > the opposite, moving cons_text_buf::text pointer to point to
> > cons_text_buf::text - strlen("... dropped messages...") looks
> > somewhat fragile.
>
> It relies on @ext_text and @text being packed together, which yes, may
> be fragile.
Yes, it is a nasty hack ;-)
I suggest to increase CONSOLE_LOG_MAX to 2048,
define LOG_LINE_MAX as 1024, and use the buffer for both
dropped message and normal message.
It would simplify the code. Also it would make enough
space for more potential line headers needed by more
lines in one record.
It would require moving the normal message to make a space for
the dropped messages. But the dropping should be rare. And we
do a lot of moving in record_print_text() anyway.
I think that I was against increasing the buffer size some time ago.
I was worried about small devices. But I think that the patch
just increased the buffer size without any bug report so that
the justification was weak.
But simplifying the code looks like a good justification to me.
And I really like the removal of the extra buffer.
Best Regards,
Petr