diff options
| author | Shell <[email protected]> | 2024-05-28 14:27:55 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-05-28 14:27:55 +0800 |
| commit | f17f994f8c85a0ca58d42c81a14f1134af6ada91 (patch) | |
| tree | 49cb8514b38fc30884553e6b572c873a09f6935c /src/thread.c | |
| parent | b45fb59df2a7d938965c241431436adf77769b5b (diff) | |
[arm64] add hw thread self (#8942)
* [libcpu] arm64: Add hardware thread_self support
This patch introduces hardware-based thread self-identification
for the AArch64 architecture. It optimizes thread management by
using hardware registers to store and access the current thread's
pointer, reducing overhead and improving overall performance.
Changes include:
- Added `ARCH_USING_HW_THREAD_SELF` configuration option.
- Modified `rtdef.h`, `rtsched.h` to conditionally include
`critical_switch_flag` based on the new config.
- Updated context management in `context_gcc.S`, `cpuport.h`
to support hardware-based thread self.
- Enhanced `scheduler_mp.c` and `thread.c` to leverage the new
hardware thread self feature.
These modifications ensure better scheduling and thread handling,
particularly in multi-core environments, by minimizing the
software overhead associated with thread management.
Signed-off-by: Shell <[email protected]>
* fixup: address suggestion
* fixup: rt_current_thread as global
* scheduler: add cpu object for UP scheduler
Also, maintain the rt_current_thread in cpu object on UP scheduler.
---------
Signed-off-by: Shell <[email protected]>
Diffstat (limited to 'src/thread.c')
| -rw-r--r-- | src/thread.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/thread.c b/src/thread.c index 8d4752409d..1369b7560a 100644 --- a/src/thread.c +++ b/src/thread.c @@ -355,20 +355,22 @@ RTM_EXPORT(rt_thread_init); */ rt_thread_t rt_thread_self(void) { -#ifdef RT_USING_SMP - rt_base_t lock; +#ifndef RT_USING_SMP + return rt_cpu_self()->current_thread; + +#elif defined (ARCH_USING_HW_THREAD_SELF) + return rt_hw_thread_self(); + +#else /* !ARCH_USING_HW_THREAD_SELF */ rt_thread_t self; + rt_base_t lock; lock = rt_hw_local_irq_disable(); self = rt_cpu_self()->current_thread; rt_hw_local_irq_enable(lock); - return self; - -#else /* !RT_USING_SMP */ - extern rt_thread_t rt_current_thread; - return rt_current_thread; -#endif /* RT_USING_SMP */ + return self; +#endif /* ARCH_USING_HW_THREAD_SELF */ } RTM_EXPORT(rt_thread_self); |
