Skip to content

Commit 4f09903

Browse files
svanheuleakpm00
authored andcommitted
cpumask: add UP optimised for_each_*_cpu versions
On uniprocessor builds, the following loops will always run over a mask that contains one enabled CPU (cpu0): - for_each_possible_cpu - for_each_online_cpu - for_each_present_cpu Provide uniprocessor-specific macros for these loops, that always run exactly once. Link: https://lkml.kernel.org/r/3a92869b902a075b97be5d1452c9c6badbbff0df.1656777646.git.sander@svanheule.net Signed-off-by: Sander Vanheule <[email protected]> Acked-by: Yury Norov <[email protected]> Cc: Andy Shevchenko <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Marco Elver <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Valentin Schneider <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent adbcaef commit 4f09903

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

include/linux/cpumask.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,9 +811,16 @@ extern const DECLARE_BITMAP(cpu_all_bits, NR_CPUS);
811811
/* First bits of cpu_bit_bitmap are in fact unset. */
812812
#define cpu_none_mask to_cpumask(cpu_bit_bitmap[0])
813813

814+
#if NR_CPUS == 1
815+
/* Uniprocessor: the possible/online/present masks are always "1" */
816+
#define for_each_possible_cpu(cpu) for ((cpu) = 0; (cpu) < 1; (cpu)++)
817+
#define for_each_online_cpu(cpu) for ((cpu) = 0; (cpu) < 1; (cpu)++)
818+
#define for_each_present_cpu(cpu) for ((cpu) = 0; (cpu) < 1; (cpu)++)
819+
#else
814820
#define for_each_possible_cpu(cpu) for_each_cpu((cpu), cpu_possible_mask)
815821
#define for_each_online_cpu(cpu) for_each_cpu((cpu), cpu_online_mask)
816822
#define for_each_present_cpu(cpu) for_each_cpu((cpu), cpu_present_mask)
823+
#endif
817824

818825
/* Wrappers for arch boot code to manipulate normally-constant masks */
819826
void init_cpu_present(const struct cpumask *src);

0 commit comments

Comments
 (0)