summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYury Norov [NVIDIA] <yury.norov@gmail.com>2025-06-04 15:39:37 -0400
committerLeon Romanovsky <leon@kernel.org>2025-06-26 05:19:15 -0400
commit16e2707cf15e09234445d40ddd76f11240be8767 (patch)
treefa518e34268b62d59125ddaa2d304ac76bccd7ba
parent43163f4c30f94d2103c948a247cdf2cda5068ca7 (diff)
cpumask: add cpumask_clear_cpus()
When user wants to clear a range in cpumask, the only option the API provides now is a for-loop, like: for_each_cpu_from(cpu, mask) { if (cpu >= ncpus) break; __cpumask_clear_cpu(cpu, mask); } In the bitmap API we have bitmap_clear() for that, which is significantly faster than a for-loop. Propagate it to cpumasks. Signed-off-by: Yury Norov [NVIDIA] <yury.norov@gmail.com> Link: https://patch.msgid.link/20250604193947.11834-2-yury.norov@gmail.com Signed-off-by: Leon Romanovsky <leon@kernel.org>
-rw-r--r--include/linux/cpumask.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index 7ae80a7ca81e..ede95bbe8b80 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -609,6 +609,18 @@ void __cpumask_set_cpu(unsigned int cpu, struct cpumask *dstp)
__set_bit(cpumask_check(cpu), cpumask_bits(dstp));
}
+/**
+ * cpumask_clear_cpus - clear cpus in a cpumask
+ * @dstp: the cpumask pointer
+ * @cpu: cpu number (< nr_cpu_ids)
+ * @ncpus: number of cpus to clear (< nr_cpu_ids)
+ */
+static __always_inline void cpumask_clear_cpus(struct cpumask *dstp,
+ unsigned int cpu, unsigned int ncpus)
+{
+ cpumask_check(cpu + ncpus - 1);
+ bitmap_clear(cpumask_bits(dstp), cpumask_check(cpu), ncpus);
+}
/**
* cpumask_clear_cpu - clear a cpu in a cpumask