Thread (6 messages) 6 messages, 3 authors, 2023-01-11

Re: [PATCH v5] sock: add tracepoint for send recv length

From: Steven Rostedt <rostedt@goodmis.org>
Date: 2023-01-10 15:44:44
Also in: lkml, netdev

On Tue, 10 Jan 2023 12:49:30 +0100
Eric Dumazet [off-list ref] wrote:
quoted
+static noinline void call_trace_sock_recv_length(struct sock *sk, int ret, int flags)
+{
+       trace_sock_recv_length(sk, !(flags & MSG_PEEK) ? ret :
+                              (ret < 0 ? ret : 0), flags);  
Maybe we should only 'fast assign' the two fields (ret and flags),
and let this logic happen later at 'print' time ?

This would reduce storage by one integer, and make fast path really fast.

This also could potentially remove the need for the peculiar construct with
these noinline helpers.
I noticed that the trace_sock_send_length() doesn't have this logic, and
they are both DEFINE_EVENT() of the same DECLARE_EVENT_CLASS(). But we
could change this too, by the following:

/*
 * sock send/recv msg length
 */
DECLARE_EVENT_CLASS(sock_msg_length,

	TP_PROTO(struct sock *sk, int ret, int flags),

	TP_ARGS(sk, ret, flags),

	TP_STRUCT__entry(
		__field(void *, sk)
		__field(__u16, family)
		__field(__u16, protocol)
		__field(int, ret)
		__field(int, flags)
	),

	TP_fast_assign(
		__entry->sk = sk;
		__entry->family = sk->sk_family;
		__entry->protocol = sk->sk_protocol;
		__entry->length = ret > 0 ? ret : 0;
		__entry->error = ret < 0 ? ret : 0;
		__entry->flags = flags;
	),

	TP_printk("sk address = %p, family = %s protocol = %s, length = %d, error = %d, flags = 0x%x",
		  __entry->sk, show_family_name(__entry->family),
		  show_inet_protocol_name(__entry->protocol),
		  __entry->ret > 0 ? ret : 0, __entry->ret < 0 ? ret : 0,
		  __entry->flags)
);

DEFINE_EVENT(sock_msg_length, sock_send_length,
	TP_PROTO(struct sock *sk, int ret, int flags),

	TP_ARGS(sk, ret, flags)
);

DEFINE_EVENT_PRINT(sock_msg_length, sock_recv_length,
	TP_PROTO(struct sock *sk, int ret, int flags),

	TP_ARGS(sk, ret, flags)

	TP_printk("sk address = %p, family = %s protocol = %s, length = %d, error = %d, flags = 0x%x",
		  __entry->sk, show_family_name(__entry->family),
		  show_inet_protocol_name(__entry->protocol),
		  !(__entry->flags & MSG_PEEK) ? __entry->ret : __entry->ret > 0 ? ret : 0,
		  __entry->ret < 0 ? ret : 0,
		  __entry->flags)
);
#endif /* _TRACE_SOCK_H */

As DEFINE_EVENT_PRINT() uses the class template, but overrides the
TP_printk() portion (still saving memory).

And then both calls can just do:

	trace_sock_send_length(sk, ret, 0);

	trace_sock_recv_length(sock->sk, ret, flags);

And I bet that will also solve all the gcc being smart waste.

-- Steve
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help