From 35379403f83be4997b872fd646bfecbc810e2ad5 Mon Sep 17 00:00:00 2001 From: ligd Date: Wed, 25 Aug 2021 15:05:50 +0800 Subject: [PATCH] sched/wdog: move SMP enter_critical_section to sched_timerexpiration.c Change-Id: Id654e6d2151e3b807ed2df4ab8169b90ab07b015 Signed-off-by: ligd --- sched/sched/sched_processtimer.c | 38 ++++++++++++++++++++++++- sched/sched/sched_timerexpiration.c | 43 ++++++++++++++++++++++++++++- sched/wdog/wd_start.c | 39 -------------------------- 3 files changed, 79 insertions(+), 41 deletions(-) diff --git a/sched/sched/sched_processtimer.c b/sched/sched/sched_processtimer.c index aaeba021ea..3108a5c8ca 100644 --- a/sched/sched/sched_processtimer.c +++ b/sched/sched/sched_processtimer.c @@ -142,6 +142,42 @@ static inline void nxsched_process_scheduler(void) # define nxsched_process_scheduler() #endif +/**************************************************************************** + * Name: nxsched_process_wdtimer + * + * Description: + * Wdog timer process, should with critical_section when SMP mode. + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ****************************************************************************/ + +#ifdef CONFIG_SMP +static inline void nxsched_process_wdtimer(void) +{ + irqstate_t flags; + + /* We are in an interrupt handler and, as a consequence, interrupts are + * disabled. But in the SMP case, interrupts MAY be disabled only on + * the local CPU since most architectures do not permit disabling + * interrupts on other CPUS. + * + * Hence, we must follow rules for critical sections even here in the + * SMP case. + */ + + flags = enter_critical_section(); + wd_timer(); + leave_critical_section(flags); +} +#else +# define nxsched_process_wdtimer() wd_timer() +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -210,7 +246,7 @@ void nxsched_process_timer(void) /* Process watchdogs */ - wd_timer(); + nxsched_process_wdtimer(); #ifdef CONFIG_SYSTEMTICK_HOOK /* Call out to a user-provided function in order to perform board-specific, diff --git a/sched/sched/sched_timerexpiration.c b/sched/sched/sched_timerexpiration.c index ce3348f6ca..a8999ed460 100644 --- a/sched/sched/sched_timerexpiration.c +++ b/sched/sched/sched_timerexpiration.c @@ -313,6 +313,47 @@ static uint32_t nxsched_process_scheduler(uint32_t ticks, bool noswitches) # define nxsched_process_scheduler(t,n) (0) #endif +/**************************************************************************** + * Name: nxsched_process_wdtimer + * + * Description: + * Wdog timer process, should with critical_section when SMP mode. + * + * Input Parameters: + * ticks - The number of ticks that have elapsed on the interval timer. + * noswitches - True: Can't do context switches now. + * + * Returned Value: + * The number of ticks for the next delay is provided (zero if no delay). + * + ****************************************************************************/ + +#ifdef CONFIG_SMP +static inline unsigned int nxsched_process_wdtimer(uint32_t ticks, + bool noswitches) +{ + unsigned int ret; + irqstate_t flags; + + /* We are in an interrupt handler and, as a consequence, interrupts are + * disabled. But in the SMP case, interrupts MAY be disabled only on + * the local CPU since most architectures do not permit disabling + * interrupts on other CPUS. + * + * Hence, we must follow rules for critical sections even here in the + * SMP case. + */ + + flags = enter_critical_section(); + ret = wd_timer(ticks, noswitches); + leave_critical_section(flags); + + return ret; +} +#else +# define nxsched_process_wdtimer(t,n) wd_timer(t,n) +#endif + /**************************************************************************** * Name: nxsched_timer_process * @@ -344,7 +385,7 @@ static unsigned int nxsched_timer_process(unsigned int ticks, /* Process watchdogs */ - tmp = wd_timer(ticks, noswitches); + tmp = nxsched_process_wdtimer(ticks, noswitches); if (tmp > 0) { cmptime = tmp; diff --git a/sched/wdog/wd_start.c b/sched/wdog/wd_start.c index d7e2a27881..4888358357 100644 --- a/sched/wdog/wd_start.c +++ b/sched/wdog/wd_start.c @@ -367,25 +367,9 @@ int wd_start(FAR struct wdog_s *wdog, int32_t delay, unsigned int wd_timer(int ticks, bool noswitches) { FAR struct wdog_s *wdog; -#ifdef CONFIG_SMP - irqstate_t flags; -#endif unsigned int ret; int decr; -#ifdef CONFIG_SMP - /* We are in an interrupt handler as, as a consequence, interrupts are - * disabled. But in the SMP case, interrupts MAY be disabled only on - * the local CPU since most architectures do not permit disabling - * interrupts on other CPUS. - * - * Hence, we must follow rules for critical sections even here in the - * SMP case. - */ - - flags = enter_critical_section(); -#endif - /* Check if there are any active watchdogs to process */ wdog = (FAR struct wdog_s *)g_wdactivelist.head; @@ -428,10 +412,6 @@ unsigned int wd_timer(int ticks, bool noswitches) ret = g_wdactivelist.head ? MAX(((FAR struct wdog_s *)g_wdactivelist.head)->lag, 1) : 0; -#ifdef CONFIG_SMP - leave_critical_section(flags); -#endif - /* Return the delay for the next watchdog to expire */ return ret; @@ -440,21 +420,6 @@ unsigned int wd_timer(int ticks, bool noswitches) #else void wd_timer(void) { -#ifdef CONFIG_SMP - irqstate_t flags; - - /* We are in an interrupt handler as, as a consequence, interrupts are - * disabled. But in the SMP case, interrupts MAY be disabled only on - * the local CPU since most architectures do not permit disabling - * interrupts on other CPUS. - * - * Hence, we must follow rules for critical sections even here in the - * SMP case. - */ - - flags = enter_critical_section(); -#endif - /* Check if there are any active watchdogs to process */ if (g_wdactivelist.head) @@ -467,9 +432,5 @@ void wd_timer(void) wd_expiration(); } - -#ifdef CONFIG_SMP - leave_critical_section(flags); -#endif } #endif /* CONFIG_SCHED_TICKLESS */