summaryrefslogtreecommitdiffstats
path: root/include/linux/cpumask.h
diff options
context:
space:
mode:
authorYury Norov <yury.norov@gmail.com>2022-09-17 20:07:12 -0700
committerYury Norov <yury.norov@gmail.com>2022-09-26 12:19:12 -0700
commit24291caf8447f6fc060c8d00136bdc30ee207f38 (patch)
tree13d0a9d2b34cc58777852bce8ed9732c3882e669 /include/linux/cpumask.h
parent70a1cb106d9410f1f37e0261728e46722b74c29f (diff)
downloadlinux-stable-24291caf8447f6fc060c8d00136bdc30ee207f38.tar.gz
linux-stable-24291caf8447f6fc060c8d00136bdc30ee207f38.tar.bz2
linux-stable-24291caf8447f6fc060c8d00136bdc30ee207f38.zip
lib/bitmap: add bitmap_weight_and()
The function calculates Hamming weight of (bitmap1 & bitmap2). Now we have to do like this: tmp = bitmap_alloc(nbits); bitmap_and(tmp, map1, map2, nbits); weight = bitmap_weight(tmp, nbits); bitmap_free(tmp); This requires additional memory, adds pressure on alloc subsystem, and way less cache-friendly than just: weight = bitmap_weight_and(map1, map2, nbits); The following patches apply it for cpumask functions. Signed-off-by: Yury Norov <yury.norov@gmail.com>
Diffstat (limited to 'include/linux/cpumask.h')
-rw-r--r--include/linux/cpumask.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index 1b442fb2001f..9a71af8097ca 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -587,6 +587,17 @@ static inline unsigned int cpumask_weight(const struct cpumask *srcp)
}
/**
+ * cpumask_weight_and - Count of bits in (*srcp1 & *srcp2)
+ * @srcp1: the cpumask to count bits (< nr_cpu_ids) in.
+ * @srcp2: the cpumask to count bits (< nr_cpu_ids) in.
+ */
+static inline unsigned int cpumask_weight_and(const struct cpumask *srcp1,
+ const struct cpumask *srcp2)
+{
+ return bitmap_weight_and(cpumask_bits(srcp1), cpumask_bits(srcp2), nr_cpumask_bits);
+}
+
+/**
* cpumask_shift_right - *dstp = *srcp >> n
* @dstp: the cpumask result
* @srcp: the input to shift