Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1649564 > unrolled thread

bitmap API consistency

Started byAndy Shevchenko <andriy.shevchenko@linux.intel.com>
First post2017-05-24 14:20 +0200
Last post2017-05-24 14:50 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel


Contents

  bitmap API consistency Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2017-05-24 14:20 +0200
    Re: bitmap API consistency Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2017-05-24 14:40 +0200
      Re: bitmap API consistency Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2017-05-24 14:50 +0200

#1649564 — bitmap API consistency

FromAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Date2017-05-24 14:20 +0200
Subjectbitmap API consistency
Message-ID<tKDqG-2fU-15@gated-at.bofh.it>
Hi!

Surprisingly discovered today that bitmap API is not consistent in some
cases (at least one I found recently).

bitmap_fill() sets area of bits in a bitmap.
bitmap_zero() clears them.

However, if _fill() does something sane, _zero() clears _all_ bits up to
word size (long).

I think it should be fixed to be consistent with _fill() variant.

Thoughts?

-- 
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy

[toc] | [next] | [standalone]


#1649581

FromRasmus Villemoes <linux@rasmusvillemoes.dk>
Date2017-05-24 14:40 +0200
Message-ID<tKDK2-2mu-9@gated-at.bofh.it>
In reply to#1649564
On 24 May 2017 at 14:11, Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
> Hi!
>
> Surprisingly discovered today that bitmap API is not consistent in some
> cases (at least one I found recently).
>
> bitmap_fill() sets area of bits in a bitmap.
> bitmap_zero() clears them.
>
> However, if _fill() does something sane, _zero() clears _all_ bits up to
> word size (long).
>
> I think it should be fixed to be consistent with _fill() variant.

What do you want it to do? It always acts on whole words, so the last
word must be set to something. One might as well say that _zero and
_fill are consistent in that they both set the bits beyond nbits in
the last word to 0.

If anything, I'd change bitmap_fill to do a memset(0xff) of the entire
region. There used to be bugs where some of the bitmap_* functions
didn't actually ignore the trailing bits, making it somewhat important
that they were always 0, but I think they're fixed now.

Note that if one wants a guarantee that the trailing bits are not
touched at all, the APIs to use are bitmap_{set, clear}(dst, 0,
count). bitmap_{zero,fill} assumes that nbits is the total size of the
bitmap (i.e. that the user will never care about bits beyond nbits).
Maybe a few comments could be added somewhere.

Rasmus

[toc] | [prev] | [next] | [standalone]


#1649584

FromAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Date2017-05-24 14:50 +0200
Message-ID<tKDTH-2pQ-7@gated-at.bofh.it>
In reply to#1649581
On Wed, 2017-05-24 at 14:38 +0200, Rasmus Villemoes wrote:
> On 24 May 2017 at 14:11, Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> > Hi!
> > 
> > Surprisingly discovered today that bitmap API is not consistent in
> > some
> > cases (at least one I found recently).
> > 
> > bitmap_fill() sets area of bits in a bitmap.
> > bitmap_zero() clears them.
> > 
> > However, if _fill() does something sane, _zero() clears _all_ bits
> > up to
> > word size (long).
> > 
> > I think it should be fixed to be consistent with _fill() variant.
> 
> What do you want it to do?

Based on my vision and your answer below, thanks for it, I think we need
to
a) make _fill() to fill entire _aligned_ area
b) update comments in the header and documentation, if needed, to
specify that _fill() / _zero() operates on aligned to word size area,
while _set() and _clear() do exact amount of bits.

>  It always acts on whole words, so the last
> word must be set to something. One might as well say that _zero and
> _fill are consistent in that they both set the bits beyond nbits in
> the last word to 0.
> 
> If anything, I'd change bitmap_fill to do a memset(0xff) of the entire
> region. There used to be bugs where some of the bitmap_* functions
> didn't actually ignore the trailing bits, making it somewhat important
> that they were always 0, but I think they're fixed now.
> 
> Note that if one wants a guarantee that the trailing bits are not
> touched at all, the APIs to use are bitmap_{set, clear}(dst, 0,
> count). bitmap_{zero,fill} assumes that nbits is the total size of the
> bitmap (i.e. that the user will never care about bits beyond nbits).
> Maybe a few comments could be added somewhere.
> 
> Rasmus

-- 
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web