printk: new ringbuffer implementation
John Ogness
maintainerv3 cover printk: new ringbuffer implementation
Hello,
This is a follow-up RFC on the work to re-implement much of the core of printk. The threads for the previous RFC versions are here: v1[0], v2[1].
As was planned[2], this is only the first piece: a new lockless ringbuffer.
Changes from v2:
- Moved all code into kernel/printk/. Let's keep it private for now.
- Split the ringbuffer into 3 components:
* a data ringbuffer (dataring) to manage the raw data and data descriptors
* a numbered list (numlist) to manage committed entries and their sequence numbers
* the printk_ringbuffer, which is the high-level structure providing the reader/writer API and glue for the other structures
Splitting the components apart helped to document their roles and their related memory barriers (and will hopefully also simplify the review process).
- Renamed most functions, structures, and variables based on v2 feedback.
- Rewrote and reformatted nearly all comments (particularly the memory barrier comments) based on v2 feedback.
- Addressed implementation issues with v2:
* invalid data blocks potentially becoming valid because of overflows
* weak associations between data blocks and descriptors
* excessive freeing of data blocks due to unavailable descriptors
- Improved error handling and data integrity checks in the test module.
For the memory barrier work I wrote a litmus test for nearly every memory barrier. I did not include these in the series. Should I? If yes, where should they be placed?
I would like to point out that Petr Mladek posted a proof-of-concept[3] alternate implementation. I wanted to base my v3 on his work, but ran into too many problems getting it to run acceptably. I will address those issues in that thread. This is why my v3 is based directly on my v2.
John Ogness
[0] https://lkml.kernel.org/r/[email protected]
[1] https://lkml.kernel.org/r/[email protected]
[2] https://lkml.kernel.org/r/[email protected]
[3] https://lkml.kernel.org/r/[email protected]
John Ogness (2):
printk-rb: add a new printk ringbuffer implementation
printk-rb: add test module
kernel/printk/Makefile | 5 + kernel/printk/dataring.c | 761 ++++++++++++++++++++++++++++++++++++++++++ kernel/printk/dataring.h | 95 ++++++ kernel/printk/numlist.c | 375 +++++++++++++++++++++ kernel/printk/numlist.h | 72 ++++ kernel/printk/ringbuffer.c | 800 +++++++++++++++++++++++++++++++++++++++++++++ kernel/printk/ringbuffer.h | 288 ++++++++++++++++ kernel/printk/test_prb.c | 256 +++++++++++++++ 8 files changed, 2652 insertions(+) create mode 100644 kernel/printk/dataring.c create mode 100644 kernel/printk/dataring.h create mode 100644 kernel/printk/numlist.c create mode 100644 kernel/printk/numlist.h create mode 100644 kernel/printk/ringbuffer.c create mode 100644 kernel/printk/ringbuffer.h create mode 100644 kernel/printk/test_prb.c
Signature · 1 line
2.11.0
John Ogness
maintainerRFC PATCH v3 1/2 printk-rb: add a new printk ringbuffer implementation
See documentation for details.
For the real patch the "prb overview" documentation section in kernel/printk/ringbuffer.c will be included in the commit message.
--- kernel/printk/Makefile | 3 + kernel/printk/dataring.c | 761 ++++++++++++++++++++++++++++++++++++++++++ kernel/printk/dataring.h | 95 ++++++ kernel/printk/numlist.c | 375 +++++++++++++++++++++ kernel/printk/numlist.h | 72 ++++ kernel/printk/ringbuffer.c | 800 +++++++++++++++++++++++++++++++++++++++++++++ kernel/printk/ringbuffer.h | 288 ++++++++++++++++ 7 files changed, 2394 insertions(+) create mode 100644 kernel/printk/dataring.c create mode 100644 kernel/printk/dataring.h create mode 100644 kernel/printk/numlist.c create mode 100644 kernel/printk/numlist.h create mode 100644 kernel/printk/ringbuffer.c create mode 100644 kernel/printk/ringbuffer.h
kernel/printk/Makefile +3 -0
@@ -1,4 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only obj-y = printk.o obj-$(CONFIG_PRINTK) += printk_safe.o +obj-$(CONFIG_PRINTK) += ringbuffer.o +obj-$(CONFIG_PRINTK) += numlist.o +obj-$(CONFIG_PRINTK) += dataring.o obj-$(CONFIG_A11Y_BRAILLE_CONSOLE) += braille.o
kernel/printk/dataring.c new file +761 -0
761 lines not on this page · raw message
kernel/printk/dataring.h new file +95 -0
95 lines not on this page · raw message
kernel/printk/numlist.c new file +375 -0
375 lines not on this page · raw message
kernel/printk/numlist.h new file +72 -0
72 lines not on this page · raw message
kernel/printk/ringbuffer.c new file +800 -0
800 lines not on this page · raw message
kernel/printk/ringbuffer.h new file +288 -0
288 lines not on this page · raw message
Signature · 1 line
2.11.0
John Ogness
maintainerRFC PATCH v3 2/2 printk-rb: add test module
In reply to John OgnessThis module does some heavy write stress testing on the ringbuffer with a reader that is checking for integrity.
--- kernel/printk/Makefile | 2 + kernel/printk/test_prb.c | 256 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 258 insertions(+) create mode 100644 kernel/printk/test_prb.c
kernel/printk/Makefile +2 -0
@@ -5,3 +5,5 @@ obj-$(CONFIG_PRINTK) += ringbuffer.o obj-$(CONFIG_PRINTK) += numlist.o obj-$(CONFIG_PRINTK) += dataring.o obj-$(CONFIG_A11Y_BRAILLE_CONSOLE) += braille.o + +obj-m += test_prb.o
kernel/printk/test_prb.c new file +256 -0
256 lines not on this page · raw message
Signature · 1 line
2.11.0
John Ogness
maintainerRe: [RFC PATCH v3 2/2] printk-rb: add test module
Add missing includes and exports.
---
In case anyone wants to build/run my test module, this patch needs to be applied. For my arm64 tests I need to build the module slightly different, which is why I didn't catch this. Sorry.
Tested on 5.3-rc2.
kernel/printk/dataring.c | 1 + kernel/printk/numlist.c | 1 + kernel/printk/ringbuffer.c | 4 ++++
kernel/printk/dataring.c +1 -0
@@ -1,5 +1,6 @@// SPDX-License-Identifier: GPL-2.0 +#include <linux/kernel.h> #include "dataring.h" /**
kernel/printk/numlist.c +1 -0
@@ -1,5 +1,6 @@// SPDX-License-Identifier: GPL-2.0 +#include <linux/kernel.h> #include <linux/sched.h> #include "numlist.h"
kernel/printk/ringbuffer.c +4 -0
@@ -1,5 +1,6 @@// SPDX-License-Identifier: GPL-2.0 +#include <linux/kernel.h> #include <linux/irqflags.h> #include <linux/string.h> #include <linux/err.h>
@@ -222,6 +223,7 @@ struct nl_node *prb_desc_node(unsigned long id, void *arg)return &d->list; } +EXPORT_SYMBOL (prb_desc_node);/** * prb_desc_busy() - Numbered list callback to report if a node is busy.
@@ -262,6 +264,7 @@ bool prb_desc_busy(unsigned long id, void *arg)/* hC: */ return (id ==atomic_long_read (&d->id)); } +EXPORT_SYMBOL (prb_desc_busy);/** * prb_getdesc() - Data ringbuffer callback to lookup a descriptor from an ID.
@@ -296,6 +299,7 @@ struct dr_desc *prb_getdesc(unsigned long id, void *arg)/* iB: */ return &d->desc; } +EXPORT_SYMBOL (prb_getdesc);/** * assign_desc() - Assign a descriptor to the caller.
Signature · 1 line
2.11.0