* [PATCH 0/2] powerpc: A few misc cpumask refactors
@ 2026-03-27 6:31 Shrikanth Hegde
2026-03-27 6:31 ` [PATCH 1/2] powerpc: Use cpumask_next_wrap instead Shrikanth Hegde
2026-03-27 6:31 ` [PATCH 2/2] powerpc: Few misc cpumask code refactors Shrikanth Hegde
0 siblings, 2 replies; 6+ messages in thread
From: Shrikanth Hegde @ 2026-03-27 6:31 UTC (permalink / raw)
To: maddy, linuxppc-dev, yury.norov, linux, linux-kernel; +Cc: sshegde, chleroy
While going through the code, spotted these cpumask miscellaneous
changes. These are pure code refactors, they dont affect functionality
or performance. They just use the updated cpumask api and remove some
checks which are not necessary now.
Major one being:
cpu = cpumask_next(cpu, mask)
if (cpu >= nr_cpu_ids)
cpu = cpumask_first(mask)
Above block can be replaced by cpu = cpumask_next_wrap(cpu, mask)
Note that exact same blocks are still present in:
arch/x86/kernel/tsc_sync.c
drivers/char/random.c
drivers/net/wireguard/queueing.h
drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c
drivers/net/ethernet/sfc/siena/efx_channels.c
drivers/net/ethernet/sfc/efx_channels.c
kernel/rcu/rcutorture.c
Yury, Rasmus,
Do you think it makes sense to send for the above files too?
Shrikanth Hegde (2):
powerpc: Use cpumask_next_wrap instead
powerpc: Few misc cpumask code refactors
arch/powerpc/kernel/irq.c | 5 +----
arch/powerpc/kernel/setup-common.c | 7 ++-----
arch/powerpc/mm/book3s64/hash_utils.c | 4 +---
arch/powerpc/sysdev/xive/common.c | 12 ++++--------
4 files changed, 8 insertions(+), 20 deletions(-)
--
2.47.3
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] powerpc: Use cpumask_next_wrap instead
2026-03-27 6:31 [PATCH 0/2] powerpc: A few misc cpumask refactors Shrikanth Hegde
@ 2026-03-27 6:31 ` Shrikanth Hegde
2026-03-28 20:44 ` Yury Norov
2026-03-27 6:31 ` [PATCH 2/2] powerpc: Few misc cpumask code refactors Shrikanth Hegde
1 sibling, 1 reply; 6+ messages in thread
From: Shrikanth Hegde @ 2026-03-27 6:31 UTC (permalink / raw)
To: maddy, linuxppc-dev, yury.norov, linux, linux-kernel; +Cc: sshegde, chleroy
cpu = cpumask_next(cpu, mask)
if (cpu >= nr_cpu_ids)
cpu = cpumask_first(mask)
Above block is identical to:
cpu = cpumask_next_wrap(cpu, mask)
Replace it, No change in functionality or performance.
Slightly simpler code.
Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
---
arch/powerpc/kernel/irq.c | 5 +----
arch/powerpc/mm/book3s64/hash_utils.c | 4 +---
arch/powerpc/sysdev/xive/common.c | 5 +----
3 files changed, 3 insertions(+), 11 deletions(-)
diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
index a0e8b998c9b5..f69de08ad347 100644
--- a/arch/powerpc/kernel/irq.c
+++ b/arch/powerpc/kernel/irq.c
@@ -370,10 +370,7 @@ int irq_choose_cpu(const struct cpumask *mask)
do_round_robin:
raw_spin_lock_irqsave(&irq_rover_lock, flags);
- irq_rover = cpumask_next(irq_rover, cpu_online_mask);
- if (irq_rover >= nr_cpu_ids)
- irq_rover = cpumask_first(cpu_online_mask);
-
+ irq_rover = cpumask_next_wrap(irq_rover, cpu_online_mask);
cpuid = irq_rover;
raw_spin_unlock_irqrestore(&irq_rover_lock, flags);
diff --git a/arch/powerpc/mm/book3s64/hash_utils.c b/arch/powerpc/mm/book3s64/hash_utils.c
index 9dc5889d6ecb..e4fcf929cb33 100644
--- a/arch/powerpc/mm/book3s64/hash_utils.c
+++ b/arch/powerpc/mm/book3s64/hash_utils.c
@@ -1299,9 +1299,7 @@ static void stress_hpt_timer_fn(struct timer_list *timer)
if (!firmware_has_feature(FW_FEATURE_LPAR))
tlbiel_all();
- next_cpu = cpumask_next(raw_smp_processor_id(), cpu_online_mask);
- if (next_cpu >= nr_cpu_ids)
- next_cpu = cpumask_first(cpu_online_mask);
+ next_cpu = cpumask_next_wrap(raw_smp_processor_id(), cpu_online_mask);
stress_hpt_timer.expires = jiffies + msecs_to_jiffies(10);
add_timer_on(&stress_hpt_timer, next_cpu);
}
diff --git a/arch/powerpc/sysdev/xive/common.c b/arch/powerpc/sysdev/xive/common.c
index e1a4f8a97393..b6446abe29a6 100644
--- a/arch/powerpc/sysdev/xive/common.c
+++ b/arch/powerpc/sysdev/xive/common.c
@@ -577,10 +577,7 @@ static int xive_find_target_in_mask(const struct cpumask *mask,
*/
if (cpu_online(cpu) && xive_try_pick_target(cpu))
return cpu;
- cpu = cpumask_next(cpu, mask);
- /* Wrap around */
- if (cpu >= nr_cpu_ids)
- cpu = cpumask_first(mask);
+ cpu = cpumask_next_wrap(cpu, mask);
} while (cpu != first);
return -1;
--
2.47.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] powerpc: Few misc cpumask code refactors
2026-03-27 6:31 [PATCH 0/2] powerpc: A few misc cpumask refactors Shrikanth Hegde
2026-03-27 6:31 ` [PATCH 1/2] powerpc: Use cpumask_next_wrap instead Shrikanth Hegde
@ 2026-03-27 6:31 ` Shrikanth Hegde
2026-03-28 20:27 ` Yury Norov
1 sibling, 1 reply; 6+ messages in thread
From: Shrikanth Hegde @ 2026-03-27 6:31 UTC (permalink / raw)
To: maddy, linuxppc-dev, yury.norov, linux, linux-kernel; +Cc: sshegde, chleroy
A few miscellanous changes in handling cpumask api's in the order
they appear:
- cpumask_next(cpu, mask) >= nr_cpu_ids is used to determine if
cpu is the last CPU.
- cpumask_next can take -1 as valid argument. So simplify cpuinfo
iterator. /proc/cpuinfo shows same info with patch.
- cpumask_weight can't be more than nr_cpu_ids. So remove the pointless
comparison.
Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
---
arch/powerpc/kernel/setup-common.c | 7 ++-----
arch/powerpc/sysdev/xive/common.c | 7 +++----
2 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/arch/powerpc/kernel/setup-common.c b/arch/powerpc/kernel/setup-common.c
index b1761909c23f..47215eab296b 100644
--- a/arch/powerpc/kernel/setup-common.c
+++ b/arch/powerpc/kernel/setup-common.c
@@ -323,7 +323,7 @@ static int show_cpuinfo(struct seq_file *m, void *v)
seq_putc(m, '\n');
/* If this is the last cpu, print the summary */
- if (cpumask_next(cpu_id, cpu_online_mask) >= nr_cpu_ids)
+ if (cpu_id == cpumask_last(cpu_online_mask))
show_cpuinfo_summary(m);
return 0;
@@ -331,10 +331,7 @@ static int show_cpuinfo(struct seq_file *m, void *v)
static void *c_start(struct seq_file *m, loff_t *pos)
{
- if (*pos == 0) /* just in case, cpu 0 is not the first */
- *pos = cpumask_first(cpu_online_mask);
- else
- *pos = cpumask_next(*pos - 1, cpu_online_mask);
+ *pos = cpumask_next(*pos - 1, cpu_online_mask);
if ((*pos) < nr_cpu_ids)
return (void *)(unsigned long)(*pos + 1);
return NULL;
diff --git a/arch/powerpc/sysdev/xive/common.c b/arch/powerpc/sysdev/xive/common.c
index b6446abe29a6..91dd3b364d7d 100644
--- a/arch/powerpc/sysdev/xive/common.c
+++ b/arch/powerpc/sysdev/xive/common.c
@@ -548,11 +548,10 @@ static void xive_dec_target_count(int cpu)
static int xive_find_target_in_mask(const struct cpumask *mask,
unsigned int fuzz)
{
- int cpu, first, num, i;
+ int cpu, first, i;
- /* Pick up a starting point CPU in the mask based on fuzz */
- num = min_t(int, cpumask_weight(mask), nr_cpu_ids);
- first = fuzz % num;
+ /* Pick up a starting point CPU in the mask based on fuzz */
+ first = fuzz % cpumask_weight(mask);
/* Locate it */
cpu = cpumask_first(mask);
--
2.47.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] powerpc: Few misc cpumask code refactors
2026-03-27 6:31 ` [PATCH 2/2] powerpc: Few misc cpumask code refactors Shrikanth Hegde
@ 2026-03-28 20:27 ` Yury Norov
0 siblings, 0 replies; 6+ messages in thread
From: Yury Norov @ 2026-03-28 20:27 UTC (permalink / raw)
To: Shrikanth Hegde
Cc: maddy, linuxppc-dev, yury.norov, linux, linux-kernel, chleroy
On Fri, Mar 27, 2026 at 12:01:29PM +0530, Shrikanth Hegde wrote:
> A few miscellanous changes in handling cpumask api's in the order
> they appear:
>
> - cpumask_next(cpu, mask) >= nr_cpu_ids is used to determine if
> cpu is the last CPU.
>
> - cpumask_next can take -1 as valid argument. So simplify cpuinfo
> iterator. /proc/cpuinfo shows same info with patch.
>
> - cpumask_weight can't be more than nr_cpu_ids. So remove the pointless
> comparison.
>
> Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
> ---
> arch/powerpc/kernel/setup-common.c | 7 ++-----
> arch/powerpc/sysdev/xive/common.c | 7 +++----
> 2 files changed, 5 insertions(+), 9 deletions(-)
>
> diff --git a/arch/powerpc/kernel/setup-common.c b/arch/powerpc/kernel/setup-common.c
> index b1761909c23f..47215eab296b 100644
> --- a/arch/powerpc/kernel/setup-common.c
> +++ b/arch/powerpc/kernel/setup-common.c
> @@ -323,7 +323,7 @@ static int show_cpuinfo(struct seq_file *m, void *v)
> seq_putc(m, '\n');
>
> /* If this is the last cpu, print the summary */
> - if (cpumask_next(cpu_id, cpu_online_mask) >= nr_cpu_ids)
> + if (cpu_id == cpumask_last(cpu_online_mask))
> show_cpuinfo_summary(m);
>
> return 0;
> @@ -331,10 +331,7 @@ static int show_cpuinfo(struct seq_file *m, void *v)
>
> static void *c_start(struct seq_file *m, loff_t *pos)
> {
> - if (*pos == 0) /* just in case, cpu 0 is not the first */
> - *pos = cpumask_first(cpu_online_mask);
> - else
> - *pos = cpumask_next(*pos - 1, cpu_online_mask);
> + *pos = cpumask_next(*pos - 1, cpu_online_mask);
> if ((*pos) < nr_cpu_ids)
> return (void *)(unsigned long)(*pos + 1);
> return NULL;
> diff --git a/arch/powerpc/sysdev/xive/common.c b/arch/powerpc/sysdev/xive/common.c
> index b6446abe29a6..91dd3b364d7d 100644
> --- a/arch/powerpc/sysdev/xive/common.c
> +++ b/arch/powerpc/sysdev/xive/common.c
> @@ -548,11 +548,10 @@ static void xive_dec_target_count(int cpu)
> static int xive_find_target_in_mask(const struct cpumask *mask,
> unsigned int fuzz)
> {
> - int cpu, first, num, i;
> + int cpu, first, i;
>
> - /* Pick up a starting point CPU in the mask based on fuzz */
> - num = min_t(int, cpumask_weight(mask), nr_cpu_ids);
> - first = fuzz % num;
> + /* Pick up a starting point CPU in the mask based on fuzz */
> + first = fuzz % cpumask_weight(mask);
For this function I've got a deeper rework.
https://lore.kernel.org/all/20260319033647.881246-3-ynorov@nvidia.com/
For the rest:
Reviewed-by: Yury Norov <ynorov@nvidia.com>
>
> /* Locate it */
> cpu = cpumask_first(mask);
> --
> 2.47.3
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] powerpc: Use cpumask_next_wrap instead
2026-03-27 6:31 ` [PATCH 1/2] powerpc: Use cpumask_next_wrap instead Shrikanth Hegde
@ 2026-03-28 20:44 ` Yury Norov
2026-03-29 9:18 ` Shrikanth Hegde
0 siblings, 1 reply; 6+ messages in thread
From: Yury Norov @ 2026-03-28 20:44 UTC (permalink / raw)
To: Shrikanth Hegde
Cc: maddy, linuxppc-dev, yury.norov, linux, linux-kernel, chleroy
On Fri, Mar 27, 2026 at 12:01:28PM +0530, Shrikanth Hegde wrote:
> cpu = cpumask_next(cpu, mask)
> if (cpu >= nr_cpu_ids)
> cpu = cpumask_first(mask)
>
> Above block is identical to:
> cpu = cpumask_next_wrap(cpu, mask)
>
> Replace it, No change in functionality or performance.
> Slightly simpler code.
>
> Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
> ---
> arch/powerpc/kernel/irq.c | 5 +----
> arch/powerpc/mm/book3s64/hash_utils.c | 4 +---
> arch/powerpc/sysdev/xive/common.c | 5 +----
> 3 files changed, 3 insertions(+), 11 deletions(-)
>
> diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
> index a0e8b998c9b5..f69de08ad347 100644
> --- a/arch/powerpc/kernel/irq.c
> +++ b/arch/powerpc/kernel/irq.c
> @@ -370,10 +370,7 @@ int irq_choose_cpu(const struct cpumask *mask)
> do_round_robin:
> raw_spin_lock_irqsave(&irq_rover_lock, flags);
>
> - irq_rover = cpumask_next(irq_rover, cpu_online_mask);
> - if (irq_rover >= nr_cpu_ids)
> - irq_rover = cpumask_first(cpu_online_mask);
> -
> + irq_rover = cpumask_next_wrap(irq_rover, cpu_online_mask);
> cpuid = irq_rover;
>
> raw_spin_unlock_irqrestore(&irq_rover_lock, flags);
> diff --git a/arch/powerpc/mm/book3s64/hash_utils.c b/arch/powerpc/mm/book3s64/hash_utils.c
> index 9dc5889d6ecb..e4fcf929cb33 100644
> --- a/arch/powerpc/mm/book3s64/hash_utils.c
> +++ b/arch/powerpc/mm/book3s64/hash_utils.c
> @@ -1299,9 +1299,7 @@ static void stress_hpt_timer_fn(struct timer_list *timer)
> if (!firmware_has_feature(FW_FEATURE_LPAR))
> tlbiel_all();
>
> - next_cpu = cpumask_next(raw_smp_processor_id(), cpu_online_mask);
> - if (next_cpu >= nr_cpu_ids)
> - next_cpu = cpumask_first(cpu_online_mask);
> + next_cpu = cpumask_next_wrap(raw_smp_processor_id(), cpu_online_mask);
> stress_hpt_timer.expires = jiffies + msecs_to_jiffies(10);
> add_timer_on(&stress_hpt_timer, next_cpu);
> }
> diff --git a/arch/powerpc/sysdev/xive/common.c b/arch/powerpc/sysdev/xive/common.c
> index e1a4f8a97393..b6446abe29a6 100644
> --- a/arch/powerpc/sysdev/xive/common.c
> +++ b/arch/powerpc/sysdev/xive/common.c
> @@ -577,10 +577,7 @@ static int xive_find_target_in_mask(const struct cpumask *mask,
> */
> if (cpu_online(cpu) && xive_try_pick_target(cpu))
> return cpu;
> - cpu = cpumask_next(cpu, mask);
> - /* Wrap around */
> - if (cpu >= nr_cpu_ids)
> - cpu = cpumask_first(mask);
> + cpu = cpumask_next_wrap(cpu, mask);
Again, for all except this:
Reviewed-by: Yury Norov <yury.norov@gmail.com>
Can you move my series for xive_find_target_in_mask() together with
your patches?
> } while (cpu != first);
>
> return -1;
> --
> 2.47.3
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] powerpc: Use cpumask_next_wrap instead
2026-03-28 20:44 ` Yury Norov
@ 2026-03-29 9:18 ` Shrikanth Hegde
0 siblings, 0 replies; 6+ messages in thread
From: Shrikanth Hegde @ 2026-03-29 9:18 UTC (permalink / raw)
To: Yury Norov; +Cc: maddy, linuxppc-dev, yury.norov, linux, linux-kernel, chleroy
Hi Yury.
On 3/29/26 2:14 AM, Yury Norov wrote:
> On Fri, Mar 27, 2026 at 12:01:28PM +0530, Shrikanth Hegde wrote:
>> cpu = cpumask_next(cpu, mask)
>> if (cpu >= nr_cpu_ids)
>> cpu = cpumask_first(mask)
>>
>> Above block is identical to:
>> cpu = cpumask_next_wrap(cpu, mask)
>>
>> Replace it, No change in functionality or performance.
>> Slightly simpler code.
>>
>> Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
>> ---
>> arch/powerpc/kernel/irq.c | 5 +----
>> arch/powerpc/mm/book3s64/hash_utils.c | 4 +---
>> arch/powerpc/sysdev/xive/common.c | 5 +----
>> 3 files changed, 3 insertions(+), 11 deletions(-)
>>
>> diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
>> index a0e8b998c9b5..f69de08ad347 100644
>> --- a/arch/powerpc/kernel/irq.c
>> +++ b/arch/powerpc/kernel/irq.c
>> @@ -370,10 +370,7 @@ int irq_choose_cpu(const struct cpumask *mask)
>> do_round_robin:
>> raw_spin_lock_irqsave(&irq_rover_lock, flags);
>>
>> - irq_rover = cpumask_next(irq_rover, cpu_online_mask);
>> - if (irq_rover >= nr_cpu_ids)
>> - irq_rover = cpumask_first(cpu_online_mask);
>> -
>> + irq_rover = cpumask_next_wrap(irq_rover, cpu_online_mask);
>> cpuid = irq_rover;
>>
>> raw_spin_unlock_irqrestore(&irq_rover_lock, flags);
>> diff --git a/arch/powerpc/mm/book3s64/hash_utils.c b/arch/powerpc/mm/book3s64/hash_utils.c
>> index 9dc5889d6ecb..e4fcf929cb33 100644
>> --- a/arch/powerpc/mm/book3s64/hash_utils.c
>> +++ b/arch/powerpc/mm/book3s64/hash_utils.c
>> @@ -1299,9 +1299,7 @@ static void stress_hpt_timer_fn(struct timer_list *timer)
>> if (!firmware_has_feature(FW_FEATURE_LPAR))
>> tlbiel_all();
>>
>> - next_cpu = cpumask_next(raw_smp_processor_id(), cpu_online_mask);
>> - if (next_cpu >= nr_cpu_ids)
>> - next_cpu = cpumask_first(cpu_online_mask);
>> + next_cpu = cpumask_next_wrap(raw_smp_processor_id(), cpu_online_mask);
>> stress_hpt_timer.expires = jiffies + msecs_to_jiffies(10);
>> add_timer_on(&stress_hpt_timer, next_cpu);
>> }
>> diff --git a/arch/powerpc/sysdev/xive/common.c b/arch/powerpc/sysdev/xive/common.c
>> index e1a4f8a97393..b6446abe29a6 100644
>> --- a/arch/powerpc/sysdev/xive/common.c
>> +++ b/arch/powerpc/sysdev/xive/common.c
>> @@ -577,10 +577,7 @@ static int xive_find_target_in_mask(const struct cpumask *mask,
>> */
>> if (cpu_online(cpu) && xive_try_pick_target(cpu))
>> return cpu;
>> - cpu = cpumask_next(cpu, mask);
>> - /* Wrap around */
>> - if (cpu >= nr_cpu_ids)
>> - cpu = cpumask_first(mask);
>> + cpu = cpumask_next_wrap(cpu, mask);
>
> Again, for all except this:
>
> Reviewed-by: Yury Norov <yury.norov@gmail.com>
>
Thanks for the review.
>
> Can you move my series for xive_find_target_in_mask() together with
> your patches?
Sure.
I can add your patch to this series and send it.
PS: Sorry, I hadn't seen your series.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-03-29 9:18 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-27 6:31 [PATCH 0/2] powerpc: A few misc cpumask refactors Shrikanth Hegde
2026-03-27 6:31 ` [PATCH 1/2] powerpc: Use cpumask_next_wrap instead Shrikanth Hegde
2026-03-28 20:44 ` Yury Norov
2026-03-29 9:18 ` Shrikanth Hegde
2026-03-27 6:31 ` [PATCH 2/2] powerpc: Few misc cpumask code refactors Shrikanth Hegde
2026-03-28 20:27 ` Yury Norov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox