powerpc: A few misc cpumask refactors
Shrikanth Hegde
reviewercover powerpc: A few misc cpumask refactors
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.cdrivers/char/random.cdrivers/net/wireguard/queueing.hdrivers/net/ethernet/freescale/dpaa2/dpaa2-eth.cdrivers/net/ethernet/sfc/siena/efx_channels.cdrivers/net/ethernet/sfc/efx_channels.ckernel/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(-)
Signature · 1 line
2.47.3
Shrikanth Hegde
reviewerPATCH 1/2 powerpc: Use cpumask_next_wrap instead
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.
--- 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(-)
arch/powerpc/kernel/irq.c +1 -4
@@ -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);
arch/powerpc/mm/book3s64/hash_utils.c +1 -3
@@ -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); }
arch/powerpc/sysdev/xive/common.c +1 -4
@@ -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 ;
Signature · 1 line
2.47.3
Shrikanth Hegde
reviewerPATCH 2/2 powerpc: Few misc cpumask code refactors
In reply to Shrikanth HegdeA 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.
--- arch/powerpc/kernel/setup-common.c | 7 ++----- arch/powerpc/sysdev/xive/common.c | 7 +++---- 2 files changed, 5 insertions(+), 9 deletions(-)
arch/powerpc/kernel/setup-common.c +2 -5
@@ -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 ;
arch/powerpc/sysdev/xive/common.c +3 -4
@@ -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);
Signature · 1 line
2.47.3
Re: [PATCH 2/2] powerpc: Few misc cpumask code refactors
Quoted 49 lines · Shrikanth Hegde
A few miscellanous changes in handling cpumask api's in the order they appear:
-
cpumask_next(cpu, mask)>=nr_cpu_idsis used to determine if cpu is the last CPU.-
cpumask_nextcan take -1 as valid argument. So simplify cpuinfo iterator./proc/cpuinfoshows same info with patch.-
cpumask_weightcan't be more thannr_cpu_ids. So remove the pointless comparison.Signed-off-by Shrikanth Hegde <[email protected]>--- arch/powerpc/kernel/setup-common.c | 7 ++----- arch/powerpc/sysdev/xive/common.c | 7 +++---- 2 files changed, 5 insertions(+), 9 deletions(-)arch/powerpc/kernel/setup-common.c +2
-5@@ -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 ;arch/powerpc/sysdev/xive/common.c +0
-0@@ -548,11 +548,10 @@ static void xive_dec_target_count(int cpu) static int xive_find_target_in_mask(const struct cpumask *mask,
arch/powerpc/sysdev/xive/common.c static void xive_dec_target_count(int cpu) · line 554
Quoted 10 lines
arch/powerpc/sysdev/xive/common.c +3
-4unsigned 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/[email protected]/
For the rest:
Quoted 5 lines
arch/powerpc/sysdev/xive/common.c +0
-0/* Locate it */ cpu =cpumask_first (mask);Signature · 1 line
2.47.3
Re: [PATCH 1/2] powerpc: Use cpumask_next_wrap instead
In reply to Shrikanth HegdeQuoted 53 lines · Shrikanth Hegde
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 <[email protected]>--- 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(-)arch/powerpc/kernel/irq.c +1
-4@@ -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);arch/powerpc/mm/book3s64/hash_utils.c +1
-3@@ -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); }arch/powerpc/sysdev/xive/common.c +0
-0
arch/powerpc/sysdev/xive/common.c static int xive_find_target_in_mask(const struct cpumask *mask, · line 580
Quoted 8 lines
arch/powerpc/sysdev/xive/common.c +1
-4@@ -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:
Can you move my series for xive_find_target_in_mask() together with your patches?
Quoted 5 lines
arch/powerpc/sysdev/xive/common.c +0
-0}while (cpu != first);return -1 ;Signature · 1 line
2.47.3
Shrikanth Hegde
reviewerRe: [PATCH 1/2] powerpc: Use cpumask_next_wrap instead
Hi Yury.
Quoted 65 lines · Yury Norov
Quoted 53 lines · Shrikanth Hegde
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 <[email protected]>--- 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(-)arch/powerpc/kernel/irq.c +1
-4@@ -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);arch/powerpc/mm/book3s64/hash_utils.c +1
-3@@ -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); }arch/powerpc/sysdev/xive/common.c +0
-0arch/powerpc/sysdev/xive/common.c static int xive_find_target_in_mask(const struct cpumask *mask, · line 580
Quoted 8 lines
arch/powerpc/sysdev/xive/common.c +1
-4@@ -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:
Quoted 2 lines
Reviewed-by Yury Norov <[email protected]>
Thanks for the review.
Quoted 3 lines
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.