mirror of
https://github.com/apache/nuttx.git
synced 2026-05-27 19:36:35 +08:00
clock/perf: add critical section protection
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
This commit is contained in:
@@ -26,8 +26,9 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <nuttx/clock.h>
|
|
||||||
#include <nuttx/arch.h>
|
#include <nuttx/arch.h>
|
||||||
|
#include <nuttx/clock.h>
|
||||||
|
#include <nuttx/spinlock.h>
|
||||||
#include <nuttx/wdog.h>
|
#include <nuttx/wdog.h>
|
||||||
|
|
||||||
#if defined(CONFIG_PERF_OVERFLOW_CORRECTION) && ULONG_MAX != UINT64_MAX
|
#if defined(CONFIG_PERF_OVERFLOW_CORRECTION) && ULONG_MAX != UINT64_MAX
|
||||||
@@ -39,6 +40,7 @@
|
|||||||
struct perf_s
|
struct perf_s
|
||||||
{
|
{
|
||||||
struct wdog_s wdog;
|
struct wdog_s wdog;
|
||||||
|
spinlock_t lock;
|
||||||
unsigned long last;
|
unsigned long last;
|
||||||
unsigned long overflow;
|
unsigned long overflow;
|
||||||
};
|
};
|
||||||
@@ -93,6 +95,8 @@ clock_t perf_gettime(void)
|
|||||||
{
|
{
|
||||||
FAR struct perf_s *perf = &g_perf;
|
FAR struct perf_s *perf = &g_perf;
|
||||||
unsigned long now = up_perf_gettime();
|
unsigned long now = up_perf_gettime();
|
||||||
|
irqstate_t flags = spin_lock_irqsave(&perf->lock);
|
||||||
|
clock_t result;
|
||||||
|
|
||||||
/* Check if overflow */
|
/* Check if overflow */
|
||||||
|
|
||||||
@@ -102,7 +106,9 @@ clock_t perf_gettime(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
perf->last = now;
|
perf->last = now;
|
||||||
return (clock_t)now | (clock_t)perf->overflow << 32;
|
result = (clock_t)now | (clock_t)perf->overflow << 32;
|
||||||
|
spin_unlock_irqrestore(&perf->lock, flags);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
Reference in New Issue
Block a user