summaryrefslogtreecommitdiff
path: root/libcpu/aarch64/common/include
diff options
context:
space:
mode:
authorShell <[email protected]>2024-09-25 10:28:38 +0800
committerMeco Man <[email protected]>2024-10-11 00:09:01 -0400
commit5796e0d646b9fa97e14065859f308b2f5553cc12 (patch)
tree82e41c5496d8aab26da5dcd9b9b134b979122b18 /libcpu/aarch64/common/include
parent906d1caea6f82dcb45dc1925842e89b76c01bbfd (diff)
feat: arm64: update thread self on sp-switch
This patch improves the atomicity of context switching by ensuring that the stack pointer (sp) and thread self updates occur simultaneously. This enhancement is crucial for maintaining thread safety and preventing potential inconsistencies during context switches. Changes: - Modified `cpuport.h` to use `ARM64_THREAD_REG` for thread self access. - Added an `update_tidr` macro in `context_gcc.S` to streamline thread ID updates. - Adjusted `rt_hw_context_switch_to` and `rt_hw_context_switch` to call `update_tidr`, ensuring atomic updates during context switches. - Cleaned up `scheduler_mp.c` by removing redundant thread self assignments. Signed-off-by: Shell <[email protected]>
Diffstat (limited to 'libcpu/aarch64/common/include')
-rw-r--r--libcpu/aarch64/common/include/armv8.h6
-rw-r--r--libcpu/aarch64/common/include/cpuport.h4
2 files changed, 8 insertions, 2 deletions
diff --git a/libcpu/aarch64/common/include/armv8.h b/libcpu/aarch64/common/include/armv8.h
index 9063a8337d..7388b078a2 100644
--- a/libcpu/aarch64/common/include/armv8.h
+++ b/libcpu/aarch64/common/include/armv8.h
@@ -11,6 +11,12 @@
#ifndef __ARMV8_H__
#define __ARMV8_H__
+#include <rtconfig.h>
+
+#ifdef ARCH_USING_HW_THREAD_SELF
+#define ARM64_THREAD_REG tpidr_el1
+#endif /* ARCH_USING_HW_THREAD_SELF */
+
#ifdef __ASSEMBLY__
/*********************
diff --git a/libcpu/aarch64/common/include/cpuport.h b/libcpu/aarch64/common/include/cpuport.h
index e5e256b57b..e5216f3b89 100644
--- a/libcpu/aarch64/common/include/cpuport.h
+++ b/libcpu/aarch64/common/include/cpuport.h
@@ -57,14 +57,14 @@ void _thread_start(void);
rt_inline struct rt_thread *rt_hw_thread_self(void)
{
struct rt_thread *thread;
- __asm__ volatile ("mrs %0, tpidr_el1":"=r"(thread));
+ __asm__ volatile ("mrs %0, " RT_STRINGIFY(ARM64_THREAD_REG) :"=r"(thread));
return thread;
}
rt_inline void rt_hw_thread_set_self(struct rt_thread *thread)
{
- __asm__ volatile ("msr tpidr_el1, %0"::"r"(thread));
+ __asm__ volatile ("msr " RT_STRINGIFY(ARM64_THREAD_REG) ", %0"::"r"(thread));
}
#endif /* ARCH_USING_HW_THREAD_SELF */