From 4e1637b54ebe01ff38d62b8b85cf16821527ee38 Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Wed, 15 Jan 2020 08:57:29 -0800 Subject: [PATCH] kernel: add sys init level for SMP This adds a sys init level which allows device and sys_init to be done after SMP initialization, z_smp_init(), when all cores are up and running. Signed-off-by: Daniel Leung --- include/device.h | 3 +++ include/init.h | 4 ++++ include/linker/linker-defs.h | 1 + kernel/device.c | 6 ++++++ kernel/init.c | 1 + 5 files changed, 15 insertions(+) diff --git a/include/device.h b/include/device.h index 8f556058203..11b4ecf2206 100644 --- a/include/device.h +++ b/include/device.h @@ -69,6 +69,9 @@ extern "C" { * \li POST_KERNEL: Used for devices that require kernel services during * configuration. * \n + * \li POST_KERNEL_SMP: Used for devices that require kernel services during + * configuration after SMP initialization. + * \n * \li APPLICATION: Used for application components (i.e. non-kernel components) * that need automatic configuration. These devices can use all services * provided by the kernel during configuration. diff --git a/include/init.h b/include/init.h index 9899c853037..70deba16113 100644 --- a/include/init.h +++ b/include/init.h @@ -25,6 +25,10 @@ extern "C" { #define _SYS_INIT_LEVEL_POST_KERNEL 2 #define _SYS_INIT_LEVEL_APPLICATION 3 +#ifdef CONFIG_SMP +#define _SYS_INIT_LEVEL_SMP 4 +#endif + /* A counter is used to avoid issues when two or more system devices * are declared in the same C file with the same init function. */ diff --git a/include/linker/linker-defs.h b/include/linker/linker-defs.h index 4ea3dc07d51..23e3b5e3b9a 100644 --- a/include/linker/linker-defs.h +++ b/include/linker/linker-defs.h @@ -68,6 +68,7 @@ DEVICE_INIT_LEVEL(PRE_KERNEL_2) \ DEVICE_INIT_LEVEL(POST_KERNEL) \ DEVICE_INIT_LEVEL(APPLICATION) \ + DEVICE_INIT_LEVEL(SMP) \ __device_init_end = .; \ DEVICE_BUSY_BITFIELD() \ diff --git a/kernel/device.c b/kernel/device.c index 5636a708bc3..d9361b0c829 100644 --- a/kernel/device.c +++ b/kernel/device.c @@ -16,6 +16,9 @@ extern struct device __device_POST_KERNEL_start[]; extern struct device __device_APPLICATION_start[]; extern struct device __device_init_end[]; +#ifdef CONFIG_SMP +extern struct device __device_SMP_start[]; +#endif #ifdef CONFIG_DEVICE_POWER_MANAGEMENT extern u32_t __device_busy_start[]; @@ -42,6 +45,9 @@ void z_sys_device_do_config_level(s32_t level) __device_PRE_KERNEL_2_start, __device_POST_KERNEL_start, __device_APPLICATION_start, +#ifdef CONFIG_SMP + __device_SMP_start, +#endif /* End marker */ __device_init_end, }; diff --git a/kernel/init.c b/kernel/init.c index 1afebbbf764..a08f4383f43 100644 --- a/kernel/init.c +++ b/kernel/init.c @@ -249,6 +249,7 @@ static void bg_thread_main(void *unused1, void *unused2, void *unused3) #ifdef CONFIG_SMP z_smp_init(); + z_sys_device_do_config_level(_SYS_INIT_LEVEL_SMP); #endif #ifdef CONFIG_BOOT_TIME_MEASUREMENT