lkml.org 
[lkml]   [2021]   [Jun]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v8 09/22] tools lib: Introduce bitmap_intersects() operation
Em Wed, Jun 30, 2021 at 02:24:26PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Wed, Jun 30, 2021 at 06:54:48PM +0300, Alexey Bayduraev escreveu:
> > Introduce bitmap_intersects() routine that tests whether
>
> Is this _adopting_ bitmap_intersects() from the kernel sources?

Ok, clarified that in the changeset comment and applied this patch to
reduce the number of patches in this patchset, there is another patch I
think can cherry picked, checking.

- ARnaldo

> > bitmaps bitmap1 and bitmap2 intersects. This routine will
> > be used during thread masks initialization.
> >
> > Acked-by: Andi Kleen <ak@linux.intel.com>
> > Acked-by: Namhyung Kim <namhyung@gmail.com>
> > Signed-off-by: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com>
> > ---
> > tools/include/linux/bitmap.h | 11 +++++++++++
> > tools/lib/bitmap.c | 14 ++++++++++++++
> > 2 files changed, 25 insertions(+)
> >
> > diff --git a/tools/include/linux/bitmap.h b/tools/include/linux/bitmap.h
> > index 330dbf7509cc..9d959bc24859 100644
> > --- a/tools/include/linux/bitmap.h
> > +++ b/tools/include/linux/bitmap.h
> > @@ -18,6 +18,8 @@ int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
> > int __bitmap_equal(const unsigned long *bitmap1,
> > const unsigned long *bitmap2, unsigned int bits);
> > void bitmap_clear(unsigned long *map, unsigned int start, int len);
> > +int __bitmap_intersects(const unsigned long *bitmap1,
> > + const unsigned long *bitmap2, unsigned int bits);
> >
> > #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1)))
> > #define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1)))
> > @@ -170,4 +172,13 @@ static inline int bitmap_equal(const unsigned long *src1,
> > return __bitmap_equal(src1, src2, nbits);
> > }
> >
> > +static inline int bitmap_intersects(const unsigned long *src1,
> > + const unsigned long *src2, unsigned int nbits)
> > +{
> > + if (small_const_nbits(nbits))
> > + return ((*src1 & *src2) & BITMAP_LAST_WORD_MASK(nbits)) != 0;
> > + else
> > + return __bitmap_intersects(src1, src2, nbits);
> > +}
> > +
> > #endif /* _PERF_BITOPS_H */
> > diff --git a/tools/lib/bitmap.c b/tools/lib/bitmap.c
> > index f4e914712b6f..db466ef7be9d 100644
> > --- a/tools/lib/bitmap.c
> > +++ b/tools/lib/bitmap.c
> > @@ -86,3 +86,17 @@ int __bitmap_equal(const unsigned long *bitmap1,
> >
> > return 1;
> > }
> > +
> > +int __bitmap_intersects(const unsigned long *bitmap1,
> > + const unsigned long *bitmap2, unsigned int bits)
> > +{
> > + unsigned int k, lim = bits/BITS_PER_LONG;
> > + for (k = 0; k < lim; ++k)
> > + if (bitmap1[k] & bitmap2[k])
> > + return 1;
> > +
> > + if (bits % BITS_PER_LONG)
> > + if ((bitmap1[k] & bitmap2[k]) & BITMAP_LAST_WORD_MASK(bits))
> > + return 1;
> > + return 0;
> > +}
> > --
> > 2.19.0
> >
>
> --
>
> - Arnaldo

--

- Arnaldo

\
 
 \ /
  Last update: 2021-06-30 19:43    [W:0.059 / U:0.184 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site