This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 6e66e4cbef8c22860ace2a67a98405f520a253b5 Author: ouyangxiangzhen <[email protected]> AuthorDate: Thu Oct 29 16:58:49 2026 +0800 sched/hrtimer: Add branch hints for the non-empty queue case The hrtimer queue is virtually never empty in steady state: workloads keep timers pending, so the emptiness checks in hrtimer_get_first(), hrtimer_next_expired(), hrtimer_insert() and the hrtimer_process() loop are strongly biased towards the non-empty path. Mark them with predict_true()/predict_false() to guide static prediction. Measured on qemu-intel64 (KVM, out-of-order core) with a never-firing timer keeping the queue non-empty across the whole run: unchanged within noise, as the dynamic predictor already handles these branches; the hints target in-order cores where prediction is static. Assisted-by: mimo-v2.6-pro Signed-off-by: ouyangxiangzhen <[email protected]> --- sched/hrtimer/hrtimer.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sched/hrtimer/hrtimer.h b/sched/hrtimer/hrtimer.h index 8c3eeb1db50..ebc14ccd65c 100644 --- a/sched/hrtimer/hrtimer.h +++ b/sched/hrtimer/hrtimer.h @@ -186,7 +186,7 @@ static inline_function FAR hrtimer_t *hrtimer_get_first(void) #ifdef CONFIG_HRTIMER_TREE return g_hrtimer_head; #else - return list_is_empty(&g_hrtimer_list) ? + return predict_false(list_is_empty(&g_hrtimer_list)) ? NULL : list_first_entry(&g_hrtimer_list, FAR hrtimer_t, node); #endif } @@ -228,7 +228,8 @@ static inline_function uint64_t hrtimer_next_expired(void) { FAR hrtimer_t *first = hrtimer_get_first(); - return first != NULL ? first->expired : hrtimer_last_expired() + INT64_MAX; + return predict_true(first != NULL) ? first->expired : + hrtimer_last_expired() + INT64_MAX; } /**************************************************************************** @@ -398,7 +399,7 @@ static inline_function void hrtimer_insert(FAR hrtimer_t *hrtimer) #ifdef CONFIG_HRTIMER_TREE RB_INSERT(hrtimer_tree_s, &g_hrtimer_tree, hrtimer); - if (g_hrtimer_head == NULL || + if (predict_false(g_hrtimer_head == NULL) || HRTIMER_TIME_BEFORE(hrtimer->expired, g_hrtimer_head->expired)) { g_hrtimer_head = hrtimer; @@ -686,7 +687,7 @@ static inline_function void hrtimer_process(uint64_t now) * the queue. */ - while ((hrtimer = hrtimer_get_first()) != NULL) + while (predict_true((hrtimer = hrtimer_get_first()) != NULL)) { expired = hrtimer->expired;
