linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: John Ogness <john.ogness@linutronix.de>
Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	linux-kernel@vger.kernel.org
Subject: vprintk_store: was: [PATCH next v2 3/3] printk: remove logbuf_lock, add syslog_lock
Date: Fri, 4 Dec 2020 17:15:56 +0100	[thread overview]
Message-ID: <X8pgvA3wKRwAyyaS@alley> (raw)
In-Reply-To: <20201201205341.3871-4-john.ogness@linutronix.de>

On Tue 2020-12-01 21:59:41, John Ogness wrote:
> Since the ringbuffer is lockless, there is no need for it to be
> protected by @logbuf_lock. Remove @logbuf_lock.
> 
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -1867,40 +1890,75 @@ static inline u32 printk_caller_id(void)
>  		0x80000000 + raw_smp_processor_id();
>  }
>  
> -/* Must be called under logbuf_lock. */
> +static u16 printk_sprint(char *text, u16 size, int facility, enum log_flags *lflags,
> +			 const char *fmt, va_list args)
> +{
> +	char *orig_text = text;
> +	u16 text_len;
> +
> +	text_len = vscnprintf(text, size, fmt, args);
> +
> +	/* Mark and strip a trailing newline. */
> +	if (text_len && text[text_len - 1] == '\n') {
> +		text_len--;
> +		*lflags |= LOG_NEWLINE;
> +	}

We reserve the space for '\n' anyway. It would make sense to just
store it and remove all these LOG_NEWLINE-specific hacks.

Well, let's leave it as is now. It is still possible that people
will not love this approach and we will need to format the message
into some temporary buffer first.


> +	/* Strip kernel syslog prefix. */

Syslog actually uses: <level> format. We are skipping log level
and control flags here.


> +	if (facility == 0) {
> +		while (text_len >= 2 && printk_get_level(text)) {
> +			text_len -= 2;
> +			text += 2;
> +		}

We should avoid two completely different approaches
that handle printk_level prefix.

One solution is to implement something like:

     static char *parse_prefix(text, &level, &flags)

That would return pointer to the text after the prefix.
And fill level and flags only when non-NULL pointers are passed.

Another solution would be to pass this information from
vprintk_store(). The prefix has already been parsed
after all.

> +
> +		if (text != orig_text)
> +			memmove(orig_text, text, text_len);
> +	}

We should clear the freed space to make the ring buffer as
human readable as possible when someone just dumps the memory.

Sigh, I have to admit that I missed the problem with prefix and
trailing '\n' when I suggested to avoid the temporary buffers.
This memmove() and the space wasting is pity.

Well, it is typically 3 bytes per message. And the copying would
be necessary even with the temporary buffer. So, I am less convinced
but I would still try to avoid the temporary buffers for now.

> +
> +	return text_len;
> +}
> +
> +__printf(4, 0)

Best Regards,
Petr

  parent reply	other threads:[~2020-12-04 16:16 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-01 20:53 [PATCH next v2 0/3] printk: remove logbuf_lock John Ogness
2020-12-01 20:53 ` [PATCH next v2 1/3] printk: inline log_output(),log_store() in vprintk_store() John Ogness
2020-12-03 15:57   ` Petr Mladek
2020-12-03 16:25     ` John Ogness
2020-12-04  6:13       ` Sergey Senozhatsky
2020-12-04  8:26       ` Petr Mladek
2020-12-01 20:53 ` [PATCH next v2 2/3] printk: change @clear_seq to atomic64_t John Ogness
2020-12-04  9:12   ` Petr Mladek
2020-12-06 20:23     ` John Ogness
2020-12-07  9:34       ` Peter Zijlstra
2020-12-07 10:03         ` John Ogness
2020-12-07 12:56           ` Peter Zijlstra
2020-12-07 12:56           ` Petr Mladek
2020-12-07 16:46           ` David Laight
2020-12-08 20:34     ` Sergey Senozhatsky
2020-12-08 22:30       ` John Ogness
2020-12-09  1:04         ` Sergey Senozhatsky
2020-12-09  8:16         ` Peter Zijlstra
2020-12-09  9:22           ` Sergey Senozhatsky
2020-12-09 10:46             ` Sergey Senozhatsky
2020-12-09 11:00               ` Peter Zijlstra
2020-12-09 11:28                 ` Sergey Senozhatsky
2020-12-09 12:29                   ` Peter Zijlstra
2020-12-09  8:07       ` Peter Zijlstra
2020-12-01 20:53 ` [PATCH next v2 3/3] printk: remove logbuf_lock, add syslog_lock John Ogness
2020-12-04  6:41   ` Sergey Senozhatsky
2020-12-06 20:44     ` John Ogness
2020-12-04 15:52   ` devkmsg: was " Petr Mladek
2020-12-06 20:51     ` John Ogness
2020-12-07  9:56       ` Petr Mladek
2020-12-04 15:57   ` syslog: was: " Petr Mladek
2020-12-06 21:06     ` John Ogness
2020-12-07 10:01       ` Petr Mladek
2020-12-04 16:10   ` recursion handling: " Petr Mladek
2020-12-05  4:25     ` Sergey Senozhatsky
2020-12-06 22:08       ` John Ogness
2020-12-05  9:41     ` Sergey Senozhatsky
2020-12-06 22:17       ` John Ogness
2020-12-06 21:44     ` John Ogness
2020-12-07 11:17       ` Petr Mladek
2020-12-04 16:15   ` Petr Mladek [this message]
2020-12-06 22:30     ` vprintk_store: was: " John Ogness
2020-12-07 12:46       ` Petr Mladek
2020-12-04 16:19   ` consoles: " Petr Mladek
2020-12-05  4:39     ` Sergey Senozhatsky
2020-12-07  9:50       ` Petr Mladek
2020-12-08 20:51         ` Sergey Senozhatsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=X8pgvA3wKRwAyyaS@alley \
    --to=pmladek@suse.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=john.ogness@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=sergey.senozhatsky.work@gmail.com \
    --cc=sergey.senozhatsky@gmail.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).