-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
arch/risc-v: Implement up_this_task using Thread Pointer (TP) #15563
base: master
Are you sure you want to change the base?
Conversation
Summary: - Added up_this_task() and up_update_task() macros to use TP register for fast task pointer access - Modified CPU startup and initial state code to initialize TP with task pointer - Updated context save/restore macros to handle TP only when TLS is enabled - Added irq.h include to riscv_cpustart.c for new macros Impact: - Improves performance by using TP for fast task pointer access - Reduces overhead of getting current task pointer in scheduler - Maintains compatibility with TLS configuration - No impact when CONFIG_SCHED_THREAD_LOCAL is enabled - Changes context save/restore behavior for TP Signed-off-by: Huang Qi <[email protected]>
[Experimental Bot, please feedback here] Yes, this PR appears to meet the NuttX requirements, although more detail could be provided. Here's a breakdown of why and where improvements could be made: Strengths:
Weaknesses & Suggestions for Improvement:
By addressing these points, the PR would be even stronger and provide reviewers with all the necessary information to efficiently assess the changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested OK with rv-virt:knsh64
. Thanks :-)
https://gist.github.com/lupyuen/4b7811d6dae690e3a61b68cf359826aa
nsh> uname -a
NuttX 10.0.1 c2f6dd3d17 Jan 15 2025 18:29:25 risc-v rv-virt
nsh> ostest
ostest_main: Exiting with status 0
* thread-local storage. | ||
*/ | ||
|
||
#ifndef CONFIG_SCHED_THREAD_LOCAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use TP when system calls are enabled as well, even when SCHED_THREAD_LOCAL is in use.
The current logic in exception_common just needs to be modified to swap user TP with kernel TP (from the scratch area) always (not just when a system call is taken).
In flat mode where the kernel symbols are directly visible/callable this obviously does not work.
@@ -153,6 +153,8 @@ void up_initial_state(struct tcb_s *tcb) | |||
#ifdef CONFIG_SCHED_THREAD_LOCAL | |||
xcp->regs[REG_TP] = (uintptr_t)tcb->stack_alloc_ptr + | |||
sizeof(struct tls_info_s); | |||
#else | |||
xcp->regs[REG_TP] = (uintptr_t)tcb; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not necessary, just set tcb -> tp directly when a context switch occurs.
@@ -58,7 +58,9 @@ | |||
#ifdef RISCV_SAVE_GP | |||
REGSTORE x3, REG_X3(\in) /* gp */ | |||
#endif | |||
#ifdef CONFIG_SCHED_THREAD_LOCAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary as well, TP will remain stable when the user process is running, as well as during a trap. Only time when TP needs to be updated is when a context switch occurs.
}) | ||
|
||
/* Update the current task pointer stored in TP register */ | ||
#define up_update_task(t) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should call this when a context switch occurs.
Summary
Impact
Testing
GitHub CI and local board with CONFIG_SCHED_THREAD_LOCAL enabled/disabled