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

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

commit 89dbed25a0d8eac52b7b3d684f697bfb046e9bbc
Author: ouyangxiangzhen <[email protected]>
AuthorDate: Wed Jan 7 20:56:55 2026 +0800

    sched/hrtimer: Replace hrtimer_gettime with clock_systime_nsec.
    
    This commit move the hrtimer_gettime to clock_systime_nsec to improve
    the code reusability.
    
    Signed-off-by: ouyangxiangzhen <[email protected]>
---
 include/nuttx/clock.h         | 22 ++++++++++++++++++++++
 sched/hrtimer/hrtimer.h       | 24 ------------------------
 sched/hrtimer/hrtimer_start.c |  2 +-
 sched/sched/sched_timer.c     |  2 +-
 4 files changed, 24 insertions(+), 26 deletions(-)

diff --git a/include/nuttx/clock.h b/include/nuttx/clock.h
index 9dbf64dbd3b..6c176e6ef06 100644
--- a/include/nuttx/clock.h
+++ b/include/nuttx/clock.h
@@ -733,6 +733,28 @@ clock_t clock_systime_ticks(void);
 
 void clock_systime_timespec(FAR struct timespec *ts);
 
+/****************************************************************************
+ * Name: clock_systime_nsec
+ *
+ * Description:
+ *   Return the current value of the system timer counter as
+ *   uint64_t nanoseconds.
+ *
+ * Input Parameters:
+ *   ts - Location to return the time
+ *
+ * Returned Value:
+ *   The current system time in nanoseconds.
+ *
+ ****************************************************************************/
+
+static inline_function uint64_t clock_systime_nsec(void)
+{
+  struct timespec ts;
+  clock_systime_timespec(&ts);
+  return clock_time2nsec(&ts);
+}
+
 /****************************************************************************
  * Name:  clock_cpuload
  *
diff --git a/sched/hrtimer/hrtimer.h b/sched/hrtimer/hrtimer.h
index 42801ff4d8a..9ec29bc227f 100644
--- a/sched/hrtimer/hrtimer.h
+++ b/sched/hrtimer/hrtimer.h
@@ -110,30 +110,6 @@ void hrtimer_process(uint64_t now);
  * Inline Functions
  ****************************************************************************/
 
-/****************************************************************************
- * Name: hrtimer_gettime
- *
- * Description:
- *   Get the current high-resolution time in nanoseconds.
- *
- * Returned Value:
- *   Current time in nanoseconds.
- ****************************************************************************/
-
-static inline_function
-uint64_t hrtimer_gettime(void)
-{
-  struct timespec ts;
-
-  /* Get current time from platform-specific timer */
-
-  clock_systime_timespec(&ts);
-
-  /* Convert timespec to nanoseconds */
-
-  return clock_time2nsec(&ts);
-}
-
 /****************************************************************************
  * Name: hrtimer_reprogram
  *
diff --git a/sched/hrtimer/hrtimer_start.c b/sched/hrtimer/hrtimer_start.c
index 86b37f3cce2..d270dd21eee 100644
--- a/sched/hrtimer/hrtimer_start.c
+++ b/sched/hrtimer/hrtimer_start.c
@@ -92,7 +92,7 @@ int hrtimer_start(FAR hrtimer_t *hrtimer, hrtimer_entry_t 
func,
     }
   else
     {
-      hrtimer->expired = hrtimer_gettime() + expired;
+      hrtimer->expired = clock_systime_nsec() + expired;
     }
 
   /* Ensure expiration time does not overflow */
diff --git a/sched/sched/sched_timer.c b/sched/sched/sched_timer.c
index 5f5c4bc0b50..9bf3c39aa8b 100644
--- a/sched/sched/sched_timer.c
+++ b/sched/sched/sched_timer.c
@@ -135,7 +135,7 @@ void nxsched_process_timer(void)
                     HRTIMER_MODE_REL);
     }
 
-  hrtimer_process(hrtimer_gettime());
+  hrtimer_process(clock_systime_nsec());
 #else
   /* Fallback: process one scheduler tick */
 

Reply via email to