power HAL: Removing support for stats related APIs

power.stats HAL is what will be supported going forward.

Bug: 120549967
Test: run vts -m VtsHalPowerV1_0Target
Test: run vts -m VtsHalPowerV1_1Target
Test: Booted device and made sure getSubsystemLowPowerStats and
getPlatformLowPowerStats did not show up in logcat.

Change-Id: I55eeec13e3460be4e2130556b66e0b02337349de
This commit is contained in:
Benjamin Schwartz
2019-01-14 16:40:52 -08:00
parent d4e53ad444
commit 19d369237c
5 changed files with 5 additions and 495 deletions

View File

@@ -16,7 +16,7 @@ cc_binary {
name: "android.hardware.power@1.2-service.wahoo-libperfmgr",
relative_install_path: "hw",
init_rc: ["android.hardware.power@1.2-service.wahoo-libperfmgr.rc"],
srcs: ["service.cpp", "Power.cpp", "InteractionHandler.cpp", "power-helper.c"],
srcs: ["service.cpp", "Power.cpp", "InteractionHandler.cpp"],
cflags: [
"-Wall",
"-Werror",

View File

@@ -29,10 +29,6 @@
#include <utils/Trace.h>
#include "Power.h"
#include "power-helper.h"
/* RPM runs at 19.2Mhz. Divide by 19200 for msec */
#define RPM_CLK 19200
extern struct stat_pair rpm_stat_map[];
@@ -43,10 +39,7 @@ namespace V1_2 {
namespace implementation {
using ::android::hardware::power::V1_0::Feature;
using ::android::hardware::power::V1_0::PowerStatePlatformSleepState;
using ::android::hardware::power::V1_0::Status;
using ::android::hardware::power::V1_1::PowerStateSubsystem;
using ::android::hardware::power::V1_1::PowerStateSubsystemSleepState;
using ::android::hardware::hidl_vec;
using ::android::hardware::Return;
using ::android::hardware::Void;
@@ -215,166 +208,15 @@ Return<void> Power::setFeature(Feature /*feature*/, bool /*activate*/) {
}
Return<void> Power::getPlatformLowPowerStats(getPlatformLowPowerStats_cb _hidl_cb) {
hidl_vec<PowerStatePlatformSleepState> states;
uint64_t stats[MAX_PLATFORM_STATS * MAX_RPM_PARAMS] = {0};
uint64_t *values;
struct PowerStatePlatformSleepState *state;
int ret;
states.resize(PLATFORM_SLEEP_MODES_COUNT);
ret = extract_platform_stats(stats);
if (ret != 0) {
states.resize(0);
goto done;
}
/* Update statistics for XO_shutdown */
state = &states[RPM_MODE_XO];
state->name = "XO_shutdown";
values = stats + (RPM_MODE_XO * MAX_RPM_PARAMS);
state->residencyInMsecSinceBoot = values[1];
state->totalTransitions = values[0];
state->supportedOnlyInSuspend = false;
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 VMIN state */
state = &states[RPM_MODE_VMIN];
state->name = "VMIN";
values = stats + (RPM_MODE_VMIN * MAX_RPM_PARAMS);
state->residencyInMsecSinceBoot = values[1];
state->totalTransitions = values[0];
state->supportedOnlyInSuspend = false;
state->voters.resize(VMIN_VOTERS);
//Note: No filling of state voters since VMIN_VOTERS = 0
done:
_hidl_cb(states, Status::SUCCESS);
LOG(ERROR) << "getPlatformLowPowerStats not supported. Use IPowerStats HAL.";
_hidl_cb({}, Status::SUCCESS);
return Void();
}
static int get_wlan_low_power_stats(struct PowerStateSubsystem *subsystem) {
uint64_t stats[WLAN_POWER_PARAMS_COUNT] = {0};
struct PowerStateSubsystemSleepState *state;
subsystem->name = "wlan";
if (extract_wlan_stats(stats) != 0) {
subsystem->states.resize(0);
return -1;
}
subsystem->states.resize(WLAN_STATES_COUNT);
/* Update statistics for Active State */
state = &subsystem->states[WLAN_STATE_ACTIVE];
state->name = "Active";
state->residencyInMsecSinceBoot = stats[CUMULATIVE_TOTAL_ON_TIME_MS];
state->totalTransitions = stats[DEEP_SLEEP_ENTER_COUNTER];
state->lastEntryTimestampMs = 0; //FIXME need a new value from Qcom
state->supportedOnlyInSuspend = false;
/* Update statistics for Deep-Sleep state */
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];
state->lastEntryTimestampMs = stats[LAST_DEEP_SLEEP_ENTER_TSTAMP_MS];
state->supportedOnlyInSuspend = false;
return 0;
}
enum easel_state {
EASEL_OFF = 0,
EASEL_ON,
EASEL_SUSPENDED,
NUM_EASEL_STATES
};
// Get low power stats for easel subsystem
static int get_easel_low_power_stats(struct PowerStateSubsystem *subsystem) {
// This implementation is a workaround to provide minimal visibility into
// Easel state behavior until canonical low power stats are supported.
// It takes an "external observer" snapshot of the current Easel state every
// time it is called, and synthesizes an artificial sleep state that will
// behave similarly to real stats if Easel gets "wedged" in the "on" state.
static std::mutex statsLock;
static uint64_t totalOnSnapshotCount = 0;
static uint64_t totalNotOnSnapshotCount = 0;
unsigned long currentState;
struct PowerStateSubsystemSleepState *state;
subsystem->name = "Easel";
if (get_easel_state(&currentState) != 0) {
subsystem->states.resize(0);
return -1;
}
if (currentState >= NUM_EASEL_STATES) {
ALOGE("%s: unrecognized Easel state(%lu)", __func__, currentState);
return -1;
}
subsystem->states.resize(1);
// Since we are storing stats locally but can have multiple parallel
// callers, locking is required to ensure stats are not corrupted.
std::lock_guard<std::mutex> lk(statsLock);
// Update statistics for synthetic sleep state. We combine OFF and
// SUSPENDED to act as a composite "not on" state so the numbers will behave
// like a real sleep state.
if ((currentState == EASEL_OFF) || (currentState == EASEL_SUSPENDED)) {
totalNotOnSnapshotCount++;
} else {
totalOnSnapshotCount++;
}
// Update statistics for synthetic sleep state, where
// totalTransitions = cumulative count of Easel state0 (as seen by PowerHAL)
// residencyInMsecsSinceBoot = cumulative count of Easel state1 (as seen by
// PowerHAL)
// lastEntryTimestampMs = cumulative count of Easel state2 (as seen by
// PowerHAL)
state = &subsystem->states[0];
state->name = "SyntheticSleep";
state->totalTransitions = totalOnSnapshotCount;
state->residencyInMsecSinceBoot = totalNotOnSnapshotCount;
state->lastEntryTimestampMs = 0; // No added value for the workaround
state->supportedOnlyInSuspend = false;
return 0;
}
// Methods from ::android::hardware::power::V1_1::IPower follow.
Return<void> Power::getSubsystemLowPowerStats(getSubsystemLowPowerStats_cb _hidl_cb) {
hidl_vec<PowerStateSubsystem> subsystems;
subsystems.resize(SUBSYSTEM_COUNT);
// Get WLAN subsystem low power stats.
if (get_wlan_low_power_stats(&subsystems[SUBSYSTEM_WLAN]) != 0) {
ALOGE("%s: failed to process wlan stats", __func__);
}
// Get Easel subsystem low power stats.
if (get_easel_low_power_stats(&subsystems[SUBSYSTEM_EASEL]) != 0) {
ALOGE("%s: failed to process Easel stats", __func__);
}
_hidl_cb(subsystems, Status::SUCCESS);
LOG(ERROR) << "getSubsystemLowPowerStats not supported. Use IPowerStats HAL.";
_hidl_cb({}, Status::SUCCESS);
return Void();
}

View File

@@ -1,221 +0,0 @@
/*
* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define LOG_NIDEBUG 0
#define LOG_TAG "android.hardware.power@1.2-service.wahoo-libperfmgr"
#include <errno.h>
#include <inttypes.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dlfcn.h>
#include <stdlib.h>
#include <log/log.h>
#include "power-helper.h"
#ifndef RPM_SYSTEM_STAT
#define RPM_SYSTEM_STAT "/d/system_stats"
#endif
#ifndef WLAN_POWER_STAT
#define WLAN_POWER_STAT "/d/wlan0/power_stats"
#endif
#ifndef EASEL_STATE_FILE
#define EASEL_STATE_FILE "/sys/devices/virtual/misc/mnh_sm/state"
#endif
#define ARRAY_SIZE(x) (sizeof((x))/sizeof((x)[0]))
#define LINE_SIZE 128
const char *rpm_stat_params[MAX_RPM_PARAMS] = {
"count",
"actual last sleep(msec)",
};
const char *master_stat_params[MAX_RPM_PARAMS] = {
"Accumulated XO duration",
"XO 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 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 **params, size_t params_size,
uint64_t *list, FILE *fp) {
ssize_t nread;
size_t len = LINE_SIZE;
char *line;
size_t params_read = 0;
size_t i;
line = malloc(len);
if (!line) {
ALOGE("%s: no memory to hold line", __func__);
return -ENOMEM;
}
while ((params_read < params_size) &&
(nread = getline(&line, &len, fp) > 0)) {
char *key = line + strspn(line, " \t");
char *value = strchr(key, ':');
if (!value || (value > (line + len)))
continue;
*value++ = '\0';
for (i = 0; i < params_size; i++) {
if (!strcmp(key, params[i])) {
list[i] = strtoull(value, NULL, 0);
params_read++;
break;
}
}
}
free(line);
return 0;
}
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, stats_read = 0;
int ret = 0;
fp = fopen(file, "re");
if (fp == NULL) {
ALOGE("%s: failed to open: %s Error = %s", __func__, file, strerror(errno));
return -errno;
}
line = malloc(len);
if (!line) {
ALOGE("%s: no memory to hold line", __func__);
fclose(fp);
return -ENOMEM;
}
while ((stats_read < map_size) && (read = getline(&line, &len, fp) != -1)) {
size_t begin = strspn(line, " \t");
for (i = 0; i < map_size; i++) {
if (!strncmp(line + begin, map[i].label, strlen(map[i].label))) {
stats_read++;
break;
}
}
if (i == map_size)
continue;
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_platform_stats(uint64_t *list) {
return extract_stats(list, RPM_SYSTEM_STAT, rpm_stat_map, ARRAY_SIZE(rpm_stat_map));
}
int extract_wlan_stats(uint64_t *list) {
return extract_stats(list, WLAN_POWER_STAT, wlan_stat_map, ARRAY_SIZE(wlan_stat_map));
}
int get_easel_state(unsigned long *current_state) {
FILE *fp = NULL;
static const size_t EASEL_STATE_LINE_SIZE = 16;
char buffer[EASEL_STATE_LINE_SIZE];
char *parse_end = buffer;
unsigned long state;
if (current_state == NULL) {
ALOGD("%s: null current_state pointer from caller", __func__);
return -1;
}
fp = fopen(EASEL_STATE_FILE, "re");
if (fp == NULL) {
ALOGE("%s: failed to open: %s Error = %s", __func__, EASEL_STATE_FILE,
strerror(errno));
return -errno;
}
if (fgets(buffer, EASEL_STATE_LINE_SIZE, fp) == NULL) {
fclose(fp);
ALOGE("%s: failed to read: %s", __func__, EASEL_STATE_FILE);
return -1;
}
fclose(fp);
parse_end = buffer;
state = strtoul(buffer, &parse_end, 10);
if ((parse_end == buffer) || (state > 2)) {
ALOGE("%s: unrecognized format: %s '%s'", __func__, EASEL_STATE_FILE,
buffer);
return -1;
}
*current_state = state;
return 0;
}

View File

@@ -1,102 +0,0 @@
/*
* Copyright (c) 2018, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __POWER_HELPER_H__
#define __POWER_HELPER_H__
#ifdef __cplusplus
extern "C" {
#endif
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 subsystem_type {
SUBSYSTEM_WLAN = 0,
SUBSYSTEM_EASEL,
//Don't add any lines after this line
SUBSYSTEM_COUNT
};
enum wlan_sleep_states {
WLAN_STATE_ACTIVE = 0,
WLAN_STATE_DEEP_SLEEP,
//Don't add any lines after this line
WLAN_STATES_COUNT
};
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_POWER_PARAMS_COUNT
};
#define PLATFORM_SLEEP_MODES_COUNT RPM_MODE_MAX
#define MAX_RPM_PARAMS 2
#define XO_VOTERS (MAX_PLATFORM_STATS - XO_VOTERS_START)
#define VMIN_VOTERS 0
struct stat_pair {
enum stats_type stat;
const char *label;
const char **parameters;
size_t num_parameters;
};
int extract_platform_stats(uint64_t *list);
int extract_wlan_stats(uint64_t *list);
int get_easel_state(unsigned long *current_state);
#ifdef __cplusplus
}
#endif
#endif //__POWER_HELPER_H__

View File

@@ -1,15 +1,6 @@
allow hal_power_default sysfs_graphics:dir search;
allow hal_power_default sysfs_graphics:file r_file_perms;
allow hal_power_default debugfs_rpm:file r_file_perms;
allow hal_power_default debugfs_wlan:dir r_dir_perms;
allow hal_power_default debugfs_wlan:file r_file_perms;
allow hal_power_default sysfs_easel:dir search;
allow hal_power_default sysfs_easel:file r_file_perms;
# To do powerhint on nodes defined in powerhint.json
allow hal_power_default sysfs_msm_subsys:dir search;
allow hal_power_default sysfs_msm_subsys:file rw_file_perms;