diff --git a/arch/Kconfig b/arch/Kconfig index d059e2a2a22..8ad36e11150 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -1181,3 +1181,9 @@ config ARCH_HAS_CUSTOM_CURRENT_IMPL help Select when architecture implements arch_current_thread() & arch_current_thread_set(). + +config ARCH_IPI_LAZY_COPROCESSORS_SAVE + bool + help + Select when the architecture has multi-CPU lazy context switching + of coprocessor registers. diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig index 6912ddb2a65..26029a833a5 100644 --- a/arch/xtensa/Kconfig +++ b/arch/xtensa/Kconfig @@ -153,6 +153,34 @@ config XTENSA_HIFI_SHARING across context switches to allow multiple threads to perform concurrent HiFi operations. +if XTENSA_HIFI_SHARING + +choice XTENSA_HIFI_SHARING_MODEL + prompt "Xtensa HiFi Sharing Model" + depends on XTENSA_HIFI_SHARING + default XTENSA_EAGER_HIFI_SHARING + +config XTENSA_EAGER_HIFI_SHARING + bool "Eager HiFi Sharing" + help + This option enables eager sharing of HiFi registers across context + switches. This means that the HiFi registers are unconditionally + saved and restored on every context switch, allowing multiple threads + to use HiFi instructions concurrently. + +config XTENSA_LAZY_HIFI_SHARING + bool "Lazy HiFi Sharing" + depends on SCHED_IPI_SUPPORTED || (MP_MAX_NUM_CPUS = 1) + select ARCH_IPI_LAZY_COPROCESSORS_SAVE + help + This option enables lazy sharing of HiFi registers across context + switches. This means that the HiFi registers are saved and restored + only when a thread actually uses HiFi instructions, allowing for + more efficient use of resources when HiFi instructions are not used. +endchoice + +endif # XTENSA_HIFI_SHARING + endif # XTENSA_CPU_HAS_HIFI endmenu # Xtensa HiFi Options diff --git a/arch/xtensa/core/CMakeLists.txt b/arch/xtensa/core/CMakeLists.txt index 9ac52b16317..69a56e37ffc 100644 --- a/arch/xtensa/core/CMakeLists.txt +++ b/arch/xtensa/core/CMakeLists.txt @@ -29,7 +29,7 @@ zephyr_library_sources_ifdef(CONFIG_XTENSA_MPU mpu.c) zephyr_library_sources_ifdef(CONFIG_USERSPACE userspace.S syscall_helper.c) zephyr_library_sources_ifdef(CONFIG_LLEXT elf.c) zephyr_library_sources_ifdef(CONFIG_SMP smp.c) -zephyr_library_sources_ifdef(CONFIG_XTENSA_HIFI_SHARING xtensa_hifi.S) +zephyr_library_sources_ifdef(CONFIG_XTENSA_EAGER_HIFI_SHARING xtensa_hifi.S) zephyr_library_sources_ifdef( CONFIG_KERNEL_VM_USE_CUSTOM_MEM_RANGE_CHECK diff --git a/arch/xtensa/core/offsets/offsets.c b/arch/xtensa/core/offsets/offsets.c index f0b75c999cc..9edf341b7a7 100644 --- a/arch/xtensa/core/offsets/offsets.c +++ b/arch/xtensa/core/offsets/offsets.c @@ -61,7 +61,7 @@ GEN_OFFSET_SYM(_xtensa_irq_bsa_t, fpu14); GEN_OFFSET_SYM(_xtensa_irq_bsa_t, fpu15); #endif -#if defined(CONFIG_XTENSA_HIFI_SHARING) +#if defined(CONFIG_XTENSA_EAGER_HIFI_SHARING) GEN_OFFSET_SYM(_xtensa_irq_bsa_t, hifi); #endif diff --git a/arch/xtensa/core/xtensa_asm2_util.S b/arch/xtensa/core/xtensa_asm2_util.S index c488aeee1ce..028edde7b75 100644 --- a/arch/xtensa/core/xtensa_asm2_util.S +++ b/arch/xtensa/core/xtensa_asm2_util.S @@ -185,7 +185,7 @@ _restore_ps_after: FPU_REG_RESTORE #endif -#if defined(CONFIG_XTENSA_HIFI_SHARING) +#if defined(CONFIG_XTENSA_EAGER_HIFI_SHARING) .extern _xtensa_hifi_load call0 _xtensa_hifi_load #endif @@ -305,7 +305,7 @@ xtensa_switch: movi a0, _switch_restore_pc s32i a0, a1, ___xtensa_irq_bsa_t_pc_OFFSET -#if defined(CONFIG_XTENSA_HIFI_SHARING) +#if defined(CONFIG_XTENSA_EAGER_HIFI_SHARING) call0 _xtensa_hifi_save #endif diff --git a/arch/xtensa/include/xtensa_asm2_context.h b/arch/xtensa/include/xtensa_asm2_context.h index ac13a611c67..56fc84b56ac 100644 --- a/arch/xtensa/include/xtensa_asm2_context.h +++ b/arch/xtensa/include/xtensa_asm2_context.h @@ -91,7 +91,7 @@ # define _BSA_PADDING_FPU (0) #endif -#if defined(CONFIG_XTENSA_HIFI_SHARING) +#if defined(CONFIG_XTENSA_EAGER_HIFI_SHARING) # define _BSA_PADDING_HIFI (XCHAL_CP1_SA_SIZE + XCHAL_CP1_SA_ALIGN) #else # define _BSA_PADDING_HIFI (0) @@ -173,7 +173,7 @@ struct xtensa_irq_base_save_area { uintptr_t fpu15; #endif -#if defined(CONFIG_XTENSA_HIFI_SHARING) +#if defined(CONFIG_XTENSA_EAGER_HIFI_SHARING) /* * Carve space for the registers used by the HiFi audio engine diff --git a/arch/xtensa/include/xtensa_asm2_s.h b/arch/xtensa/include/xtensa_asm2_s.h index a189d604fd8..af345ab3083 100644 --- a/arch/xtensa/include/xtensa_asm2_s.h +++ b/arch/xtensa/include/xtensa_asm2_s.h @@ -17,7 +17,7 @@ * only by the assembler. */ -#if defined(CONFIG_XTENSA_HIFI_SHARING) +#if defined(CONFIG_XTENSA_EAGER_HIFI_SHARING) .extern _xtensa_hifi_save #endif @@ -437,7 +437,7 @@ _xstack_returned_\@: FPU_REG_SAVE #endif -#if defined(CONFIG_XTENSA_HIFI_SHARING) +#if defined(CONFIG_XTENSA_EAGER_HIFI_SHARING) call0 _xtensa_hifi_save /* Save HiFi registers */ #endif