All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Dumazet <edumazet@google.com>
To: I Hsin Cheng <richard120310@gmail.com>
Cc: davem@davemloft.net, dsahern@kernel.org, kuba@kernel.org,
	 pabeni@redhat.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org,  bpf@vger.kernel.org
Subject: Re: [PATCH] tcp_bbr: replace lambda expression with bitwise operation for bit flip
Date: Fri, 26 Apr 2024 17:32:57 +0200	[thread overview]
Message-ID: <CANn89iKenW5SxMGm753z8eawg+7drUz7oZcTR06habjcFmdqVg@mail.gmail.com> (raw)
In-Reply-To: <20240426152011.37069-1-richard120310@gmail.com>

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

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.

  reply	other threads:[~2024-04-26 15:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2024-04-26 17:01   ` I Hsin Cheng
2024-04-26 20:19     ` Al Viro
2024-04-27  8:31       ` I Hsin Cheng

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=CANn89iKenW5SxMGm753z8eawg+7drUz7oZcTR06habjcFmdqVg@mail.gmail.com \
    --to=edumazet@google.com \
    --cc=bpf@vger.kernel.org \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=richard120310@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.