From a73982fb0000c274bce78c68cfe7850aa76a4c09 Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Wed, 8 Nov 2023 16:51:40 -0800 Subject: [PATCH 1/4] zephyr: cpu: use arch_cpu_start instead of arch_start_cpu This uses arch_cpu_start() instead of arch_start_cpu() as it has been renamed to align with the CPU namespace. Signed-off-by: Daniel Leung (cherry picked from commit b22ce6da92f2fca793fa17aeaa0d5399f40f8987) --- zephyr/lib/cpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zephyr/lib/cpu.c b/zephyr/lib/cpu.c index 3dde19dc38bc..8efe99c1532f 100644 --- a/zephyr/lib/cpu.c +++ b/zephyr/lib/cpu.c @@ -155,7 +155,7 @@ int cpu_enable_core(int id) atomic_clear(&start_flag); atomic_clear(&ready_flag); - arch_start_cpu(id, z_interrupt_stacks[id], CONFIG_ISR_STACK_SIZE, + arch_cpu_start(id, z_interrupt_stacks[id], CONFIG_ISR_STACK_SIZE, secondary_init, &start_flag); while (!atomic_get(&ready_flag)) @@ -255,7 +255,7 @@ int cpu_enable_secondary_core(int id) atomic_clear(&start_flag); atomic_clear(&ready_flag); - arch_start_cpu(id, z_interrupt_stacks[id], CONFIG_ISR_STACK_SIZE, + arch_cpu_start(id, z_interrupt_stacks[id], CONFIG_ISR_STACK_SIZE, secondary_init, &start_flag); while (!atomic_get(&ready_flag)) From 48436f931888dd0cdcd5a158be6fe0e043bb2edf Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Fri, 3 Nov 2023 11:57:30 -0700 Subject: [PATCH 2/4] zephyr: use k_smp_cpu_start/_resume for secondary core power up This changes the seconday 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. Signed-off-by: Daniel Leung (cherry picked from commit 11c251a506ea171831fd04f1c5b0c2e94eade396) --- zephyr/lib/cpu.c | 55 +++++++++--------------------------------------- 1 file changed, 10 insertions(+), 45 deletions(-) diff --git a/zephyr/lib/cpu.c b/zephyr/lib/cpu.c index 8efe99c1532f..9424cdc140e2 100644 --- a/zephyr/lib/cpu.c +++ b/zephyr/lib/cpu.c @@ -19,6 +19,7 @@ /* Zephyr includes */ #include #include +#include #include #include @@ -27,37 +28,13 @@ 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); - smp_timer_init(); 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 @@ -131,13 +108,10 @@ void cpu_notify_state_exit(enum pm_state state) int cpu_enable_core(int id) { + bool cpu_resume = true; + /* only called from single core, no RMW lock */ __ASSERT_NO_MSG(cpu_is_primary(arch_proc_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; @@ -149,20 +123,19 @@ int cpu_enable_core(int id) * and the idle thread stack. */ if (pm_state_next_get(id)->state == PM_STATE_ACTIVE) - z_init_cpu(id); + cpu_resume = false; #endif - atomic_clear(&start_flag); atomic_clear(&ready_flag); - arch_cpu_start(id, z_interrupt_stacks[id], CONFIG_ISR_STACK_SIZE, - secondary_init, &start_flag); + if (cpu_resume) + k_smp_cpu_resume(id, secondary_init, NULL, true, false); + else + k_smp_cpu_start(id, secondary_init, NULL); while (!atomic_get(&ready_flag)) k_busy_wait(100); - atomic_set(&start_flag, 1); - return 0; } @@ -248,21 +221,13 @@ int cpu_enable_secondary_core(int id) 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_cpu_start(id, z_interrupt_stacks[id], CONFIG_ISR_STACK_SIZE, - secondary_init, &start_flag); + k_smp_cpu_start(id, secondary_init, NULL); while (!atomic_get(&ready_flag)) k_busy_wait(100); - atomic_set(&start_flag, 1); - return 0; } From b9ff109a23c68ca2e0bc8df94ba348de8c141961 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Fri, 26 Jan 2024 13:17:46 +0000 Subject: [PATCH 3/4] zephyr: use system cache APIs instead of custom soc calls Use system cache API instead of soc specific calls. Signed-off-by: Anas Nashif (cherry picked from commit 0606152d4aafc1f7ed43df1b1813252bfc74e154) --- zephyr/lib/alloc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/zephyr/lib/alloc.c b/zephyr/lib/alloc.c index 436b11eca113..750ab62cebc6 100644 --- a/zephyr/lib/alloc.c +++ b/zephyr/lib/alloc.c @@ -115,7 +115,7 @@ static inline uintptr_t get_l3_heap_start(void) * - main_fw_load_offset * - main fw size in manifest */ - return (uintptr_t)z_soc_uncached_ptr((__sparse_force void __sparse_cache *) + return (uintptr_t)sys_cache_uncached_ptr_get((__sparse_force void __sparse_cache *) ROUND_UP(IMR_L3_HEAP_BASE, L3_MEM_PAGE_SIZE)); } @@ -145,7 +145,7 @@ static bool is_l3_heap_pointer(void *ptr) uintptr_t l3_heap_end = l3_heap_start + get_l3_heap_size(); if (is_cached(ptr)) - ptr = z_soc_uncached_ptr((__sparse_force void __sparse_cache *)ptr); + ptr = sys_cache_uncached_ptr_get((__sparse_force void __sparse_cache *)ptr); if ((POINTER_TO_UINT(ptr) >= l3_heap_start) && (POINTER_TO_UINT(ptr) < l3_heap_end)) return true; @@ -198,7 +198,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; @@ -211,7 +211,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 42d39f1fb629980a1cc65fb0435ff576adcc21ac Mon Sep 17 00:00:00 2001 From: Marc Herbert Date: Wed, 31 Jan 2024 21:15:55 +0000 Subject: [PATCH 4/4] [DNM] test Zephyr cache API 68140 + pick SMP revert 68366 Test Zephyr cache API 68140 + pick SMP revert 68366 Signed-off-by: Marc Herbert --- scripts/xtensa-build-zephyr.py | 3 ++- west.yml | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/xtensa-build-zephyr.py b/scripts/xtensa-build-zephyr.py index 2e8f810d9444..cafd44155923 100755 --- a/scripts/xtensa-build-zephyr.py +++ b/scripts/xtensa-build-zephyr.py @@ -523,7 +523,8 @@ def create_zephyr_sof_symlink(): def west_update(): """[summary] Clones all west manifest projects to specified revisions""" global west_top - execute_command(["west", "update"], check=True, timeout=3000, cwd=west_top) + # --narrow to fetch SHA1s directly from forks + execute_command(["west", "update", "--narrow"], check=True, timeout=3000, cwd=west_top) def get_sof_version(): diff --git a/west.yml b/west.yml index 37418754dda6..51147f917dce 100644 --- a/west.yml +++ b/west.yml @@ -43,7 +43,10 @@ manifest: - name: zephyr repo-path: zephyr - revision: 9852e8e15bc8536aa1a49cc2697c1e8f802e331f + # DNM: testing cache API change + # https://github.com/zephyrproject-rtos/zephyr/pull/68140 + # + revert / fix 68366 + revision: 5daaa64245d6b226efd2ef2571c409a689a958e2 remote: zephyrproject # Import some projects listed in zephyr/west.yml@revision