public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Anton Protopopov <aspsk@isovalent.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: bpf <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	John Fastabend <john.fastabend@gmail.com>
Subject: Re: [PATCH bpf-next] bpf: optimize hashmap lookups when key_size is divisible by 4
Date: Sat, 1 Apr 2023 19:53:10 +0000	[thread overview]
Message-ID: <ZCiLplR/MqqF7479@zh-lab-node-5> (raw)
In-Reply-To: <CAADnVQK9n2yhC9GGFCwHbVHQB_0kq5M7TLyoGZq5MQFsw92xyA@mail.gmail.com>

On Sat, Apr 01, 2023 at 12:35:55PM -0700, Alexei Starovoitov wrote:
> On Sat, Apr 1, 2023 at 12:24 PM Anton Protopopov <aspsk@isovalent.com> wrote:
> > > > -static inline u32 htab_map_hash(const void *key, u32 key_len, u32 hashrnd)
> > > > +static inline u32 htab_map_hash(const struct bpf_htab *htab, const void *key, u32 key_len)
> > > >  {
> > > > -   return jhash(key, key_len, hashrnd);
> > > > +   if (likely(htab->key_size_u32))
> > > > +           return jhash2(key, htab->key_size_u32, htab->hashrnd);
> > > > +   return jhash(key, key_len, htab->hashrnd);
> > >
> > > Could you measure the speed when &3 and /4 is done in the hot path ?
> > > I would expect the performance to be the same or faster,
> > > since extra load is gone.
> >
> > I don't see any visible difference (I've tested "&3 and /4" and "%4==0 and /4"
> > variants).
> 
> I bet compiler generates the same code for these two variants.
> % is optimized into &.
> / is optimized into >>.

Yes, it does "test $0x3,%dl"

> > Do you still prefer division in favor of using htab->key_size_u32?
> 
> yes, because it's a shift.

ok, thanks, I will send v2 with division

      reply	other threads:[~2023-04-01 19:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-01 10:10 [PATCH bpf-next] bpf: optimize hashmap lookups when key_size is divisible by 4 Anton Protopopov
2023-04-01 16:20 ` Alexei Starovoitov
2023-04-01 19:25   ` Anton Protopopov
2023-04-01 19:35     ` Alexei Starovoitov
2023-04-01 19:53       ` Anton Protopopov [this message]

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=ZCiLplR/MqqF7479@zh-lab-node-5 \
    --to=aspsk@isovalent.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=john.fastabend@gmail.com \
    --cc=martin.lau@linux.dev \
    /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