Skip to content

Conversation

@ycsin
Copy link
Member

@ycsin ycsin commented Nov 8, 2024

See #80716

@ycsin ycsin force-pushed the pr/riscv-thread-in-gp-alt branch 2 times, most recently from 9090373 to f2b1734 Compare November 8, 2024 17:45
@ycsin ycsin requested a review from andyross November 8, 2024 18:07
@ycsin ycsin force-pushed the pr/riscv-thread-in-gp-alt branch from f2b1734 to 15d5b0b Compare November 9, 2024 05:54
@rruuaanng rruuaanng added RFC Request For Comments: want input from the community area: Architectures labels Nov 9, 2024
@ycsin ycsin force-pushed the pr/riscv-thread-in-gp-alt branch from 15d5b0b to 45b5b86 Compare November 10, 2024 06:29
@ycsin ycsin force-pushed the pr/riscv-thread-in-gp-alt branch from 45b5b86 to c0a56c0 Compare November 19, 2024 04:15
Add the following arch-specific APIs:
- arch_curr_thread()
- arch_set_curr_thread()

which allow SMP architectures to implement a faster "get current
thread pointer" than the default provided by the kernel. The 'set'
function is required for the 'get' to work, more on that later.

When `CONFIG_ARCH_HAS_CUSTOM_CURRENT_IMPL` is selected, calls to
`_current` & `k_sched_current_thread_query()` will be redirected to
`arch_curr_thread()`, which ideally should translate into a single
instruction read, avoiding the current
"lock > read CPU > read current thread > unlock" path in SMP
architectures and thus greatly improves the read performance.

However, since the kernel relies on a copy of the "current thread"s on
every CPU for certain operations (i.e. to compare the priority of the
currently scheduled thread on another CPU to determine if IPI should be
sent), we can't eliminate the copy of "current thread" (`current`) from
the `struct _cpu` and therefore the kernel now has to invoke
`arch_set_curr_thread()` in addition to what it has been doing. This
means that it will take slightly longer (most likely one instruction
write) to change the current thread pointer on the current
CPU.

Signed-off-by: Yong Cong Sin <[email protected]>
Signed-off-by: Yong Cong Sin <[email protected]>
Implement `arch_curr_thread()` & `arch_set_curr_thread()`
with the global pointer (GP) register.

Signed-off-by: Yong Cong Sin <[email protected]>
Signed-off-by: Yong Cong Sin <[email protected]>
@ycsin ycsin force-pushed the pr/riscv-thread-in-gp-alt branch from c0a56c0 to 8789c80 Compare November 19, 2024 05:11
@ycsin ycsin closed this Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Architectures RFC Request For Comments: want input from the community

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants