From patchwork Wed Mar 30 13:01:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: jackygam2001 X-Patchwork-Id: 12795800 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 732DFC433F5 for ; Wed, 30 Mar 2022 13:04:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345659AbiC3NGE (ORCPT ); Wed, 30 Mar 2022 09:06:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244903AbiC3NGC (ORCPT ); Wed, 30 Mar 2022 09:06:02 -0400 Received: from m12-12.163.com (m12-12.163.com [220.181.12.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 51619C38; Wed, 30 Mar 2022 06:04:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=cHMQ7 WoXLVIhypyQ8WPqd9becVvlyEmkctQb5Tr1eQI=; b=O4IaNn5MPK/T1jNqaCPNM eaVN9jS9V+B2IAhGgbis5fIRI25CB4e/JpPhqGURryeaDRdsOnCXxR059vFzbjxp Y21Np5mdm/Cbx/ns4aUCTpLkYpvBup8ZrkhfDh9u9P7axmJlHSSQwBwK2iyJrNP0 q19KKrvur7N2YRjnhm6GiM= Received: from localhost.localdomain (unknown [101.86.110.112]) by smtp8 (Coremail) with SMTP id DMCowAAH01QUVURi01bAAA--.22186S2; Wed, 30 Mar 2022 21:03:17 +0800 (CST) From: jackygam2001 To: edumazet@google.com, davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, rostedt@goodmis.org, mingo@redhat.com, yoshfuji@linux-ipv6.org, dsahern@kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, ping.gan@dell.com, jackygam2001 Subject: [PATCH] tcp: Add tracepoint for tcp_set_ca_state Date: Wed, 30 Mar 2022 21:01:28 +0800 Message-Id: <20220330130128.10256-1-jacky_gam_2001@163.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-CM-TRANSID: DMCowAAH01QUVURi01bAAA--.22186S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxAw4UXFWDCr47Zw13Xw1fWFg_yoWrAr15pF 1DAr1Sg3y5Jryagas3Jry8twnxW348ur1agry7Ww1ak3ZFqF1rtF1ktryjyayYvrWFy39x Wa129r1rGa17Zr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pE380ZUUUUU= X-Originating-IP: [101.86.110.112] X-CM-SenderInfo: 5mdfy55bjdzsisqqiqqrwthudrp/xS2BdBXTKVgi1YcKDwAAs2 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The congestion status of a tcp flow may be updated since there is congestion between tcp sender and receiver. It makes sense for adding tracepoint for congestion status update function to evaluate the performance of network and congestion algorithm. Link: https://github.com/iovisor/bcc/pull/3899 Signed-off-by: jackygam2001 --- include/net/tcp.h | 12 +++--------- include/trace/events/tcp.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ net/ipv4/tcp_cong.c | 12 ++++++++++++ 3 files changed, 60 insertions(+), 9 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index 70ca4a5e330a..9a3786f33798 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -1139,15 +1139,6 @@ 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_set_ca_state(struct sock *sk, const u8 ca_state) -{ - struct inet_connection_sock *icsk = inet_csk(sk); - - if (icsk->icsk_ca_ops->set_state) - icsk->icsk_ca_ops->set_state(sk, ca_state); - icsk->icsk_ca_state = ca_state; -} - static inline void tcp_ca_event(struct sock *sk, const enum tcp_ca_event event) { const struct inet_connection_sock *icsk = inet_csk(sk); @@ -1156,6 +1147,9 @@ static inline void tcp_ca_event(struct sock *sk, const enum tcp_ca_event event) icsk->icsk_ca_ops->cwnd_event(sk, event); } +/* From tcp_cong.c */ +void tcp_set_ca_state(struct sock *sk, const u8 ca_state); + /* From tcp_rate.c */ void tcp_rate_skb_sent(struct sock *sk, struct sk_buff *skb); void tcp_rate_skb_delivered(struct sock *sk, struct sk_buff *skb, diff --git a/include/trace/events/tcp.h b/include/trace/events/tcp.h index 521059d8dc0a..69a68b01c1de 100644 --- a/include/trace/events/tcp.h +++ b/include/trace/events/tcp.h @@ -371,6 +371,51 @@ DEFINE_EVENT(tcp_event_skb, tcp_bad_csum, TP_ARGS(skb) ); +TRACE_EVENT(tcp_cong_state_set, + + TP_PROTO(struct sock *sk, const u8 ca_state), + + TP_ARGS(sk, ca_state), + + TP_STRUCT__entry( + __field(const void *, skaddr) + __field(__u16, sport) + __field(__u16, dport) + __array(__u8, saddr, 4) + __array(__u8, daddr, 4) + __array(__u8, saddr_v6, 16) + __array(__u8, daddr_v6, 16) + __field(__u8, cong_state) + ), + + 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); + + 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->cong_state = ca_state; + ), + + TP_printk("sport=%hu dport=%hu saddr=%pI4 daddr=%pI4 saddrv6=%pI6c daddrv6=%pI6c cong_state=%u", + __entry->sport, __entry->dport, + __entry->saddr, __entry->daddr, + __entry->saddr_v6, __entry->daddr_v6, + __entry->cong_state) +); + #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 dc95572163df..98b48bdb8be7 100644 --- a/net/ipv4/tcp_cong.c +++ b/net/ipv4/tcp_cong.c @@ -16,6 +16,7 @@ #include #include #include +#include static DEFINE_SPINLOCK(tcp_cong_list_lock); static LIST_HEAD(tcp_cong_list); @@ -33,6 +34,17 @@ struct tcp_congestion_ops *tcp_ca_find(const char *name) return NULL; } +void tcp_set_ca_state(struct sock *sk, const u8 ca_state) +{ + struct inet_connection_sock *icsk = inet_csk(sk); + + trace_tcp_cong_state_set(sk, ca_state); + + if (icsk->icsk_ca_ops->set_state) + icsk->icsk_ca_ops->set_state(sk, ca_state); + icsk->icsk_ca_state = ca_state; +} + /* Must be called with rcu lock held */ static struct tcp_congestion_ops *tcp_ca_find_autoload(struct net *net, const char *name)