Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp1728505rdg; Sat, 12 Aug 2023 13:49:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEnvPYB669lgLv9icQXgz0wXiHZZRIeAvLeGCBtXvMpqyz08fIPc6unU1SflhTXk34O0h4n X-Received: by 2002:a17:90a:d489:b0:269:21ad:bdec with SMTP id s9-20020a17090ad48900b0026921adbdecmr3619270pju.28.1691873388012; Sat, 12 Aug 2023 13:49:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691873387; cv=none; d=google.com; s=arc-20160816; b=zkW6r5o6nm99DUQi41lu5K2GeAjtCRGOjjPgQkk12OIHqaR9lvqtGDWGG0PdMV1VUI UxcgNJz0rv5pH4MkIapbKVSy7X4/DrM0kxUaK/bn+3npoEr8Z1dC9zksxHSSJkFyo6FJ zTf6O6HKvJ3EWuGn9dogiHZbiYj+VM3Dk7Ph4aVe9/MzNeIi1x3nB5yIBcPfDih8HYig h3ZAx1gIxJGs/GwSvo56mwT9naUbtqL4I9rc0AaY/ugT54fYiGu2nMf70aO0frmscQQ4 ZyR3TDmZj3mHEw4Bo5FVJ7Z9EAvHN2CqegAPBmG65cr0NUtzxfjOu8D3tqUdpvcBHuov IFLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=RQ3Xqsivr0DrTB+AWrtlmTNgnQOpoq3hiqDAxny7d0o=; fh=FSLVOsztWcfWW0V82hOz/+jJh8Al9AvzzOAHHQfCnro=; b=NQEKNlfRKZG6ra/V+rlfIbzVj8t5cOZ1AL0P4zP7XRje4bN4SIR4T1veVD/38WyVL9 uDnJNcteO+r8HaNa6Gkz6jlN43ddHkTj1i/mYOV4WRxmWsgmbRj366SE98jwQU7SG8e+ mezrnNAZqZZnCG17vTp07xVhNH2C0yzZxha6AjwC0E5m22Cu7pJu3lp4GkkNZP+2YV+z WIXVABXDhusxoFy5P7FgKYp2QoiI4x7Qy/yCx4YCv8RRLX9niqlGyrgoLeU+lCARYauD GcGICyIckrTf55zg0X1Vd5hAlA2zCOptc/b8PohesCw6JHNVimK8sO8Reho/rzPhF6CA 6Tmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@manjusaka.me header.s=fm3 header.b=RTHNhuh1; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=tmsmmC0V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t11-20020a17090b018b00b002694ae34910si5397106pjs.66.2023.08.12.13.49.36; Sat, 12 Aug 2023 13:49:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@manjusaka.me header.s=fm3 header.b=RTHNhuh1; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=tmsmmC0V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231267AbjHLUOD (ORCPT + 99 others); Sat, 12 Aug 2023 16:14:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230022AbjHLUOC (ORCPT ); Sat, 12 Aug 2023 16:14:02 -0400 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB221CE; Sat, 12 Aug 2023 13:14:04 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 64F7A5C0041; Sat, 12 Aug 2023 16:14:02 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Sat, 12 Aug 2023 16:14:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=manjusaka.me; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1691871242; x= 1691957642; bh=RQ3Xqsivr0DrTB+AWrtlmTNgnQOpoq3hiqDAxny7d0o=; b=R THNhuh1kIV8+POkhFtCI4iJOQMFdUX6nGtRLtIjMSvIQheH0zF4QMmoUqKp4wcj/ cMCH2y+kC0FYUtRHTTVh2U6bPCg2+9/Y9f2HP0j97HJc/2vWTj/gcJbH9VxC8l68 /UAc00/vcxtGpuftxbkslWCQWR3Ltvu3XJtDCjHLO9yRF87AVONpOKe+cmefhyPj Br47rnniC6Xu1CN9/yf7pE7RHEuZVam0Lb+nQd48l+kZA81oEtPqshFYvSq0aUM0 //iUzNQPsY8FNw8QD/9RDfXGkbfKj1TmmDv7hiIc2+QPOHBbPknY+miw1UM9e9CG ukOqDi+CGe+N6dbs0KuEA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1691871242; x= 1691957642; bh=RQ3Xqsivr0DrTB+AWrtlmTNgnQOpoq3hiqDAxny7d0o=; b=t msmmC0VY69aVEAFdiu8aksT6K6p7IVW6slX+R1F/AeEHbCVIsXimUSwemwwsohJe +7N9H7riGLWhK8cey+Riuk+XOH2pgnpQHCOGRRV39Iy2pIwN6/962G290JQ0H8qu xBWSZ/A5MOSmvZOC3yGRTME55UThC2wi2nmLKZGNgYLM6OhXYaB8/g0BYQrTdJMF +1G/uNxo+946CnwRGMCjDJ53QztNOfF9qpNyIpFzXYx6pyS/I2OIWExgDHXWNq1X 7o6h5FiQnCltYRdTdqrTXIRzcAXSYzoyxtNuBH3TiCquMD+xVLjeuHraHWqigfmU FhlkUqQ2Iu9Stp0K1I8GQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedruddttddgudeggecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhephffvvefufffkofgjfhgggfestd ekredtredttdenucfhrhhomhepkghhvggrohcunfhiuceomhgvsehmrghnjhhushgrkhgr rdhmvgeqnecuggftrfgrthhtvghrnhepfeduueffhefgleeguedtgffgffegleejueevge ffveekfeeileduledujeevleeunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghm pehmrghilhhfrhhomhepmhgvsehmrghnjhhushgrkhgrrdhmvg X-ME-Proxy: Feedback-ID: i3ea9498d:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 12 Aug 2023 16:13:56 -0400 (EDT) From: Zheao Li 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 Message-Id: <20230812201249.62237-1-me@manjusaka.me> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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