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 9b9423a638eae33aad14c9f4498766e9cbe7528f
Author: Daniel P. Carvalho <[email protected]>
AuthorDate: Thu Sep 17 09:40:20 2026 -0300

    sched/clock: update wall time on tickless tick and support slew limit PPM
    
    1. nxsched_process_timer: call clock_update_wall_time() under
       CONFIG_CLOCK_TIMEKEEPING so that wall time is updated on timer
       events during tickless operation.
    
    2. clock_timekeeping_get_wall_time: call clock_update_wall_time()
       before sampling the base and counter.
    
    3. clock_timekeeping: allow overriding NTP_MAX_ADJUST with
       CONFIG_CLOCK_ADJTIME_SLEWLIMIT_PPM if configured.
    
    4. Use clock_t consistently for counter values in clock_timekeeping.c.
    
    Signed-off-by: Daniel P. Carvalho <[email protected]>
---
 sched/clock/clock_timekeeping.c     | 24 +++++++++++++++---------
 sched/sched/sched_processtickless.c |  6 ++++++
 2 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/sched/clock/clock_timekeeping.c b/sched/clock/clock_timekeeping.c
index 4d5a48b684c..9afe11494b1 100644
--- a/sched/clock/clock_timekeeping.c
+++ b/sched/clock/clock_timekeeping.c
@@ -39,20 +39,25 @@
 #include <nuttx/clock_notifier.h>
 
 #include "clock/clock.h"
+#include "clock/clock_timekeeping.h"
 
 /****************************************************************************
  * Pre-processor Definitions
  ****************************************************************************/
 
-#define NTP_MAX_ADJUST 500
+#ifdef CONFIG_CLOCK_ADJTIME_SLEWLIMIT_PPM
+#  define NTP_MAX_ADJUST CONFIG_CLOCK_ADJTIME_SLEWLIMIT_PPM
+#else
+#  define NTP_MAX_ADJUST 500
+#endif
 
 /****************************************************************************
  * Private Data
  ****************************************************************************/
 
 static struct timespec g_clock_wall_time;
-static uint64_t        g_clock_last_counter;
-static uint64_t        g_clock_mask;
+static clock_t         g_clock_last_counter;
+static clock_t         g_clock_mask;
 static long            g_clock_adjust;
 static spinlock_t      g_clock_lock = SP_UNLOCKED;
 
@@ -68,8 +73,8 @@ static int clock_get_current_time(FAR struct timespec *ts,
                                   FAR struct timespec *base)
 {
   irqstate_t flags;
-  uint64_t counter;
-  uint64_t offset;
+  clock_t counter;
+  clock_t offset;
   uint64_t nsec;
   time_t sec;
   int ret;
@@ -112,6 +117,7 @@ errout_in_critical_section:
 
 int clock_timekeeping_get_wall_time(FAR struct timespec *ts)
 {
+  clock_update_wall_time();
   return clock_get_current_time(ts, &g_clock_wall_time);
 }
 
@@ -122,7 +128,7 @@ int clock_timekeeping_get_wall_time(FAR struct timespec *ts)
 int clock_timekeeping_set_wall_time(FAR const struct timespec *ts)
 {
   irqstate_t flags;
-  uint64_t counter;
+  clock_t counter;
   int ret;
 
   flags = spin_lock_irqsave(&g_clock_lock);
@@ -214,8 +220,8 @@ int adjtime(FAR const struct timeval *delta, FAR struct 
timeval *olddelta)
 void clock_update_wall_time(void)
 {
   irqstate_t flags;
-  uint64_t counter;
-  uint64_t offset;
+  clock_t counter;
+  clock_t offset;
   int64_t nsec;
   time_t sec;
   int ret;
@@ -261,8 +267,8 @@ void clock_update_wall_time(void)
           adjust = -limit;
         }
 
-      nsec += adjust * NSEC_PER_USEC;
       g_clock_adjust -= adjust;
+      nsec += adjust * NSEC_PER_USEC;
 
       while (nsec < 0)
         {
diff --git a/sched/sched/sched_processtickless.c 
b/sched/sched/sched_processtickless.c
index 1111dd0349b..c91eda9aa5f 100644
--- a/sched/sched/sched_processtickless.c
+++ b/sched/sched/sched_processtickless.c
@@ -354,6 +354,12 @@ void nxsched_process_timer(void)
 
   flags = enter_critical_section();
 
+#ifdef CONFIG_CLOCK_TIMEKEEPING
+  /* Process wall time */
+
+  clock_update_wall_time();
+#endif
+
   /* Do not move the up_timer_gettick out of the critical section,
    * it will violate the invariant that the g_timer_tick should be monotonic.
    */

Reply via email to