clock_adjtime: use small lock to protect g_adjtime_ppb g_adjtime_wdog

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:
hujun5 2024-12-11 16:40:52 +08:00
parent aa0aecbd80
commit dfcae8d1f1

View file

@ -49,6 +49,7 @@
static struct wdog_s g_adjtime_wdog; static struct wdog_s g_adjtime_wdog;
static long g_adjtime_ppb; static long g_adjtime_ppb;
static spinlock_t g_adjtime_lock = SP_UNLOCKED;
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
@ -58,8 +59,12 @@ static long g_adjtime_ppb;
static void adjtime_wdog_callback(wdparm_t arg) static void adjtime_wdog_callback(wdparm_t arg)
{ {
irqstate_t flags;
UNUSED(arg); UNUSED(arg);
flags = spin_lock_irqsave(&g_adjtime_lock);
#ifdef CONFIG_ARCH_HAVE_ADJTIME #ifdef CONFIG_ARCH_HAVE_ADJTIME
up_adjtime(0); up_adjtime(0);
#endif #endif
@ -69,6 +74,7 @@ static void adjtime_wdog_callback(wdparm_t arg)
#endif #endif
g_adjtime_ppb = 0; g_adjtime_ppb = 0;
spin_unlock_irqrestore(&g_adjtime_lock, flags);
} }
/* Query remaining adjustment in microseconds */ /* Query remaining adjustment in microseconds */
@ -108,7 +114,8 @@ static int adjtime_start(long long adjust_usec)
ppb = -ppb_limit; ppb = -ppb_limit;
} }
flags = enter_critical_section(); flags = spin_lock_irqsave(&g_adjtime_lock);
sched_lock();
/* Set new adjustment */ /* Set new adjustment */
@ -134,7 +141,8 @@ static int adjtime_start(long long adjust_usec)
wd_cancel(&g_adjtime_wdog); wd_cancel(&g_adjtime_wdog);
} }
leave_critical_section(flags); spin_unlock_irqrestore(&g_adjtime_lock, flags);
sched_unlock();
return ret; return ret;
} }