From: Steven Rostedt <rostedt@goodmis.org>
To: John Ogness <john.ogness@linutronix.de>
Cc: Petr Mladek <pmladek@suse.com>,
Peter Zijlstra <peterz@infradead.org>,
Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>,
Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Andrea Parri <parri.andrea@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
kexec@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] printk: add lockless buffer
Date: Tue, 28 Jan 2020 22:53:16 -0500 [thread overview]
Message-ID: <20200128225316.0a735187@rorschach.local.home> (raw)
In-Reply-To: <20200128161948.8524-2-john.ogness@linutronix.de>
On Tue, 28 Jan 2020 17:25:47 +0106
John Ogness <john.ogness@linutronix.de> wrote:
> diff --git a/kernel/printk/printk_ringbuffer.c b/kernel/printk/printk_ringbuffer.c
> new file mode 100644
> index 000000000000..796257f226ee
> --- /dev/null
> +++ b/kernel/printk/printk_ringbuffer.c
> @@ -0,0 +1,1370 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#include <linux/kernel.h>
> +#include <linux/irqflags.h>
> +#include <linux/string.h>
> +#include <linux/errno.h>
> +#include <linux/bug.h>
> +#include "printk_ringbuffer.h"
> +
> +/**
> + * DOC: printk_ringbuffer overview
> + *
> + * Data Structure
> + * --------------
> + * The printk_ringbuffer is made up of 3 internal ringbuffers::
> + *
> + * * desc_ring: A ring of descriptors. A descriptor contains all record
> + * meta data (sequence number, timestamp, loglevel, etc.)
> + * as well as internal state information about the record
> + * and logical positions specifying where in the other
> + * ringbuffers the text and dictionary strings are
> + * located.
> + *
> + * * text_data_ring: A ring of data blocks. A data block consists of an
> + * unsigned long integer (ID) that maps to a desc_ring
> + * index followed by the text string of the record.
> + *
> + * * dict_data_ring: A ring of data blocks. A data block consists of an
> + * unsigned long integer (ID) that maps to a desc_ring
> + * index followed by the dictionary string of the record.
> + *
> + * Implementation
> + * --------------
> + *
> + * ABA Issues
> + * ~~~~~~~~~~
> + * To help avoid ABA issues, descriptors are referenced by IDs (index values
> + * with tagged states) and data blocks are referenced by logical positions
> + * (index values with tagged states). However, on 32-bit systems the number
> + * of tagged states is relatively small such that an ABA incident is (at
> + * least theoretically) possible. For example, if 4 million maximally sized
4 million? I'm guessing that maximally sized printk messages are 1k?
Perhaps say that, otherwise one might think this is a mistake. "4
million maximally sized (1k) printk messages"
> + * printk messages were to occur in NMI context on a 32-bit system, the
> + * interrupted task would not be able to recognize that the 32-bit integer
> + * wrapped and thus represents a different data block than the one the
> + * interrupted task expects.
> + *
> + * To help combat this possibility, additional state checking is performed
> + * (such as using cmpxchg() even though set() would suffice). These extra
> + * checks will hopefully catch any ABA issue that a 32-bit system might
> + * experience.
> + *
[..]
> + * Usage
> + * -----
> + * Here are some simple examples demonstrating writers and readers. For the
> + * examples a global ringbuffer (test_rb) is available (which is not the
> + * actual ringbuffer used by printk)::
> + *
> + * DECLARE_PRINTKRB(test_rb, 15, 5, 3);
> + *
> + * This ringbuffer allows up to 32768 records (2 ^ 15) and has a size of
> + * 1 MiB (2 ^ 20) for text data and 256 KiB (2 ^ 18) for dictionary data.
(2 ^ (15 + 5)) ... (2 ^ (15 + 3)) ?
I'll play around more with this this week. But so far it looks good.
-- Steve
> + *
> + * Sample writer code::
> + *
> + * struct prb_reserved_entry e;
> + * struct printk_record r;
> + *
> + * // specify how much to allocate
> + * r.text_buf_size = strlen(textstr) + 1;
> + * r.dict_buf_size = strlen(dictstr) + 1;
> + *
> + * if (prb_reserve(&e, &test_rb, &r)) {
> + * snprintf(r.text_buf, r.text_buf_size, "%s", textstr);
> + *
> + * // dictionary allocation may have failed
> + * if (r.dict_buf)
> + * snprintf(r.dict_buf, r.dict_buf_size, "%s", dictstr);
> + *
> + * r.info->ts_nsec = local_clock();
> + *
> + * prb_commit(&e);
> + * }
> + *
next prev parent reply other threads:[~2020-01-29 3:54 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-28 16:19 [PATCH 0/2] printk: replace ringbuffer John Ogness
2020-01-28 16:19 ` [PATCH 1/2] printk: add lockless buffer John Ogness
2020-01-29 3:53 ` Steven Rostedt [this message]
2020-02-21 11:54 ` more barriers: " Petr Mladek
2020-02-27 12:04 ` John Ogness
2020-03-04 15:08 ` Petr Mladek
2020-03-13 10:13 ` John Ogness
2020-02-21 12:05 ` misc nits " Petr Mladek
2020-03-02 10:38 ` John Ogness
2020-03-02 12:17 ` Joe Perches
2020-03-02 12:32 ` Petr Mladek
2020-03-02 13:43 ` John Ogness
2020-03-03 9:47 ` Petr Mladek
2020-03-03 15:42 ` John Ogness
2020-03-04 10:09 ` Petr Mladek
2020-03-04 9:40 ` Petr Mladek
2020-01-28 16:19 ` [PATCH 2/2] printk: use the lockless ringbuffer John Ogness
2020-02-13 9:07 ` Sergey Senozhatsky
2020-02-13 9:42 ` John Ogness
2020-02-13 11:59 ` Sergey Senozhatsky
2020-02-13 22:36 ` John Ogness
2020-02-14 1:41 ` Sergey Senozhatsky
2020-02-14 2:09 ` Sergey Senozhatsky
2020-02-14 9:48 ` John Ogness
2020-02-14 13:29 ` lijiang
2020-02-14 13:50 ` John Ogness
2020-02-15 4:15 ` lijiang
2020-02-17 15:40 ` crashdump: " Petr Mladek
2020-02-17 16:14 ` John Ogness
2020-02-17 14:41 ` misc details: " Petr Mladek
2020-02-25 20:11 ` John Ogness
2020-02-26 9:54 ` Petr Mladek
2020-02-05 4:25 ` [PATCH 0/2] printk: replace ringbuffer lijiang
2020-02-05 4:42 ` Sergey Senozhatsky
2020-02-05 4:48 ` Sergey Senozhatsky
2020-02-05 5:02 ` Sergey Senozhatsky
2020-02-05 5:38 ` lijiang
2020-02-05 6:36 ` Sergey Senozhatsky
2020-02-05 9:00 ` John Ogness
2020-02-05 9:28 ` Sergey Senozhatsky
2020-02-05 10:19 ` lijiang
2020-02-05 16:12 ` John Ogness
2020-02-06 9:12 ` lijiang
2020-02-13 13:07 ` Petr Mladek
2020-02-14 1:07 ` Sergey Senozhatsky
2020-02-05 11:07 ` Sergey Senozhatsky
2020-02-05 15:48 ` John Ogness
2020-02-05 19:29 ` Joe Perches
2020-02-06 6:31 ` Sergey Senozhatsky
2020-02-06 7:30 ` lijiang
2020-02-07 1:40 ` Steven Rostedt
2020-02-07 7:43 ` John Ogness
2020-02-14 15:56 ` Petr Mladek
2020-02-17 11:13 ` John Ogness
2020-02-17 14:50 ` Petr Mladek
2020-02-25 19:27 ` John Ogness
2020-02-05 9:36 ` lijiang
2020-02-06 9:21 ` lijiang
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=20200128225316.0a735187@rorschach.local.home \
--to=rostedt@goodmis.org \
--cc=gregkh@linuxfoundation.org \
--cc=john.ogness@linutronix.de \
--cc=kexec@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=parri.andrea@gmail.com \
--cc=peterz@infradead.org \
--cc=pmladek@suse.com \
--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
all inboxes | Powered by JetHome®