On Wed, Feb 26, 2025 at 11:31:49AM -0700, David Ahern wrote:
> On 2/26/25 11:27 AM, Eric Dumazet wrote:
>
> ie., moving the tracepoint to tcp_sendmsg_locked should solve the inline
> problem. From there, the question is inside the loop or at entry to the
> function. Inside the loop has been very helpful for me.

I am happy to get it inside the loop. I am planning to send the
following patch when the MW opens. How does it sound?


    trace: tcp: Add tracepoint for tcp_sendmsg_locked()
    
    Add a tracepoint to monitor TCP sendmsg operations, enabling the tracing
    of TCP messages being sent.
    
    Meta has been using BPF programs to monitor tcp_sendmsg() for years,
    indicating significant interest in observing this important
    functionality. Adding a proper tracepoint provides a stable API for all
    users who need visibility into TCP message transmission.
    
    David Ahern is using a similar functionality with a custom patch[1]. So,
    this means we have more than a single use case for this request.
    
    The implementation adopts David's approach[1] for greater flexibility
    compared to the initial proposal.
    
    Link: 
https://lore.kernel.org/all/[email protected]/ [1]
    Signed-off-by: Breno Leitao <[email protected]>

diff --git a/include/trace/events/tcp.h b/include/trace/events/tcp.h
index 1a40c41ff8c30..cd90a8c66d683 100644
--- a/include/trace/events/tcp.h
+++ b/include/trace/events/tcp.h
@@ -259,6 +259,29 @@ TRACE_EVENT(tcp_retransmit_synack,
                  __entry->saddr_v6, __entry->daddr_v6)
 );
 
+TRACE_EVENT(tcp_sendmsg_locked,
+       TP_PROTO(struct msghdr *msg, struct sk_buff *skb, int size_goal),
+
+       TP_ARGS(msg, skb, size_goal),
+
+       TP_STRUCT__entry(
+               __field(__u64, skb)
+               __field(int, skb_len)
+               __field(int, msg_left)
+               __field(int, size_goal)
+       ),
+
+       TP_fast_assign(
+               __entry->skb = (__u64)skb;
+               __entry->skb_len = skb ? skb->len : 0;
+               __entry->msg_left = msg_data_left(msg);
+               __entry->size_goal = size_goal;
+       ),
+
+       TP_printk("skb %llx skb_len %d msg_left %d size_goal %d", __entry->skb,
+               __entry->skb_len, __entry->msg_left, __entry->size_goal)
+);
+
 DECLARE_TRACE(tcp_cwnd_reduction_tp,
        TP_PROTO(const struct sock *sk, int newly_acked_sacked,
                 int newly_lost, int flag),
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index ea8de00f669d0..822cd40ce2b7f 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -1160,6 +1160,8 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr 
*msg, size_t size)
                if (skb)
                        copy = size_goal - skb->len;
 
+               trace_tcp_sendmsg_locked(msg, skb, size_goal);
+
                if (copy <= 0 || !tcp_skb_can_collapse_to(skb)) {
                        bool first_skb;
 

Reply via email to