All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] tracing/ipv4/ipv6: Use static array for name field in fib*_lookup_table event
@ 2022-07-04 13:14 Steven Rostedt
  2022-07-04 19:09 ` David Ahern
  0 siblings, 1 reply; 4+ messages in thread
From: Steven Rostedt @ 2022-07-04 13:14 UTC (permalink / raw)
  To: LKML; +Cc: David Ahern, David S. Miller, netdev

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

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.

Cc: David Ahern <dsahern@gmail.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: netdev@vger.kernel.org
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
Changes since v1: https://lkml.kernel.org/r/20220703102359.30f12e39@rorschach.local.home
 - Just use a fixed size array instead of calculating the
   size needed for the dynamic allocation.

 include/trace/events/fib.h  | 6 +++---
 include/trace/events/fib6.h | 8 ++++----
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/include/trace/events/fib.h b/include/trace/events/fib.h
index 6f2a4dc35e37..c2300c407f58 100644
--- a/include/trace/events/fib.h
+++ b/include/trace/events/fib.h
@@ -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(
@@ -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) {
@@ -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 */
 
diff --git a/include/trace/events/fib6.h b/include/trace/events/fib6.h
index c6abdcc77c12..6e821eb79450 100644
--- a/include/trace/events/fib6.h
+++ b/include/trace/events/fib6.h
@@ -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	 )
 	),
 
@@ -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 = {};
@@ -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 */
-- 
2.35.1


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

* Re: [PATCH v2] tracing/ipv4/ipv6: Use static array for name field in fib*_lookup_table event
  2022-07-04 13:14 [PATCH v2] tracing/ipv4/ipv6: Use static array for name field in fib*_lookup_table event Steven Rostedt
@ 2022-07-04 19:09 ` David Ahern
  2022-07-05 14:00   ` Steven Rostedt
  0 siblings, 1 reply; 4+ messages in thread
From: David Ahern @ 2022-07-04 19:09 UTC (permalink / raw)
  To: Steven Rostedt, LKML; +Cc: David S. Miller, netdev

On 7/4/22 7:14 AM, Steven Rostedt wrote:
> From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
> 
> 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.
> 
> Cc: David Ahern <dsahern@gmail.com>
> Cc: David S. Miller <davem@davemloft.net>
> Cc: netdev@vger.kernel.org
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> ---
> Changes since v1: https://lkml.kernel.org/r/20220703102359.30f12e39@rorschach.local.home
>  - Just use a fixed size array instead of calculating the
>    size needed for the dynamic allocation.
> 
>  include/trace/events/fib.h  | 6 +++---
>  include/trace/events/fib6.h | 8 ++++----
>  2 files changed, 7 insertions(+), 7 deletions(-)
> 

Reviewed-by: David Ahern <dsahern@kernel.org>



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

* Re: [PATCH v2] tracing/ipv4/ipv6: Use static array for name field in fib*_lookup_table event
  2022-07-04 19:09 ` David Ahern
@ 2022-07-05 14:00   ` Steven Rostedt
  2022-07-05 19:18     ` Jakub Kicinski
  0 siblings, 1 reply; 4+ messages in thread
From: Steven Rostedt @ 2022-07-05 14:00 UTC (permalink / raw)
  To: David Ahern; +Cc: LKML, David S. Miller, netdev

On Mon, 4 Jul 2022 13:09:01 -0600
David Ahern <dsahern@gmail.com> wrote:

> >  include/trace/events/fib.h  | 6 +++---
> >  include/trace/events/fib6.h | 8 ++++----
> >  2 files changed, 7 insertions(+), 7 deletions(-)
> >   
> 
> Reviewed-by: David Ahern <dsahern@kernel.org>
> 

Is everyone OK if I take this through my tree then?

I'm fine if it goes through net-next too.

-- Steve

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

* Re: [PATCH v2] tracing/ipv4/ipv6: Use static array for name field in fib*_lookup_table event
  2022-07-05 14:00   ` Steven Rostedt
@ 2022-07-05 19:18     ` Jakub Kicinski
  0 siblings, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2022-07-05 19:18 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: David Ahern, LKML, David S. Miller, netdev

On Tue, 5 Jul 2022 10:00:41 -0400 Steven Rostedt wrote:
> On Mon, 4 Jul 2022 13:09:01 -0600
> David Ahern <dsahern@gmail.com> wrote:
> 
> > >  include/trace/events/fib.h  | 6 +++---
> > >  include/trace/events/fib6.h | 8 ++++----
> > >  2 files changed, 7 insertions(+), 7 deletions(-)
> > >     
> > 
> > Reviewed-by: David Ahern <dsahern@kernel.org>
> >   
> 
> Is everyone OK if I take this through my tree then?
> 
> I'm fine if it goes through net-next too.

Slight risk of conflicts there if someone decides to add another FIB
trace point, but seems unlikely so feel free to take it:

Acked-by: Jakub Kicinski <kuba@kernel.org>

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

end of thread, other threads:[~2022-07-05 19:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-04 13:14 [PATCH v2] tracing/ipv4/ipv6: Use static array for name field in fib*_lookup_table event Steven Rostedt
2022-07-04 19:09 ` David Ahern
2022-07-05 14:00   ` Steven Rostedt
2022-07-05 19:18     ` Jakub Kicinski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.