[PATCH v5 5/9] tracing: Rename __dynamic_array() to __dynamic_field() for ftrace events

Steven Rostedt
2025-04-24T19:24:17Z

From: Steven Rostedt <rostedt@goodmis.org>

The ftrace events (like function, trace_print, etc) are created somewhat
manually and not via the TRACE_EVENT() or tracepoint magic macros. It has
its own macros.

The dynamic fields used __dynamic_array() to be created, but the output is
different than the __dynamic_array() used by TRACE_EVENT().

The TRACE_EVENT() __dynamic_array() creates the field like:

field:__data_loc u8[] v_data; offset:120; size:4; signed:0;

Whereas the ftrace event is created as:

field:char buf[]; offset:12; size:0; signed:0;

The difference is that the ftrace field is defined as the rest of the size
of the event saved in the ring buffer. TRACE_EVENT() doesn't have such a
dynamic field, and its version saves a word that holds the offset into the
event that the field is stored, as well as the size.

For consistency rename the ftrace event macro to __dynamic_field(). This
way the ftrace event can also include a __dynamic_array() later that works
the same as the TRACE_EVENT() dynamic array.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
kernel/trace/trace.h | 4 ++--
kernel/trace/trace_entries.h | 10 +++++-----
kernel/trace/trace_export.c | 12 ++++++------
3 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index 79be1995db44..3c733b9e7b32 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -92,8 +92,8 @@ enum trace_type {
#undef __array_desc
#define __array_desc(type, container, item, size)

-#undef __dynamic_array
-#define __dynamic_array(type, item) type item[];
+#undef __dynamic_field
+#define __dynamic_field(type, item) type item[];

#undef __rel_dynamic_array
#define __rel_dynamic_array(type, item) type item[];
diff --git a/kernel/trace/trace_entries.h b/kernel/trace/trace_entries.h
index 4ef4df6623a8..7100d8f86011 100644
--- a/kernel/trace/trace_entries.h
+++ b/kernel/trace/trace_entries.h
@@ -63,7 +63,7 @@ FTRACE_ENTRY_REG(function, ftrace_entry,
F_STRUCT(
__field_fn( unsigned long, ip )
__field_fn( unsigned long, parent_ip )
- __dynamic_array( unsigned long, args )
+ __dynamic_field( unsigned long, args )
),

F_printk(" %ps <-- %ps",
@@ -81,7 +81,7 @@ FTRACE_ENTRY(funcgraph_entry, ftrace_graph_ent_entry,
__field_struct( struct ftrace_graph_ent, graph_ent )
__field_packed( unsigned long, graph_ent, func )
__field_packed( unsigned int, graph_ent, depth )
- __dynamic_array(unsigned long, args )
+ __dynamic_field(unsigned long, args )
),

F_printk("--> %ps (%u)", (void *)__entry->func, __entry->depth)
@@ -259,7 +259,7 @@ FTRACE_ENTRY(bprint, bprint_entry,
F_STRUCT(
__field( unsigned long, ip )
__field( const char *, fmt )
- __dynamic_array( u32, buf )
+ __dynamic_field( u32, buf )
),

F_printk("%ps: %s",
@@ -272,7 +272,7 @@ FTRACE_ENTRY_REG(print, print_entry,

F_STRUCT(
__field( unsigned long, ip )
- __dynamic_array( char, buf )
+ __dynamic_field( char, buf )
),

F_printk("%ps: %s",
@@ -287,7 +287,7 @@ FTRACE_ENTRY(raw_data, raw_data_entry,

F_STRUCT(
__field( unsigned int, id )
- __dynamic_array( char, buf )
+ __dynamic_field( char, buf )
),

F_printk("id:%04x %08x",
diff --git a/kernel/trace/trace_export.c b/kernel/trace/trace_export.c
index 1698fc22afa0..d9d41e3ba379 100644
--- a/kernel/trace/trace_export.c
+++ b/kernel/trace/trace_export.c
@@ -57,8 +57,8 @@ static int ftrace_event_register(struct trace_event_call *call,
#undef __array_desc
#define __array_desc(type, container, item, size) type item[size];

-#undef __dynamic_array
-#define __dynamic_array(type, item) type item[];
+#undef __dynamic_field
+#define __dynamic_field(type, item) type item[];

#undef F_STRUCT
#define F_STRUCT(args...) args
@@ -123,8 +123,8 @@ static void __always_unused ____ftrace_check_##name(void) \
#undef __array_desc
#define __array_desc(_type, _container, _item, _len) __array(_type, _item, _len)

-#undef __dynamic_array
-#define __dynamic_array(_type, _item) { \
+#undef __dynamic_field
+#define __dynamic_field(_type, _item) { \
.type = #_type "[]", .name = #_item, \
.size = 0, .align = __alignof__(_type), \
is_signed_type(_type), .filter_type = FILTER_OTHER },
@@ -161,8 +161,8 @@ static struct trace_event_fields ftrace_event_fields_##name[] = { \
#undef __array_desc
#define __array_desc(type, container, item, len)

-#undef __dynamic_array
-#define __dynamic_array(type, item)
+#undef __dynamic_field
+#define __dynamic_field(type, item)

#undef F_printk
#define F_printk(fmt, args...) __stringify(fmt) ", " __stringify(args)
--
2.47.2