[tip: perf/core] perf: Use cpumask_intersects where applicable

From: tip-bot2 for Shrikanth Hegde

Date: Wed Nov 18 2026 - 08:40:30 EST


The following commit has been merged into the perf/core branch of tip:

Commit-ID: 16bc76f9da9673bde4f8c84087e13573d2baa468
Gitweb: https://git.kernel.org/tip/16bc76f9da9673bde4f8c84087e13573d2baa468
Author: Shrikanth Hegde <sshegde@xxxxxxxxxxxxx>
AuthorDate: Wed, 11 Nov 2026 13:29:43 +05:30
Committer: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
CommitterDate: Wed, 18 Nov 2026 14:32:21 +01:00

perf: Use cpumask_intersects where applicable

cpumask_any_and returns, usually the first cpu in the intersection
of the two cpumasks. However, if the returned value is not used or
only to check it against nr_cpu_ids, that implies whether the two
cpumask have a bit in common. i.e cpumask_intersects.

cpumask_any_and uses ffs on (addr1[idx] & addr2[idx]) whereas
cpumask_intersects checks only (addr1[idx] & addr2[idx]).

So replace such occurrences.

Signed-off-by: Shrikanth Hegde <sshegde@xxxxxxxxxxxxx>
Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
Link: https://patch.msgid.link/20261111075945.3930230-4-sshegde@xxxxxxxxxxxxx
---
kernel/events/core.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index e870f12..687bd39 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -13274,7 +13274,6 @@ static int perf_try_init_event(struct pmu *pmu, struct perf_event *event)
if (pmu->scope != PERF_PMU_SCOPE_NONE && event->cpu >= 0) {
const struct cpumask *cpumask;
struct cpumask *pmu_cpumask;
- int cpu;

cpumask = perf_scope_cpu_topology_cpumask(pmu->scope, event->cpu);
pmu_cpumask = perf_scope_cpumask(pmu->scope);
@@ -13283,8 +13282,7 @@ static int perf_try_init_event(struct pmu *pmu, struct perf_event *event)
if (!pmu_cpumask || !cpumask)
goto err_destroy;

- cpu = cpumask_any_and(pmu_cpumask, cpumask);
- if (cpu >= nr_cpu_ids)
+ if (!cpumask_intersects(pmu_cpumask, cpumask))
goto err_destroy;

event->event_caps |= PERF_EV_CAP_READ_SCOPE;
@@ -15442,8 +15440,7 @@ static void perf_event_setup_cpumask(unsigned int cpu)
if (WARN_ON_ONCE(!pmu_cpumask || !cpumask))
continue;

- if (!cpumask_empty(cpumask) &&
- cpumask_any_and(pmu_cpumask, cpumask) >= nr_cpu_ids)
+ if (!cpumask_empty(cpumask) && !cpumask_intersects(pmu_cpumask, cpumask))
cpumask_set_cpu(cpu, pmu_cpumask);
}
end: