linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tracing: Have unsigned int function args displayed as hexadecimal
@ 2025-07-31 23:31 Steven Rostedt
  2025-08-01 14:49 ` Yonghong Song
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Steven Rostedt @ 2025-07-31 23:31 UTC (permalink / raw)
  To: LKML, Linux Trace Kernel
  Cc: Masami Hiramatsu, Mathieu Desnoyers, bpf, Douglas Raillard

From: Steven Rostedt <rostedt@goodmis.org>

Most function arguments that are passed in as unsigned int or unsigned
long are better displayed as hexadecimal than normal integer. For example,
the functions:

static void __create_object(unsigned long ptr, size_t size,
				int min_count, gfp_t gfp, unsigned int objflags);

static bool stack_access_ok(struct unwind_state *state, unsigned long _addr,
			    size_t len);

void __local_bh_disable_ip(unsigned long ip, unsigned int cnt);

Show up in the trace as:

    __create_object(ptr=-131387050520576, size=4096, min_count=1, gfp=3264, objflags=0) <-kmem_cache_alloc_noprof
    stack_access_ok(state=0xffffc9000233fc98, _addr=-60473102566256, len=8) <-unwind_next_frame
    __local_bh_disable_ip(ip=-2127311112, cnt=256) <-handle_softirqs

Instead, by displaying unsigned as hexadecimal, they look more like this:

    __create_object(ptr=0xffff8881028d2080, size=0x280, min_count=1, gfp=0x82820, objflags=0x0) <-kmem_cache_alloc_node_noprof
    stack_access_ok(state=0xffffc90000003938, _addr=0xffffc90000003930, len=0x8) <-unwind_next_frame
    __local_bh_disable_ip(ip=0xffffffff8133cef8, cnt=0x100) <-handle_softirqs

Which is much easier to understand as most unsigned longs are usually just
pointers. Even the "unsigned int cnt" in __local_bh_disable_ip() looks
better as hexadecimal as a lot of flags are passed as unsigned.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 kernel/trace/trace_output.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
index 0b3db02030a7..b18393d66a7f 100644
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -690,6 +690,12 @@ int trace_print_lat_context(struct trace_iterator *iter)
 }
 
 #ifdef CONFIG_FUNCTION_TRACE_ARGS
+
+static u32 btf_type_int(const struct btf_type *t)
+{
+	return *(u32 *)(t + 1);
+}
+
 void print_function_args(struct trace_seq *s, unsigned long *args,
 			 unsigned long func)
 {
@@ -701,6 +707,8 @@ void print_function_args(struct trace_seq *s, unsigned long *args,
 	struct btf *btf;
 	s32 tid, nr = 0;
 	int a, p, x;
+	int int_data;
+	u16 encode;
 
 	trace_seq_printf(s, "(");
 
@@ -744,7 +752,14 @@ void print_function_args(struct trace_seq *s, unsigned long *args,
 			trace_seq_printf(s, "0x%lx", arg);
 			break;
 		case BTF_KIND_INT:
-			trace_seq_printf(s, "%ld", arg);
+			/* Get the INT encodoing */
+			int_data = btf_type_int(t);
+                        encode = BTF_INT_ENCODING(int_data);
+                        /* Print unsigned ints as hex */
+                        if (encode & BTF_INT_SIGNED)
+				trace_seq_printf(s, "%ld", arg);
+                        else
+                                trace_seq_printf(s, "0x%lx", arg);
 			break;
 		case BTF_KIND_ENUM:
 			trace_seq_printf(s, "%ld", arg);
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] tracing: Have unsigned int function args displayed as hexadecimal
  2025-07-31 23:31 [PATCH] tracing: Have unsigned int function args displayed as hexadecimal Steven Rostedt
@ 2025-08-01 14:49 ` Yonghong Song
  2025-08-01 15:09   ` Steven Rostedt
  2025-08-01 19:59 ` Martin KaFai Lau
  2025-08-04 13:19 ` Masami Hiramatsu
  2 siblings, 1 reply; 6+ messages in thread
From: Yonghong Song @ 2025-08-01 14:49 UTC (permalink / raw)
  To: Steven Rostedt, LKML, Linux Trace Kernel
  Cc: Masami Hiramatsu, Mathieu Desnoyers, bpf, Douglas Raillard



On 7/31/25 4:31 PM, Steven Rostedt wrote:
> From: Steven Rostedt <rostedt@goodmis.org>
>
> Most function arguments that are passed in as unsigned int or unsigned
> long are better displayed as hexadecimal than normal integer. For example,
> the functions:
>
> static void __create_object(unsigned long ptr, size_t size,
> 				int min_count, gfp_t gfp, unsigned int objflags);
>
> static bool stack_access_ok(struct unwind_state *state, unsigned long _addr,
> 			    size_t len);
>
> void __local_bh_disable_ip(unsigned long ip, unsigned int cnt);
>
> Show up in the trace as:
>
>      __create_object(ptr=-131387050520576, size=4096, min_count=1, gfp=3264, objflags=0) <-kmem_cache_alloc_noprof
>      stack_access_ok(state=0xffffc9000233fc98, _addr=-60473102566256, len=8) <-unwind_next_frame
>      __local_bh_disable_ip(ip=-2127311112, cnt=256) <-handle_softirqs
>
> Instead, by displaying unsigned as hexadecimal, they look more like this:
>
>      __create_object(ptr=0xffff8881028d2080, size=0x280, min_count=1, gfp=0x82820, objflags=0x0) <-kmem_cache_alloc_node_noprof
>      stack_access_ok(state=0xffffc90000003938, _addr=0xffffc90000003930, len=0x8) <-unwind_next_frame
>      __local_bh_disable_ip(ip=0xffffffff8133cef8, cnt=0x100) <-handle_softirqs
>
> Which is much easier to understand as most unsigned longs are usually just
> pointers. Even the "unsigned int cnt" in __local_bh_disable_ip() looks
> better as hexadecimal as a lot of flags are passed as unsigned.
>
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

LGTM. But it seems some format issue. See below.

Acked-by: Yonghong Song <yonghong.song@linux.dev>

> ---
>   kernel/trace/trace_output.c | 17 ++++++++++++++++-
>   1 file changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
> index 0b3db02030a7..b18393d66a7f 100644
> --- a/kernel/trace/trace_output.c
> +++ b/kernel/trace/trace_output.c
> @@ -690,6 +690,12 @@ int trace_print_lat_context(struct trace_iterator *iter)
>   }
>   
>   #ifdef CONFIG_FUNCTION_TRACE_ARGS
> +
> +static u32 btf_type_int(const struct btf_type *t)
> +{
> +	return *(u32 *)(t + 1);
> +}
> +
>   void print_function_args(struct trace_seq *s, unsigned long *args,
>   			 unsigned long func)
>   {
> @@ -701,6 +707,8 @@ void print_function_args(struct trace_seq *s, unsigned long *args,
>   	struct btf *btf;
>   	s32 tid, nr = 0;
>   	int a, p, x;
> +	int int_data;
> +	u16 encode;
>   
>   	trace_seq_printf(s, "(");
>   
> @@ -744,7 +752,14 @@ void print_function_args(struct trace_seq *s, unsigned long *args,
>   			trace_seq_printf(s, "0x%lx", arg);
>   			break;
>   		case BTF_KIND_INT:
> -			trace_seq_printf(s, "%ld", arg);
> +			/* Get the INT encodoing */
> +			int_data = btf_type_int(t);
> +                        encode = BTF_INT_ENCODING(int_data);

See different identation between above 'int_data' and 'encode'. The same as below.

> +                        /* Print unsigned ints as hex */
> +                        if (encode & BTF_INT_SIGNED)
> +				trace_seq_printf(s, "%ld", arg);
> +                        else
> +                                trace_seq_printf(s, "0x%lx", arg);
>   			break;
>   		case BTF_KIND_ENUM:
>   			trace_seq_printf(s, "%ld", arg);


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] tracing: Have unsigned int function args displayed as hexadecimal
  2025-08-01 14:49 ` Yonghong Song
@ 2025-08-01 15:09   ` Steven Rostedt
  0 siblings, 0 replies; 6+ messages in thread
From: Steven Rostedt @ 2025-08-01 15:09 UTC (permalink / raw)
  To: Yonghong Song
  Cc: LKML, Linux Trace Kernel, Masami Hiramatsu, Mathieu Desnoyers,
	bpf, Douglas Raillard

On Fri, 1 Aug 2025 07:49:53 -0700
Yonghong Song <yonghong.song@linux.dev> wrote:

> > @@ -744,7 +752,14 @@ void print_function_args(struct trace_seq *s, unsigned long *args,
> >   			trace_seq_printf(s, "0x%lx", arg);
> >   			break;
> >   		case BTF_KIND_INT:
> > -			trace_seq_printf(s, "%ld", arg);
> > +			/* Get the INT encodoing */
> > +			int_data = btf_type_int(t);
> > +                        encode = BTF_INT_ENCODING(int_data);  
> 
> See different identation between above 'int_data' and 'encode'. The same as below.

Bah, I think I cut and pasted into emacs and it used spaces instead of tabs.

-- Steve


> 
> > +                        /* Print unsigned ints as hex */
> > +                        if (encode & BTF_INT_SIGNED)
> > +				trace_seq_printf(s, "%ld", arg);
> > +                        else
> > +                                trace_seq_printf(s, "0x%lx", arg);
> >   			break;
> >   		case BTF_KIND_ENUM:
> >   			trace_seq_printf(s, "%ld", arg);  


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] tracing: Have unsigned int function args displayed as hexadecimal
  2025-07-31 23:31 [PATCH] tracing: Have unsigned int function args displayed as hexadecimal Steven Rostedt
  2025-08-01 14:49 ` Yonghong Song
@ 2025-08-01 19:59 ` Martin KaFai Lau
  2025-08-01 20:05   ` Steven Rostedt
  2025-08-04 13:19 ` Masami Hiramatsu
  2 siblings, 1 reply; 6+ messages in thread
From: Martin KaFai Lau @ 2025-08-01 19:59 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Masami Hiramatsu, Mathieu Desnoyers, bpf, Douglas Raillard, LKML,
	Linux Trace Kernel

On 7/31/25 4:31 PM, Steven Rostedt wrote:
> +			int_data = btf_type_int(t);
> +                        encode = BTF_INT_ENCODING(int_data);

There is a btf_int_encoding(t) helper in btf.h, so only "encode = 
btf_int_encoding(t);" will be simpler.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] tracing: Have unsigned int function args displayed as hexadecimal
  2025-08-01 19:59 ` Martin KaFai Lau
@ 2025-08-01 20:05   ` Steven Rostedt
  0 siblings, 0 replies; 6+ messages in thread
From: Steven Rostedt @ 2025-08-01 20:05 UTC (permalink / raw)
  To: Martin KaFai Lau
  Cc: Masami Hiramatsu, Mathieu Desnoyers, bpf, Douglas Raillard, LKML,
	Linux Trace Kernel

On Fri, 1 Aug 2025 12:59:05 -0700
Martin KaFai Lau <martin.lau@linux.dev> wrote:

> On 7/31/25 4:31 PM, Steven Rostedt wrote:
> > +			int_data = btf_type_int(t);
> > +                        encode = BTF_INT_ENCODING(int_data);  
> 
> There is a btf_int_encoding(t) helper in btf.h, so only "encode = 
> btf_int_encoding(t);" will be simpler.

Thanks, I didn't see that. I was looking at the code in btf.c which had
this open coded.

-- Steve

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] tracing: Have unsigned int function args displayed as hexadecimal
  2025-07-31 23:31 [PATCH] tracing: Have unsigned int function args displayed as hexadecimal Steven Rostedt
  2025-08-01 14:49 ` Yonghong Song
  2025-08-01 19:59 ` Martin KaFai Lau
@ 2025-08-04 13:19 ` Masami Hiramatsu
  2 siblings, 0 replies; 6+ messages in thread
From: Masami Hiramatsu @ 2025-08-04 13:19 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: LKML, Linux Trace Kernel, Masami Hiramatsu, Mathieu Desnoyers,
	bpf, Douglas Raillard

On Thu, 31 Jul 2025 19:31:26 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:

> From: Steven Rostedt <rostedt@goodmis.org>
> 
> Most function arguments that are passed in as unsigned int or unsigned
> long are better displayed as hexadecimal than normal integer. For example,
> the functions:
> 
> static void __create_object(unsigned long ptr, size_t size,
> 				int min_count, gfp_t gfp, unsigned int objflags);
> 
> static bool stack_access_ok(struct unwind_state *state, unsigned long _addr,
> 			    size_t len);
> 
> void __local_bh_disable_ip(unsigned long ip, unsigned int cnt);
> 
> Show up in the trace as:
> 
>     __create_object(ptr=-131387050520576, size=4096, min_count=1, gfp=3264, objflags=0) <-kmem_cache_alloc_noprof
>     stack_access_ok(state=0xffffc9000233fc98, _addr=-60473102566256, len=8) <-unwind_next_frame
>     __local_bh_disable_ip(ip=-2127311112, cnt=256) <-handle_softirqs
> 
> Instead, by displaying unsigned as hexadecimal, they look more like this:
> 
>     __create_object(ptr=0xffff8881028d2080, size=0x280, min_count=1, gfp=0x82820, objflags=0x0) <-kmem_cache_alloc_node_noprof
>     stack_access_ok(state=0xffffc90000003938, _addr=0xffffc90000003930, len=0x8) <-unwind_next_frame
>     __local_bh_disable_ip(ip=0xffffffff8133cef8, cnt=0x100) <-handle_softirqs
> 
> Which is much easier to understand as most unsigned longs are usually just
> pointers. Even the "unsigned int cnt" in __local_bh_disable_ip() looks
> better as hexadecimal as a lot of flags are passed as unsigned.
> 

Looks good to me. Maybe this format is better for programers :)

Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Thanks,

> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> ---
>  kernel/trace/trace_output.c | 17 ++++++++++++++++-
>  1 file changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
> index 0b3db02030a7..b18393d66a7f 100644
> --- a/kernel/trace/trace_output.c
> +++ b/kernel/trace/trace_output.c
> @@ -690,6 +690,12 @@ int trace_print_lat_context(struct trace_iterator *iter)
>  }
>  
>  #ifdef CONFIG_FUNCTION_TRACE_ARGS
> +
> +static u32 btf_type_int(const struct btf_type *t)
> +{
> +	return *(u32 *)(t + 1);
> +}
> +
>  void print_function_args(struct trace_seq *s, unsigned long *args,
>  			 unsigned long func)
>  {
> @@ -701,6 +707,8 @@ void print_function_args(struct trace_seq *s, unsigned long *args,
>  	struct btf *btf;
>  	s32 tid, nr = 0;
>  	int a, p, x;
> +	int int_data;
> +	u16 encode;
>  
>  	trace_seq_printf(s, "(");
>  
> @@ -744,7 +752,14 @@ void print_function_args(struct trace_seq *s, unsigned long *args,
>  			trace_seq_printf(s, "0x%lx", arg);
>  			break;
>  		case BTF_KIND_INT:
> -			trace_seq_printf(s, "%ld", arg);
> +			/* Get the INT encodoing */
> +			int_data = btf_type_int(t);
> +                        encode = BTF_INT_ENCODING(int_data);
> +                        /* Print unsigned ints as hex */
> +                        if (encode & BTF_INT_SIGNED)
> +				trace_seq_printf(s, "%ld", arg);
> +                        else
> +                                trace_seq_printf(s, "0x%lx", arg);
>  			break;
>  		case BTF_KIND_ENUM:
>  			trace_seq_printf(s, "%ld", arg);
> -- 
> 2.47.2
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-08-04 13:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-31 23:31 [PATCH] tracing: Have unsigned int function args displayed as hexadecimal Steven Rostedt
2025-08-01 14:49 ` Yonghong Song
2025-08-01 15:09   ` Steven Rostedt
2025-08-01 19:59 ` Martin KaFai Lau
2025-08-01 20:05   ` Steven Rostedt
2025-08-04 13:19 ` Masami Hiramatsu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).