From: Zheao Li <me@manjusaka.me>
To: edumazet@google.com
Cc: bpf@vger.kernel.org, davem@davemloft.net, dsahern@kernel.org,
kuba@kernel.org, linux-kernel@vger.kernel.org,
linux-trace-kernel@vger.kernel.org, me@manjusaka.me,
mhiramat@kernel.org, ncardwell@google.com,
netdev@vger.kernel.org, pabeni@redhat.com, rostedt@goodmis.org
Subject: [PATCH v3] tracepoint: add new `tcp:tcp_ca_event` trace event
Date: Sat, 12 Aug 2023 20:12:50 +0000 [thread overview]
Message-ID: <20230812201249.62237-1-me@manjusaka.me> (raw)
In-Reply-To: <CANn89iKQXhqgOTkSchH6Bz-xH--pAoSyEORBtawqBTvgG+dFig@mail.gmail.com>
In normal use case, the tcp_ca_event would be changed in high frequency.
The developer can monitor the network quality more easier by tracing
TCP stack with this TP event.
So I propose to add a `tcp:tcp_ca_event` trace event
like `tcp:tcp_cong_state_set` to help the people to
trace the TCP connection status
Signed-off-by: Zheao Li <me@manjusaka.me>
---
include/net/tcp.h | 9 ++----
include/trace/events/tcp.h | 60 ++++++++++++++++++++++++++++++++++++++
net/ipv4/tcp_cong.c | 10 +++++++
3 files changed, 72 insertions(+), 7 deletions(-)
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 0ca972ebd3dd..a68c5b61889c 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -1154,13 +1154,8 @@ static inline bool tcp_ca_needs_ecn(const struct sock *sk)
return icsk->icsk_ca_ops->flags & TCP_CONG_NEEDS_ECN;
}
-static inline void tcp_ca_event(struct sock *sk, const enum tcp_ca_event event)
-{
- const struct inet_connection_sock *icsk = inet_csk(sk);
-
- if (icsk->icsk_ca_ops->cwnd_event)
- icsk->icsk_ca_ops->cwnd_event(sk, event);
-}
+/* from tcp_cong.c */
+void tcp_ca_event(struct sock *sk, const enum tcp_ca_event event);
/* From tcp_cong.c */
void tcp_set_ca_state(struct sock *sk, const u8 ca_state);
diff --git a/include/trace/events/tcp.h b/include/trace/events/tcp.h
index 7b1ddffa3dfc..993eb00403ea 100644
--- a/include/trace/events/tcp.h
+++ b/include/trace/events/tcp.h
@@ -41,6 +41,18 @@
TP_STORE_V4MAPPED(__entry, saddr, daddr)
#endif
+/* The TCP CA event traced by tcp_ca_event*/
+#define tcp_ca_event_names \
+ EM(CA_EVENT_TX_START) \
+ EM(CA_EVENT_CWND_RESTART) \
+ EM(CA_EVENT_COMPLETE_CWR) \
+ EM(CA_EVENT_LOSS) \
+ EM(CA_EVENT_ECN_NO_CE) \
+ EMe(CA_EVENT_ECN_IS_CE)
+
+#define show_tcp_ca_event_names(val) \
+ __print_symbolic(val, tcp_ca_event_names)
+
/*
* tcp event with arguments sk and skb
*
@@ -419,6 +431,54 @@ TRACE_EVENT(tcp_cong_state_set,
__entry->cong_state)
);
+TRACE_EVENT(tcp_ca_event,
+
+ TP_PROTO(struct sock *sk, const u8 ca_event),
+
+ TP_ARGS(sk, ca_event),
+
+ TP_STRUCT__entry(
+ __field(const void *, skaddr)
+ __field(__u16, sport)
+ __field(__u16, dport)
+ __field(__u16, family)
+ __array(__u8, saddr, 4)
+ __array(__u8, daddr, 4)
+ __array(__u8, saddr_v6, 16)
+ __array(__u8, daddr_v6, 16)
+ __field(__u8, ca_event)
+ ),
+
+ TP_fast_assign(
+ struct inet_sock *inet = inet_sk(sk);
+ __be32 *p32;
+
+ __entry->skaddr = sk;
+
+ __entry->sport = ntohs(inet->inet_sport);
+ __entry->dport = ntohs(inet->inet_dport);
+ __entry->family = sk->sk_family;
+
+ p32 = (__be32 *) __entry->saddr;
+ *p32 = inet->inet_saddr;
+
+ p32 = (__be32 *) __entry->daddr;
+ *p32 = inet->inet_daddr;
+
+ TP_STORE_ADDRS(__entry, inet->inet_saddr, inet->inet_daddr,
+ sk->sk_v6_rcv_saddr, sk->sk_v6_daddr);
+
+ __entry->ca_event = ca_event;
+ ),
+
+ TP_printk("family=%s sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c ca_event=%s",
+ show_family_name(__entry->family),
+ __entry->sport, __entry->dport,
+ __entry->saddr, __entry->daddr,
+ __entry->saddr_v6, __entry->daddr_v6,
+ show_tcp_ca_event_names(__entry->ca_event))
+);
+
#endif /* _TRACE_TCP_H */
/* This part must be outside protection */
diff --git a/net/ipv4/tcp_cong.c b/net/ipv4/tcp_cong.c
index 1b34050a7538..fb7ec6ebbbd0 100644
--- a/net/ipv4/tcp_cong.c
+++ b/net/ipv4/tcp_cong.c
@@ -34,6 +34,16 @@ struct tcp_congestion_ops *tcp_ca_find(const char *name)
return NULL;
}
+void tcp_ca_event(struct sock *sk, const enum tcp_ca_event event)
+{
+ const struct inet_connection_sock *icsk = inet_csk(sk);
+
+ trace_tcp_ca_event(sk, (u8)event);
+
+ if (icsk->icsk_ca_ops->cwnd_event)
+ icsk->icsk_ca_ops->cwnd_event(sk, event);
+}
+
void tcp_set_ca_state(struct sock *sk, const u8 ca_state)
{
struct inet_connection_sock *icsk = inet_csk(sk);
--
2.34.1
next prev parent reply other threads:[~2023-08-12 20:14 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-07 18:33 [PATCH] tracepoint: add new `tcp:tcp_ca_event_set` trace event Manjusaka
2023-08-07 20:00 ` Neal Cardwell
2023-08-08 4:29 ` Manjusaka
2023-08-08 4:50 ` Manjusaka
2023-08-08 5:58 ` [PATCH v2] tracepoint: add new `tcp:tcp_ca_event` " Manjusaka
2023-08-08 8:26 ` Eric Dumazet
2023-08-08 8:46 ` Manjusaka
2023-08-08 8:48 ` Eric Dumazet
2023-08-12 20:12 ` Zheao Li [this message]
2023-08-12 20:17 ` [PATCH v3] " Manjusaka
2023-08-12 23:00 ` Steven Rostedt
2023-08-13 0:59 ` Steven Rostedt
2023-08-13 1:01 ` Steven Rostedt
2023-08-13 1:04 ` Steven Rostedt
2023-08-13 1:17 ` Joe Perches
2023-08-13 1:53 ` Steven Rostedt
2023-08-13 2:08 ` Joe Perches
2023-08-16 6:09 ` Manjusaka
2023-08-16 15:02 ` Steven Rostedt
2023-08-16 16:58 ` Manjusaka
2023-08-19 1:51 ` Jakub Kicinski
2023-08-19 3:10 ` Eric Dumazet
2023-08-19 8:15 ` Manjusaka
2023-08-08 20:21 ` [PATCH v2] " Jakub Kicinski
2023-08-09 16:55 ` Manjusaka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230812201249.62237-1-me@manjusaka.me \
--to=me@manjusaka.me \
--cc=bpf@vger.kernel.org \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).