public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] tracing: Optimize __string()/__assign_str() processing
@ 2024-02-22 19:51 Steven Rostedt
  2024-02-22 19:51 ` [PATCH 1/2] tracing: Rework __assign_str() and __string() to not duplicate getting the string Steven Rostedt
  2024-02-22 19:51 ` [PATCH 2/2] tracing: Do not calculate strlen() twice for __string() fields Steven Rostedt
  0 siblings, 2 replies; 3+ messages in thread
From: Steven Rostedt @ 2024-02-22 19:51 UTC (permalink / raw)
  To: linux-kernel, linux-trace-kernel
  Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton,
	Ville Syrjälä, Rodrigo Vivi, Chuck Lever


The TRACE_EVENT() macro handles dynamic strings by having:

  TP_PROTO(struct some_struct *s),
  TP_ARGS(s),
  TP_STRUCT__entry(
        __string(my_string, s->string)
 ),
 TP_fast_assign(
        __assign_str(my_string, s->string);
 )
 TP_printk("%s", __get_str(my_string))

There's even some code that may call a function helper to find the
s->string value. The problem with the above is that the work to get the
s->string is done twice. Once at the __string() and again in the
__assign_str().

The length of the string is calculated via a strlen(), not once, but
twice (using strcpy). The length is actually already recorded in the data
location from __string() and here's no reason to call strcpy() in
__assign_str() as the length is already known.

The __string() macro uses dynamic_array() which has a helper structure that
is created holding the offsets and length of the string fields. Instead of
finding the string twice, just save it off in another field in that helper
structure, and have __assign_str() use that instead.

Steven Rostedt (Google) (2):
      tracing: Rework __assign_str() and __string() to not duplicate getting the string
      tracing: Do not calculate strlen() twice for __string() fields

----
 include/trace/stages/stage2_data_offsets.h   |  4 ++--
 include/trace/stages/stage5_get_offsets.h    | 15 ++++++++++-----
 include/trace/stages/stage6_event_callback.h | 14 ++++++++++----
 3 files changed, 22 insertions(+), 11 deletions(-)

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

end of thread, other threads:[~2024-02-22 19:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-22 19:51 [PATCH 0/2] tracing: Optimize __string()/__assign_str() processing Steven Rostedt
2024-02-22 19:51 ` [PATCH 1/2] tracing: Rework __assign_str() and __string() to not duplicate getting the string Steven Rostedt
2024-02-22 19:51 ` [PATCH 2/2] tracing: Do not calculate strlen() twice for __string() fields Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox