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 71f53c6c74e322d20f712243e4db2a0283672ea3
Author: wangchengdong <[email protected]>
AuthorDate: Mon Nov 10 15:49:13 2025 +0800

    sched/wdog: Inline wd_start() to improve performance
    
        Move wd_start() to an inline function to reduce function call
        overhead and improve performance in time-critical watchdog operations.
    
    Signed-off-by: Chengdong Wang <[email protected]>
---
 include/nuttx/wdog.h  | 33 ++++++++++++++++++++++-----------
 sched/wdog/wd_start.c | 49 -------------------------------------------------
 2 files changed, 22 insertions(+), 60 deletions(-)

diff --git a/include/nuttx/wdog.h b/include/nuttx/wdog.h
index fc935b3ba3c..072632a6725 100644
--- a/include/nuttx/wdog.h
+++ b/include/nuttx/wdog.h
@@ -105,12 +105,12 @@ extern "C"
 #endif
 
 /****************************************************************************
- * Name: wd_start
+ * Name: wd_start_abstick
  *
  * Description:
  *   This function adds a watchdog timer to the active timer queue.  The
  *   specified watchdog function at 'wdentry' will be called from the
- *   interrupt level after the specified number of ticks has elapsed.
+ *   interrupt level after the specified number of ticks has reached.
  *   Watchdog timers may be started from the interrupt level.
  *
  *   Watchdog timers execute in the address environment that was in effect
@@ -124,7 +124,7 @@ extern "C"
  *
  * Input Parameters:
  *   wdog     - Watchdog ID
- *   delay    - Delay count in clock ticks
+ *   ticks    - Absolute time in clock ticks
  *   wdentry  - Function to call on timeout
  *   arg      - Parameter to pass to wdentry.
  *
@@ -140,16 +140,16 @@ extern "C"
  *
  ****************************************************************************/
 
-int wd_start(FAR struct wdog_s *wdog, clock_t delay,
-             wdentry_t wdentry, wdparm_t arg);
+int wd_start_abstick(FAR struct wdog_s *wdog, clock_t ticks,
+                     wdentry_t wdentry, wdparm_t arg);
 
 /****************************************************************************
- * Name: wd_start_abstick
+ * Name: wd_start
  *
  * Description:
  *   This function adds a watchdog timer to the active timer queue.  The
  *   specified watchdog function at 'wdentry' will be called from the
- *   interrupt level after the specified number of ticks has reached.
+ *   interrupt level after the specified number of ticks has elapsed.
  *   Watchdog timers may be started from the interrupt level.
  *
  *   Watchdog timers execute in the address environment that was in effect
@@ -163,9 +163,9 @@ int wd_start(FAR struct wdog_s *wdog, clock_t delay,
  *
  * Input Parameters:
  *   wdog     - Watchdog ID
- *   ticks    - Absolute time in clock ticks
+ *   delay    - Delay count in clock ticks
  *   wdentry  - Function to call on timeout
- *   arg      - Parameter to pass to wdentry.
+ *   arg      - Parameter to pass to wdentry
  *
  *   NOTE:  The parameter must be of type wdparm_t.
  *
@@ -179,8 +179,19 @@ int wd_start(FAR struct wdog_s *wdog, clock_t delay,
  *
  ****************************************************************************/
 
-int wd_start_abstick(FAR struct wdog_s *wdog, clock_t ticks,
-                     wdentry_t wdentry, wdparm_t arg);
+static inline_function
+int wd_start(FAR struct wdog_s *wdog, clock_t delay,
+             wdentry_t wdentry, wdparm_t arg)
+{
+  /* Ensure delay is within the range the wdog can handle. */
+
+  if (delay >= WDOG_MAX_DELAY)
+    {
+      return -EINVAL;
+    }
+
+  return wd_start_abstick(wdog, clock_delay2abstick(delay), wdentry, arg);
+}
 
 /****************************************************************************
  * Name: wd_start_abstime
diff --git a/sched/wdog/wd_start.c b/sched/wdog/wd_start.c
index a8d2b01f451..2b4ac7b4d51 100644
--- a/sched/wdog/wd_start.c
+++ b/sched/wdog/wd_start.c
@@ -345,55 +345,6 @@ int wd_start_abstick(FAR struct wdog_s *wdog, clock_t 
ticks,
   return OK;
 }
 
-/****************************************************************************
- * Name: wd_start
- *
- * Description:
- *   This function adds a watchdog timer to the active timer queue.  The
- *   specified watchdog function at 'wdentry' will be called from the
- *   interrupt level after the specified number of ticks has elapsed.
- *   Watchdog timers may be started from the interrupt level.
- *
- *   Watchdog timers execute in the address environment that was in effect
- *   when wd_start() is called.
- *
- *   Watchdog timers execute only once.
- *
- *   To replace either the timeout delay or the function to be executed,
- *   call wd_start again with the same wdog; only the most recent wdStart()
- *   on a given watchdog ID has any effect.
- *
- * Input Parameters:
- *   wdog     - Watchdog ID
- *   delay    - Delay count in clock ticks
- *   wdentry  - Function to call on timeout
- *   arg      - Parameter to pass to wdentry
- *
- *   NOTE:  The parameter must be of type wdparm_t.
- *
- * Returned Value:
- *   Zero (OK) is returned on success; a negated errno value is return to
- *   indicate the nature of any failure.
- *
- * Assumptions:
- *   The watchdog routine runs in the context of the timer interrupt handler
- *   and is subject to all ISR restrictions.
- *
- ****************************************************************************/
-
-int wd_start(FAR struct wdog_s *wdog, clock_t delay,
-             wdentry_t wdentry, wdparm_t arg)
-{
-  /* Ensure delay is within the range the wdog can handle. */
-
-  if (delay >= WDOG_MAX_DELAY)
-    {
-      return -EINVAL;
-    }
-
-  return wd_start_abstick(wdog, clock_delay2abstick(delay), wdentry, arg);
-}
-
 /****************************************************************************
  * Name: wd_timer
  *

Reply via email to