Re: [PATCH] printk: add support for lockless ringbuffer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2020-11-20, HAGIO KAZUHITO(萩尾 一仁)	<k-hagio-ab@xxxxxxx> wrote:
> I've updated John's RFC crash patch to match 5.10-rc4 kernel.
> Changes from the RFC patch:
> - followed the following kernel commits
>     cfe2790b163a ("printk: move printk_info into separate array")
>     74caba7f2a06 ("printk: move dictionary keys to dev_printk_info")
>     f35efc78add6 ("printk: remove dict ring")
> - moved the added members in offset_table and size_table to the end
>   of them
> - print offsets and sizes with "help -o" option
> - support "log -T" option

Thank you for this work. I've attached a followup "crash" patch to
correctly interpret the state value. With this followup patch applied,
this passes all my tests.

Note that support for "./crash --log ./vmcore" is still not
implemented. That can be done in a separate patch.

John Ogness

>From a825be51da728f668bfeb770f2a8cf1bc3ef6a23 Mon Sep 17 00:00:00 2001
From: John Ogness <john.ogness@xxxxxxxxxxxxx>
Date: Wed, 25 Nov 2020 05:27:53 +0106
Subject: [PATCH] printk: use committed/finalized state values

The ringbuffer entries use 2 state values (committed and finalized)
rather than a single flag to represent being available for reading.
Copy the definitions and state lookup function directly from the
kernel source and use the new states.

Signed-off-by: John Ogness <john.ogness@xxxxxxxxxxxxx>
Signed-off-by: Nikolay Borisov <nborisov@xxxxxxxx>
---
 printk.c | 48 +++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 41 insertions(+), 7 deletions(-)

diff --git a/printk.c b/printk.c
index 7be7218..ac135fc 100644
--- a/printk.c
+++ b/printk.c
@@ -1,12 +1,6 @@
 #include "defs.h"
 #include <ctype.h>
 
-#define DESC_SV_BITS		(sizeof(unsigned long) * 8)
-#define DESC_COMMITTED_MASK	(1UL << (DESC_SV_BITS - 1))
-#define DESC_REUSE_MASK		(1UL << (DESC_SV_BITS - 2))
-#define DESC_FLAGS_MASK		(DESC_COMMITTED_MASK | DESC_REUSE_MASK)
-#define DESC_ID_MASK		(~DESC_FLAGS_MASK)
-
 /* convenience struct for passing many values to helper functions */
 struct prb_map {
 	char *prb;
@@ -21,6 +15,44 @@ struct prb_map {
 	char *text_data;
 };
 
+/*
+ * desc_state and DESC_* definitions taken from kernel source:
+ *
+ * kernel/printk/printk_ringbuffer.h
+ */
+
+/* The possible responses of a descriptor state-query. */
+enum desc_state {
+	desc_miss	=  -1,	/* ID mismatch (pseudo state) */
+	desc_reserved	= 0x0,	/* reserved, in use by writer */
+	desc_committed	= 0x1,	/* committed by writer, could get reopened */
+	desc_finalized	= 0x2,	/* committed, no further modification allowed */
+	desc_reusable	= 0x3,	/* free, not yet used by any writer */
+};
+
+#define DESC_SV_BITS		(sizeof(unsigned long) * 8)
+#define DESC_FLAGS_SHIFT	(DESC_SV_BITS - 2)
+#define DESC_FLAGS_MASK		(3UL << DESC_FLAGS_SHIFT)
+#define DESC_STATE(sv)		(3UL & (sv >> DESC_FLAGS_SHIFT))
+#define DESC_ID_MASK		(~DESC_FLAGS_MASK)
+#define DESC_ID(sv)		((sv) & DESC_ID_MASK)
+
+/*
+ * get_desc_state() taken from kernel source:
+ *
+ * kernel/printk/printk_ringbuffer.c
+ */
+
+/* Query the state of a descriptor. */
+static enum desc_state get_desc_state(unsigned long id,
+				      unsigned long state_val)
+{
+	if (id != DESC_ID(state_val))
+		return desc_miss;
+
+	return DESC_STATE(state_val);
+}
+
 static void
 init_offsets(void)
 {
@@ -74,6 +106,7 @@ dump_record(struct prb_map *m, unsigned long id, int msg_flags)
 	unsigned short text_len;
 	unsigned long state_var;
 	unsigned int caller_id;
+	enum desc_state state;
 	unsigned char level;
 	unsigned long begin;
 	unsigned long next;
@@ -90,7 +123,8 @@ dump_record(struct prb_map *m, unsigned long id, int msg_flags)
 	/* skip non-committed record */
 	state_var = ULONG(desc + OFFSET(prb_desc_state_var) +
 			OFFSET(atomic_long_t_counter));
-	if ((state_var & DESC_FLAGS_MASK) != DESC_COMMITTED_MASK)
+	state = get_desc_state(id, state_var);
+	if (state != desc_committed && state != desc_finalized)
 		return;
 
 	info = m->infos + ((id % m->desc_ring_count) * SIZE(printk_info));
-- 
2.20.1

--
Crash-utility mailing list
Crash-utility@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/crash-utility

[Index of Archives]     [Fedora Development]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]     [Fedora Tools]

 

Powered by Linux