summaryrefslogtreecommitdiff
path: root/power-libperfmgr
diff options
context:
space:
mode:
authorKelly Rossmoyer <krossmo@google.com>2018-03-15 20:38:08 +0000
committerKelly Rossmoyer <krossmo@google.com>2018-03-15 20:39:31 +0000
commit85e7c87e06e05a857a61923656b0ca2b7c6d2765 (patch)
tree1673417317b1f67a77eaf8b826109a010e59a2dd /power-libperfmgr
parent4d40822b371f9ba76ad7dfd9702284c1d8869f8d (diff)
downloadbonito-85e7c87e06e05a857a61923656b0ca2b7c6d2765.tar.gz
Revert "2018 PowerHAL support for master stats"
This reverts commit 4d40822b371f9ba76ad7dfd9702284c1d8869f8d. Reason for revert: Build breakage due to incorrect printf format spec Bug:67381845 Change-Id: Ib302f0aaf46bb4f5889a314e45bc170e66053ada
Diffstat (limited to 'power-libperfmgr')
-rw-r--r--power-libperfmgr/Power.cpp118
-rw-r--r--power-libperfmgr/power-helper.c143
-rw-r--r--power-libperfmgr/power-helper.h98
3 files changed, 126 insertions, 233 deletions
diff --git a/power-libperfmgr/Power.cpp b/power-libperfmgr/Power.cpp
index 1d71e52f..7f1105d3 100644
--- a/power-libperfmgr/Power.cpp
+++ b/power-libperfmgr/Power.cpp
@@ -32,7 +32,7 @@
/* RPM runs at 19.2Mhz. Divide by 19200 for msec */
#define RPM_CLK 19200
-extern struct stats_section master_sections[];
+extern struct stat_pair rpm_stat_map[];
namespace android {
namespace hardware {
@@ -233,89 +233,67 @@ Return<void> Power::setFeature(Feature /*feature*/, bool /*activate*/) {
Return<void> Power::getPlatformLowPowerStats(getPlatformLowPowerStats_cb _hidl_cb) {
hidl_vec<PowerStatePlatformSleepState> states;
- uint64_t stats[SYSTEM_SLEEP_STATE_COUNT * SYSTEM_STATE_STATS_COUNT] = {0};
- uint64_t *state_stats;
+ uint64_t stats[MAX_PLATFORM_STATS * MAX_RPM_PARAMS] = {0};
+ uint64_t *values;
struct PowerStatePlatformSleepState *state;
+ int ret;
- states.resize(SYSTEM_SLEEP_STATE_COUNT);
+ states.resize(PLATFORM_SLEEP_MODES_COUNT);
- if (extract_system_stats(stats, ARRAY_SIZE(stats)) != 0) {
+ ret = extract_platform_stats(stats);
+ if (ret != 0) {
states.resize(0);
goto done;
}
- /* Update statistics for AOSD */
- state = &states[SYSTEM_STATE_AOSD];
- state->name = "AOSD";
- state_stats = &stats[SYSTEM_STATE_AOSD * SYSTEM_STATE_STATS_COUNT];
+ /* Update statistics for XO_shutdown */
+ state = &states[RPM_MODE_XO];
+ state->name = "XO_shutdown";
+ values = stats + (RPM_MODE_XO * MAX_RPM_PARAMS);
- state->residencyInMsecSinceBoot = state_stats[ACCUMULATED_TIME_MS];
- state->totalTransitions = state_stats[TOTAL_COUNT];
+ state->residencyInMsecSinceBoot = values[1];
+ state->totalTransitions = values[0];
state->supportedOnlyInSuspend = false;
- state->voters.resize(0);
+ state->voters.resize(XO_VOTERS);
+ for(size_t i = 0; i < XO_VOTERS; i++) {
+ int voter = static_cast<int>(i + XO_VOTERS_START);
+ state->voters[i].name = rpm_stat_map[voter].label;
+ values = stats + (voter * MAX_RPM_PARAMS);
+ state->voters[i].totalTimeInMsecVotedForSinceBoot = values[0] / RPM_CLK;
+ state->voters[i].totalNumberOfTimesVotedSinceBoot = values[1];
+ }
- /* Update statistics for CXSD */
- state = &states[SYSTEM_STATE_CXSD];
- state->name = "CXSD";
- state_stats = &stats[SYSTEM_STATE_CXSD * SYSTEM_STATE_STATS_COUNT];
+ /* Update statistics for VMIN state */
+ state = &states[RPM_MODE_VMIN];
+ state->name = "VMIN";
+ values = stats + (RPM_MODE_VMIN * MAX_RPM_PARAMS);
- state->residencyInMsecSinceBoot = state_stats[ACCUMULATED_TIME_MS];
- state->totalTransitions = state_stats[TOTAL_COUNT];
+ state->residencyInMsecSinceBoot = values[1];
+ state->totalTransitions = values[0];
state->supportedOnlyInSuspend = false;
- state->voters.resize(0);
+ state->voters.resize(VMIN_VOTERS);
+ //Note: No filling of state voters since VMIN_VOTERS = 0
done:
_hidl_cb(states, Status::SUCCESS);
return Void();
}
-static int get_master_low_power_stats(hidl_vec<PowerStateSubsystem> *subsystems) {
- uint64_t all_stats[MASTER_COUNT * MASTER_STATS_COUNT] = {0};
- uint64_t *section_stats;
- struct PowerStateSubsystem *subsystem;
- struct PowerStateSubsystemSleepState *state;
-
- if (extract_master_stats(all_stats, ARRAY_SIZE(all_stats)) != 0) {
- for (size_t i = 0; i < MASTER_COUNT; i++) {
- (*subsystems)[i].name = master_sections[i].label;
- (*subsystems)[i].states.resize(0);
- }
- return -1;
- }
-
- for (size_t i = 0; i < MASTER_COUNT; i++) {
- subsystem = &(*subsystems)[i];
- subsystem->name = master_sections[i].label;
- subsystem->states.resize(MASTER_SLEEP_STATE_COUNT);
-
- state = &(subsystem->states[MASTER_SLEEP]);
- section_stats = &all_stats[i * MASTER_STATS_COUNT];
+static int get_wlan_low_power_stats(struct PowerStateSubsystem &subsystem) {
- state->name = "Sleep";
- state->totalTransitions = section_stats[SLEEP_ENTER_COUNT];
- state->residencyInMsecSinceBoot = section_stats[SLEEP_CUMULATIVE_DURATION_MS] / RPM_CLK;
- state->lastEntryTimestampMs = section_stats[SLEEP_LAST_ENTER_TSTAMP_MS] / RPM_CLK;
- state->supportedOnlyInSuspend = false;
- }
-
- return 0;
-}
-
-static int get_wlan_low_power_stats(struct PowerStateSubsystem *subsystem) {
- uint64_t stats[WLAN_STATS_COUNT] = {0};
+ uint64_t stats[WLAN_POWER_PARAMS_COUNT] = {0};
struct PowerStateSubsystemSleepState *state;
+ int ret;
- subsystem->name = "wlan";
+ ret = extract_wlan_stats(stats);
+ if (ret)
+ return ret;
- if (extract_wlan_stats(stats, ARRAY_SIZE(stats)) != 0) {
- subsystem->states.resize(0);
- return -1;
- }
-
- subsystem->states.resize(WLAN_SLEEP_STATE_COUNT);
+ subsystem.name = "wlan";
+ subsystem.states.resize(WLAN_STATES_COUNT);
/* Update statistics for Active State */
- state = &subsystem->states[WLAN_STATE_ACTIVE];
+ state = &subsystem.states[WLAN_STATE_ACTIVE];
state->name = "Active";
state->residencyInMsecSinceBoot = stats[CUMULATIVE_TOTAL_ON_TIME_MS];
state->totalTransitions = stats[DEEP_SLEEP_ENTER_COUNTER];
@@ -323,7 +301,7 @@ static int get_wlan_low_power_stats(struct PowerStateSubsystem *subsystem) {
state->supportedOnlyInSuspend = false;
/* Update statistics for Deep-Sleep state */
- state = &subsystem->states[WLAN_STATE_DEEP_SLEEP];
+ state = &subsystem.states[WLAN_STATE_DEEP_SLEEP];
state->name = "Deep-Sleep";
state->residencyInMsecSinceBoot = stats[CUMULATIVE_SLEEP_TIME_MS];
state->totalTransitions = stats[DEEP_SLEEP_ENTER_COUNTER];
@@ -335,20 +313,20 @@ static int get_wlan_low_power_stats(struct PowerStateSubsystem *subsystem) {
// Methods from ::android::hardware::power::V1_1::IPower follow.
Return<void> Power::getSubsystemLowPowerStats(getSubsystemLowPowerStats_cb _hidl_cb) {
+
hidl_vec<PowerStateSubsystem> subsystems;
+ int ret;
- subsystems.resize(STATS_SOURCE_COUNT);
+ subsystems.resize(SUBSYSTEM_COUNT);
- // Get low power stats for all of the system masters.
- if (get_master_low_power_stats(&subsystems) != 0) {
- ALOGE("%s: failed to process master stats", __func__);
- }
+ //We currently have only one Subsystem for WLAN
+ ret = get_wlan_low_power_stats(subsystems[SUBSYSTEM_WLAN]);
+ if (ret != 0)
+ goto done;
- // Get WLAN subsystem low power stats.
- if (get_wlan_low_power_stats(&subsystems[SUBSYSTEM_WLAN]) != 0) {
- ALOGE("%s: failed to process wlan stats", __func__);
- }
+ //Add query for other subsystems here
+done:
_hidl_cb(subsystems, Status::SUCCESS);
return Void();
}
diff --git a/power-libperfmgr/power-helper.c b/power-libperfmgr/power-helper.c
index d22438da..d978e267 100644
--- a/power-libperfmgr/power-helper.c
+++ b/power-libperfmgr/power-helper.c
@@ -43,63 +43,54 @@
#include "power-helper.h"
-#ifndef MASTER_STATS_FILE
-#define MASTER_STATS_FILE "/sys/power/rpmh_stats/master_stats"
+#ifndef RPM_SYSTEM_STAT
+#define RPM_SYSTEM_STAT "/d/system_stats"
#endif
-#ifndef WLAN_STATS_FILE
-#define WLAN_STATS_FILE "/d/wlan0/power_stats"
-#endif
-
-#ifndef SYSTEM_STATS_FILE
-#define SYSTEM_STATS_FILE "/sys/power/system_sleep/stats"
+#ifndef WLAN_POWER_STAT
+#define WLAN_POWER_STAT "/d/wlan0/power_stats"
#endif
+#define ARRAY_SIZE(x) (sizeof((x))/sizeof((x)[0]))
#define LINE_SIZE 128
-const char *master_stats_labels[MASTER_STATS_COUNT] = {
- "Sleep Accumulated Duration",
- "Sleep Count",
- "Sleep Last Entered At",
+const char *rpm_stat_params[MAX_RPM_PARAMS] = {
+ "count",
+ "actual last sleep(msec)",
};
-struct stats_section master_sections[MASTER_COUNT] = {
- { MASTER_APSS, "APSS", master_stats_labels, ARRAY_SIZE(master_stats_labels) },
- { MASTER_MPSS, "MPSS", master_stats_labels, ARRAY_SIZE(master_stats_labels) },
- { MASTER_ADSP, "ADSP", master_stats_labels, ARRAY_SIZE(master_stats_labels) },
- { MASTER_SLPI, "SLPI", master_stats_labels, ARRAY_SIZE(master_stats_labels) },
- { MASTER_CDSP, "CDSP", master_stats_labels, ARRAY_SIZE(master_stats_labels) },
- { MASTER_GPU, "GPU", master_stats_labels, ARRAY_SIZE(master_stats_labels) },
- { MASTER_DISPLAY, "DISPLAY", master_stats_labels, ARRAY_SIZE(master_stats_labels) },
+const char *master_stat_params[MAX_RPM_PARAMS] = {
+ "Accumulated XO duration",
+ "XO Count",
};
-const char *wlan_stats_labels[WLAN_STATS_COUNT] = {
+struct stat_pair rpm_stat_map[] = {
+ { RPM_MODE_XO, "RPM Mode:vlow", rpm_stat_params, ARRAY_SIZE(rpm_stat_params) },
+ { RPM_MODE_VMIN, "RPM Mode:vmin", rpm_stat_params, ARRAY_SIZE(rpm_stat_params) },
+ { VOTER_APSS, "APSS", master_stat_params, ARRAY_SIZE(master_stat_params) },
+ { VOTER_MPSS, "MPSS", master_stat_params, ARRAY_SIZE(master_stat_params) },
+ { VOTER_ADSP, "ADSP", master_stat_params, ARRAY_SIZE(master_stat_params) },
+ { VOTER_SLPI, "SLPI", master_stat_params, ARRAY_SIZE(master_stat_params) },
+};
+
+
+const char *wlan_power_stat_params[] = {
"cumulative_sleep_time_ms",
"cumulative_total_on_time_ms",
"deep_sleep_enter_counter",
"last_deep_sleep_enter_tstamp_ms"
};
-struct stats_section wlan_sections[] = {
- { SUBSYSTEM_WLAN, "POWER DEBUG STATS", wlan_stats_labels, ARRAY_SIZE(wlan_stats_labels) },
-};
-
-const char *system_stats_labels[SYSTEM_STATE_STATS_COUNT] = {
- "count",
- "actual last sleep(msec)"
-};
-
-struct stats_section system_sections[] = {
- { SYSTEM_STATES, "RPM Mode:aosd", system_stats_labels, ARRAY_SIZE(system_stats_labels) },
- { SYSTEM_STATES, "RPM Mode:cxsd", system_stats_labels, ARRAY_SIZE(system_stats_labels) },
+struct stat_pair wlan_stat_map[] = {
+ { WLAN_POWER_DEBUG_STATS, "POWER DEBUG STATS", wlan_power_stat_params, ARRAY_SIZE(wlan_power_stat_params) },
};
-static int parse_stats(const char **stat_labels, size_t num_stats,
- uint64_t *list, FILE *fp) {
+static int parse_stats(const char **params, size_t params_size,
+ uint64_t *list, FILE *fp) {
ssize_t nread;
size_t len = LINE_SIZE;
char *line;
- size_t stats_read = 0;
+ size_t params_read = 0;
size_t i;
line = malloc(len);
@@ -108,7 +99,7 @@ static int parse_stats(const char **stat_labels, size_t num_stats,
return -ENOMEM;
}
- while ((stats_read < num_stats) &&
+ while ((params_read < params_size) &&
(nread = getline(&line, &len, fp) > 0)) {
char *key = line + strspn(line, " \t");
char *value = strchr(key, ':');
@@ -116,30 +107,27 @@ static int parse_stats(const char **stat_labels, size_t num_stats,
continue;
*value++ = '\0';
- for (i = 0; i < num_stats; i++) {
- if (!strncmp(key, stat_labels[i], strlen(stat_labels[i]))) {
+ for (i = 0; i < params_size; i++) {
+ if (!strcmp(key, params[i])) {
list[i] = strtoull(value, NULL, 0);
- stats_read++;
+ params_read++;
break;
}
}
}
-
free(line);
- return stats_read;
+ return 0;
}
-static int extract_stats(uint64_t *stats_list, size_t entries_per_section, char *file,
- struct stats_section *sections, size_t num_sections) {
+static int extract_stats(uint64_t *list, char *file,
+ struct stat_pair *map, size_t map_size) {
FILE *fp;
ssize_t read;
size_t len = LINE_SIZE;
char *line;
- size_t i;
- size_t sections_read = 0;
- size_t stats_read = 0;
+ size_t i, stats_read = 0;
int ret = 0;
fp = fopen(file, "re");
@@ -155,71 +143,34 @@ static int extract_stats(uint64_t *stats_list, size_t entries_per_section, char
return -ENOMEM;
}
- // Ensure that any missing stats default to 0
- for (i = 0; i < (entries_per_section * num_sections); i++) {
- stats_list[i] = 0L;
- }
-
- // Iterate over the sections we expect to find in the file, calling parse_stats()
- // to process each section as we detect section headers
- while ((sections_read < num_sections) && (read = getline(&line, &len, fp) != -1)) {
+ while ((stats_read < map_size) && (read = getline(&line, &len, fp) != -1)) {
size_t begin = strspn(line, " \t");
- for (i = 0; i < num_sections; i++) {
- if (!strncmp(line + begin, sections[i].label, strlen(sections[i].label))) {
- sections_read++;
+ for (i = 0; i < map_size; i++) {
+ if (!strncmp(line + begin, map[i].label, strlen(map[i].label))) {
+ stats_read++;
break;
}
}
- if (i == num_sections) {
+ if (i == map_size)
continue;
- }
- stats_read = parse_stats(sections[i].stats_labels, sections[i].num_stats,
- &stats_list[i * entries_per_section], fp);
- // If we don't find all of the stats we expect in this section, our understanding of
- // the input is wrong, and we can't just carry on as if everything is okay. Better
- // to log the error and give up than potentially return incorrect data as stats.
- if (stats_read != sections[i].num_stats) {
- ALOGE("%s: failed to read all stats for %s section (%lu of %lu)", __func__,
- sections[i].label, stats_read, sections[i].num_stats);
+ ret = parse_stats(map[i].parameters, map[i].num_parameters,
+ &list[map[i].stat * MAX_RPM_PARAMS], fp);
+ if (ret < 0)
break;
- }
}
-
free(line);
fclose(fp);
return ret;
}
-int extract_master_stats(uint64_t *list, size_t list_length) {
- size_t entries_per_section = list_length / ARRAY_SIZE(master_sections);
- if (list_length % entries_per_section != 0) {
- ALOGW("%s: stats list size not an even multiple of section count", __func__);
- }
-
- return extract_stats(list, entries_per_section, MASTER_STATS_FILE,
- master_sections, ARRAY_SIZE(master_sections));
-}
-
-int extract_wlan_stats(uint64_t *list, size_t list_length) {
- size_t entries_per_section = list_length / ARRAY_SIZE(wlan_sections);
- if (list_length % entries_per_section != 0) {
- ALOGW("%s: stats list size not an even multiple of section count", __func__);
- }
-
- return extract_stats(list, entries_per_section, WLAN_STATS_FILE,
- wlan_sections, ARRAY_SIZE(wlan_sections));
+int extract_platform_stats(uint64_t *list) {
+ return extract_stats(list, RPM_SYSTEM_STAT, rpm_stat_map, ARRAY_SIZE(rpm_stat_map));
}
-int extract_system_stats(uint64_t *list, size_t list_length) {
- size_t entries_per_section = list_length / ARRAY_SIZE(system_sections);
- if (list_length % entries_per_section != 0) {
- ALOGW("%s: stats list size not an even multiple of section count", __func__);
- }
-
- return extract_stats(list, entries_per_section, SYSTEM_STATS_FILE,
- system_sections, ARRAY_SIZE(system_sections));
+int extract_wlan_stats(uint64_t *list) {
+ return extract_stats(list, WLAN_POWER_STAT, wlan_stat_map, ARRAY_SIZE(wlan_stat_map));
}
diff --git a/power-libperfmgr/power-helper.h b/power-libperfmgr/power-helper.h
index e6a017ed..60646464 100644
--- a/power-libperfmgr/power-helper.h
+++ b/power-libperfmgr/power-helper.h
@@ -34,48 +34,28 @@
extern "C" {
#endif
-// These values are used as indices in getSubsystemLowPowerStats(), as source IDs
-// in stats_section instances, and (in the case of the _COUNT values) to dimension
-// containers. The values used as indices need to be contiguous, but others do
-// not (which is why SYSTEM_STATES is all the way at the end; it is not used as
-// an index, but only as a source ID).
-enum stats_source {
- // Master stats
- MASTER_APSS = 0,
- MASTER_MPSS,
- MASTER_ADSP,
- MASTER_SLPI,
- MASTER_CDSP,
- MASTER_GPU,
- MASTER_DISPLAY,
- MASTER_COUNT, // Total master sources
-
- // Subsystem stats. (Numbering starts at MASTER_COUNT to preserve
- // contiguous source numbering.)
- SUBSYSTEM_WLAN = MASTER_COUNT,
- SUBSYSTEM_CITADEL,
-
- // Don't add any lines after this line
- STATS_SOURCE_COUNT, // Total sources of any kind excluding system states
- SUBSYSTEM_COUNT = STATS_SOURCE_COUNT - MASTER_COUNT,
-
- SYSTEM_STATES
+enum stats_type {
+ //Platform Stats
+ RPM_MODE_XO = 0,
+ RPM_MODE_VMIN,
+ RPM_MODE_MAX,
+ XO_VOTERS_START = RPM_MODE_MAX,
+ VOTER_APSS = XO_VOTERS_START,
+ VOTER_MPSS,
+ VOTER_ADSP,
+ VOTER_SLPI,
+ MAX_PLATFORM_STATS,
+
+ //WLAN Stats
+ WLAN_POWER_DEBUG_STATS = 0,
+ MAX_WLAN_STATS,
};
-enum master_sleep_states {
- MASTER_SLEEP = 0,
+enum subsystem_type {
+ SUBSYSTEM_WLAN = 0,
//Don't add any lines after this line
- MASTER_SLEEP_STATE_COUNT
-};
-
-enum master_stats {
- SLEEP_CUMULATIVE_DURATION_MS = 0,
- SLEEP_ENTER_COUNT,
- SLEEP_LAST_ENTER_TSTAMP_MS,
-
- //Don't add any lines after this line
- MASTER_STATS_COUNT
+ SUBSYSTEM_COUNT
};
enum wlan_sleep_states {
@@ -83,51 +63,35 @@ enum wlan_sleep_states {
WLAN_STATE_DEEP_SLEEP,
//Don't add any lines after this line
- WLAN_SLEEP_STATE_COUNT
+ WLAN_STATES_COUNT
};
-// Note that stats for both WLAN sleep states are in a single section of the
-// source file, so there's only 1 stats section despite having 2 states
-enum wlan_stats {
+enum wlan_power_params {
CUMULATIVE_SLEEP_TIME_MS = 0,
CUMULATIVE_TOTAL_ON_TIME_MS,
DEEP_SLEEP_ENTER_COUNTER,
LAST_DEEP_SLEEP_ENTER_TSTAMP_MS,
//Don't add any lines after this line
- WLAN_STATS_COUNT
+ WLAN_POWER_PARAMS_COUNT
};
-enum system_sleep_states {
- SYSTEM_STATE_AOSD = 0,
- SYSTEM_STATE_CXSD,
- //Don't add any lines after this line
- SYSTEM_SLEEP_STATE_COUNT
-};
+#define PLATFORM_SLEEP_MODES_COUNT RPM_MODE_MAX
-enum system_state_stats {
- TOTAL_COUNT = 0,
- ACCUMULATED_TIME_MS,
-
- //Don't add any lines after this line
- SYSTEM_STATE_STATS_COUNT
-};
-
-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(x) (sizeof((x))/sizeof((x)[0]))
-#endif
+#define MAX_RPM_PARAMS 2
+#define XO_VOTERS (MAX_PLATFORM_STATS - XO_VOTERS_START)
+#define VMIN_VOTERS 0
-struct stats_section {
- enum stats_source source;
+struct stat_pair {
+ enum stats_type stat;
const char *label;
- const char **stats_labels;
- size_t num_stats;
+ const char **parameters;
+ size_t num_parameters;
};
-int extract_master_stats(uint64_t *list, size_t list_length);
-int extract_wlan_stats(uint64_t *list, size_t list_length);
-int extract_system_stats(uint64_t *list, size_t list_length);
+int extract_platform_stats(uint64_t *list);
+int extract_wlan_stats(uint64_t *list);
#ifdef __cplusplus
}