Skip to content

Commit 2530ba5

Browse files
galakstephanosio
authored andcommitted
arch: smp: Allow for number of cpus to be determined at runtime
Introduce a Kconfig (MP_MAX_NUM_CPUS) and an api arch_num_cpus() to allow for systems that might determine the number of CPUs available to Zephyr at runtime. CONFIG_MP_MAX_NUM_CPUS is intented to be use for any array initialization and such that need to occur at build time. For most systems arch_num_cpus() will just report the value of CONFIG_MP_MAX_NUM_CPUS. The intent is to phase out CONFIG_NP_NUM_CPUS. Signed-off-by: Kumar Gala <[email protected]>
1 parent 2666702 commit 2530ba5

File tree

8 files changed

+49
-0
lines changed

8 files changed

+49
-0
lines changed

include/zephyr/arch/arc/arch_inlines.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,10 @@ static ALWAYS_INLINE uint32_t arch_proc_id(void)
3636
return arch_curr_cpu()->id;
3737
}
3838

39+
static ALWAYS_INLINE unsigned int arch_num_cpus(void)
40+
{
41+
return CONFIG_MP_MAX_NUM_CPUS;
42+
}
43+
3944
#endif /* !_ASMLANGUAGE */
4045
#endif /* ZEPHYR_INCLUDE_ARCH_XTENSA_ARCH_INLINES_H_ */

include/zephyr/arch/arm/aarch32/arch_inlines.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@ static ALWAYS_INLINE uint32_t arch_proc_id(void)
2626
return arch_curr_cpu()->id;
2727
}
2828

29+
static ALWAYS_INLINE unsigned int arch_num_cpus(void)
30+
{
31+
return CONFIG_MP_MAX_NUM_CPUS;
32+
}
33+
2934
#endif /* ZEPHYR_INCLUDE_ARCH_ARM_AARCH32_ARCH_INLINES_H */

include/zephyr/arch/arm64/arch_inlines.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,10 @@ static ALWAYS_INLINE uint32_t arch_proc_id(void)
3333
return (uint32_t)cpu_mpid;
3434
}
3535

36+
static ALWAYS_INLINE unsigned int arch_num_cpus(void)
37+
{
38+
return CONFIG_MP_MAX_NUM_CPUS;
39+
}
40+
3641
#endif /* !_ASMLANGUAGE */
3742
#endif /* ZEPHYR_INCLUDE_ARCH_ARM64_ARCH_INLINES_H */

include/zephyr/arch/riscv/arch_inlines.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,10 @@ static ALWAYS_INLINE _cpu_t *arch_curr_cpu(void)
3030
return &_kernel.cpus[arch_proc_id()];
3131
}
3232

33+
static ALWAYS_INLINE unsigned int arch_num_cpus(void)
34+
{
35+
return CONFIG_MP_MAX_NUM_CPUS;
36+
}
37+
3338
#endif /* !_ASMLANGUAGE */
3439
#endif /* ZEPHYR_INCLUDE_ARCH_RISCV_ARCH_INLINES_H_ */

include/zephyr/arch/x86/arch_inlines.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ static ALWAYS_INLINE uint32_t arch_proc_id(void)
3535
return arch_curr_cpu()->id;
3636
}
3737

38+
static ALWAYS_INLINE unsigned int arch_num_cpus(void)
39+
{
40+
return CONFIG_MP_MAX_NUM_CPUS;
41+
}
42+
3843
#endif /* CONFIG_X86_64 */
3944

4045
#endif /* !_ASMLANGUAGE */

include/zephyr/arch/xtensa/arch_inlines.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ static ALWAYS_INLINE uint32_t arch_proc_id(void)
5050
return prid;
5151
}
5252

53+
static ALWAYS_INLINE unsigned int arch_num_cpus(void)
54+
{
55+
return CONFIG_MP_MAX_NUM_CPUS;
56+
}
57+
5358
#endif /* !_ASMLANGUAGE */
5459

5560
#endif /* ZEPHYR_INCLUDE_ARCH_XTENSA_ARCH_INLINES_H_ */

include/zephyr/sys/arch_interface.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,17 @@ static inline uint32_t arch_proc_id(void);
459459
* This will invoke z_sched_ipi() on other CPUs in the system.
460460
*/
461461
void arch_sched_ipi(void);
462+
463+
/**
464+
* @brief Returns the number of CPUs
465+
*
466+
* For most systems this will be the same as CONFIG_MP_MAX_NUM_CPUS,
467+
* however some systems may determine this at runtime instead.
468+
*
469+
* @return the number of CPUs
470+
*/
471+
static inline unsigned int arch_num_cpus(void);
472+
462473
#endif /* CONFIG_SMP */
463474

464475
/** @} */

kernel/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,14 @@ config MP_NUM_CPUS
879879
Number of multiprocessing-capable cores available to the
880880
multicpu API and SMP features.
881881

882+
config MP_MAX_NUM_CPUS
883+
int "Maximum number of CPUs/cores"
884+
default MP_NUM_CPUS
885+
range 1 4
886+
help
887+
Maximum number of multiprocessing-capable cores available to the
888+
multicpu API and SMP features.
889+
882890
config SCHED_IPI_SUPPORTED
883891
bool
884892
help

0 commit comments

Comments
 (0)