* [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
* [PATCH 1/2] tracing: Rework __assign_str() and __string() to not duplicate getting the string
2024-02-22 19:51 [PATCH 0/2] tracing: Optimize __string()/__assign_str() processing Steven Rostedt
@ 2024-02-22 19:51 ` Steven Rostedt
2024-02-22 19:51 ` [PATCH 2/2] tracing: Do not calculate strlen() twice for __string() fields Steven Rostedt
1 sibling, 0 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
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
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 __string() 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.
Note, this also means that the second parameter of __assign_str() isn't
even used anymore, and may be removed in the future.
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
include/trace/stages/stage2_data_offsets.h | 4 ++--
include/trace/stages/stage5_get_offsets.h | 15 ++++++++++-----
include/trace/stages/stage6_event_callback.h | 12 ++++++++----
3 files changed, 20 insertions(+), 11 deletions(-)
diff --git a/include/trace/stages/stage2_data_offsets.h b/include/trace/stages/stage2_data_offsets.h
index 469b6a64293d..8b0cff06d346 100644
--- a/include/trace/stages/stage2_data_offsets.h
+++ b/include/trace/stages/stage2_data_offsets.h
@@ -24,7 +24,7 @@
#define __array(type, item, len)
#undef __dynamic_array
-#define __dynamic_array(type, item, len) u32 item;
+#define __dynamic_array(type, item, len) u32 item; const void *item##_ptr_;
#undef __string
#define __string(item, src) __dynamic_array(char, item, -1)
@@ -45,7 +45,7 @@
#define __sockaddr(field, len) __dynamic_array(u8, field, len)
#undef __rel_dynamic_array
-#define __rel_dynamic_array(type, item, len) u32 item;
+#define __rel_dynamic_array(type, item, len) u32 item; const void *item##_ptr_;
#undef __rel_string
#define __rel_string(item, src) __rel_dynamic_array(char, item, -1)
diff --git a/include/trace/stages/stage5_get_offsets.h b/include/trace/stages/stage5_get_offsets.h
index e30a13be46ba..c71f38e10419 100644
--- a/include/trace/stages/stage5_get_offsets.h
+++ b/include/trace/stages/stage5_get_offsets.h
@@ -47,10 +47,12 @@
#undef __string
#define __string(item, src) __dynamic_array(char, item, \
- strlen((src) ? (const char *)(src) : "(null)") + 1)
+ strlen((src) ? (const char *)(src) : "(null)") + 1) \
+ __data_offsets->item##_ptr_ = src;
#undef __string_len
-#define __string_len(item, src, len) __dynamic_array(char, item, (len) + 1)
+#define __string_len(item, src, len) __dynamic_array(char, item, (len) + 1)\
+ __data_offsets->item##_ptr_ = src;
#undef __vstring
#define __vstring(item, fmt, ap) __dynamic_array(char, item, \
@@ -67,11 +69,14 @@
__data_size += __item_length;
#undef __rel_string
-#define __rel_string(item, src) __rel_dynamic_array(char, item, \
- strlen((src) ? (const char *)(src) : "(null)") + 1)
+#define __rel_string(item, src) __rel_dynamic_array(char, item, \
+ strlen((src) ? (const char *)(src) : "(null)") + 1); \
+ __data_offsets->item##_ptr_ = src;
#undef __rel_string_len
-#define __rel_string_len(item, src, len) __rel_dynamic_array(char, item, (len) + 1)
+#define __rel_string_len(item, src, len) __rel_dynamic_array(char, item, (len) + 1)\
+ __data_offsets->item##_ptr_ = src;
+
/*
* __bitmask_size_in_bytes_raw is the number of bytes needed to hold
* num_possible_cpus().
diff --git a/include/trace/stages/stage6_event_callback.h b/include/trace/stages/stage6_event_callback.h
index 919b1a4da980..e09e3d019dcc 100644
--- a/include/trace/stages/stage6_event_callback.h
+++ b/include/trace/stages/stage6_event_callback.h
@@ -32,12 +32,14 @@
#undef __assign_str
#define __assign_str(dst, src) \
- strcpy(__get_str(dst), (src) ? (const char *)(src) : "(null)");
+ strcpy(__get_str(dst), __data_offsets.dst##_ptr_ ? \
+ __data_offsets.dst##_ptr_ : "(null)")
#undef __assign_str_len
#define __assign_str_len(dst, src, len) \
do { \
- memcpy(__get_str(dst), (src), (len)); \
+ memcpy(__get_str(dst), __data_offsets.dst##_ptr_ ? \
+ __data_offsets.dst##_ptr_ : "(null)", len); \
__get_str(dst)[len] = '\0'; \
} while(0)
@@ -92,12 +94,14 @@
#undef __assign_rel_str
#define __assign_rel_str(dst, src) \
- strcpy(__get_rel_str(dst), (src) ? (const char *)(src) : "(null)");
+ strcpy(__get_rel_str(dst), __data_offsets.dst##_ptr_ ? \
+ __data_offsets.dst##_ptr_ : "(null)")
#undef __assign_rel_str_len
#define __assign_rel_str_len(dst, src, len) \
do { \
- memcpy(__get_rel_str(dst), (src), (len)); \
+ memcpy(__get_str(dst), __data_offsets.dst##_ptr_ ? \
+ __data_offsets.dst##_ptr_ : "(null)", len); \
__get_rel_str(dst)[len] = '\0'; \
} while (0)
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] tracing: Do not calculate strlen() twice for __string() fields
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 ` Steven Rostedt
1 sibling, 0 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
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
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
length of 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
(via strcpy() in __assign_str()). Once during the __string() macro and again
in __assign_str(). But the length is actually already recorded in the data
location and there's no reason to call strlen() again.
Just use the saved length that was saved in the __string() code for the
__assign_str() code.
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
include/trace/stages/stage6_event_callback.h | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/include/trace/stages/stage6_event_callback.h b/include/trace/stages/stage6_event_callback.h
index e09e3d019dcc..d389725937e9 100644
--- a/include/trace/stages/stage6_event_callback.h
+++ b/include/trace/stages/stage6_event_callback.h
@@ -32,8 +32,9 @@
#undef __assign_str
#define __assign_str(dst, src) \
- strcpy(__get_str(dst), __data_offsets.dst##_ptr_ ? \
- __data_offsets.dst##_ptr_ : "(null)")
+ memcpy(__get_str(dst), __data_offsets.dst##_ptr_ ? \
+ __data_offsets.dst##_ptr_ : "(null)", \
+ __get_dynamic_array_len(dst))
#undef __assign_str_len
#define __assign_str_len(dst, src, len) \
@@ -94,8 +95,9 @@
#undef __assign_rel_str
#define __assign_rel_str(dst, src) \
- strcpy(__get_rel_str(dst), __data_offsets.dst##_ptr_ ? \
- __data_offsets.dst##_ptr_ : "(null)")
+ memcpy(__get_rel_str(dst), __data_offsets.dst##_ptr_ ? \
+ __data_offsets.dst##_ptr_ : "(null)", \
+ __get_rel_dynamic_array_len(dst))
#undef __assign_rel_str_len
#define __assign_rel_str_len(dst, src, len) \
--
2.43.0
^ permalink raw reply related [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;
as well as URLs for NNTP newsgroup(s).