Skip to content

Commit cd35120

Browse files
peter-mitsiscfriedt
authored andcommitted
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 <[email protected]>
1 parent b59d8d5 commit cd35120

File tree

7 files changed

+42
-8
lines changed

7 files changed

+42
-8
lines changed

arch/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,3 +1181,9 @@ config ARCH_HAS_CUSTOM_CURRENT_IMPL
11811181
help
11821182
Select when architecture implements arch_current_thread() &
11831183
arch_current_thread_set().
1184+
1185+
config ARCH_IPI_LAZY_COPROCESSORS_SAVE
1186+
bool
1187+
help
1188+
Select when the architecture has multi-CPU lazy context switching
1189+
of coprocessor registers.

arch/xtensa/Kconfig

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,34 @@ config XTENSA_HIFI_SHARING
153153
across context switches to allow multiple threads to perform
154154
concurrent HiFi operations.
155155

156+
if XTENSA_HIFI_SHARING
157+
158+
choice XTENSA_HIFI_SHARING_MODEL
159+
prompt "Xtensa HiFi Sharing Model"
160+
depends on XTENSA_HIFI_SHARING
161+
default XTENSA_EAGER_HIFI_SHARING
162+
163+
config XTENSA_EAGER_HIFI_SHARING
164+
bool "Eager HiFi Sharing"
165+
help
166+
This option enables eager sharing of HiFi registers across context
167+
switches. This means that the HiFi registers are unconditionally
168+
saved and restored on every context switch, allowing multiple threads
169+
to use HiFi instructions concurrently.
170+
171+
config XTENSA_LAZY_HIFI_SHARING
172+
bool "Lazy HiFi Sharing"
173+
depends on SCHED_IPI_SUPPORTED || (MP_MAX_NUM_CPUS = 1)
174+
select ARCH_IPI_LAZY_COPROCESSORS_SAVE
175+
help
176+
This option enables lazy sharing of HiFi registers across context
177+
switches. This means that the HiFi registers are saved and restored
178+
only when a thread actually uses HiFi instructions, allowing for
179+
more efficient use of resources when HiFi instructions are not used.
180+
endchoice
181+
182+
endif # XTENSA_HIFI_SHARING
183+
156184
endif # XTENSA_CPU_HAS_HIFI
157185

158186
endmenu # Xtensa HiFi Options

arch/xtensa/core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ zephyr_library_sources_ifdef(CONFIG_XTENSA_MPU mpu.c)
2929
zephyr_library_sources_ifdef(CONFIG_USERSPACE userspace.S syscall_helper.c)
3030
zephyr_library_sources_ifdef(CONFIG_LLEXT elf.c)
3131
zephyr_library_sources_ifdef(CONFIG_SMP smp.c)
32-
zephyr_library_sources_ifdef(CONFIG_XTENSA_HIFI_SHARING xtensa_hifi.S)
32+
zephyr_library_sources_ifdef(CONFIG_XTENSA_EAGER_HIFI_SHARING xtensa_hifi.S)
3333

3434
zephyr_library_sources_ifdef(
3535
CONFIG_KERNEL_VM_USE_CUSTOM_MEM_RANGE_CHECK

arch/xtensa/core/offsets/offsets.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ GEN_OFFSET_SYM(_xtensa_irq_bsa_t, fpu14);
6161
GEN_OFFSET_SYM(_xtensa_irq_bsa_t, fpu15);
6262
#endif
6363

64-
#if defined(CONFIG_XTENSA_HIFI_SHARING)
64+
#if defined(CONFIG_XTENSA_EAGER_HIFI_SHARING)
6565
GEN_OFFSET_SYM(_xtensa_irq_bsa_t, hifi);
6666
#endif
6767

arch/xtensa/core/xtensa_asm2_util.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ _restore_ps_after:
185185
FPU_REG_RESTORE
186186
#endif
187187

188-
#if defined(CONFIG_XTENSA_HIFI_SHARING)
188+
#if defined(CONFIG_XTENSA_EAGER_HIFI_SHARING)
189189
.extern _xtensa_hifi_load
190190
call0 _xtensa_hifi_load
191191
#endif
@@ -305,7 +305,7 @@ xtensa_switch:
305305
movi a0, _switch_restore_pc
306306
s32i a0, a1, ___xtensa_irq_bsa_t_pc_OFFSET
307307

308-
#if defined(CONFIG_XTENSA_HIFI_SHARING)
308+
#if defined(CONFIG_XTENSA_EAGER_HIFI_SHARING)
309309
call0 _xtensa_hifi_save
310310
#endif
311311

arch/xtensa/include/xtensa_asm2_context.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
# define _BSA_PADDING_FPU (0)
9292
#endif
9393

94-
#if defined(CONFIG_XTENSA_HIFI_SHARING)
94+
#if defined(CONFIG_XTENSA_EAGER_HIFI_SHARING)
9595
# define _BSA_PADDING_HIFI (XCHAL_CP1_SA_SIZE + XCHAL_CP1_SA_ALIGN)
9696
#else
9797
# define _BSA_PADDING_HIFI (0)
@@ -173,7 +173,7 @@ struct xtensa_irq_base_save_area {
173173
uintptr_t fpu15;
174174
#endif
175175

176-
#if defined(CONFIG_XTENSA_HIFI_SHARING)
176+
#if defined(CONFIG_XTENSA_EAGER_HIFI_SHARING)
177177

178178
/*
179179
* Carve space for the registers used by the HiFi audio engine

arch/xtensa/include/xtensa_asm2_s.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* only by the assembler.
1818
*/
1919

20-
#if defined(CONFIG_XTENSA_HIFI_SHARING)
20+
#if defined(CONFIG_XTENSA_EAGER_HIFI_SHARING)
2121
.extern _xtensa_hifi_save
2222
#endif
2323

@@ -437,7 +437,7 @@ _xstack_returned_\@:
437437
FPU_REG_SAVE
438438
#endif
439439

440-
#if defined(CONFIG_XTENSA_HIFI_SHARING)
440+
#if defined(CONFIG_XTENSA_EAGER_HIFI_SHARING)
441441
call0 _xtensa_hifi_save /* Save HiFi registers */
442442
#endif
443443

0 commit comments

Comments
 (0)