summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorShell <[email protected]>2024-05-28 14:27:55 +0800
committerGitHub <[email protected]>2024-05-28 14:27:55 +0800
commitf17f994f8c85a0ca58d42c81a14f1134af6ada91 (patch)
tree49cb8514b38fc30884553e6b572c873a09f6935c /include
parentb45fb59df2a7d938965c241431436adf77769b5b (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 'include')
-rw-r--r--include/rtdef.h15
-rw-r--r--include/rtsched.h5
-rw-r--r--include/rtthread.h9
3 files changed, 24 insertions, 5 deletions
diff --git a/include/rtdef.h b/include/rtdef.h
index f0918d5dd6..72b61de7aa 100644
--- a/include/rtdef.h
+++ b/include/rtdef.h
@@ -740,8 +740,10 @@ struct rt_cpu
struct rt_thread *current_thread;
rt_uint8_t irq_switch_flag:1;
- rt_uint8_t critical_switch_flag:1;
rt_uint8_t sched_lock_flag:1;
+#ifndef ARCH_USING_HW_THREAD_SELF
+ rt_uint8_t critical_switch_flag:1;
+#endif /* ARCH_USING_HW_THREAD_SELF */
rt_uint8_t current_priority;
rt_list_t priority_table[RT_THREAD_PRIORITY_MAX];
@@ -763,10 +765,19 @@ struct rt_cpu
struct rt_cpu_usage_stats cpu_stat;
#endif
};
-typedef struct rt_cpu *rt_cpu_t;
+
+#else /* !RT_USING_SMP */
+struct rt_cpu
+{
+ struct rt_thread *current_thread;
+};
#endif /* RT_USING_SMP */
+typedef struct rt_cpu *rt_cpu_t;
+/* Noted: As API to reject writing to this variable from application codes */
+#define rt_current_thread rt_thread_self()
+
struct rt_thread;
#ifdef RT_USING_SMART
diff --git a/include/rtsched.h b/include/rtsched.h
index 9e31320095..786ca8b54e 100644
--- a/include/rtsched.h
+++ b/include/rtsched.h
@@ -56,6 +56,10 @@ struct rt_sched_thread_ctx
rt_uint8_t sched_flag_locked:1; /**< calling thread have the scheduler locked */
rt_uint8_t sched_flag_ttmr_set:1; /**< thread timer is start */
+#ifdef ARCH_USING_HW_THREAD_SELF
+ rt_uint8_t critical_switch_flag:1; /**< critical switch pending */
+#endif /* ARCH_USING_HW_THREAD_SELF */
+
#ifdef RT_USING_SMP
rt_uint8_t bind_cpu; /**< thread is bind to cpu */
rt_uint8_t oncpu; /**< process on cpu */
@@ -170,6 +174,7 @@ rt_err_t rt_sched_thread_timer_stop(struct rt_thread *thread);
rt_err_t rt_sched_thread_timer_start(struct rt_thread *thread);
void rt_sched_insert_thread(struct rt_thread *thread);
void rt_sched_remove_thread(struct rt_thread *thread);
+struct rt_thread *rt_sched_thread_self(void);
#endif /* defined(__RT_KERNEL_SOURCE__) || defined(__RT_IPC_SOURCE__) */
diff --git a/include/rtthread.h b/include/rtthread.h
index 1cad47931a..386fbaf47e 100644
--- a/include/rtthread.h
+++ b/include/rtthread.h
@@ -669,6 +669,12 @@ rt_err_t rt_device_control(rt_device_t dev, int cmd, void *arg);
void rt_interrupt_enter(void);
void rt_interrupt_leave(void);
+/**
+ * CPU object
+ */
+struct rt_cpu *rt_cpu_self(void);
+struct rt_cpu *rt_cpu_index(int index);
+
#ifdef RT_USING_SMP
/*
@@ -679,9 +685,6 @@ rt_base_t rt_cpus_lock(void);
void rt_cpus_unlock(rt_base_t level);
void rt_cpus_lock_status_restore(struct rt_thread *thread);
-struct rt_cpu *rt_cpu_self(void);
-struct rt_cpu *rt_cpu_index(int index);
-
#ifdef RT_USING_DEBUG
rt_base_t rt_cpu_get_id(void);
#else /* !RT_USING_DEBUG */