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
28
28
global pointer at program start or earlier than any instruction
29
29
using GP relative addressing.
30
30
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
+
31
41
config RISCV_ALWAYS_SWITCH_THROUGH_ECALL
32
42
bool "Do not use mret outside a trap handler context"
33
43
depends on MULTITHREADING
Original file line number Diff line number Diff line change @@ -52,6 +52,9 @@ Architectures
52
52
53
53
* RISC-V
54
54
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
+
55
58
* Xtensa
56
59
57
60
* native/POSIX
Original file line number Diff line number Diff line change 11
11
12
12
#include <zephyr/kernel_structs.h>
13
13
#include "csr.h"
14
+ #include "reg.h"
14
15
15
16
static ALWAYS_INLINE uint32_t arch_proc_id (void )
16
17
{
@@ -26,6 +27,17 @@ static ALWAYS_INLINE _cpu_t *arch_curr_cpu(void)
26
27
#endif
27
28
}
28
29
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
+
29
41
static ALWAYS_INLINE unsigned int arch_num_cpus (void )
30
42
{
31
43
return CONFIG_MP_MAX_NUM_CPUS ;
You can’t perform that action at this time.
0 commit comments