From: Ziran Zhang <zhangcoder@yeah.net>
To: Eric Dumazet <edumazet@google.com>,
Neal Cardwell <ncardwell@google.com>,
"David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: Kuniyuki Iwashima <kuniyu@google.com>,
Simon Horman <horms@kernel.org>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Ziran Zhang <zhangcoder@yeah.net>
Subject: [PATCH net-next] tcp: use likely() for srtt check in tcp_rtt_estimator()
Date: Sat, 8 Aug 2026 19:00:54 +0800 [thread overview]
Message-ID: <20260808110054.6892-1-zhangcoder@yeah.net> (raw)
In tcp_rtt_estimator(), srtt is initialized to a non-zero value
after the first RTT measurement (srtt = m << 3) and never returns
to zero for the lifetime of the connection. Thus, the "srtt != 0"
branch is almost always true.
Marking it with likely() helps the compiler generate better code
for this hot path.
No functional change is introduced.
Signed-off-by: Ziran Zhang <zhangcoder@yeah.net>
---
net/ipv4/tcp_input.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 5b6378b94..a4c4d4760 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -1089,7 +1089,7 @@ static void tcp_rtt_estimator(struct sock *sk, long mrtt_us)
* does not matter how to _calculate_ it. Seems, it was trap
* that VJ failed to avoid. 8)
*/
- if (srtt != 0) {
+ if (likely(srtt != 0)) {
m -= (srtt >> 3); /* m is now error in rtt est */
srtt += m; /* rtt = 7/8 rtt + 1/8 new */
if (m < 0) {
--
2.51.0
reply other threads:[~2026-08-08 11:02 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260808110054.6892-1-zhangcoder@yeah.net \
--to=zhangcoder@yeah.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/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