pm: add pm procfs support

Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
ligd
2022-06-20 18:16:42 +08:00
committed by Xiang Xiao
parent f7a1c2a585
commit c0f2b7811e
8 changed files with 655 additions and 0 deletions
+5
View File
@@ -24,6 +24,11 @@ config PM_NDOMAINS
Network domain, shutting down the network when it is not be used,
from the UI domain, shutting down the UI when it is not in use.
config PM_PROCFS
bool "PM proc fs support"
---help---
Enable procfs for pm.
config PM_GOVERNOR_GREEDY
bool "Greedy governor"
---help---
+6
View File
@@ -25,6 +25,12 @@ ifeq ($(CONFIG_PM),y)
CSRCS += pm_initialize.c pm_activity.c pm_changestate.c pm_checkstate.c
CSRCS += pm_register.c pm_unregister.c pm_autoupdate.c pm_governor.c pm_lock.c
ifeq ($(CONFIG_PM_PROCFS),y)
CSRCS += pm_procfs.c
endif
# Governor implementations
ifeq ($(CONFIG_PM_GOVERNOR_ACTIVITY),y)
+7
View File
@@ -58,6 +58,13 @@ struct pm_domain_s
struct dq_queue_s wakelock[PM_COUNT];
#ifdef CONFIG_PM_PROCFS
struct dq_queue_s wakelockall;
struct timespec start;
struct timespec wake[PM_COUNT];
struct timespec sleep[PM_COUNT];
#endif
/* Auto update or not */
bool auto_update;
+38
View File
@@ -51,6 +51,40 @@ static void pm_waklock_cb(wdparm_t arg)
pm_wakelock_relax((FAR struct pm_wakelock_s *)arg);
}
#ifdef CONFIG_PM_PROCFS
static void pm_wakelock_stats_rm(FAR struct pm_wakelock_s *wakelock)
{
FAR struct pm_domain_s *pdom = &g_pmglobals.domain[wakelock->domain];
dq_rem(&wakelock->fsnode, &pdom->wakelockall);
}
static void pm_wakelock_stats(FAR struct pm_wakelock_s *wakelock, bool stay)
{
FAR struct pm_domain_s *pdom = &g_pmglobals.domain[wakelock->domain];
struct timespec ts;
if (stay)
{
if (!wakelock->fsnode.blink && !wakelock->fsnode.flink)
{
dq_addlast(&wakelock->fsnode, &pdom->wakelockall);
}
clock_systime_timespec(&wakelock->start);
}
else
{
clock_systime_timespec(&ts);
clock_timespec_subtract(&ts, &wakelock->start, &ts);
clock_timespec_add(&ts, &wakelock->elapse, &wakelock->elapse);
}
}
#else
#define pm_wakelock_stats_rm(w)
#define pm_wakelock_stats(w, s)
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -279,6 +313,7 @@ void pm_wakelock_uninit(FAR struct pm_wakelock_s *wakelock)
wakelock->count = 0;
wd_cancel(wdog);
pm_wakelock_stats_rm(wakelock);
pm_unlock(domain, flags);
}
@@ -323,6 +358,7 @@ void pm_wakelock_stay(FAR struct pm_wakelock_s *wakelock)
if (wakelock->count++ == 0)
{
dq_addfirst(&wakelock->node, dq);
pm_wakelock_stats(wakelock, true);
}
pm_unlock(domain, flags);
@@ -369,6 +405,7 @@ void pm_wakelock_relax(FAR struct pm_wakelock_s *wakelock)
if (--wakelock->count == 0)
{
dq_rem(&wakelock->node, dq);
pm_wakelock_stats(wakelock, false);
}
pm_unlock(domain, flags);
@@ -422,6 +459,7 @@ void pm_wakelock_staytimeout(FAR struct pm_wakelock_s *wakelock, int ms)
if (wakelock->count++ == 0)
{
dq_addfirst(&wakelock->node, dq);
pm_wakelock_stats(wakelock, true);
}
}
+34
View File
@@ -168,6 +168,35 @@ static inline void pm_changeall(int domain, enum pm_state_e newstate)
}
}
#ifdef CONFIG_PM_PROCFS
static void pm_stats(FAR struct pm_domain_s *dom, int curstate, int newstate)
{
struct timespec ts;
clock_systime_timespec(&ts);
clock_timespec_subtract(&ts, &dom->start, &ts);
if (newstate == PM_RESTORE)
{
/* Wakeup from WFI */
clock_timespec_add(&ts, &dom->sleep[curstate], &dom->sleep[curstate]);
}
else
{
/* Sleep to WFI */
clock_timespec_add(&ts, &dom->wake[curstate], &dom->wake[curstate]);
}
/* Update start */
clock_systime_timespec(&dom->start);
}
#else
#define pm_stats(dom, curstate, newstate)
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -233,6 +262,11 @@ int pm_changestate(int domain, enum pm_state_e newstate)
}
}
/* Statistics */
pm_stats(&g_pmglobals.domain[domain],
g_pmglobals.domain[domain].state, newstate);
/* All drivers have agreed to the state change (or, one or more have
* disagreed and the state has been reverted). Set the new state.
*/
File diff suppressed because it is too large Load Diff
+6
View File
@@ -62,6 +62,7 @@
****************************************************************************/
extern const struct procfs_operations proc_operations;
extern const struct procfs_operations pm_operations;
extern const struct procfs_operations irq_operations;
extern const struct procfs_operations cpuload_operations;
extern const struct procfs_operations critmon_operations;
@@ -158,6 +159,11 @@ static const struct procfs_entry_s g_procfs_entries[] =
{ "partitions", &part_procfsoperations, PROCFS_FILE_TYPE },
#endif
#if defined(CONFIG_PM) && defined(CONFIG_PM_PROCFS)
{ "pm", &pm_operations, PROCFS_DIR_TYPE },
{ "pm/**", &pm_operations, PROCFS_UNKOWN_TYPE },
#endif
#ifndef CONFIG_FS_PROCFS_EXCLUDE_PROCESS
{ "self", &proc_operations, PROCFS_DIR_TYPE },
{ "self/**", &proc_operations, PROCFS_UNKOWN_TYPE },
+7
View File
@@ -57,6 +57,7 @@
#include <nuttx/wdog.h>
#include <stdbool.h>
#include <time.h>
#include <queue.h>
#ifdef CONFIG_PM
@@ -303,6 +304,12 @@ struct pm_wakelock_s
uint32_t count;
struct dq_entry_s node;
struct wdog_s wdog;
#ifdef CONFIG_PM_PROCFS
struct dq_entry_s fsnode;
struct timespec start;
struct timespec elapse;
#endif
};
/****************************************************************************