linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tracing: use %ps format string to print symbols
@ 2021-10-15  8:34 Arnd Bergmann
  2021-10-15 13:57 ` Steven Rostedt
  0 siblings, 1 reply; 3+ messages in thread
From: Arnd Bergmann @ 2021-10-15  8:34 UTC (permalink / raw)
  To: Steven Rostedt, Ingo Molnar
  Cc: Arnd Bergmann, Nathan Chancellor, Nick Desaulniers, Tom Zanussi,
	Namhyung Kim, Jiapeng Chong, linux-kernel, llvm

From: Arnd Bergmann <arnd@arndb.de>

clang started warning about excessive stack usage in
hist_trigger_print_key()

kernel/trace/trace_events_hist.c:4723:13: error: stack frame size (1336) exceeds limit (1024) in function 'hist_trigger_print_key' [-Werror,-Wframe-larger-than]

The problem is that there are two 512-byte arrays on the stack if
hist_trigger_stacktrace_print() gets inlined. I don't think this has
changed in the past five years, but something probably changed the
inlining decisions made by the compiler, so the problem is now made
more obvious.

Rather than printing the symbol names into separate buffers, it
seems we can simply use the special %ps format string modifier
to print the pointers symbolically and get rid of both buffers.

Fixes: 69a0200c2e25 ("tracing: Add hist trigger support for stacktraces as keys")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
I'm not sure if the %ps format string actually works as intended
with the explicit length modifier, it would be good if someone
could try this out before applying. Would it be ok to remove the
length modifier otherwise?
---
 kernel/trace/trace_events_hist.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index a6061a69aa84..640c79898b51 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -4706,7 +4706,6 @@ static void hist_trigger_stacktrace_print(struct seq_file *m,
 					  unsigned long *stacktrace_entries,
 					  unsigned int max_entries)
 {
-	char str[KSYM_SYMBOL_LEN];
 	unsigned int spaces = 8;
 	unsigned int i;
 
@@ -4715,8 +4714,7 @@ static void hist_trigger_stacktrace_print(struct seq_file *m,
 			return;
 
 		seq_printf(m, "%*c", 1 + spaces, ' ');
-		sprint_symbol(str, stacktrace_entries[i]);
-		seq_printf(m, "%s\n", str);
+		seq_printf(m, "%pS\n", stacktrace_entries[i]);
 	}
 }
 
@@ -4726,7 +4724,6 @@ static void hist_trigger_print_key(struct seq_file *m,
 				   struct tracing_map_elt *elt)
 {
 	struct hist_field *key_field;
-	char str[KSYM_SYMBOL_LEN];
 	bool multiline = false;
 	const char *field_name;
 	unsigned int i;
@@ -4747,14 +4744,12 @@ static void hist_trigger_print_key(struct seq_file *m,
 			seq_printf(m, "%s: %llx", field_name, uval);
 		} else if (key_field->flags & HIST_FIELD_FL_SYM) {
 			uval = *(u64 *)(key + key_field->offset);
-			sprint_symbol_no_offset(str, uval);
-			seq_printf(m, "%s: [%llx] %-45s", field_name,
-				   uval, str);
+			seq_printf(m, "%s: [%llx] %-45ps", field_name,
+				   uval, (void *)uval);
 		} else if (key_field->flags & HIST_FIELD_FL_SYM_OFFSET) {
 			uval = *(u64 *)(key + key_field->offset);
-			sprint_symbol(str, uval);
-			seq_printf(m, "%s: [%llx] %-55s", field_name,
-				   uval, str);
+			seq_printf(m, "%s: [%llx] %-55ps", field_name,
+				   uval, (void *)uval);
 		} else if (key_field->flags & HIST_FIELD_FL_EXECNAME) {
 			struct hist_elt_data *elt_data = elt->private_data;
 			char *comm;
-- 
2.29.2


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

* Re: [PATCH] tracing: use %ps format string to print symbols
  2021-10-15  8:34 [PATCH] tracing: use %ps format string to print symbols Arnd Bergmann
@ 2021-10-15 13:57 ` Steven Rostedt
  2021-10-15 14:40   ` Arnd Bergmann
  0 siblings, 1 reply; 3+ messages in thread
From: Steven Rostedt @ 2021-10-15 13:57 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Ingo Molnar, Arnd Bergmann, Nathan Chancellor, Nick Desaulniers,
	Tom Zanussi, Namhyung Kim, Jiapeng Chong, linux-kernel, llvm

On Fri, 15 Oct 2021 10:34:31 +0200
Arnd Bergmann <arnd@kernel.org> wrote:

> From: Arnd Bergmann <arnd@arndb.de>
> 
> clang started warning about excessive stack usage in
> hist_trigger_print_key()
> 
> kernel/trace/trace_events_hist.c:4723:13: error: stack frame size (1336) exceeds limit (1024) in function 'hist_trigger_print_key' [-Werror,-Wframe-larger-than]
> 
> The problem is that there are two 512-byte arrays on the stack if
> hist_trigger_stacktrace_print() gets inlined. I don't think this has
> changed in the past five years, but something probably changed the
> inlining decisions made by the compiler, so the problem is now made
> more obvious.

Could we just add "noinline" attribute to that function?

> 
> Rather than printing the symbol names into separate buffers, it
> seems we can simply use the special %ps format string modifier
> to print the pointers symbolically and get rid of both buffers.
> 
> Fixes: 69a0200c2e25 ("tracing: Add hist trigger support for stacktraces as keys")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> I'm not sure if the %ps format string actually works as intended
> with the explicit length modifier, it would be good if someone
> could try this out before applying. Would it be ok to remove the
> length modifier otherwise?

I believe that shows a "table" format. So the length modifier is required.

> ---
>  kernel/trace/trace_events_hist.c | 15 +++++----------
>  1 file changed, 5 insertions(+), 10 deletions(-)
> 
> diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
> index a6061a69aa84..640c79898b51 100644
> --- a/kernel/trace/trace_events_hist.c
> +++ b/kernel/trace/trace_events_hist.c
> @@ -4706,7 +4706,6 @@ static void hist_trigger_stacktrace_print(struct seq_file *m,
>  					  unsigned long *stacktrace_entries,
>  					  unsigned int max_entries)
>  {
> -	char str[KSYM_SYMBOL_LEN];
>  	unsigned int spaces = 8;
>  	unsigned int i;
>  
> @@ -4715,8 +4714,7 @@ static void hist_trigger_stacktrace_print(struct seq_file *m,
>  			return;
>  
>  		seq_printf(m, "%*c", 1 + spaces, ' ');
> -		sprint_symbol(str, stacktrace_entries[i]);
> -		seq_printf(m, "%s\n", str);
> +		seq_printf(m, "%pS\n", stacktrace_entries[i]);
>  	}
>  }
>  
> @@ -4726,7 +4724,6 @@ static void hist_trigger_print_key(struct seq_file *m,
>  				   struct tracing_map_elt *elt)
>  {
>  	struct hist_field *key_field;
> -	char str[KSYM_SYMBOL_LEN];
>  	bool multiline = false;
>  	const char *field_name;
>  	unsigned int i;
> @@ -4747,14 +4744,12 @@ static void hist_trigger_print_key(struct seq_file *m,
>  			seq_printf(m, "%s: %llx", field_name, uval);
>  		} else if (key_field->flags & HIST_FIELD_FL_SYM) {
>  			uval = *(u64 *)(key + key_field->offset);
> -			sprint_symbol_no_offset(str, uval);
> -			seq_printf(m, "%s: [%llx] %-45s", field_name,
> -				   uval, str);
> +			seq_printf(m, "%s: [%llx] %-45ps", field_name,
> +				   uval, (void *)uval);
>  		} else if (key_field->flags & HIST_FIELD_FL_SYM_OFFSET) {
>  			uval = *(u64 *)(key + key_field->offset);
> -			sprint_symbol(str, uval);
> -			seq_printf(m, "%s: [%llx] %-55s", field_name,
> -				   uval, str);
> +			seq_printf(m, "%s: [%llx] %-55ps", field_name,
> +				   uval, (void *)uval);

The above requires "Ps" not "ps".

But other than that, I could test if this doesn't change the formatting and
functionality at all.

-- Steve


>  		} else if (key_field->flags & HIST_FIELD_FL_EXECNAME) {
>  			struct hist_elt_data *elt_data = elt->private_data;
>  			char *comm;


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

* Re: [PATCH] tracing: use %ps format string to print symbols
  2021-10-15 13:57 ` Steven Rostedt
@ 2021-10-15 14:40   ` Arnd Bergmann
  0 siblings, 0 replies; 3+ messages in thread
From: Arnd Bergmann @ 2021-10-15 14:40 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Ingo Molnar, Arnd Bergmann, Nathan Chancellor, Nick Desaulniers,
	Tom Zanussi, Namhyung Kim, Jiapeng Chong,
	Linux Kernel Mailing List, llvm

On Fri, Oct 15, 2021 at 3:57 PM Steven Rostedt <rostedt@goodmis.org> wrote:
>
> On Fri, 15 Oct 2021 10:34:31 +0200
> Arnd Bergmann <arnd@kernel.org> wrote:
>
> > From: Arnd Bergmann <arnd@arndb.de>
> >
> > clang started warning about excessive stack usage in
> > hist_trigger_print_key()
> >
> > kernel/trace/trace_events_hist.c:4723:13: error: stack frame size (1336) exceeds limit (1024) in function 'hist_trigger_print_key' [-Werror,-Wframe-larger-than]
> >
> > The problem is that there are two 512-byte arrays on the stack if
> > hist_trigger_stacktrace_print() gets inlined. I don't think this has
> > changed in the past five years, but something probably changed the
> > inlining decisions made by the compiler, so the problem is now made
> > more obvious.
>
> Could we just add "noinline" attribute to that function?

It would avoid the warning, but not reduce the overall stack
usage. If that's good enough for you, I'm fine with that as well.

> > @@ -4715,8 +4714,7 @@ static void hist_trigger_stacktrace_print(struct seq_file *m,
> >                       return;
> >
> >               seq_printf(m, "%*c", 1 + spaces, ' ');
> > -             sprint_symbol(str, stacktrace_entries[i]);
> > -             seq_printf(m, "%s\n", str);
> > +             seq_printf(m, "%pS\n", stacktrace_entries[i]);

I just noticed this needs an extra cast to (void*) to avoid a warning
with clang,
not sure why I saw it build cleanly before.

> > @@ -4747,14 +4744,12 @@ static void hist_trigger_print_key(struct seq_file *m,
> >                       seq_printf(m, "%s: %llx", field_name, uval);
> >               } else if (key_field->flags & HIST_FIELD_FL_SYM) {
> >                       uval = *(u64 *)(key + key_field->offset);
> > -                     sprint_symbol_no_offset(str, uval);
> > -                     seq_printf(m, "%s: [%llx] %-45s", field_name,
> > -                                uval, str);
> > +                     seq_printf(m, "%s: [%llx] %-45ps", field_name,
> > +                                uval, (void *)uval);
> >               } else if (key_field->flags & HIST_FIELD_FL_SYM_OFFSET) {
> >                       uval = *(u64 *)(key + key_field->offset);
> > -                     sprint_symbol(str, uval);
> > -                     seq_printf(m, "%s: [%llx] %-55s", field_name,
> > -                                uval, str);
> > +                     seq_printf(m, "%s: [%llx] %-55ps", field_name,
> > +                                uval, (void *)uval);
>
> The above requires "Ps" not "ps".

you mean "%-55pS", right?

> But other than that, I could test if this doesn't change the formatting and
> functionality at all.

Ok, let me know if I should resend with the two small changes I mentioned,
or if you want to just go with the 'noinline_for_stack' annotation.

        Arnd

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

end of thread, other threads:[~2021-10-15 14:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-15  8:34 [PATCH] tracing: use %ps format string to print symbols Arnd Bergmann
2021-10-15 13:57 ` Steven Rostedt
2021-10-15 14:40   ` Arnd Bergmann

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).