trace: tcp: Add tracepoint for tcp_cwnd_reduction()
authorBreno Leitao <leitao@debian.org>
Fri, 14 Feb 2025 17:07:11 +0000 (09:07 -0800)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 18 Feb 2025 14:29:53 +0000 (15:29 +0100)
Add a lightweight tracepoint to monitor TCP congestion window
adjustments via tcp_cwnd_reduction(). This tracepoint enables tracking
of:
- TCP window size fluctuations
- Active socket behavior
- Congestion window reduction events

Meta has been using BPF programs to monitor this function for years.
Adding a proper tracepoint provides a stable API for all users who need
to monitor TCP congestion window behavior.

Use DECLARE_TRACE instead of TRACE_EVENT to avoid creating trace event
infrastructure and exporting to tracefs, keeping the implementation
minimal. (Thanks Steven Rostedt)

Given that this patch creates a rawtracepoint, you could hook into it
using regular tooling, like bpftrace, using regular rawtracepoint
infrastructure, such as:

rawtracepoint:tcp_cwnd_reduction_tp {
....
}

Signed-off-by: Breno Leitao <leitao@debian.org>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20250214-cwnd_tracepoint-v2-1-ef8d15162d95@debian.org
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
include/trace/events/tcp.h
net/ipv4/tcp_input.c

index a27c4b619dffd7dcc72fffa71bf0fd5e34fe6681..1a40c41ff8c30a31b5c7002a4109de1cd8ef389e 100644 (file)
@@ -259,6 +259,12 @@ TRACE_EVENT(tcp_retransmit_synack,
                  __entry->saddr_v6, __entry->daddr_v6)
 );
 
+DECLARE_TRACE(tcp_cwnd_reduction_tp,
+       TP_PROTO(const struct sock *sk, int newly_acked_sacked,
+                int newly_lost, int flag),
+       TP_ARGS(sk, newly_acked_sacked, newly_lost, flag)
+);
+
 #include <trace/events/net_probe_common.h>
 
 TRACE_EVENT(tcp_probe,
index 074406890552a7e253ddf65f7cd9eaa2cdb16266..fbb67a098543beafff66fddcd9e05760d80906d9 100644 (file)
@@ -2709,6 +2709,8 @@ void tcp_cwnd_reduction(struct sock *sk, int newly_acked_sacked, int newly_lost,
        if (newly_acked_sacked <= 0 || WARN_ON_ONCE(!tp->prior_cwnd))
                return;
 
+       trace_tcp_cwnd_reduction_tp(sk, newly_acked_sacked, newly_lost, flag);
+
        tp->prr_delivered += newly_acked_sacked;
        if (delta < 0) {
                u64 dividend = (u64)tp->snd_ssthresh * tp->prr_delivered +