* [PATCH 1/5] sched/rt: cpupri_find: Use cpumask_intersects where applicable
2026-11-11 7:59 [PATCH 0/5] cpumask: Use cpumask_intersects* APIs where applicable Shrikanth Hegde
@ 2026-11-11 7:59 ` Shrikanth Hegde
2026-11-11 7:59 ` [PATCH 2/5] cpu/hotplug: " Shrikanth Hegde
` (4 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Shrikanth Hegde @ 2026-11-11 7:59 UTC (permalink / raw)
To: linux-kernel, yury.norov, linux-perf-users
Cc: sshegde, mingo, peterz, juri.lelli, vincent.guittot, tglx,
sudeep.holla, linux
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@linux.ibm.com>
---
kernel/sched/cpupri.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/sched/cpupri.c b/kernel/sched/cpupri.c
index 8f2237e8b484..44d67fbc4ab2 100644
--- a/kernel/sched/cpupri.c
+++ b/kernel/sched/cpupri.c
@@ -97,7 +97,7 @@ static inline int __cpupri_find(struct cpupri *cp, struct task_struct *p,
if (skip)
return 0;
- if (cpumask_any_and(&p->cpus_mask, vec->mask) >= nr_cpu_ids)
+ if (!cpumask_intersects(&p->cpus_mask, vec->mask))
return 0;
if (lowest_mask) {
--
2.52.0
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH 2/5] cpu/hotplug: Use cpumask_intersects where applicable
2026-11-11 7:59 [PATCH 0/5] cpumask: Use cpumask_intersects* APIs where applicable Shrikanth Hegde
2026-11-11 7:59 ` [PATCH 1/5] sched/rt: cpupri_find: Use cpumask_intersects " Shrikanth Hegde
@ 2026-11-11 7:59 ` Shrikanth Hegde
2026-11-11 7:59 ` [PATCH 3/5] perf: " Shrikanth Hegde
` (3 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Shrikanth Hegde @ 2026-11-11 7:59 UTC (permalink / raw)
To: linux-kernel, yury.norov, linux-perf-users
Cc: sshegde, mingo, peterz, juri.lelli, vincent.guittot, tglx,
sudeep.holla, linux
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@linux.ibm.com>
---
kernel/cpu.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/kernel/cpu.c b/kernel/cpu.c
index 376d297a6292..e39245d9bffe 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -1418,8 +1418,7 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen,
* Keep at least one housekeeping cpu onlined to avoid generating
* an empty sched_domain span.
*/
- if (cpumask_any_and(cpu_online_mask,
- housekeeping_cpumask(HK_TYPE_DOMAIN)) >= nr_cpu_ids) {
+ if (!cpumask_intersects(cpu_online_mask, housekeeping_cpumask(HK_TYPE_DOMAIN))) {
ret = -EBUSY;
goto out;
}
--
2.52.0
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH 3/5] perf: Use cpumask_intersects where applicable
2026-11-11 7:59 [PATCH 0/5] cpumask: Use cpumask_intersects* APIs where applicable Shrikanth Hegde
2026-11-11 7:59 ` [PATCH 1/5] sched/rt: cpupri_find: Use cpumask_intersects " Shrikanth Hegde
2026-11-11 7:59 ` [PATCH 2/5] cpu/hotplug: " Shrikanth Hegde
@ 2026-11-11 7:59 ` Shrikanth Hegde
2026-11-11 7:59 ` [PATCH 4/5] cpuidle: Use cpumask_intersects_and " Shrikanth Hegde
` (2 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Shrikanth Hegde @ 2026-11-11 7:59 UTC (permalink / raw)
To: linux-kernel, yury.norov, linux-perf-users
Cc: sshegde, mingo, peterz, juri.lelli, vincent.guittot, tglx,
sudeep.holla, linux
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@linux.ibm.com>
---
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 a6c8e38a3110..f9fa1b47ddf4 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -13159,7 +13159,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);
@@ -13168,8 +13167,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;
@@ -15312,8 +15310,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:
--
2.52.0
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH 4/5] cpuidle: Use cpumask_intersects_and where applicable
2026-11-11 7:59 [PATCH 0/5] cpumask: Use cpumask_intersects* APIs where applicable Shrikanth Hegde
` (2 preceding siblings ...)
2026-11-11 7:59 ` [PATCH 3/5] perf: " Shrikanth Hegde
@ 2026-11-11 7:59 ` Shrikanth Hegde
2026-11-11 7:59 ` [PATCH 5/5] arch_topology: Use cpumask_intersects " Shrikanth Hegde
2026-11-11 9:16 ` [PATCH 0/5] cpumask: Use cpumask_intersects* APIs " Peter Zijlstra
5 siblings, 0 replies; 10+ messages in thread
From: Shrikanth Hegde @ 2026-11-11 7:59 UTC (permalink / raw)
To: linux-kernel, yury.norov, linux-perf-users
Cc: sshegde, mingo, peterz, juri.lelli, vincent.guittot, tglx,
sudeep.holla, linux
cpumask_first_and_and returns, usually the first CPU in the intersection
of the three cpumasks. However, if the returned CPU is not used or
only to check it against nr_cpu_ids, that implies to check whether the
three cpumasks have a bit in common. I.e use cpumask_intersects_and.
cpumask_first_and_and uses ffs on (addr1[idx] & addr2[idx] & addr3[idx])
whereas cpumask_intersects_and checks only
(addr1[idx] & addr2[idx] & addr3[idx]).
So replace such an occurrence.
Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
---
drivers/cpuidle/coupled.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/cpuidle/coupled.c b/drivers/cpuidle/coupled.c
index fb91a9e0e3c2..40db5c86a466 100644
--- a/drivers/cpuidle/coupled.c
+++ b/drivers/cpuidle/coupled.c
@@ -439,8 +439,8 @@ static int cpuidle_coupled_clear_pokes(int cpu)
static bool cpuidle_coupled_any_pokes_pending(struct cpuidle_coupled *coupled)
{
- return cpumask_first_and_and(cpu_online_mask, &coupled->coupled_cpus,
- &cpuidle_coupled_poke_pending) < nr_cpu_ids;
+ return cpumask_intersects_and(cpu_online_mask, &coupled->coupled_cpus,
+ &cpuidle_coupled_poke_pending);
}
/**
--
2.52.0
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH 5/5] arch_topology: Use cpumask_intersects where applicable
2026-11-11 7:59 [PATCH 0/5] cpumask: Use cpumask_intersects* APIs where applicable Shrikanth Hegde
` (3 preceding siblings ...)
2026-11-11 7:59 ` [PATCH 4/5] cpuidle: Use cpumask_intersects_and " Shrikanth Hegde
@ 2026-11-11 7:59 ` Shrikanth Hegde
2026-11-11 10:20 ` Sudeep Holla
2026-11-11 9:16 ` [PATCH 0/5] cpumask: Use cpumask_intersects* APIs " Peter Zijlstra
5 siblings, 1 reply; 10+ messages in thread
From: Shrikanth Hegde @ 2026-11-11 7:59 UTC (permalink / raw)
To: linux-kernel, yury.norov, linux-perf-users
Cc: sshegde, mingo, peterz, juri.lelli, vincent.guittot, tglx,
sudeep.holla, linux
Looping over one cpumask and checking if any bit is set in another
cpumask is same as evaluating if two cpumasks intersects or not.
So use cpumask_intersects instead. It is probably faster too.
Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
---
drivers/base/arch_topology.c | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c
index 8c5e47c28d9a..aba86e9c2516 100644
--- a/drivers/base/arch_topology.c
+++ b/drivers/base/arch_topology.c
@@ -34,14 +34,7 @@ EXPORT_PER_CPU_SYMBOL_GPL(capacity_freq_ref);
static bool supports_scale_freq_counters(const struct cpumask *cpus)
{
- int i;
-
- for_each_cpu(i, cpus) {
- if (cpumask_test_cpu(i, &scale_freq_counters_mask))
- return true;
- }
-
- return false;
+ return cpumask_intersects(cpus, &scale_freq_counters_mask);
}
bool topology_scale_freq_invariant(void)
--
2.52.0
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH 5/5] arch_topology: Use cpumask_intersects where applicable
2026-11-11 7:59 ` [PATCH 5/5] arch_topology: Use cpumask_intersects " Shrikanth Hegde
@ 2026-11-11 10:20 ` Sudeep Holla
0 siblings, 0 replies; 10+ messages in thread
From: Sudeep Holla @ 2026-11-11 10:20 UTC (permalink / raw)
To: Shrikanth Hegde
Cc: linux-kernel, yury.norov, Sudeep Holla, linux-perf-users, mingo,
peterz, juri.lelli, vincent.guittot, tglx, linux
On Wed, Nov 11, 2026 at 01:29:45PM +0530, Shrikanth Hegde wrote:
> Looping over one cpumask and checking if any bit is set in another
> cpumask is same as evaluating if two cpumasks intersects or not.
>
> So use cpumask_intersects instead. It is probably faster too.
>
Reviewed-by: Sudeep Holla <sudeep.holla@kernel.org>
--
Regards,
Sudeep
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/5] cpumask: Use cpumask_intersects* APIs where applicable
2026-11-11 7:59 [PATCH 0/5] cpumask: Use cpumask_intersects* APIs where applicable Shrikanth Hegde
` (4 preceding siblings ...)
2026-11-11 7:59 ` [PATCH 5/5] arch_topology: Use cpumask_intersects " Shrikanth Hegde
@ 2026-11-11 9:16 ` Peter Zijlstra
2026-11-11 9:22 ` Shrikanth Hegde
5 siblings, 1 reply; 10+ messages in thread
From: Peter Zijlstra @ 2026-11-11 9:16 UTC (permalink / raw)
To: Shrikanth Hegde
Cc: linux-kernel, yury.norov, linux-perf-users, mingo, juri.lelli,
vincent.guittot, tglx, sudeep.holla, linux, Rafael J. Wysocki
On Wed, Nov 11, 2026 at 01:29:40PM +0530, Shrikanth Hegde wrote:
> Shrikanth Hegde (5):
> cpuidle: Use cpumask_intersects_and where applicable
> arch_topology: Use cpumask_intersects where applicable
> drivers/base/arch_topology.c | 9 +--------
> drivers/cpuidle/coupled.c | 4 ++--
That's not actually code I maintain. That's rjw stuff.
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH 0/5] cpumask: Use cpumask_intersects* APIs where applicable
2026-11-11 9:16 ` [PATCH 0/5] cpumask: Use cpumask_intersects* APIs " Peter Zijlstra
@ 2026-11-11 9:22 ` Shrikanth Hegde
2026-11-11 10:10 ` Peter Zijlstra
0 siblings, 1 reply; 10+ messages in thread
From: Shrikanth Hegde @ 2026-11-11 9:22 UTC (permalink / raw)
To: Peter Zijlstra, Rafael J. Wysocki
Cc: linux-kernel, yury.norov, linux-perf-users, mingo, juri.lelli,
vincent.guittot, tglx, sudeep.holla, linux
On 11/11/26 2:46 PM, Peter Zijlstra wrote:
> On Wed, Nov 11, 2026 at 01:29:40PM +0530, Shrikanth Hegde wrote:
>
>> Shrikanth Hegde (5):
>
>> cpuidle: Use cpumask_intersects_and where applicable
>> arch_topology: Use cpumask_intersects where applicable
>
>> drivers/base/arch_topology.c | 9 +--------
>> drivers/cpuidle/coupled.c | 4 ++--
>
> That's not actually code I maintain. That's rjw stuff.
Yes. Sorry, I should have cc'ed him.
Should I split this series and send it to each subsystem instead?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/5] cpumask: Use cpumask_intersects* APIs where applicable
2026-11-11 9:22 ` Shrikanth Hegde
@ 2026-11-11 10:10 ` Peter Zijlstra
0 siblings, 0 replies; 10+ messages in thread
From: Peter Zijlstra @ 2026-11-11 10:10 UTC (permalink / raw)
To: Shrikanth Hegde
Cc: Rafael J. Wysocki, linux-kernel, yury.norov, linux-perf-users,
mingo, juri.lelli, vincent.guittot, tglx, sudeep.holla, linux
On Wed, Nov 11, 2026 at 02:52:58PM +0530, Shrikanth Hegde wrote:
>
>
> On 11/11/26 2:46 PM, Peter Zijlstra wrote:
> > On Wed, Nov 11, 2026 at 01:29:40PM +0530, Shrikanth Hegde wrote:
> >
> > > Shrikanth Hegde (5):
> >
> > > cpuidle: Use cpumask_intersects_and where applicable
> > > arch_topology: Use cpumask_intersects where applicable
> > > drivers/base/arch_topology.c | 9 +--------
> > > drivers/cpuidle/coupled.c | 4 ++--
> >
> > That's not actually code I maintain. That's rjw stuff.
>
> Yes. Sorry, I should have cc'ed him.
>
> Should I split this series and send it to each subsystem instead?
I've taken the first 3 patches since that's all tip stuff. Feel free to
resend the last two with appropriate Ccs. Its all independent patches
anyway.
^ permalink raw reply [flat|nested] 10+ messages in thread