mips: micro-optimize calculate_cpu_foreign_map()
PATCH 1/1 mips: micro-optimize calculate_cpu_foreign_map()
The inner loop in calculate_cpu_foreign_map() walks the whole cpumask to check if we have siblings for a given cpu.
We can just break after a 1st match and avoid useless traversing the rest of mask.
Loongarch has an identical function, so fix it here as well.
---
It looks like loongarch copied quite a lot from arch/mips/kernel/smp.c. For loongarch folks: Guys, can you consider moving shared code into a shared file(s)?
arch/loongarch/kernel/smp.c | 7 +++---- arch/mips/kernel/smp.c | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-)
arch/loongarch/kernel/smp.c +3 -4
@@ -463,17 +463,16 @@ static inline void set_cpu_core_map(int cpu)*/ void calculate_cpu_foreign_map (void ) { -int i, k, core_present; +int i, k;cpumask_t temp_foreign_map;/* Re-calculate the mask */ cpumask_clear (&temp_foreign_map);for_each_online_cpu (i) { - core_present =0 ;for_each_cpu (k, &temp_foreign_map)if (cpus_are_siblings (i, k)) - core_present =1 ; -if (!core_present) +break ; +if (k >= nr_cpu_ids)cpumask_set_cpu (i, &temp_foreign_map); }
arch/mips/kernel/smp.c +3 -4
@@ -115,17 +115,16 @@ static inline void set_cpu_core_map(int cpu)*/ void calculate_cpu_foreign_map (void ) { -int i, k, core_present; +int i, k;cpumask_t temp_foreign_map;/* Re-calculate the mask */ cpumask_clear (&temp_foreign_map);for_each_online_cpu (i) { - core_present =0 ;for_each_cpu (k, &temp_foreign_map)if (cpus_are_siblings (i, k)) - core_present =1 ; -if (!core_present) +break ; +if (k >= nr_cpu_ids)cpumask_set_cpu (i, &temp_foreign_map); }
Signature · 1 line
2.32.0
Quoted 9 lines · Yury Norov
The inner loop in
calculate_cpu_foreign_map()walks the whole cpumask to check if we have siblings for a given cpu.We can just break after a 1st match and avoid useless traversing the rest of mask.
Loongarch has an identical function, so fix it here as well.
Signed-off-by Yury Norov <[email protected]>
Ping?
Quoted 62 lines
---
It looks like loongarch copied quite a lot from
arch/mips/kernel/smp.c. For loongarch folks: Guys, can you consider moving shared code into a shared file(s)?arch/loongarch/kernel/smp.c | 7 +++---- arch/mips/kernel/smp.c | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-)arch/loongarch/kernel/smp.c +3
-4@@ -463,17 +463,16 @@ static inline void set_cpu_core_map(int cpu)*/ void calculate_cpu_foreign_map (void ) { -int i, k, core_present; +int i, k;cpumask_t temp_foreign_map;/* Re-calculate the mask */ cpumask_clear (&temp_foreign_map);for_each_online_cpu (i) { - core_present =0 ;for_each_cpu (k, &temp_foreign_map)if (cpus_are_siblings (i, k)) - core_present =1 ; -if (!core_present) +break ; +if (k >= nr_cpu_ids)cpumask_set_cpu (i, &temp_foreign_map); }arch/mips/kernel/smp.c +3
-4@@ -115,17 +115,16 @@ static inline void set_cpu_core_map(int cpu)*/ void calculate_cpu_foreign_map (void ) { -int i, k, core_present; +int i, k;cpumask_t temp_foreign_map;/* Re-calculate the mask */ cpumask_clear (&temp_foreign_map);for_each_online_cpu (i) { - core_present =0 ;for_each_cpu (k, &temp_foreign_map)if (cpus_are_siblings (i, k)) - core_present =1 ; -if (!core_present) +break ; +if (k >= nr_cpu_ids)cpumask_set_cpu (i, &temp_foreign_map); }Signature · 1 line
2.32.0
Thomas Bogendoerfer
maintainerQuoted 4 lines · Yury Norov
Quoted 3 lines · Yury Norov
The inner loop in
calculate_cpu_foreign_map()walks the whole cpumask to check if we have siblings for a given cpu.
Quoted 8 lines
Quoted 6 lines
We can just break after a 1st match and avoid useless traversing the rest of mask.
Loongarch has an identical function, so fix it here as well.
Signed-off-by Yury Norov <[email protected]>Ping?
as this is touching two different archs, it would have been easier to send this in two different patches.
Huacai, should I take the patch ?
Thomas.
Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a good idea. [ RFC1925, 2.3 ]