diff --git a/sched/sched/sched_timerexpiration.c b/sched/sched/sched_timerexpiration.c index 82c86450e1f..546fb9f246b 100644 --- a/sched/sched/sched_timerexpiration.c +++ b/sched/sched/sched_timerexpiration.c @@ -100,6 +100,10 @@ static clock_t g_timer_tick; static atomic_t g_timer_interval; +#ifdef CONFIG_SCHED_TICKLESS +static unsigned int g_timernested; +#endif + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -470,12 +474,19 @@ clock_t nxsched_timer_update(clock_t ticks, bool noswitches) void nxsched_timer_expiration(void) { clock_t ticks; + irqstate_t flags = enter_critical_section(); /* Get the interval associated with last expiration */ + g_timernested++; + up_timer_gettick(&ticks); nxsched_timer_update(ticks, false); + + g_timernested--; + + leave_critical_section(flags); } /**************************************************************************** @@ -519,17 +530,20 @@ void nxsched_reassess_timer(void) { clock_t ticks; - /* Cancel the timer and get the current time */ + if (!g_timernested) + { + /* Cancel the timer and get the current time */ #ifdef CONFIG_SCHED_TICKLESS_ALARM - up_alarm_tick_cancel(&ticks); + up_alarm_tick_cancel(&ticks); #else - clock_t elapsed; - up_timer_gettick(&ticks); - up_timer_tick_cancel(&elapsed); + clock_t elapsed; + up_timer_gettick(&ticks); + up_timer_tick_cancel(&elapsed); #endif - nxsched_timer_update(ticks, true); + nxsched_timer_update(ticks, true); + } } /**************************************************************************** diff --git a/sched/wdog/wd_start.c b/sched/wdog/wd_start.c index aca3d3f0751..77a50e4f4cf 100644 --- a/sched/wdog/wd_start.c +++ b/sched/wdog/wd_start.c @@ -85,14 +85,6 @@ #define wdparm_to_ptr(type, arg) ((type)(uintptr_t)arg) #define ptr_to_wdparm(ptr) wdparm_to_ptr(wdparm_t, ptr) -/**************************************************************************** - * Private Data - ****************************************************************************/ - -#ifdef CONFIG_SCHED_TICKLESS -static unsigned int g_wdtimernested; -#endif - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -121,14 +113,6 @@ static inline_function void wd_expiration(clock_t ticks) flags = spin_lock_irqsave(&g_wdspinlock); -#ifdef CONFIG_SCHED_TICKLESS - /* Increment the nested watchdog timer count to handle cases where wd_start - * is called in the watchdog callback functions. - */ - - g_wdtimernested++; -#endif - /* Process the watchdog at the head of the list as well as any * other watchdogs that became ready to run at this time */ @@ -173,12 +157,6 @@ static inline_function void wd_expiration(clock_t ticks) flags = spin_lock_irqsave(&g_wdspinlock); } -#ifdef CONFIG_SCHED_TICKLESS - /* Decrement the nested watchdog timer count */ - - g_wdtimernested--; -#endif - spin_unlock_irqrestore(&g_wdspinlock, flags); } @@ -313,7 +291,7 @@ int wd_start_abstick(FAR struct wdog_s *wdog, clock_t ticks, reassess |= wd_insert(wdog, ticks, wdentry, arg); - if (!g_wdtimernested && reassess) + if (reassess) { /* Resume the interval timer that will generate the next * interval event. If the timer at the head of the list changed,