tcp: Add skb addr and sock addr to arguments of tracepoint tcp_probe.

Message ID 20240229052813.GA23899@didi-ThinkCentre-M920t-N000
State New
Headers
Series tcp: Add skb addr and sock addr to arguments of tracepoint tcp_probe. |

Commit Message

fuyuanli Feb. 29, 2024, 5:28 a.m. UTC
  It is useful to expose skb addr and sock addr to user in tracepoint
tcp_probe, so that we can get more information while monitoring
receiving of tcp data, by ebpf or other ways.

For example, we need to identify a packet by seq and end_seq when
calculate transmit latency between lay 2 and lay 4 by ebpf, but which is
not available in tcp_probe, so we can only use kprobe hooking
tcp_rcv_esatblised to get them. But we can use tcp_probe directly if skb
addr and sock addr are available, which is more efficient.

Signed-off-by: fuyuanli <fuyuanli@didiglobal.com>
---
 include/trace/events/tcp.h | 5 +++++
 1 file changed, 5 insertions(+)
  

Comments

Jason Xing Feb. 29, 2024, 7:29 a.m. UTC | #1
On Thu, Feb 29, 2024 at 1:33 PM fuyuanli <fuyuanli@didiglobal.com> wrote:
>
> It is useful to expose skb addr and sock addr to user in tracepoint
> tcp_probe, so that we can get more information while monitoring
> receiving of tcp data, by ebpf or other ways.
>
> For example, we need to identify a packet by seq and end_seq when
> calculate transmit latency between lay 2 and lay 4 by ebpf, but which is
> not available in tcp_probe, so we can only use kprobe hooking
> tcp_rcv_esatblised to get them. But we can use tcp_probe directly if skb
> addr and sock addr are available, which is more efficient.
>
> Signed-off-by: fuyuanli <fuyuanli@didiglobal.com>

Please target 'net-next' in the title of your v2 patch.

> ---
>  include/trace/events/tcp.h | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/include/trace/events/tcp.h b/include/trace/events/tcp.h
> index 7b1ddffa3dfc..096c15f64b92 100644
> --- a/include/trace/events/tcp.h
> +++ b/include/trace/events/tcp.h
> @@ -258,6 +258,8 @@ TRACE_EVENT(tcp_probe,
>                 __field(__u32, srtt)
>                 __field(__u32, rcv_wnd)
>                 __field(__u64, sock_cookie)
> +               __field(const void *, skbaddr)
> +               __field(const void *, skaddr)
>         ),
>
>         TP_fast_assign(
> @@ -285,6 +287,9 @@ TRACE_EVENT(tcp_probe,
>                 __entry->ssthresh = tcp_current_ssthresh(sk);
>                 __entry->srtt = tp->srtt_us >> 3;
>                 __entry->sock_cookie = sock_gen_cookie(sk);
> +
> +               __entry->skbaddr = skb;
> +               __entry->skaddr = sk;
>         ),
>
>         TP_printk("family=%s src=%pISpc dest=%pISpc mark=%#x data_len=%d snd_nxt=%#x snd_una=%#x snd_cwnd=%u ssthresh=%u snd_wnd=%u srtt=%u rcv_wnd=%u sock_cookie=%llx",

If they are useful, at least you should printk those two addresses
like what trace_kfree_skb() does.

May I ask how it could be useful if there is no more function printing
such information in the receive path?

Thanks,
Jason
> --
> 2.17.1
>
>
  
yuanli fu Feb. 29, 2024, 10:02 a.m. UTC | #2
---------- Forwarded message ---------
发件人: yuanli fu <fuyuanli0722@gmail.com>
Date: 2024年2月29日周四 16:27
Subject: Re: [PATCH] tcp: Add skb addr and sock addr to arguments of
tracepoint tcp_probe.
To: Jason Xing <kerneljasonxing@gmail.com>


Jason Xing <kerneljasonxing@gmail.com> 于2024年2月29日周四 15:30写道:
>
> On Thu, Feb 29, 2024 at 1:33 PM fuyuanli <fuyuanli@didiglobal.com> wrote:
> >
> > It is useful to expose skb addr and sock addr to user in tracepoint
> > tcp_probe, so that we can get more information while monitoring
> > receiving of tcp data, by ebpf or other ways.
> >
> > For example, we need to identify a packet by seq and end_seq when
> > calculate transmit latency between lay 2 and lay 4 by ebpf, but which is
> > not available in tcp_probe, so we can only use kprobe hooking
> > tcp_rcv_esatblised to get them. But we can use tcp_probe directly if skb
> > addr and sock addr are available, which is more efficient.
> >
> > Signed-off-by: fuyuanli <fuyuanli@didiglobal.com>
>
> Please target 'net-next' in the title of your v2 patch.
Got it, thanks.
>
> > ---
> >  include/trace/events/tcp.h | 5 +++++
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/include/trace/events/tcp.h b/include/trace/events/tcp.h
> > index 7b1ddffa3dfc..096c15f64b92 100644
> > --- a/include/trace/events/tcp.h
> > +++ b/include/trace/events/tcp.h
> > @@ -258,6 +258,8 @@ TRACE_EVENT(tcp_probe,
> >                 __field(__u32, srtt)
> >                 __field(__u32, rcv_wnd)
> >                 __field(__u64, sock_cookie)
> > +               __field(const void *, skbaddr)
> > +               __field(const void *, skaddr)
> >         ),
> >
> >         TP_fast_assign(
> > @@ -285,6 +287,9 @@ TRACE_EVENT(tcp_probe,
> >                 __entry->ssthresh = tcp_current_ssthresh(sk);
> >                 __entry->srtt = tp->srtt_us >> 3;
> >                 __entry->sock_cookie = sock_gen_cookie(sk);
> > +
> > +               __entry->skbaddr = skb;
> > +               __entry->skaddr = sk;
> >         ),
> >
> >         TP_printk("family=%s src=%pISpc dest=%pISpc mark=%#x data_len=%d snd_nxt=%#x snd_una=%#x snd_cwnd=%u ssthresh=%u snd_wnd=%u srtt=%u rcv_wnd=%u sock_cookie=%llx",
>
> If they are useful, at least you should printk those two addresses
> like what trace_kfree_skb() does.
>
Got it, I will add to printk
> May I ask how it could be useful if there is no more function printing
> such information in the receive path?
We can get seq and end_seq by skbaddr in netif_receive_skb, so latency
between l2->l4 can be calculated.
>
> Thanks,
> Jason
> > --
> > 2.17.1
> >
> >
>
thanks
fuyuanli
  

Patch

diff --git a/include/trace/events/tcp.h b/include/trace/events/tcp.h
index 7b1ddffa3dfc..096c15f64b92 100644
--- a/include/trace/events/tcp.h
+++ b/include/trace/events/tcp.h
@@ -258,6 +258,8 @@  TRACE_EVENT(tcp_probe,
 		__field(__u32, srtt)
 		__field(__u32, rcv_wnd)
 		__field(__u64, sock_cookie)
+		__field(const void *, skbaddr)
+		__field(const void *, skaddr)
 	),
 
 	TP_fast_assign(
@@ -285,6 +287,9 @@  TRACE_EVENT(tcp_probe,
 		__entry->ssthresh = tcp_current_ssthresh(sk);
 		__entry->srtt = tp->srtt_us >> 3;
 		__entry->sock_cookie = sock_gen_cookie(sk);
+
+		__entry->skbaddr = skb;
+		__entry->skaddr = sk;
 	),
 
 	TP_printk("family=%s src=%pISpc dest=%pISpc mark=%#x data_len=%d snd_nxt=%#x snd_una=%#x snd_cwnd=%u ssthresh=%u snd_wnd=%u srtt=%u rcv_wnd=%u sock_cookie=%llx",