Skip to content

Commit

Permalink
tracing/ipv4/ipv6: Use static array for name field in fib*_lookup_tab…
Browse files Browse the repository at this point in the history
…le event

The fib_lookup_table and fib6_lookup_table events declare name as a
dynamic_array, but also give it a fixed size, which defeats the purpose of
the dynamic array, especially since the dynamic array also includes meta
data in the event to specify its size.

Since the size of the name is at most 16 bytes (defined by IFNAMSIZ),
it is not worth spending the effort to determine the size of the string.

Just use a fixed size array and copy into it. This will save 4 bytes that
are used for the meta data that saves the size and position of a dynamic
array, and even slightly speed up the event processing.

Link: https://lkml.kernel.org/r/20220704091436.3705edbf@rorschach.local.home

Cc: David S. Miller <davem@davemloft.net>
Cc: netdev@vger.kernel.org
Acked-by: Jakub Kicinski <kuba@kernel.org>
Reviewed-by: David Ahern <dsahern@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
  • Loading branch information
Steven Rostedt (Google) committed Jul 15, 2022
1 parent 2a04b8d commit fca8300
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions include/trace/events/fib.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ TRACE_EVENT(fib_table_lookup,
__array( __u8, gw6, 16 )
__field( u16, sport )
__field( u16, dport )
__dynamic_array(char, name, IFNAMSIZ )
__array(char, name, IFNAMSIZ )
),

TP_fast_assign(
Expand Down Expand Up @@ -66,7 +66,7 @@ TRACE_EVENT(fib_table_lookup,
}

dev = nhc ? nhc->nhc_dev : NULL;
__assign_str(name, dev ? dev->name : "-");
strlcpy(__entry->name, dev ? dev->name : "-", IFNAMSIZ);

if (nhc) {
if (nhc->nhc_gw_family == AF_INET) {
Expand Down Expand Up @@ -95,7 +95,7 @@ TRACE_EVENT(fib_table_lookup,
__entry->tb_id, __entry->oif, __entry->iif, __entry->proto,
__entry->src, __entry->sport, __entry->dst, __entry->dport,
__entry->tos, __entry->scope, __entry->flags,
__get_str(name), __entry->gw4, __entry->gw6, __entry->err)
__entry->name, __entry->gw4, __entry->gw6, __entry->err)
);
#endif /* _TRACE_FIB_H */

Expand Down
8 changes: 4 additions & 4 deletions include/trace/events/fib6.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ TRACE_EVENT(fib6_table_lookup,
__field( u16, dport )
__field( u8, proto )
__field( u8, rt_type )
__dynamic_array( char, name, IFNAMSIZ )
__array( char, name, IFNAMSIZ )
__array( __u8, gw, 16 )
),

Expand Down Expand Up @@ -63,9 +63,9 @@ TRACE_EVENT(fib6_table_lookup,
}

if (res->nh && res->nh->fib_nh_dev) {
__assign_str(name, res->nh->fib_nh_dev);
strlcpy(__entry->name, res->nh->fib_nh_dev->name, IFNAMSIZ);
} else {
__assign_str(name, "-");
strcpy(__entry->name, "-");
}
if (res->f6i == net->ipv6.fib6_null_entry) {
struct in6_addr in6_zero = {};
Expand All @@ -83,7 +83,7 @@ TRACE_EVENT(fib6_table_lookup,
__entry->tb_id, __entry->oif, __entry->iif, __entry->proto,
__entry->src, __entry->sport, __entry->dst, __entry->dport,
__entry->tos, __entry->scope, __entry->flags,
__get_str(name), __entry->gw, __entry->err)
__entry->name, __entry->gw, __entry->err)
);

#endif /* _TRACE_FIB6_H */
Expand Down

0 comments on commit fca8300

Please sign in to comment.