From 44be3b9c9e965b6f5f31e28ca29c9a8cece7e812 Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Fri, 3 Nov 2023 11:57:30 -0700 Subject: [PATCH 1/4] zephyr: use k_smp_cpu_start/_resume for secondary core power up This changes the secondary core power up routine to use the newly introduced k_smp_cpu_start() and k_smp_cpu_resume(). This removes the need to mirror part of the SMP start up code from Zephyr, and no longer need to call into Zephyr private kernel code. West update includes : eefaeee061c8 kernel: smp: introduce k_smp_cpu_resume 042cb6ac4e00 soc: intel_adsp: enable DfTTS-based time stamping on ACE platforms 6a0b1da158a4 soc: intel_adsp: call framework callback function for restore e7217925c93e ace: use a 'switch' statement in pm_state_set() c99a604bbf2c ace: remove superfluous variable initialisation a0ac2faf9bde intel_adsp: ace: enable power domain 4204ca9bcb3f ace: fix DSP panic during startup (fixes c3a6274bf5e4) d4b0273ab0c4 cmake: sparse.template: add COMMAND_ERROR_IS_FATAL ca12fd13c6d3 xtensa: intel_adsp: fix a cache handling error 0ee1e28a2f5f xtensa: polish doxygen and add to missing doc 035c8d8ceb4b xtensa: remove sys_define_gpr_with_alias() a64eec6aaeec xtensa: remove XTENSA_ERR_NORET Signed-off-by: Daniel Leung Signed-off-by: Rander Wang [guennadi.liakhovetski@linux.intel.com: update Zephyr hversion] Signed-off-by: Guennadi Liakhovetski --- west.yml | 2 +- zephyr/lib/cpu.c | 89 +++++++++--------------------------------------- 2 files changed, 18 insertions(+), 73 deletions(-) diff --git a/west.yml b/west.yml index 37418754dda6..80541ded3375 100644 --- a/west.yml +++ b/west.yml @@ -43,7 +43,7 @@ manifest: - name: zephyr repo-path: zephyr - revision: 9852e8e15bc8536aa1a49cc2697c1e8f802e331f + revision: 9183ceaf911965fd1e30f4172e0518c176ed644a remote: zephyrproject # Import some projects listed in zephyr/west.yml@revision diff --git a/zephyr/lib/cpu.c b/zephyr/lib/cpu.c index 02edf67d736f..e65c85729c13 100644 --- a/zephyr/lib/cpu.c +++ b/zephyr/lib/cpu.c @@ -19,6 +19,7 @@ /* Zephyr includes */ #include #include +#include #include #include @@ -27,36 +28,9 @@ extern K_KERNEL_STACK_ARRAY_DEFINE(z_interrupt_stacks, CONFIG_MP_MAX_NUM_CPUS, CONFIG_ISR_STACK_SIZE); -static atomic_t start_flag; -static atomic_t ready_flag; - -/* Zephyr kernel_internal.h interface */ -extern void smp_timer_init(void); - -static FUNC_NORETURN void secondary_init(void *arg) +static void secondary_init(void *arg) { - struct k_thread dummy_thread; - - /* - * This is an open-coded version of zephyr/kernel/smp.c - * smp_init_top(). We do this so that we can call SOF - * secondary_core_init() for each core. - */ - - atomic_set(&ready_flag, 1); - z_smp_thread_init(arg, &dummy_thread); - secondary_core_init(sof_get()); - -#ifdef CONFIG_THREAD_STACK_INFO - dummy_thread.stack_info.start = (uintptr_t)z_interrupt_stacks + - arch_curr_cpu()->id * Z_KERNEL_STACK_LEN(CONFIG_ISR_STACK_SIZE); - dummy_thread.stack_info.size = Z_KERNEL_STACK_LEN(CONFIG_ISR_STACK_SIZE); -#endif - - z_smp_thread_swap(); - - CODE_UNREACHABLE; /* LCOV_EXCL_LINE */ } #if CONFIG_ZEPHYR_NATIVE_DRIVERS @@ -118,7 +92,6 @@ void cpu_notify_state_exit(enum pm_state state) /* Notifying primary core that secondary core successfully exit the D3 * state and is back in the Idle thread. */ - atomic_set(&ready_flag, 1); return; } #endif @@ -147,31 +120,17 @@ int cpu_enable_core(int id) if (arch_cpu_active(id)) return 0; -#if ZEPHYR_VERSION(3, 0, 99) <= ZEPHYR_VERSION_CODE /* During kernel initialization, the next pm state is set to ACTIVE. By checking this * value, we determine if this is the first core boot, if not, we need to skip idle thread * initialization. By reinitializing the idle thread, we would overwrite the kernel structs * and the idle thread stack. */ - if (pm_state_next_get(id)->state == PM_STATE_ACTIVE) - z_init_cpu(id); -#endif - - atomic_clear(&start_flag); - atomic_clear(&ready_flag); - - arch_start_cpu(id, z_interrupt_stacks[id], CONFIG_ISR_STACK_SIZE, - secondary_init, &start_flag); - - unsigned int retry; - - for (retry = 100; !atomic_get(&ready_flag) && retry; retry--) - k_busy_wait(100); - - if (!retry) - return -ETIMEDOUT; + if (pm_state_next_get(id)->state == PM_STATE_ACTIVE) { + k_smp_cpu_start(id, secondary_init, NULL); + return 0; + } - atomic_set(&start_flag, 1); + k_smp_cpu_resume(id, secondary_init, NULL, true, false); return 0; } @@ -249,34 +208,20 @@ int cpu_enable_core(int id) int cpu_enable_secondary_core(int id) { - /* - * This is an open-coded version of zephyr/kernel/smp.c - * z_smp_start_cpu(). We do this, so we can use a customized - * secondary_init() for SOF. - */ - if (arch_cpu_active(id)) return 0; -#if ZEPHYR_VERSION(3, 0, 99) <= ZEPHYR_VERSION_CODE - z_init_cpu(id); -#endif - - atomic_clear(&start_flag); - atomic_clear(&ready_flag); - - arch_start_cpu(id, z_interrupt_stacks[id], CONFIG_ISR_STACK_SIZE, - secondary_init, &start_flag); - - unsigned int retry; - - for (retry = 100; !atomic_get(&ready_flag) && retry; retry--) - k_busy_wait(100); - - if (!retry) - return -ETIMEDOUT; + /* During kernel initialization, the next pm state is set to ACTIVE. By checking this + * value, we determine if this is the first core boot, if not, we need to skip idle thread + * initialization. By reinitializing the idle thread, we would overwrite the kernel structs + * and the idle thread stack. + */ + if (pm_state_next_get(id)->state == PM_STATE_ACTIVE) { + k_smp_cpu_start(id, secondary_init, NULL); + return 0; + } - atomic_set(&start_flag, 1); + k_smp_cpu_resume(id, secondary_init, NULL, true, false); return 0; } From f1170819d47e9a1f9a7a082cccd4a8be8d31a5a1 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Mon, 26 Feb 2024 15:49:11 +0100 Subject: [PATCH 2/4] cache: switch over to the new Zephyr cache API z_soc_uncached_ptr() / z_soc_cached_ptr() have been removed from Zephyr and replaced with sys_cache_uncached_ptr_get() and sys_cache_cached_ptr_get() respectively. Signed-off-by: Guennadi Liakhovetski --- west.yml | 2 +- zephyr/lib/alloc.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/west.yml b/west.yml index 80541ded3375..45cdbd7d5589 100644 --- a/west.yml +++ b/west.yml @@ -43,7 +43,7 @@ manifest: - name: zephyr repo-path: zephyr - revision: 9183ceaf911965fd1e30f4172e0518c176ed644a + revision: 9d1df132b1ccf28e8a8a216781ca52c6c47ed1fe remote: zephyrproject # Import some projects listed in zephyr/west.yml@revision diff --git a/zephyr/lib/alloc.c b/zephyr/lib/alloc.c index 7a395397fe88..c931eeb5658a 100644 --- a/zephyr/lib/alloc.c +++ b/zephyr/lib/alloc.c @@ -233,7 +233,7 @@ static void __sparse_cache *heap_alloc_aligned_cached(struct k_heap *h, #ifdef CONFIG_SOF_ZEPHYR_HEAP_CACHED if (ptr) - ptr = z_soc_cached_ptr((__sparse_force void *)ptr); + ptr = sys_cache_cached_ptr_get((__sparse_force void *)ptr); #endif return ptr; @@ -246,7 +246,7 @@ static void heap_free(struct k_heap *h, void *mem) void *mem_uncached; if (is_cached(mem)) { - mem_uncached = z_soc_uncached_ptr((__sparse_force void __sparse_cache *)mem); + mem_uncached = sys_cache_uncached_ptr_get((__sparse_force void __sparse_cache *)mem); sys_cache_data_flush_and_invd_range(mem, sys_heap_usable_size(&h->heap, mem_uncached)); From 553a7dff081ec44d0733d03706b741c8a25dafaf Mon Sep 17 00:00:00 2001 From: Laurentiu Mihalcea Date: Tue, 5 Mar 2024 16:17:32 +0200 Subject: [PATCH 3/4] app: boards: mimx93_evk_a55: change SRAM0's address to 0xd000000 Zephyr commit b985442829dd ("dts: mimx93_evk_a55: avoid conflict with Ethos-U NPU reserved memory") changes SRAM0's address to 0xd0000000. This breaks the i.MX93 SOF build because the SRAM0 node is no longer deleted so west build complains about having 2 SRAM0 nodes with different addresses. To fix this, update the deleted node's base address. Signed-off-by: Laurentiu Mihalcea Signed-off-by: Kai Vehmanen --- app/boards/mimx93_evk_a55.overlay | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/boards/mimx93_evk_a55.overlay b/app/boards/mimx93_evk_a55.overlay index 739b454e314b..df46ffd8b080 100644 --- a/app/boards/mimx93_evk_a55.overlay +++ b/app/boards/mimx93_evk_a55.overlay @@ -5,7 +5,7 @@ */ / { - /delete-node/ memory@c0000000; + /delete-node/ memory@d0000000; /* Inmate memory, reserved through "mem=1248MB" boot argument, * starts at 0xce000000. */ From 1821869736e725ec5a30cfa99f061c0627962fd2 Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Tue, 5 Mar 2024 13:35:28 +0200 Subject: [PATCH 4/4] west.yml: update Zephyr to 9d1df132b1c + one revert Update to Zephyr in sof/main-rebase-20240305 branch of SOF project's clone of Zephyr upstream repository. Revert one Zephyr commit "pm: Remove CURRENT_CPU macro" that is leading to failed tests in SOF CI test suite. The revert allows us to update Zephyr to a newer version and tackle the SMP boot and cache interface changes in SOF. The latest Zephyr upstream has further changes needed in SOF for platform configuration and these will require separarate changes. Link: https://github.com/thesofproject/sof/issues/8818 Link: https://github.com/zephyrproject-rtos/zephyr/issues/69807 Signed-off-by: Kai Vehmanen --- west.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/west.yml b/west.yml index 45cdbd7d5589..bdd9165d241a 100644 --- a/west.yml +++ b/west.yml @@ -43,8 +43,9 @@ manifest: - name: zephyr repo-path: zephyr - revision: 9d1df132b1ccf28e8a8a216781ca52c6c47ed1fe - remote: zephyrproject + # commit in sof/main-rebase-20240305 + revision: f26f0bc09893616ccda461c815f083c4ce8cfcec + remote: thesofproject # Import some projects listed in zephyr/west.yml@revision #