mirror of
https://github.com/apache/nuttx.git
synced 2025-01-12 22:08:35 +08:00
sched/wdog: use small lock to protect g_wdactivelist
reason: We would like to replace the critical section with a small lock. Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
parent
86d6a0be6f
commit
f14378a83a
4 changed files with 32 additions and 13 deletions
|
@ -1393,10 +1393,12 @@ void sched_note_irqhandler(int irq, FAR void *handler, bool enter)
|
||||||
void sched_note_wdog(uint8_t event, FAR void *handler, FAR const void *arg)
|
void sched_note_wdog(uint8_t event, FAR void *handler, FAR const void *arg)
|
||||||
{
|
{
|
||||||
FAR struct note_driver_s **driver;
|
FAR struct note_driver_s **driver;
|
||||||
|
irqstate_t flags;
|
||||||
struct note_wdog_s note;
|
struct note_wdog_s note;
|
||||||
bool formatted = false;
|
bool formatted = false;
|
||||||
FAR struct tcb_s *tcb = this_task();
|
FAR struct tcb_s *tcb = this_task();
|
||||||
|
|
||||||
|
flags = enter_critical_section_wo_note();
|
||||||
for (driver = g_note_drivers; *driver; driver++)
|
for (driver = g_note_drivers; *driver; driver++)
|
||||||
{
|
{
|
||||||
if (note_wdog(*driver, event, handler, arg))
|
if (note_wdog(*driver, event, handler, arg))
|
||||||
|
@ -1421,6 +1423,8 @@ void sched_note_wdog(uint8_t event, FAR void *handler, FAR const void *arg)
|
||||||
|
|
||||||
note_add(*driver, ¬e, sizeof(note));
|
note_add(*driver, ¬e, sizeof(note));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
leave_critical_section_wo_note(flags);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,8 @@
|
||||||
#include "sched/sched.h"
|
#include "sched/sched.h"
|
||||||
#include "wdog/wdog.h"
|
#include "wdog/wdog.h"
|
||||||
|
|
||||||
|
spinlock_t g_wdog_spinlock = SP_UNLOCKED;
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
@ -60,15 +62,10 @@
|
||||||
|
|
||||||
int wd_cancel(FAR struct wdog_s *wdog)
|
int wd_cancel(FAR struct wdog_s *wdog)
|
||||||
{
|
{
|
||||||
irqstate_t flags;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
flags = enter_critical_section();
|
|
||||||
|
|
||||||
ret = wd_cancel_irq(wdog);
|
ret = wd_cancel_irq(wdog);
|
||||||
|
|
||||||
leave_critical_section(flags);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,12 +88,16 @@ int wd_cancel(FAR struct wdog_s *wdog)
|
||||||
|
|
||||||
int wd_cancel_irq(FAR struct wdog_s *wdog)
|
int wd_cancel_irq(FAR struct wdog_s *wdog)
|
||||||
{
|
{
|
||||||
|
irqstate_t flags;
|
||||||
bool head;
|
bool head;
|
||||||
|
|
||||||
|
flags = spin_lock_irqsave(&g_wdog_spinlock);
|
||||||
|
|
||||||
/* Make sure that the watchdog is valid and still active. */
|
/* Make sure that the watchdog is valid and still active. */
|
||||||
|
|
||||||
if (wdog == NULL || !WDOG_ISACTIVE(wdog))
|
if (wdog == NULL || !WDOG_ISACTIVE(wdog))
|
||||||
{
|
{
|
||||||
|
spin_unlock_irqrestore(&g_wdog_spinlock, flags);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,6 +117,7 @@ int wd_cancel_irq(FAR struct wdog_s *wdog)
|
||||||
/* Mark the watchdog inactive */
|
/* Mark the watchdog inactive */
|
||||||
|
|
||||||
wdog->func = NULL;
|
wdog->func = NULL;
|
||||||
|
spin_unlock_irqrestore(&g_wdog_spinlock, flags);
|
||||||
|
|
||||||
if (head)
|
if (head)
|
||||||
{
|
{
|
||||||
|
|
|
@ -112,10 +112,11 @@ static unsigned int g_wdtimernested;
|
||||||
static inline_function void wd_expiration(clock_t ticks)
|
static inline_function void wd_expiration(clock_t ticks)
|
||||||
{
|
{
|
||||||
FAR struct wdog_s *wdog;
|
FAR struct wdog_s *wdog;
|
||||||
|
wdparm_t arg;
|
||||||
irqstate_t flags;
|
irqstate_t flags;
|
||||||
wdentry_t func;
|
wdentry_t func;
|
||||||
|
|
||||||
flags = enter_critical_section();
|
flags = spin_lock_irqsave(&g_wdog_spinlock);
|
||||||
|
|
||||||
#ifdef CONFIG_SCHED_TICKLESS
|
#ifdef CONFIG_SCHED_TICKLESS
|
||||||
/* Increment the nested watchdog timer count to handle cases where wd_start
|
/* Increment the nested watchdog timer count to handle cases where wd_start
|
||||||
|
@ -147,12 +148,17 @@ static inline_function void wd_expiration(clock_t ticks)
|
||||||
/* Indicate that the watchdog is no longer active. */
|
/* Indicate that the watchdog is no longer active. */
|
||||||
|
|
||||||
func = wdog->func;
|
func = wdog->func;
|
||||||
|
arg = wdog->arg;
|
||||||
wdog->func = NULL;
|
wdog->func = NULL;
|
||||||
|
|
||||||
/* Execute the watchdog function */
|
/* Execute the watchdog function */
|
||||||
|
|
||||||
up_setpicbase(wdog->picbase);
|
up_setpicbase(wdog->picbase);
|
||||||
CALL_FUNC(func, wdog->arg);
|
spin_unlock_irqrestore(&g_wdog_spinlock, flags);
|
||||||
|
|
||||||
|
CALL_FUNC(func, arg);
|
||||||
|
|
||||||
|
flags = spin_lock_irqsave(&g_wdog_spinlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_SCHED_TICKLESS
|
#ifdef CONFIG_SCHED_TICKLESS
|
||||||
|
@ -161,7 +167,7 @@ static inline_function void wd_expiration(clock_t ticks)
|
||||||
g_wdtimernested--;
|
g_wdtimernested--;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
leave_critical_section(flags);
|
spin_unlock_irqrestore(&g_wdog_spinlock, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
@ -293,7 +299,7 @@ int wd_start_abstick(FAR struct wdog_s *wdog, clock_t ticks,
|
||||||
* the critical section is established.
|
* the critical section is established.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
flags = enter_critical_section();
|
flags = spin_lock_irqsave(&g_wdog_spinlock);
|
||||||
#ifdef CONFIG_SCHED_TICKLESS
|
#ifdef CONFIG_SCHED_TICKLESS
|
||||||
/* We need to reassess timer if the watchdog list head has changed. */
|
/* We need to reassess timer if the watchdog list head has changed. */
|
||||||
|
|
||||||
|
@ -314,8 +320,13 @@ int wd_start_abstick(FAR struct wdog_s *wdog, clock_t ticks,
|
||||||
* then this will pick that new delay.
|
* then this will pick that new delay.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
spin_unlock_irqrestore(&g_wdog_spinlock, flags);
|
||||||
nxsched_reassess_timer();
|
nxsched_reassess_timer();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
spin_unlock_irqrestore(&g_wdog_spinlock, flags);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
UNUSED(reassess);
|
UNUSED(reassess);
|
||||||
|
|
||||||
|
@ -328,8 +339,8 @@ int wd_start_abstick(FAR struct wdog_s *wdog, clock_t ticks,
|
||||||
}
|
}
|
||||||
|
|
||||||
wd_insert(wdog, ticks, wdentry, arg);
|
wd_insert(wdog, ticks, wdentry, arg);
|
||||||
|
spin_unlock_irqrestore(&g_wdog_spinlock, flags);
|
||||||
#endif
|
#endif
|
||||||
leave_critical_section(flags);
|
|
||||||
|
|
||||||
sched_note_wdog(NOTE_WDOG_START, wdentry, (FAR void *)(uintptr_t)ticks);
|
sched_note_wdog(NOTE_WDOG_START, wdentry, (FAR void *)(uintptr_t)ticks);
|
||||||
return OK;
|
return OK;
|
||||||
|
@ -425,13 +436,13 @@ clock_t wd_timer(clock_t ticks, bool noswitches)
|
||||||
wd_expiration(ticks);
|
wd_expiration(ticks);
|
||||||
}
|
}
|
||||||
|
|
||||||
flags = enter_critical_section();
|
flags = spin_lock_irqsave(&g_wdog_spinlock);
|
||||||
|
|
||||||
/* Return the delay for the next watchdog to expire */
|
/* Return the delay for the next watchdog to expire */
|
||||||
|
|
||||||
if (list_is_empty(&g_wdactivelist))
|
if (list_is_empty(&g_wdactivelist))
|
||||||
{
|
{
|
||||||
leave_critical_section(flags);
|
spin_unlock_irqrestore(&g_wdog_spinlock, flags);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -442,7 +453,7 @@ clock_t wd_timer(clock_t ticks, bool noswitches)
|
||||||
wdog = list_first_entry(&g_wdactivelist, struct wdog_s, node);
|
wdog = list_first_entry(&g_wdactivelist, struct wdog_s, node);
|
||||||
ret = wdog->expired - ticks;
|
ret = wdog->expired - ticks;
|
||||||
|
|
||||||
leave_critical_section(flags);
|
spin_unlock_irqrestore(&g_wdog_spinlock, flags);
|
||||||
|
|
||||||
/* Return the delay for the next watchdog to expire */
|
/* Return the delay for the next watchdog to expire */
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
#include <nuttx/queue.h>
|
#include <nuttx/queue.h>
|
||||||
#include <nuttx/wdog.h>
|
#include <nuttx/wdog.h>
|
||||||
#include <nuttx/list.h>
|
#include <nuttx/list.h>
|
||||||
|
#include <nuttx/spinlock_type.h>
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
|
@ -64,6 +65,7 @@ extern "C"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern struct list_node g_wdactivelist;
|
extern struct list_node g_wdactivelist;
|
||||||
|
extern spinlock_t g_wdog_spinlock;
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Function Prototypes
|
* Public Function Prototypes
|
||||||
|
|
Loading…
Reference in a new issue