OSDN Git Service

printk: add lockless ringbuffer
authorJohn Ogness <john.ogness@linutronix.de>
Thu, 9 Jul 2020 13:23:42 +0000 (15:29 +0206)
committerPetr Mladek <pmladek@suse.com>
Fri, 10 Jul 2020 06:48:19 +0000 (08:48 +0200)
commitb6cf8b3f3312e2ffe38f23c7c692eb9389277a9a
tree642deaaf81f7f747bfe5bd3b7d643bc946415f66
parent0d6f55403a47b317c0d9511a80545c19ab0ef52f
printk: add lockless ringbuffer

Introduce a multi-reader multi-writer lockless ringbuffer for storing
the kernel log messages. Readers and writers may use their API from
any context (including scheduler and NMI). This ringbuffer will make
it possible to decouple printk() callers from any context, locking,
or console constraints. It also makes it possible for readers to have
full access to the ringbuffer contents at any time and context (for
example from any panic situation).

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.

The internal state information of a descriptor is the key element to
allow readers and writers to locklessly synchronize access to the data.

Co-developed-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: John Ogness <john.ogness@linutronix.de>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Reviewed-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20200709132344.760-3-john.ogness@linutronix.de
kernel/printk/Makefile
kernel/printk/printk_ringbuffer.c [new file with mode: 0644]
kernel/printk/printk_ringbuffer.h [new file with mode: 0644]