🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
6 messages
6 total messages Started by Steven Rostedt Thu, 05 Nov 2026 14:12
Re: [PATCH v7 0/4] tracing: improve symbolic printing
#11766
Author: Steven Rostedt
Date: Thu, 05 Nov 2026 14:12
85 lines
12273 bytes
On Tue, 22 Sep 2026 13:08:39 +0200
Johannes Berg <johannes@sipsolutions.net> wrote:

> Hi,
> 
> Resend with the selftests and the two sashiko findings.

Hi Johannes,

Could you also add code in the samples/trace_events directory. Perhaps add
a new event?

This will make it easier to understand exactly how to add new __print_sym()s.

FYI, this series did pass all my tests.

Thanks,

-- Steve


> 
> v2 was:
>  - rebased on 6.9-rc1
>  - always search for __print_sym() and get rid of the DYNPRINT flag
>    and associated code; I think ideally we'll just remove the older
>    __print_symbolic() entirely
>  - use ':' as the separator instead of "//" since that makes searching
>    for it much easier and it's still not a valid char in an identifier
>  - fix RCU
> 
> v3:
>  - fix #undef issues
>  - fix drop_monitor default
>  - rebase on linux-trace/for-next (there were no conflicts)
>  - move net patches to 3/4
>  - clarify symbol name matching logic (and remove ")" from it)
> 
> v4:
>  - fix non-module build and possibly dynamic event handling
> 
> v5: (https://lore.kernel.org/all/20240614081956.19832-6-johannes@sipsolutions.net/)
>  - fix build warning in non-module build
> 
> v6: (https://lore.kernel.org/linux-trace-kernel/20260921101538.97286-6-johannes@sipsolutions.net/)
>  - rebase
>  - fix nit from Paolo (I hope, I don't remember changing it
>    but it looks fixed!)
>  - fix crash due to wrong data placement
> 
> v7: (this version)
>  - update ovs selftest
>  - don't ifdef drop_reason_lookup() prototype
>  - fix section alignment
> 
> 
> To recap, it's annoying to have
> 
>  irq/65-iwlwifi:-401   [000]    22.790000: kfree_skb:  ...  reason: 0x20000
> 
> and much nicer to see
> 
>  irq/65-iwlwifi:-401   [000]    22.790000: kfree_skb:  ...  reason: RX_DROP_MONITOR
> 
> but this doesn't work now because __print_symbolic() can only
> deal with a hard-coded list (which is actually really big.)
> 
> So here's __print_sym() which doesn't build the list into the
> kernel image, but creates it at runtime. For userspace, it
> will look the same as __print_symbolic() (it literally shows
> __print_symbolic() to userspace) so no changes are needed,
> but the actual list of values exposed to userspace in there
> is built dynamically. For SKB drop reasons, this then has all
> the reasons known when userspace queries the trace format.
> 
> I guess patches 3/4 should go through net-next, so not sure
> how to handle this patch series. Or perhaps, as this will likely
> not cause conflicts (in fact I've been rebasing it for years now),
> go through tracing anyway with an Ack from netdev? But I can
> also just wait for the trace patch(es) to land and resubmit the
> net patches after. Assuming this looks good at all :-)
> 
> Thanks,
> johannes
Re: [PATCH v7 0/4] tracing: improve symbolic printing
#11784
Author: Johannes Berg
Date: Thu, 05 Nov 2026 15:04
81 lines
11372 bytes
On Thu, 2026-11-05 at 09:12 -0500, Steven Rostedt wrote:
> Could you also add code in the samples/trace_events directory. Perhaps add
> a new event?
> 
> This will make it easier to understand exactly how to add new __print_sym()s.

I guess so. I was kinda hoping to simply convert all the others - it
clearly has advantages this way.

Any objection to simply converting the __print_symbolic() sample? It
would look something like this:


--- a/samples/trace_events/trace-events-sample.h
+++ b/samples/trace_events/trace-events-sample.h
@@ -297,6 +297,28 @@ TRACE_DEFINE_ENUM(TRACE_SAMPLE_FOO);
 TRACE_DEFINE_ENUM(TRACE_SAMPLE_BAR);
 TRACE_DEFINE_ENUM(TRACE_SAMPLE_ZOO);
 
+/* define the names as { value, "name" } tuples for __print_sym() below */
+TRACE_DEFINE_SYM_LIST(sample_names,
+	{ 0, "zero" },
+	{ TRACE_SAMPLE_FOO, "TWO" },
+	{ TRACE_SAMPLE_BAR, "FOUR" },
+	{ TRACE_SAMPLE_ZOO, "EIGHT" },
+	{ 10, "TEN" }
+);
+
+/*
+ * Alternatively, you could define a function for the names:
+ *
+ * The _lookup() function returns the string for the given value.
+ *
+ * The _show() function must
+ *	seq_printf(m, ", { %u, \"%s\" }", value, name);
+ * for each value that userspace should be able to parse.
+ */
+const char *sample_names2_lookup(unsigned long long value);
+void sample_names2_show(struct seq_file *m);
+TRACE_DEFINE_SYM_FNS(sample_names2, sample_names2_lookup, sample_names2_show);
+
 TRACE_EVENT(foo_bar,
 
 	TP_PROTO(const char *foo, int bar, const int *lst,
@@ -340,14 +362,10 @@ TRACE_EVENT(foo_bar,
  *    the variable matches one of the values, then it will print the
  *    string in that pair. If non are matched, it returns a string
  *    version of the number (if __entry->bar == 7 then "7" is returned).
+ *
+ *    See above for the declaration of "sample_names".
  */
-		  __print_symbolic(__entry->bar,
-				   { 0, "zero" },
-				   { TRACE_SAMPLE_FOO, "TWO" },
-				   { TRACE_SAMPLE_BAR, "FOUR" },
-				   { TRACE_SAMPLE_ZOO, "EIGHT" },
-				   { 10, "TEN" }
-			  ),
+		  __print_sym(__entry->bar, sample_names),
 
 /*
  *  __print_flags( variable, "delim", { value, "flag" }, ... ),



It did show a bug because TRACE_SYSTEM isn't a C var in that file (and
perhaps only in that file?), so I'll have to resend with that fixed
anyway.


> FYI, this series did pass all my tests.

Cool. Sorry the earlier (long time ago) version had the __init_data
issue, I'd mostly tested on UML and that wasn't protected there.

johannes
Re: [PATCH v7 0/4] tracing: improve symbolic printing
#11820
Author: Steven Rostedt
Date: Thu, 05 Nov 2026 16:24
92 lines
12542 bytes
On Thu, 05 Nov 2026 16:04:21 +0100
Johannes Berg <johannes@sipsolutions.net> wrote:

> On Thu, 2026-11-05 at 09:12 -0500, Steven Rostedt wrote:
> > Could you also add code in the samples/trace_events directory. Perhaps add
> > a new event?
> > 
> > This will make it easier to understand exactly how to add new __print_sym()s.  
> 
> I guess so. I was kinda hoping to simply convert all the others - it
> clearly has advantages this way.
> 
> Any objection to simply converting the __print_symbolic() sample? It
> would look something like this:

Actually, keeping them both would be very useful. That way one can see how
to do it the other way. We can say, the old way is being deprecated so
please use the new way.


> 
> 
> --- a/samples/trace_events/trace-events-sample.h
> +++ b/samples/trace_events/trace-events-sample.h
> @@ -297,6 +297,28 @@ TRACE_DEFINE_ENUM(TRACE_SAMPLE_FOO);
>  TRACE_DEFINE_ENUM(TRACE_SAMPLE_BAR);
>  TRACE_DEFINE_ENUM(TRACE_SAMPLE_ZOO);
>  
> +/* define the names as { value, "name" } tuples for __print_sym() below */
> +TRACE_DEFINE_SYM_LIST(sample_names,
> +	{ 0, "zero" },
> +	{ TRACE_SAMPLE_FOO, "TWO" },
> +	{ TRACE_SAMPLE_BAR, "FOUR" },
> +	{ TRACE_SAMPLE_ZOO, "EIGHT" },
> +	{ 10, "TEN" }
> +);
> +
> +/*
> + * Alternatively, you could define a function for the names:
> + *
> + * The _lookup() function returns the string for the given value.
> + *
> + * The _show() function must
> + *	seq_printf(m, ", { %u, \"%s\" }", value, name);
> + * for each value that userspace should be able to parse.
> + */
> +const char *sample_names2_lookup(unsigned long long value);
> +void sample_names2_show(struct seq_file *m);

Are the above going to be defined somewhere?

> +TRACE_DEFINE_SYM_FNS(sample_names2, sample_names2_lookup, sample_names2_show);
> +
>  TRACE_EVENT(foo_bar,
>  
>  	TP_PROTO(const char *foo, int bar, const int *lst,
> @@ -340,14 +362,10 @@ TRACE_EVENT(foo_bar,
>   *    the variable matches one of the values, then it will print the
>   *    string in that pair. If non are matched, it returns a string
>   *    version of the number (if __entry->bar == 7 then "7" is returned).
> + *
> + *    See above for the declaration of "sample_names".
>   */
> -		  __print_symbolic(__entry->bar,
> -				   { 0, "zero" },
> -				   { TRACE_SAMPLE_FOO, "TWO" },
> -				   { TRACE_SAMPLE_BAR, "FOUR" },
> -				   { TRACE_SAMPLE_ZOO, "EIGHT" },
> -				   { 10, "TEN" }
> -			  ),
> +		  __print_sym(__entry->bar, sample_names),
>  
>  /*
>   *  __print_flags( variable, "delim", { value, "flag" }, ... ),
> 
> 
> 
> It did show a bug because TRACE_SYSTEM isn't a C var in that file (and
> perhaps only in that file?), so I'll have to resend with that fixed
> anyway.
> 
> 
> > FYI, this series did pass all my tests.  
> 
> Cool. Sorry the earlier (long time ago) version had the __init_data
> issue, I'd mostly tested on UML and that wasn't protected there.
> 

Thanks,

-- Steve
Re: [PATCH v7 0/4] tracing: improve symbolic printing
#11795
Author: Johannes Berg
Date: Thu, 05 Nov 2026 16:26
35 lines
10209 bytes
On Thu, 2026-11-05 at 11:24 -0500, Steven Rostedt wrote:
> > Any objection to simply converting the __print_symbolic() sample? It
> > would look something like this:
> 
> Actually, keeping them both would be very useful. That way one can see how
> to do it the other way. We can say, the old way is being deprecated so
> please use the new way.

What's the point? But OK, sure.

> > +/*
> > + * Alternatively, you could define a function for the names:
> > + *
> > + * The _lookup() function returns the string for the given value.
> > + *
> > + * The _show() function must
> > + *	seq_printf(m, ", { %u, \"%s\" }", value, name);
> > + * for each value that userspace should be able to parse.
> > + */
> > +const char *sample_names2_lookup(unsigned long long value);
> > +void sample_names2_show(struct seq_file *m);
> 
> Are the above going to be defined somewhere?

Well, it's a sample, and I wasn't even using "sample_names2" in the
below, so I didn't actually define it. I can flesh that out even more,
but I'm not sure it's worth it?

I reckon most users won't even need the dynamic way, but obviously part
of the reason I'm doing this is that I _do_ need the dynamic way for the
drop reasons, which are registered/built at runtime.

johannes
Re: [PATCH v7 0/4] tracing: improve symbolic printing
#11849
Author: Steven Rostedt
Date: Thu, 05 Nov 2026 16:38
54 lines
11796 bytes
On Thu, 05 Nov 2026 17:26:58 +0100
Johannes Berg <johannes@sipsolutions.net> wrote:

> On Thu, 2026-11-05 at 11:24 -0500, Steven Rostedt wrote:
> > > Any objection to simply converting the __print_symbolic() sample? It
> > > would look something like this:  
> > 
> > Actually, keeping them both would be very useful. That way one can see how
> > to do it the other way. We can say, the old way is being deprecated so
> > please use the new way.  
> 
> What's the point? But OK, sure.

I thought I mentioned the point? "That way one can see how to do it the
other way". Basically, seeing the equivalent way.

> 
> > > +/*
> > > + * Alternatively, you could define a function for the names:
> > > + *
> > > + * The _lookup() function returns the string for the given value.
> > > + *
> > > + * The _show() function must
> > > + *	seq_printf(m, ", { %u, \"%s\" }", value, name);
> > > + * for each value that userspace should be able to parse.
> > > + */
> > > +const char *sample_names2_lookup(unsigned long long value);
> > > +void sample_names2_show(struct seq_file *m);  
> > 
> > Are the above going to be defined somewhere?  
> 
> Well, it's a sample, and I wasn't even using "sample_names2" in the
> below, so I didn't actually define it. I can flesh that out even more,
> but I'm not sure it's worth it?

It is, otherwise it is confusing. If it is in the sample code, people will
think it's required.

> 
> I reckon most users won't even need the dynamic way, but obviously part
> of the reason I'm doing this is that I _do_ need the dynamic way for the
> drop reasons, which are registered/built at runtime.

Right, but if we want to deprecate the old way, we need to have the
simplest sample of it. That is, have one event that shows the simple way to
do this (one that simply replaces the old way), and then have another
example of how to do it in a more complex and featureful way.

Honestly, this is why I asked for this. Your updates use the complex
method, I wasn't sure from the code how to do it for the simple case. That
is, what wasn't needed for just replacing static __print_symbolic() lists.

-- Steve
Re: [PATCH v7 0/4] tracing: improve symbolic printing
#11818
Author: Johannes Berg
Date: Thu, 05 Nov 2026 17:09
198 lines
15570 bytes
On Thu, 2026-11-05 at 11:38 -0500, Steven Rostedt wrote:
> On Thu, 05 Nov 2026 17:26:58 +0100
> Johannes Berg <johannes@sipsolutions.net> wrote:
> 
> > On Thu, 2026-11-05 at 11:24 -0500, Steven Rostedt wrote:
> > > > Any objection to simply converting the __print_symbolic() sample? It
> > > > would look something like this:  
> > > 
> > > Actually, keeping them both would be very useful. That way one can see how
> > > to do it the other way. We can say, the old way is being deprecated so
> > > please use the new way.  
> > 
> > What's the point? But OK, sure.
> 
> I thought I mentioned the point? "That way one can see how to do it the
> other way". Basically, seeing the equivalent way.

You did say that, but I guess I don't really understand it - I see the
point of the sample as the status quo ("how to do it"), not the
evolutionary history ("how to convert it").

But sure, whatever you say, I don't really care.

> > > > +const char *sample_names2_lookup(unsigned long long value);
> > > > +void sample_names2_show(struct seq_file *m);  
> > > 
> > > Are the above going to be defined somewhere?  
> > 
> > Well, it's a sample, and I wasn't even using "sample_names2" in the
> > below, so I didn't actually define it. I can flesh that out even more,
> > but I'm not sure it's worth it?
> 
> It is, otherwise it is confusing. If it is in the sample code, people will
> think it's required.

All of the sample code is optional though, you don't have to use any one
of the methods, either this, or enum, or ... if you want to use the
dynamic way of __print_sym() then it indeed is required.

Anyway I'll flesh this out more.

> Right, but if we want to deprecate the old way, we need to have the
> simplest sample of it. That is, have one event that shows the simple way to
> do this (one that simply replaces the old way), and then have another
> example of how to do it in a more complex and featureful way.
> 
> Honestly, this is why I asked for this. Your updates use the complex
> method, I wasn't sure from the code how to do it for the simple case. That
> is, what wasn't needed for just replacing static __print_symbolic() lists.

The simple way changes from

	__print_symbolic(foo, BRACED_LIST)

to

TRACE_DEFINE_SYM_LIST(foo_names, BRACED_LIST);
...
	__print_sym(foo, foo_names)


so I'm not sure I see how it's really that much more complex?


Anyway, how about below sample update?

johannes



--- a/samples/trace_events/trace-events-sample.c
+++ b/samples/trace_events/trace-events-sample.c
@@ -11,6 +11,36 @@
 #define CREATE_TRACE_POINTS
 #include "trace-events-sample.h"
 
+/* functions for the dynamic __print_sym() example */
+static const struct {
+	unsigned long val;
+	char *name;
+} print_sym_dynamic_names[] = {
+	{ 0, "zero" },
+	{ TRACE_SAMPLE_FOO, "TWO" },
+	{ TRACE_SAMPLE_BAR, "FOUR" },
+	{ TRACE_SAMPLE_ZOO, "EIGHT" },
+	{ 10, "TEN" }
+};
+
+const char *sample_names_dynamic_lookup(unsigned long long value)
+{
+	for (int i = 0; i < ARRAY_SIZE(print_sym_dynamic_names); i++) {
+		if (print_sym_dynamic_names[i].val == value)
+			return print_sym_dynamic_names[i].name;
+	}
+
+	return NULL;
+}
+
+void sample_names_dynamic_show(struct seq_file *m)
+{
+	for (int i = 0; i < ARRAY_SIZE(print_sym_dynamic_names); i++)
+		seq_printf(m, ", { %lu, \"%s\" }",
+			   print_sym_dynamic_names[i].val,
+			   print_sym_dynamic_names[i].name);
+}
+
 static const char *random_strings[] = {
 	"Mother Goose",
 	"Snoopy",
diff --git a/samples/trace_events/trace-events-sample.h b/samples/trace_events/trace-events-sample.h
index 816848a456a2..38d6bf808de6 100644
--- a/samples/trace_events/trace-events-sample.h
+++ b/samples/trace_events/trace-events-sample.h
@@ -297,6 +297,33 @@ TRACE_DEFINE_ENUM(TRACE_SAMPLE_FOO);
 TRACE_DEFINE_ENUM(TRACE_SAMPLE_BAR);
 TRACE_DEFINE_ENUM(TRACE_SAMPLE_ZOO);
 
+/*
+ * define the names as { value, "name" } tuples for __print_sym() below,
+ * same as the inline list for __print_dynamic()
+ */
+TRACE_DEFINE_SYM_LIST(sample_names_static,
+	{ 0, "zero" },
+	{ TRACE_SAMPLE_FOO, "TWO" },
+	{ TRACE_SAMPLE_BAR, "FOUR" },
+	{ TRACE_SAMPLE_ZOO, "EIGHT" },
+	{ 10, "TEN" }
+);
+
+/*
+ * Alternatively, you could define a function for the names:
+ *
+ * The _lookup() function returns the string for the given value.
+ *
+ * The _show() function must
+ *	seq_printf(m, ", { %u, \"%s\" }", value, name);
+ * for each value that userspace should be able to parse.
+ */
+const char *sample_names_dynamic_lookup(unsigned long long value);
+void sample_names_dynamic_show(struct seq_file *m);
+TRACE_DEFINE_SYM_FNS(sample_names_dynamic,
+		     sample_names_dynamic_lookup,
+		     sample_names_dynamic_show);
+
 TRACE_EVENT(foo_bar,
 
 	TP_PROTO(const char *foo, int bar, const int *lst,
@@ -328,7 +355,7 @@ TRACE_EVENT(foo_bar,
 		__assign_cpumask(cpum, cpumask_bits(mask));
 	),
 
-	TP_printk("foo %s %d %s %s %s %s %s %s (%s) (%s) %s [%d] %*pbl",
+	TP_printk("foo %s %d %s %s %s %s %s %s %s %s (%s) (%s) %s [%d] %*pbl",
 		  __entry->foo, __entry->bar,
 
 /*
@@ -340,6 +367,9 @@ TRACE_EVENT(foo_bar,
  *    the variable matches one of the values, then it will print the
  *    string in that pair. If non are matched, it returns a string
  *    version of the number (if __entry->bar == 7 then "7" is returned).
+ *
+ * NOTE: This variant is deprecated, it uses more space than the below
+ *	 __print_sym() which is identical to this for userspace.
  */
 		  __print_symbolic(__entry->bar,
 				   { 0, "zero" },
@@ -349,6 +379,21 @@ TRACE_EVENT(foo_bar,
 				   { 10, "TEN" }
 			  ),
 
+/*
+ *  __print_sym( variable, symbol_list_definition ),
+ *
+ *    The variable is tested against each value of the symbol list.
+ *    The symbol list can be built statically (sample_names_static) or
+ *    dynamically (sample_names_dynamic). If the variable matches one
+ *    of the values, then it will print the string in that pair. If
+ *    no entry matches, the number itself is printed (e.g. here if
+ *    if __entry->bar == 7 then "7" is shown).
+ *
+ *    See above for the declaration of sample_names_{static,dynamic}.
+ */
+		  __print_sym(__entry->bar, sample_names_static),
+		  __print_sym(__entry->bar, sample_names_dynamic),
+
 /*
  *  __print_flags( variable, "delim", { value, "flag" }, ... ),
  *
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads