From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Yury Norov <yury.norov@gmail.com>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 2/2] bitmap: Optimize memset() calls
Date: Fri, 18 Aug 2023 11:55:47 +0300 [thread overview]
Message-ID: <ZN8yE7jsI3z63EEw@smile.fi.intel.com> (raw)
In-Reply-To: <e66919a4-afdc-efdb-f6ae-07cfc5bde105@rasmusvillemoes.dk>
On Fri, Aug 18, 2023 at 08:53:38AM +0200, Rasmus Villemoes wrote:
> On 17/08/2023 18.54, Andy Shevchenko wrote:
...
> > +#if BITS_PER_LONG == 64
> > + memset64((uint64_t *)dst, 0, len);
> > +#else
> > + memset32((uint32_t *)dst, 0, len);
> > +#endif
> > }
>
> So _if_ this is worth it at all,
Yury, I believe you have a set of performance tests for bitmaps, perhaps you
can give a try and see if we got a benefit here.
Yet, not all architectures have custom implementation of the optimized
memset()/memcpy(). But at least ARM, x86 do.
> all those new '#if BITS_PER_LONG == 64'
> suggests that we should instead have a new helper memset_long(), no?
>
> In fact, string.h already has that:
>
> static inline void *memset_l(unsigned long *p, unsigned long v,
> __kernel_size_t n)
My grep skills suddenly degraded, my thoughts were exactly like yours,
but I missed the _l instead of _long for which I grepped.
...
> Please just spell an all-ones long "~0UL", that also matches the
> small_const case.
OK!
...
> > - memset(&dst[lim - off], 0, off*sizeof(unsigned long));
> > + bitmap_zero(&dst[lim - off], off);
>
> This... can't be right.
Indeed, I have in mind memset_long() and on the half-way replaced it with
bitmap_zero().
> bitmap_zero() still takes an argument which is
> the size in bits, while off is the whole number of words to shift. So if
> called with say shift=128, we'd have off==2, and that bitmap_zero()
> would, because bitmap_zero() rounds up to a whole number of words, end
> up clearing just one word.
>
> Perhaps a chance to add some more test cases? Maybe we're not exercising
> any of the "shift more than BITS_PER_LONG" logic.
>
> But rather than using bitmap_zero() here, forcing you to convert off to
> a number of bits and then bitmap_zero to divide again, if you do this at
> all, just change that memset() to memset_l().
Agree.
--
With Best Regards,
Andy Shevchenko
prev parent reply other threads:[~2023-08-18 8:56 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-17 16:54 [rfc, rft, PATCH v1 0/2] bitmap: clean up and (micro?)optimization Andy Shevchenko
2023-08-17 16:54 ` [PATCH v1 1/2] bitmap: Use constants and macros from bits.h Andy Shevchenko
2023-08-18 6:28 ` Rasmus Villemoes
2023-08-18 8:50 ` Andy Shevchenko
2023-08-18 9:13 ` Rasmus Villemoes
2023-08-17 16:54 ` [PATCH v1 2/2] bitmap: Optimize memset() calls Andy Shevchenko
2023-08-18 6:53 ` Rasmus Villemoes
2023-08-18 8:55 ` Andy Shevchenko [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=ZN8yE7jsI3z63EEw@smile.fi.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=yury.norov@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox