From 735b65aee6efc822076ec62f3e8f2556720c65ec Mon Sep 17 00:00:00 2001 From: yueling hu <502966985@qq.com> Date: Tue, 10 Jun 2025 20:21:38 +0800 Subject: [PATCH 1/4] =?UTF-8?q?rt=5Ftick=5Fget=5Fdelta=20=20=E6=9B=BF?= =?UTF-8?q?=E4=BB=A3=20rt=5Ftick=5Fget()=20-=20tick=5Fdelta=20=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=A2=9E=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ipc.c | 46 +++++++++++++++++++++------------------------- src/mempool.c | 2 +- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/ipc.c b/src/ipc.c index 35c0146dd33..3f730dacc68 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -45,7 +45,7 @@ * 2022-10-15 Bernard add nested mutex feature * 2022-10-16 Bernard add prioceiling feature in mutex * 2023-04-16 Xin-zheqi redesigen queue recv and send function return real message size - * 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable + * 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable */ #include @@ -2567,7 +2567,7 @@ static rt_err_t _rt_mb_send_wait(rt_mailbox_t mb, { struct rt_thread *thread; rt_base_t level; - rt_uint32_t tick_delta; + rt_uint32_t tick_stamp; rt_err_t ret; /* parameter check */ @@ -2577,8 +2577,8 @@ static rt_err_t _rt_mb_send_wait(rt_mailbox_t mb, /* current context checking */ RT_DEBUG_SCHEDULER_AVAILABLE(timeout != 0); - /* initialize delta tick */ - tick_delta = 0; + /* initialize tick_stamp tick */ + tick_stamp = 0; /* get current thread */ thread = rt_thread_self(); @@ -2622,7 +2622,7 @@ static rt_err_t _rt_mb_send_wait(rt_mailbox_t mb, if (timeout > 0) { /* get the start tick of timer */ - tick_delta = rt_tick_get(); + tick_stamp = rt_tick_get(); LOG_D("mb_send_wait: start timer of thread:%s", thread->parent.name); @@ -2650,8 +2650,7 @@ static rt_err_t _rt_mb_send_wait(rt_mailbox_t mb, /* if it's not waiting forever and then re-calculate timeout tick */ if (timeout > 0) { - tick_delta = rt_tick_get() - tick_delta; - timeout -= tick_delta; + timeout -= rt_tick_get_delta(tick_stamp); if (timeout < 0) timeout = 0; } @@ -2846,7 +2845,7 @@ static rt_err_t _rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeo { struct rt_thread *thread; rt_base_t level; - rt_uint32_t tick_delta; + rt_uint32_t tick_stamp; rt_err_t ret; /* parameter check */ @@ -2856,8 +2855,8 @@ static rt_err_t _rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeo /* current context checking */ RT_DEBUG_SCHEDULER_AVAILABLE(timeout != 0); - /* initialize delta tick */ - tick_delta = 0; + /* initialize tick_stamp tick */ + tick_stamp = 0; /* get current thread */ thread = rt_thread_self(); @@ -2902,7 +2901,7 @@ static rt_err_t _rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeo if (timeout > 0) { /* get the start tick of timer */ - tick_delta = rt_tick_get(); + tick_stamp = rt_tick_get(); LOG_D("mb_recv: start timer of thread:%s", thread->parent.name); @@ -2930,8 +2929,7 @@ static rt_err_t _rt_mb_recv(rt_mailbox_t mb, rt_ubase_t *value, rt_int32_t timeo /* if it's not waiting forever and then re-calculate timeout tick */ if (timeout > 0) { - tick_delta = rt_tick_get() - tick_delta; - timeout -= tick_delta; + timeout -= rt_tick_get_delta(tick_stamp); if (timeout < 0) timeout = 0; } @@ -3382,7 +3380,7 @@ static rt_err_t _rt_mq_send_wait(rt_mq_t mq, { rt_base_t level; struct rt_mq_message *msg; - rt_uint32_t tick_delta; + rt_uint32_t tick_stamp; struct rt_thread *thread; rt_err_t ret; @@ -3401,8 +3399,8 @@ static rt_err_t _rt_mq_send_wait(rt_mq_t mq, if (size > mq->msg_size) return -RT_ERROR; - /* initialize delta tick */ - tick_delta = 0; + /* initialize tick_stamp tick */ + tick_stamp = 0; /* get current thread */ thread = rt_thread_self(); @@ -3447,7 +3445,7 @@ static rt_err_t _rt_mq_send_wait(rt_mq_t mq, if (timeout > 0) { /* get the start tick of timer */ - tick_delta = rt_tick_get(); + tick_stamp = rt_tick_get(); LOG_D("mq_send_wait: start timer of thread:%s", thread->parent.name); @@ -3475,8 +3473,7 @@ static rt_err_t _rt_mq_send_wait(rt_mq_t mq, /* if it's not waiting forever and then re-calculate timeout tick */ if (timeout > 0) { - tick_delta = rt_tick_get() - tick_delta; - timeout -= tick_delta; + timeout -= rt_tick_get_delta(tick_stamp); if (timeout < 0) timeout = 0; } @@ -3765,7 +3762,7 @@ static rt_ssize_t _rt_mq_recv(rt_mq_t mq, struct rt_thread *thread; rt_base_t level; struct rt_mq_message *msg; - rt_uint32_t tick_delta; + rt_uint32_t tick_stamp; rt_err_t ret; rt_size_t len; @@ -3780,8 +3777,8 @@ static rt_ssize_t _rt_mq_recv(rt_mq_t mq, /* current context checking */ RT_DEBUG_SCHEDULER_AVAILABLE(timeout != 0); - /* initialize delta tick */ - tick_delta = 0; + /* initialize tick_stamp tick */ + tick_stamp = 0; /* get current thread */ thread = rt_thread_self(); RT_OBJECT_HOOK_CALL(rt_object_trytake_hook, (&(mq->parent.parent))); @@ -3826,7 +3823,7 @@ static rt_ssize_t _rt_mq_recv(rt_mq_t mq, if (timeout > 0) { /* get the start tick of timer */ - tick_delta = rt_tick_get(); + tick_stamp = rt_tick_get(); LOG_D("set thread:%s to timer list", thread->parent.name); @@ -3855,8 +3852,7 @@ static rt_ssize_t _rt_mq_recv(rt_mq_t mq, /* if it's not waiting forever and then re-calculate timeout tick */ if (timeout > 0) { - tick_delta = rt_tick_get() - tick_delta; - timeout -= tick_delta; + timeout -= rt_tick_get_delta(tick_stamp); if (timeout < 0) timeout = 0; } diff --git a/src/mempool.c b/src/mempool.c index 28bdb6cf896..0b80eea9a2c 100644 --- a/src/mempool.c +++ b/src/mempool.c @@ -335,7 +335,7 @@ void *rt_mp_alloc(rt_mp_t mp, rt_int32_t time) if (time > 0) { - time -= rt_tick_get() - before_sleep; + time -= rt_tick_get_delta(before_sleep); if (time < 0) time = 0; } From 823edfd9f01b85790656149c5f57ba1653237d60 Mon Sep 17 00:00:00 2001 From: yueling hu <502966985@qq.com> Date: Tue, 10 Jun 2025 20:23:26 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=BA=A2=E5=87=BA?= =?UTF-8?q?=EF=BC=8C=E5=88=A0=E9=99=A4=E5=86=97=E4=BD=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/timer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/timer.c b/src/timer.c index ae6da29f760..ee8ef304047 100644 --- a/src/timer.c +++ b/src/timer.c @@ -22,6 +22,8 @@ * 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable * 2024-01-25 Shell add RT_TIMER_FLAG_THREAD_TIMER for timer to sync with sched * 2024-05-01 wdfk-prog The rt_timer_check and _soft_timer_check functions are merged + * 2025-06-01 htl5241 remove redundancy + * fix timer overflow */ #include @@ -494,8 +496,6 @@ static void _timer_check(rt_list_t *timer_list, struct rt_spinlock *lock) level = rt_spin_lock_irqsave(lock); - current_tick = rt_tick_get(); - rt_list_init(&list); while (!rt_list_isempty(&timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1])) @@ -762,7 +762,7 @@ void rt_timer_check(void) rt_tick_t next_timeout; ret = _timer_list_next_timeout(_soft_timer_list, &next_timeout); - if ((ret == RT_EOK) && (next_timeout <= rt_tick_get())) + if ((ret == RT_EOK) && ((rt_tick_get() - next_timeout) < RT_TICK_MAX / 2)) { rt_sem_release(&_soft_timer_sem); } From aca60b576958dc20532e3378e90d4242cbac8aef Mon Sep 17 00:00:00 2001 From: yueling hu <502966985@qq.com> Date: Tue, 10 Jun 2025 20:24:48 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/timer.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/timer.c b/src/timer.c index ee8ef304047..9671997ec9b 100644 --- a/src/timer.c +++ b/src/timer.c @@ -22,8 +22,7 @@ * 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable * 2024-01-25 Shell add RT_TIMER_FLAG_THREAD_TIMER for timer to sync with sched * 2024-05-01 wdfk-prog The rt_timer_check and _soft_timer_check functions are merged - * 2025-06-01 htl5241 remove redundancy - * fix timer overflow + * 2025-06-01 htl5241 remove redundancy and fix timer overflow */ #include From f618acade9eafc39d4a408a849732b1761a43b16 Mon Sep 17 00:00:00 2001 From: yueling hu <502966985@qq.com> Date: Tue, 10 Jun 2025 20:30:33 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=B0=8F=E5=BF=83?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=9A=84=E7=A9=BA=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ipc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ipc.c b/src/ipc.c index 3f730dacc68..fea31f488b8 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -45,7 +45,7 @@ * 2022-10-15 Bernard add nested mutex feature * 2022-10-16 Bernard add prioceiling feature in mutex * 2023-04-16 Xin-zheqi redesigen queue recv and send function return real message size - * 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable + * 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable */ #include