public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tcp_bbr: replace lambda expression with bitwise operation for bit flip
@ 2024-04-26 15:20 I Hsin Cheng
  2024-04-26 15:32 ` Eric Dumazet
  0 siblings, 1 reply; 5+ messages in thread
From: I Hsin Cheng @ 2024-04-26 15:20 UTC (permalink / raw)
  To: edumazet
  Cc: davem, dsahern, kuba, pabeni, netdev, linux-kernel, bpf,
	I Hsin Cheng

In the origin implementation in function bbr_update_ack_aggregation(),
we utilize a lambda expression to flip the bit value of
bbr->extra_acked_win_idx. Since the data type of
bbr->extra_acked_win_idx is simply a single bit, we are actually trying
to perform a bit flip operation, under the fact we can simply perform a
bitwise not operation on bbr->extra_acked_win_idx.

This way we can elimate the need of possible branches which generate by
the lambda function, they could result in branch misses sometimes.
Perform a bitwise not operation is more straightforward and wouldn't
generate branches.

Signed-off-by: I Hsin Cheng <richard120310@gmail.com>
---
 net/ipv4/tcp_bbr.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/net/ipv4/tcp_bbr.c b/net/ipv4/tcp_bbr.c
index 146792cd2..75068ba25 100644
--- a/net/ipv4/tcp_bbr.c
+++ b/net/ipv4/tcp_bbr.c
@@ -829,8 +829,7 @@ static void bbr_update_ack_aggregation(struct sock *sk,
 						bbr->extra_acked_win_rtts + 1);
 		if (bbr->extra_acked_win_rtts >= bbr_extra_acked_win_rtts) {
 			bbr->extra_acked_win_rtts = 0;
-			bbr->extra_acked_win_idx = bbr->extra_acked_win_idx ?
-						   0 : 1;
+			bbr->extra_acked_win_idx = ~(bbr->extra_acked_win_idx);
 			bbr->extra_acked[bbr->extra_acked_win_idx] = 0;
 		}
 	}
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-04-27  8:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-26 15:20 [PATCH] tcp_bbr: replace lambda expression with bitwise operation for bit flip I Hsin Cheng
2024-04-26 15:32 ` Eric Dumazet
2024-04-26 17:01   ` I Hsin Cheng
2024-04-26 20:19     ` Al Viro
2024-04-27  8:31       ` I Hsin Cheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox