pm: change pm lock from mutex to spinlock
as we always want to take critical_section, and it is not long time job, take mutex is not necessary, use spinlock_irq_save as a replace is better, dont't have to take global critial_section in pm. Signed-off-by: buxiasen <buxiasen@xiaomi.com>
This commit is contained in:
parent
2827703b0c
commit
d7ab3cc1be
@ -101,7 +101,7 @@ static enum pm_state_e greedy_governor_checkstate(int domain)
|
|||||||
* invoked, which modifies the stay count which we are about to read
|
* invoked, which modifies the stay count which we are about to read
|
||||||
*/
|
*/
|
||||||
|
|
||||||
flags = pm_domain_lock(domain);
|
flags = pm_lock(&pdom->lock);
|
||||||
|
|
||||||
/* Find the lowest power-level which is not locked. */
|
/* Find the lowest power-level which is not locked. */
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ static enum pm_state_e greedy_governor_checkstate(int domain)
|
|||||||
state++;
|
state++;
|
||||||
}
|
}
|
||||||
|
|
||||||
pm_domain_unlock(domain, flags);
|
pm_unlock(&pdom->lock, flags);
|
||||||
|
|
||||||
/* Return the found state */
|
/* Return the found state */
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
#include <nuttx/queue.h>
|
#include <nuttx/queue.h>
|
||||||
#include <nuttx/mutex.h>
|
#include <nuttx/spinlock.h>
|
||||||
#include <nuttx/clock.h>
|
#include <nuttx/clock.h>
|
||||||
#include <nuttx/power/pm.h>
|
#include <nuttx/power/pm.h>
|
||||||
#include <nuttx/wqueue.h>
|
#include <nuttx/wqueue.h>
|
||||||
@ -88,9 +88,9 @@ struct pm_domain_s
|
|||||||
|
|
||||||
FAR const struct pm_governor_s *governor;
|
FAR const struct pm_governor_s *governor;
|
||||||
|
|
||||||
/* Recursive lock for race condition */
|
/* Spinlock for data read/write protect inside this struct */
|
||||||
|
|
||||||
rmutex_t lock;
|
spinlock_t lock;
|
||||||
};
|
};
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -128,7 +128,10 @@ EXTERN struct pm_domain_s g_pmdomains[CONFIG_PM_NDOMAINS];
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
irqstate_t pm_lock(FAR rmutex_t *lock);
|
static inline irqstate_t pm_lock(FAR spinlock_t *lock)
|
||||||
|
{
|
||||||
|
return spin_lock_irqsave(lock);
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: pm_unlock
|
* Name: pm_unlock
|
||||||
@ -144,7 +147,10 @@ irqstate_t pm_lock(FAR rmutex_t *lock);
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
void pm_unlock(FAR rmutex_t *lock, irqstate_t flags);
|
static inline void pm_unlock(FAR spinlock_t *lock, irqstate_t flags)
|
||||||
|
{
|
||||||
|
spin_unlock_irqrestore(lock, flags);
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: pm_domain_lock
|
* Name: pm_domain_lock
|
||||||
|
@ -305,7 +305,7 @@ void pm_wakelock_uninit(FAR struct pm_wakelock_s *wakelock)
|
|||||||
dq = &pdom->wakelock[wakelock->state];
|
dq = &pdom->wakelock[wakelock->state];
|
||||||
wdog = &wakelock->wdog;
|
wdog = &wakelock->wdog;
|
||||||
|
|
||||||
flags = pm_domain_lock(domain);
|
flags = pm_lock(&pdom->lock);
|
||||||
|
|
||||||
if (wakelock->count > 0)
|
if (wakelock->count > 0)
|
||||||
{
|
{
|
||||||
@ -316,7 +316,7 @@ void pm_wakelock_uninit(FAR struct pm_wakelock_s *wakelock)
|
|||||||
wd_cancel(wdog);
|
wd_cancel(wdog);
|
||||||
pm_wakelock_stats_rm(wakelock);
|
pm_wakelock_stats_rm(wakelock);
|
||||||
|
|
||||||
pm_domain_unlock(domain, flags);
|
pm_unlock(&pdom->lock, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -353,7 +353,7 @@ void pm_wakelock_stay(FAR struct pm_wakelock_s *wakelock)
|
|||||||
pdom = &g_pmdomains[domain];
|
pdom = &g_pmdomains[domain];
|
||||||
dq = &pdom->wakelock[wakelock->state];
|
dq = &pdom->wakelock[wakelock->state];
|
||||||
|
|
||||||
flags = pm_domain_lock(domain);
|
flags = pm_lock(&pdom->lock);
|
||||||
|
|
||||||
DEBUGASSERT(wakelock->count < UINT32_MAX);
|
DEBUGASSERT(wakelock->count < UINT32_MAX);
|
||||||
if (wakelock->count++ == 0)
|
if (wakelock->count++ == 0)
|
||||||
@ -362,7 +362,7 @@ void pm_wakelock_stay(FAR struct pm_wakelock_s *wakelock)
|
|||||||
pm_wakelock_stats(wakelock, true);
|
pm_wakelock_stats(wakelock, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
pm_domain_unlock(domain, flags);
|
pm_unlock(&pdom->lock, flags);
|
||||||
|
|
||||||
pm_auto_updatestate(domain);
|
pm_auto_updatestate(domain);
|
||||||
}
|
}
|
||||||
@ -400,7 +400,7 @@ void pm_wakelock_relax(FAR struct pm_wakelock_s *wakelock)
|
|||||||
pdom = &g_pmdomains[domain];
|
pdom = &g_pmdomains[domain];
|
||||||
dq = &pdom->wakelock[wakelock->state];
|
dq = &pdom->wakelock[wakelock->state];
|
||||||
|
|
||||||
flags = pm_domain_lock(domain);
|
flags = pm_lock(&pdom->lock);
|
||||||
|
|
||||||
DEBUGASSERT(wakelock->count > 0);
|
DEBUGASSERT(wakelock->count > 0);
|
||||||
if (--wakelock->count == 0)
|
if (--wakelock->count == 0)
|
||||||
@ -409,7 +409,7 @@ void pm_wakelock_relax(FAR struct pm_wakelock_s *wakelock)
|
|||||||
pm_wakelock_stats(wakelock, false);
|
pm_wakelock_stats(wakelock, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
pm_domain_unlock(domain, flags);
|
pm_unlock(&pdom->lock, flags);
|
||||||
|
|
||||||
pm_auto_updatestate(domain);
|
pm_auto_updatestate(domain);
|
||||||
}
|
}
|
||||||
@ -452,7 +452,7 @@ void pm_wakelock_staytimeout(FAR struct pm_wakelock_s *wakelock, int ms)
|
|||||||
dq = &pdom->wakelock[wakelock->state];
|
dq = &pdom->wakelock[wakelock->state];
|
||||||
wdog = &wakelock->wdog;
|
wdog = &wakelock->wdog;
|
||||||
|
|
||||||
flags = pm_domain_lock(domain);
|
flags = pm_lock(&pdom->lock);
|
||||||
|
|
||||||
if (!WDOG_ISACTIVE(wdog))
|
if (!WDOG_ISACTIVE(wdog))
|
||||||
{
|
{
|
||||||
@ -469,7 +469,7 @@ void pm_wakelock_staytimeout(FAR struct pm_wakelock_s *wakelock, int ms)
|
|||||||
wd_start(wdog, MSEC2TICK(ms), pm_waklock_cb, (wdparm_t)wakelock);
|
wd_start(wdog, MSEC2TICK(ms), pm_waklock_cb, (wdparm_t)wakelock);
|
||||||
}
|
}
|
||||||
|
|
||||||
pm_domain_unlock(domain, flags);
|
pm_unlock(&pdom->lock, flags);
|
||||||
|
|
||||||
pm_auto_updatestate(domain);
|
pm_auto_updatestate(domain);
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ void pm_initialize(void)
|
|||||||
clock_systime_timespec(&g_pmdomains[i].start);
|
clock_systime_timespec(&g_pmdomains[i].start);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
nxrmutex_init(&g_pmdomains[i].lock);
|
spin_lock_init(&g_pmdomains[i].lock);
|
||||||
|
|
||||||
#if CONFIG_PM_GOVERNOR_EXPLICIT_RELAX
|
#if CONFIG_PM_GOVERNOR_EXPLICIT_RELAX
|
||||||
for (state = 0; state < PM_COUNT; state++)
|
for (state = 0; state < PM_COUNT; state++)
|
||||||
|
@ -37,26 +37,6 @@
|
|||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
irqstate_t pm_lock(FAR rmutex_t *lock)
|
|
||||||
{
|
|
||||||
if (!up_interrupt_context() && !sched_idletask())
|
|
||||||
{
|
|
||||||
nxrmutex_lock(lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
return enter_critical_section();
|
|
||||||
}
|
|
||||||
|
|
||||||
void pm_unlock(FAR rmutex_t *lock, irqstate_t flags)
|
|
||||||
{
|
|
||||||
leave_critical_section(flags);
|
|
||||||
|
|
||||||
if (!up_interrupt_context() && !sched_idletask())
|
|
||||||
{
|
|
||||||
nxrmutex_unlock(lock);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
irqstate_t pm_domain_lock(int domain)
|
irqstate_t pm_domain_lock(int domain)
|
||||||
{
|
{
|
||||||
return pm_lock(&g_pmdomains[domain].lock);
|
return pm_lock(&g_pmdomains[domain].lock);
|
||||||
|
@ -165,7 +165,7 @@ static enum pm_state_e stability_governor_checkstate(int domain)
|
|||||||
* invoked, which modifies the stay count which we are about to read
|
* invoked, which modifies the stay count which we are about to read
|
||||||
*/
|
*/
|
||||||
|
|
||||||
flags = pm_domain_lock(domain);
|
flags = pm_lock(&pdom->lock);
|
||||||
|
|
||||||
/* Find the lowest power-level which is not locked. */
|
/* Find the lowest power-level which is not locked. */
|
||||||
|
|
||||||
@ -201,7 +201,7 @@ static enum pm_state_e stability_governor_checkstate(int domain)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pm_domain_unlock(domain, flags);
|
pm_unlock(&pdom->lock, flags);
|
||||||
|
|
||||||
/* Return the found state */
|
/* Return the found state */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user