File tree Expand file tree Collapse file tree 3 files changed +25
-0
lines changed
include/zephyr/arch/riscv Expand file tree Collapse file tree 3 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,16 @@ config RISCV_GP
2828 global pointer at program start or earlier than any instruction
2929 using GP relative addressing.
3030
31+ config RISCV_CURRENT_VIA_GP
32+ bool "Store current thread into the global pointer (GP) register"
33+ depends on !RISCV_GP && !USERSPACE
34+ depends on MP_MAX_NUM_CPUS > 1
35+ select ARCH_HAS_CUSTOM_CURRENT_IMPL
36+ help
37+ Store the current thread's pointer into the global pointer (GP) register.
38+ When is enabled, calls to `_current` & `k_sched_current_thread_query()` will
39+ be reduced to a single register read.
40+
3141config RISCV_ALWAYS_SWITCH_THROUGH_ECALL
3242 bool "Do not use mret outside a trap handler context"
3343 depends on MULTITHREADING
Original file line number Diff line number Diff line change @@ -52,6 +52,9 @@ Architectures
5252
5353* RISC-V
5454
55+ * Implements :c:func: `arch_current_thread_set ` & :c:func: `arch_current_thread `, which can be enabled
56+ by :kconfig:option: `CONFIG_RISCV_CURRENT_VIA_GP ` (:github: `80716 `).
57+
5558* Xtensa
5659
5760* native/POSIX
Original file line number Diff line number Diff line change 1111
1212#include <zephyr/kernel_structs.h>
1313#include "csr.h"
14+ #include "reg.h"
1415
1516static ALWAYS_INLINE uint32_t arch_proc_id (void )
1617{
@@ -26,6 +27,17 @@ static ALWAYS_INLINE _cpu_t *arch_curr_cpu(void)
2627#endif
2728}
2829
30+ #ifdef CONFIG_RISCV_CURRENT_VIA_GP
31+ register struct k_thread * __arch_current_thread __asm__("gp" );
32+
33+ #define arch_current_thread () __arch_current_thread
34+ #define arch_current_thread_set (thread ) \
35+ { \
36+ _current_cpu->current = thread; \
37+ __arch_current_thread = (thread); \
38+ }
39+ #endif /* CONFIG_RISCV_CURRENT_VIA_GP */
40+
2941static ALWAYS_INLINE unsigned int arch_num_cpus (void )
3042{
3143 return CONFIG_MP_MAX_NUM_CPUS ;
You can’t perform that action at this time.
0 commit comments