This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit c67ac63da3a100d9497457e1185c74214c0c6a00
Author: ouyangxiangzhen <ouyangxiangz...@xiaomi.com>
AuthorDate: Fri May 9 14:51:41 2025 +0800

    timer: pt_expected + 1 before set the timer.
    
    This commit is to prevent the insufficient sleep time.
    
    Signed-off-by: ouyangxiangzhen <ouyangxiangz...@xiaomi.com>
---
 sched/timer/timer_settime.c | 19 ++++++++++---------
 sched/wdog/wd_start.c       |  4 +---
 2 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/sched/timer/timer_settime.c b/sched/timer/timer_settime.c
index 9bc9578cb0..f287ac492c 100644
--- a/sched/timer/timer_settime.c
+++ b/sched/timer/timer_settime.c
@@ -328,17 +328,18 @@ int timer_settime(timer_t timerid, int flags,
        */
 
       delay = clock_time2ticks(&value->it_value);
+      timer->pt_expected = clock_systime_ticks() + delay;
+    }
 
-      /* delay+1 is to prevent the insufficient sleep time if we are
-       * currently near the boundary to the next tick.
-       * | current_tick | current_tick + 1 | current_tick + 2 | .... |
-       * |           ^ Here we get the current tick
-       * In this case we delay 1 tick, timer will be triggered at
-       * current_tick + 1, which is not enough for at least 1 tick.
-       */
+  /* delay+1 is to prevent the insufficient sleep time if we are
+   * currently near the boundary to the next tick.
+   * | current_tick | current_tick + 1 | current_tick + 2 | .... |
+   * |           ^ Here we get the current tick
+   * In this case we delay 1 tick, timer will be triggered at
+   * current_tick + 1, which is not enough for at least 1 tick.
+   */
 
-      timer->pt_expected = clock_systime_ticks() + delay + 1;
-    }
+  timer->pt_expected += 1;
 
   /* Then start the watchdog */
 
diff --git a/sched/wdog/wd_start.c b/sched/wdog/wd_start.c
index 4741ac0a41..409fada383 100644
--- a/sched/wdog/wd_start.c
+++ b/sched/wdog/wd_start.c
@@ -431,9 +431,7 @@ int wd_start(FAR struct wdog_s *wdog, sclock_t delay,
    * There is extensive documentation about this time issue elsewhere.
    */
 
-  delay++;
-
-  return wd_start_abstick(wdog, clock_systime_ticks() + delay,
+  return wd_start_abstick(wdog, clock_systime_ticks() + delay + 1,
                           wdentry, arg);
 }
 

Reply via email to