This is an automated email from the ASF dual-hosted git repository. ligd pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 6bffad62de8948d000a908fbc5be8107f7d1754b Author: wangchengdong <[email protected]> AuthorDate: Wed Jan 7 10:36:48 2026 +0800 [EXPERIMENTAL] sched/hrtimer: separate SMP logic from hrtimer Separate SMP-specific logic from the hrtimer core to improve performance and maintainability. Signed-off-by: Chengdong Wang <[email protected]> --- sched/hrtimer/hrtimer.h | 2 ++ sched/hrtimer/hrtimer_cancel.c | 19 ++++++++----------- sched/hrtimer/hrtimer_initialize.c | 2 ++ sched/hrtimer/hrtimer_process.c | 7 ++++++- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/sched/hrtimer/hrtimer.h b/sched/hrtimer/hrtimer.h index 09192ce65fd..99858415d29 100644 --- a/sched/hrtimer/hrtimer.h +++ b/sched/hrtimer/hrtimer.h @@ -62,7 +62,9 @@ extern struct hrtimer_tree_s g_hrtimer_tree; * for each CPU in SMP configurations. Index corresponds to CPU ID. */ +#ifdef CONFIG_SMP extern FAR hrtimer_t *g_hrtimer_running[CONFIG_SMP_NCPUS]; +#endif /**************************************************************************** * Public Function Prototypes diff --git a/sched/hrtimer/hrtimer_cancel.c b/sched/hrtimer/hrtimer_cancel.c index c27c2a3a412..a2b4bc6e3f7 100644 --- a/sched/hrtimer/hrtimer_cancel.c +++ b/sched/hrtimer/hrtimer_cancel.c @@ -57,7 +57,7 @@ * true - The timer is active on at least one CPU. * false - The timer is not active. ****************************************************************************/ - +#ifdef CONFIG_SMP static inline_function bool hrtimer_is_active(FAR hrtimer_t *hrtimer) { bool is_active = false; @@ -73,6 +73,7 @@ static inline_function bool hrtimer_is_active(FAR hrtimer_t *hrtimer) return is_active; } +#endif /**************************************************************************** * Public Functions @@ -177,16 +178,10 @@ int hrtimer_cancel(FAR hrtimer_t *hrtimer) int hrtimer_cancel_sync(FAR hrtimer_t *hrtimer) { - int ret; - bool cansleep; + int ret = OK; DEBUGASSERT(hrtimer != NULL); - /* Determine whether sleeping is permitted in the current context */ - - cansleep = !up_interrupt_context() && - !is_idle_task(this_task()); - /* Request cancellation of the timer */ ret = hrtimer_cancel(hrtimer); @@ -201,14 +196,16 @@ int hrtimer_cancel_sync(FAR hrtimer_t *hrtimer) * busy-waiting. Otherwise, spin until the callback completes * and the state becomes inactive. */ - +#ifdef CONFIG_SMP while (hrtimer_is_active(hrtimer)) { - if (cansleep) + if (!up_interrupt_context() && + !is_idle_task(this_task())) { nxsched_msleep(HRTIMER_CANCEL_SYNC_DELAY_MS); } } +#endif - return OK; + return ret; } diff --git a/sched/hrtimer/hrtimer_initialize.c b/sched/hrtimer/hrtimer_initialize.c index 0bde89d9c2f..51902011241 100644 --- a/sched/hrtimer/hrtimer_initialize.c +++ b/sched/hrtimer/hrtimer_initialize.c @@ -36,7 +36,9 @@ * for each CPU in SMP configurations. Index corresponds to CPU ID. */ +#ifdef CONFIG_SMP FAR hrtimer_t *g_hrtimer_running[CONFIG_SMP_NCPUS]; +#endif /* Global spinlock protecting the high-resolution timer subsystem. * diff --git a/sched/hrtimer/hrtimer_process.c b/sched/hrtimer/hrtimer_process.c index d9a915d2a6f..f94f699aa9e 100644 --- a/sched/hrtimer/hrtimer_process.c +++ b/sched/hrtimer/hrtimer_process.c @@ -74,7 +74,9 @@ void hrtimer_process(uint64_t now) hrtimer_entry_t func; uint64_t expired; uint64_t period; +#ifdef CONFIG_SMP int cpu = this_cpu(); +#endif /* Lock the hrtimer RB-tree to protect access */ @@ -105,8 +107,9 @@ void hrtimer_process(uint64_t now) hrtimer_remove(hrtimer); +#ifdef CONFIG_SMP g_hrtimer_running[cpu] = hrtimer; - +#endif /* Leave critical section before invoking the callback */ spin_unlock_irqrestore(&g_hrtimer_spinlock, flags); @@ -119,7 +122,9 @@ void hrtimer_process(uint64_t now) flags = spin_lock_irqsave(&g_hrtimer_spinlock); +#ifdef CONFIG_SMP g_hrtimer_running[cpu] = NULL; +#endif /* If the timer is periodic and has not been rearmed or * cancelled concurrently,
