From b7cd0ab796fe8f3012bde746e51755a8c0cc8bb9 Mon Sep 17 00:00:00 2001 From: ouyangxiangzhen Date: Tue, 27 Aug 2024 14:11:13 +0800 Subject: [PATCH] sched/sched: Correct the elapsed time calculation. This patch addresses an issue where the elapsed time was uncorrectly calculated. Signed-off-by: ouyangxiangzhen Signed-off-by: ligd --- sched/sched/sched_timerexpiration.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/sched/sched/sched_timerexpiration.c b/sched/sched/sched_timerexpiration.c index a2609ac376..cd5e3d7767 100644 --- a/sched/sched/sched_timerexpiration.c +++ b/sched/sched/sched_timerexpiration.c @@ -562,31 +562,20 @@ void nxsched_reassess_timer(void) clock_t ticks; clock_t elapsed; -#ifdef CONFIG_SCHED_TICKLESS_ALARM - /* Cancel the alarm and get the current time */ + /* Cancel the timer and get the current time */ +#ifdef CONFIG_SCHED_TICKLESS_ALARM up_alarm_tick_cancel(&ticks); +#else + up_timer_gettick(&ticks); + up_timer_tick_cancel(&elapsed); + DEBUGASSERT(elapsed <= g_timer_interval); +#endif /* Convert this to the elapsed time and update clock tickbase */ elapsed = ticks - g_timer_tick; g_timer_tick = ticks; -#else - /* Cancel the timer and get the current time */ - - up_timer_gettick(&ticks); - up_timer_tick_cancel(&elapsed); - DEBUGASSERT(elapsed <= g_timer_interval); - - /* Handle the partial timer. This will reassess all timer conditions and - * re-start the interval timer with the correct delay. Context switches - * are not permitted in this case because we are not certain of the - * calling conditions. - */ - - ticks += g_timer_interval - elapsed; - g_timer_tick = ticks; -#endif /* Process the timer ticks and start next timer */