[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <174747618564.406.16412301340914355967.tip-bot2@tip-bot2>
Date: Sat, 17 May 2025 10:03:05 -0000
From: "tip-bot2 for Yury Norov [NVIDIA]" <tip-bot2@...utronix.de>
To: linux-tip-commits@...r.kernel.org
Cc: "Yury Norov [NVIDIA]" <yury.norov@...il.com>,
James Morse <james.morse@....com>, "Borislav Petkov (AMD)" <bp@...en8.de>,
Reinette Chatre <reinette.chatre@...el.com>, Fenghua Yu <fenghuay@...dia.com>,
Tony Luck <tony.luck@...el.com>, x86@...nel.org, linux-kernel@...r.kernel.org
Subject: [tip: x86/cache] cpumask: Add cpumask_{first,next}_andnot() API
The following commit has been merged into the x86/cache branch of tip:
Commit-ID: 5da703ef4e4a82b2f9a00f2b3a1eae5657e68a92
Gitweb: https://git.kernel.org/tip/5da703ef4e4a82b2f9a00f2b3a1eae5657e68a92
Author: Yury Norov [NVIDIA] <yury.norov@...il.com>
AuthorDate: Thu, 15 May 2025 16:58:33
Committer: Borislav Petkov (AMD) <bp@...en8.de>
CommitterDate: Thu, 15 May 2025 20:28:12 +02:00
cpumask: Add cpumask_{first,next}_andnot() API
With the lack of the functions, client code has to abuse less efficient
cpumask_nth().
Signed-off-by: Yury Norov [NVIDIA] <yury.norov@...il.com>
Signed-off-by: James Morse <james.morse@....com>
Signed-off-by: Borislav Petkov (AMD) <bp@...en8.de>
Reviewed-by: James Morse <james.morse@....com>
Reviewed-by: Reinette Chatre <reinette.chatre@...el.com>
Reviewed-by: Fenghua Yu <fenghuay@...dia.com>
Tested-by: Fenghua Yu <fenghuay@...dia.com>
Tested-by: James Morse <james.morse@....com>
Tested-by: Tony Luck <tony.luck@...el.com>
Link: https://lore.kernel.org/20250515165855.31452-4-james.morse@arm.com
---
include/linux/cpumask.h | 59 ++++++++++++++++++++++++++++++++++++++++-
1 file changed, 59 insertions(+)
diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index a3ee875..6a569c7 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -179,6 +179,19 @@ unsigned int cpumask_first_and(const struct cpumask *srcp1, const struct cpumask
}
/**
+ * cpumask_first_andnot - return the first cpu from *srcp1 & ~*srcp2
+ * @srcp1: the first input
+ * @srcp2: the second input
+ *
+ * Return: >= nr_cpu_ids if no such cpu found.
+ */
+static __always_inline
+unsigned int cpumask_first_andnot(const struct cpumask *srcp1, const struct cpumask *srcp2)
+{
+ return find_first_andnot_bit(cpumask_bits(srcp1), cpumask_bits(srcp2), small_cpumask_bits);
+}
+
+/**
* cpumask_first_and_and - return the first cpu from *srcp1 & *srcp2 & *srcp3
* @srcp1: the first input
* @srcp2: the second input
@@ -285,6 +298,25 @@ unsigned int cpumask_next_and(int n, const struct cpumask *src1p,
}
/**
+ * cpumask_next_andnot - get the next cpu in *src1p & ~*src2p
+ * @n: the cpu prior to the place to search (i.e. return will be > @n)
+ * @src1p: the first cpumask pointer
+ * @src2p: the second cpumask pointer
+ *
+ * Return: >= nr_cpu_ids if no further cpus set in both.
+ */
+static __always_inline
+unsigned int cpumask_next_andnot(int n, const struct cpumask *src1p,
+ const struct cpumask *src2p)
+{
+ /* -1 is a legal arg here. */
+ if (n != -1)
+ cpumask_check(n);
+ return find_next_andnot_bit(cpumask_bits(src1p), cpumask_bits(src2p),
+ small_cpumask_bits, n + 1);
+}
+
+/**
* cpumask_next_and_wrap - get the next cpu in *src1p & *src2p, starting from
* @n+1. If nothing found, wrap around and start from
* the beginning
@@ -459,6 +491,33 @@ unsigned int cpumask_any_and_but(const struct cpumask *mask1,
}
/**
+ * cpumask_any_andnot_but - pick an arbitrary cpu from *mask1 & ~*mask2, but not this one.
+ * @mask1: the first input cpumask
+ * @mask2: the second input cpumask
+ * @cpu: the cpu to ignore
+ *
+ * If @cpu == -1, the function returns the first matching cpu.
+ * Returns >= nr_cpu_ids if no cpus set.
+ */
+static __always_inline
+unsigned int cpumask_any_andnot_but(const struct cpumask *mask1,
+ const struct cpumask *mask2,
+ int cpu)
+{
+ unsigned int i;
+
+ /* -1 is a legal arg here. */
+ if (cpu != -1)
+ cpumask_check(cpu);
+
+ i = cpumask_first_andnot(mask1, mask2);
+ if (i != cpu)
+ return i;
+
+ return cpumask_next_andnot(cpu, mask1, mask2);
+}
+
+/**
* cpumask_nth - get the Nth cpu in a cpumask
* @srcp: the cpumask pointer
* @cpu: the Nth cpu to find, starting from 0
Powered by blists - more mailing lists