mirror of
https://github.com/torvalds/linux.git
synced 2026-11-20 13:03:48 +00:00
cpumask: Introduce cpumask_intersects_and
Introduce bitmap_intersects_and() to determine whether the intersection of three bitmaps is non-empty. Unlike cpumask_first_and_and(), this returns immediately when an intersecting word is found and does not calculate the first matching bit. Add cpumask_intersects_and() as the corresponding cpumask wrapper. A subsequent patch uses the helper to determine whether a task has a CPU that is present in its affinity mask, the preferred CPU mask, and task possible CPU mask. Suggested-by: Yury Norov <[email protected]> Signed-off-by: Shrikanth Hegde <[email protected]> Reviwed-by: Yury Norov <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Yury Norov <[email protected]> Link: https://patch.msgid.link/[email protected]
This commit is contained in:
committed by
Peter Zijlstra
parent
a8d0854a76
commit
cfb463b717
@@ -52,6 +52,7 @@ struct device;
|
||||
* bitmap_complement(dst, src, nbits) *dst = ~(*src)
|
||||
* bitmap_equal(src1, src2, nbits) Are *src1 and *src2 equal?
|
||||
* bitmap_intersects(src1, src2, nbits) Do *src1 and *src2 overlap?
|
||||
* bitmap_intersects_and(src1, src2, src3, nbits) Do *src1, *src2 and *src3 overlap?
|
||||
* bitmap_subset(src1, src2, nbits) Is *src1 a subset of *src2?
|
||||
* bitmap_empty(src, nbits) Are all bits zero in *src?
|
||||
* bitmap_full(src, nbits) Are all bits set in *src?
|
||||
@@ -181,6 +182,9 @@ void __bitmap_replace(unsigned long *dst,
|
||||
const unsigned long *mask, unsigned int nbits);
|
||||
bool __bitmap_intersects(const unsigned long *bitmap1,
|
||||
const unsigned long *bitmap2, unsigned int nbits);
|
||||
bool __bitmap_intersects_and(const unsigned long *bitmap1,
|
||||
const unsigned long *bitmap2,
|
||||
const unsigned long *bitmap3, unsigned int nbits);
|
||||
bool __bitmap_subset(const unsigned long *bitmap1,
|
||||
const unsigned long *bitmap2, unsigned int nbits);
|
||||
unsigned int __bitmap_weight(const unsigned long *bitmap, unsigned int nbits);
|
||||
@@ -445,6 +449,16 @@ bool bitmap_intersects(const unsigned long *src1, const unsigned long *src2, uns
|
||||
return __bitmap_intersects(src1, src2, nbits);
|
||||
}
|
||||
|
||||
static __always_inline
|
||||
bool bitmap_intersects_and(const unsigned long *src1, const unsigned long *src2,
|
||||
const unsigned long *src3, unsigned int nbits)
|
||||
{
|
||||
if (small_const_nbits(nbits))
|
||||
return ((*src1 & *src2 & *src3) & BITMAP_LAST_WORD_MASK(nbits)) != 0;
|
||||
else
|
||||
return __bitmap_intersects_and(src1, src2, src3, nbits);
|
||||
}
|
||||
|
||||
static __always_inline
|
||||
bool bitmap_subset(const unsigned long *src1, const unsigned long *src2, unsigned int nbits)
|
||||
{
|
||||
|
||||
@@ -824,6 +824,24 @@ bool cpumask_intersects(const struct cpumask *src1p, const struct cpumask *src2p
|
||||
small_cpumask_bits);
|
||||
}
|
||||
|
||||
/**
|
||||
* cpumask_intersects_and - (*src1p & *src2p & *src3p) != 0
|
||||
* @src1p: the first input
|
||||
* @src2p: the second input
|
||||
* @src3p: the third input
|
||||
*
|
||||
* Return: true if AND of the three cpumasks is non-empty,
|
||||
* otherwise false
|
||||
*/
|
||||
static __always_inline
|
||||
bool cpumask_intersects_and(const struct cpumask *src1p,
|
||||
const struct cpumask *src2p,
|
||||
const struct cpumask *src3p)
|
||||
{
|
||||
return bitmap_intersects_and(cpumask_bits(src1p), cpumask_bits(src2p),
|
||||
cpumask_bits(src3p), small_cpumask_bits);
|
||||
}
|
||||
|
||||
/**
|
||||
* cpumask_subset - (*src1p & ~*src2p) == 0
|
||||
* @src1p: the first input
|
||||
|
||||
@@ -308,6 +308,23 @@ bool __bitmap_intersects(const unsigned long *bitmap1,
|
||||
}
|
||||
EXPORT_SYMBOL(__bitmap_intersects);
|
||||
|
||||
bool __bitmap_intersects_and(const unsigned long *bitmap1,
|
||||
const unsigned long *bitmap2,
|
||||
const unsigned long *bitmap3, unsigned int bits)
|
||||
{
|
||||
unsigned int k, lim = bits / BITS_PER_LONG;
|
||||
|
||||
for (k = 0; k < lim; ++k)
|
||||
if (bitmap1[k] & bitmap2[k] & bitmap3[k])
|
||||
return true;
|
||||
|
||||
if (bits % BITS_PER_LONG)
|
||||
if ((bitmap1[k] & bitmap2[k] & bitmap3[k]) & BITMAP_LAST_WORD_MASK(bits))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
EXPORT_SYMBOL(__bitmap_intersects_and);
|
||||
|
||||
bool __bitmap_subset(const unsigned long *bitmap1,
|
||||
const unsigned long *bitmap2, unsigned int bits)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user