From 71f53c6c74e322d20f712243e4db2a0283672ea3 Mon Sep 17 00:00:00 2001 From: wangchengdong Date: Mon, 10 Nov 2025 15:49:13 +0800 Subject: [PATCH] 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 --- include/nuttx/wdog.h | 89 ++++++++++++++++++++++++------------------- sched/wdog/wd_start.c | 49 ------------------------ 2 files changed, 50 insertions(+), 88 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 @@ -104,45 +104,6 @@ extern "C" #define EXTERN extern #endif -/**************************************************************************** - * 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); - /**************************************************************************** * Name: wd_start_abstick * @@ -182,6 +143,56 @@ 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); +/**************************************************************************** + * 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. + * + ****************************************************************************/ + +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 *