arch: xtensa: Refine HiFi sharing Kconfigs

Splits HiFi sharing into two different models.
 1. XTENSA_EAGER_HIFI_SHARING - unconditional save/restore
    of the HiFi registers when context switching
 2. XTENSA_LAZY_HIFI_SHARING - on demand save/restore of
    of the HiFi registers. If a thread does not use the
    HiFi registers, they are neither saved nor restored.

To maintain backwards compatibility, the eager model is the
default model when XTENSA_HIFI_SHARING is enabled.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
This commit is contained in:
Peter Mitsis 2025-06-10 12:26:30 -07:00 committed by Chris Friedt
parent b59d8d56bf
commit cd351208d5
7 changed files with 42 additions and 8 deletions

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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