lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Fri, 26 Apr 2024 17:32:57 +0200
From: Eric Dumazet <edumazet@...gle.com>
To: I Hsin Cheng <richard120310@...il.com>
Cc: davem@...emloft.net, dsahern@...nel.org, kuba@...nel.org, 
	pabeni@...hat.com, netdev@...r.kernel.org, linux-kernel@...r.kernel.org, 
	bpf@...r.kernel.org
Subject: Re: [PATCH] tcp_bbr: replace lambda expression with bitwise operation
 for bit flip

On Fri, Apr 26, 2024 at 5:20 PM I Hsin Cheng <richard120310@...il.com> wrote:
>
> 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@...il.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;
>                 }
>         }

Or

bbr->extra_acked_win_idx ^= 1;

Note that C compilers generate the same code, for the 3 variants.

They do not generate branches for something simple like this.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ