mirror of
https://github.com/Evolution-X-Devices/device_google_wahoo
synced 2026-01-30 05:29:39 +00:00
This CL removed cameraHAL to perfd interface Also changed some powerHAL logging level Bug: 63589458 Test: Build Change-Id: I4725f45b22bf3a3787dc5d77fc9c6b22a66a21aa
451 lines
15 KiB
C
451 lines
15 KiB
C
/*
|
|
* 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
|
|
|
|
#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>
|
|
|
|
#define LOG_TAG "QCOM PowerHAL"
|
|
#include <utils/Log.h>
|
|
#include <hardware/power.h>
|
|
|
|
#include "utils.h"
|
|
#include "metadata-defs.h"
|
|
#include "hint-data.h"
|
|
#include "performance.h"
|
|
#include "power-common.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
|
|
|
|
#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 saved_dcvs_cpu0_slack_max = -1;
|
|
static int saved_dcvs_cpu0_slack_min = -1;
|
|
static int saved_mpdecision_slack_max = -1;
|
|
static int saved_mpdecision_slack_min = -1;
|
|
static int saved_interactive_mode = -1;
|
|
static int slack_node_rw_failed = 0;
|
|
static int display_hint_sent;
|
|
|
|
void power_init(void)
|
|
{
|
|
ALOGI("QCOM power HAL initing.");
|
|
}
|
|
|
|
int __attribute__ ((weak)) power_hint_override(power_hint_t UNUSED(hint),
|
|
void *UNUSED(data))
|
|
{
|
|
return HINT_NONE;
|
|
}
|
|
|
|
/* Declare function before use */
|
|
void interaction(int duration, int num_args, int opt_list[]);
|
|
|
|
void power_hint(power_hint_t hint, void *data)
|
|
{
|
|
/* Check if this hint has been overridden. */
|
|
if (power_hint_override(hint, data) == HINT_HANDLED) {
|
|
/* The power_hint has been handled. We can skip the rest. */
|
|
return;
|
|
}
|
|
|
|
switch(hint) {
|
|
case POWER_HINT_VSYNC:
|
|
break;
|
|
case POWER_HINT_SUSTAINED_PERFORMANCE:
|
|
ALOGD("Sustained perf power hint not handled in power_hint_override");
|
|
break;
|
|
case POWER_HINT_VR_MODE:
|
|
ALOGD("VR mode power hint not handled in power_hint_override");
|
|
break;
|
|
case POWER_HINT_INTERACTION:
|
|
{
|
|
int resources[] = {0x702, 0x20F, 0x30F};
|
|
int duration = 3000;
|
|
|
|
interaction(duration, sizeof(resources)/sizeof(resources[0]), resources);
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
int __attribute__ ((weak)) is_perf_hint_active(int UNUSED(hint))
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
int __attribute__ ((weak)) set_interactive_override(int UNUSED(on))
|
|
{
|
|
return HINT_NONE;
|
|
}
|
|
|
|
void power_set_interactive(int on)
|
|
{
|
|
char governor[80];
|
|
char tmp_str[NODE_MAX];
|
|
struct video_encode_metadata_t video_encode_metadata;
|
|
int rc = 0;
|
|
|
|
if (set_interactive_override(on) == HINT_HANDLED) {
|
|
return;
|
|
}
|
|
|
|
ALOGD("Got set_interactive hint");
|
|
|
|
if (get_scaling_governor(governor, sizeof(governor)) == -1) {
|
|
ALOGE("Can't obtain scaling governor.");
|
|
|
|
return;
|
|
}
|
|
|
|
if (!on) {
|
|
/* Display off. */
|
|
if ((strncmp(governor, ONDEMAND_GOVERNOR, strlen(ONDEMAND_GOVERNOR)) == 0) &&
|
|
(strlen(governor) == strlen(ONDEMAND_GOVERNOR))) {
|
|
int resource_values[] = {DISPLAY_OFF, MS_500, THREAD_MIGRATION_SYNC_OFF};
|
|
|
|
if (!display_hint_sent) {
|
|
perform_hint_action(DISPLAY_STATE_HINT_ID,
|
|
resource_values, sizeof(resource_values)/sizeof(resource_values[0]));
|
|
display_hint_sent = 1;
|
|
}
|
|
} else if ((strncmp(governor, INTERACTIVE_GOVERNOR, strlen(INTERACTIVE_GOVERNOR)) == 0) &&
|
|
(strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) {
|
|
int resource_values[] = {TR_MS_50, THREAD_MIGRATION_SYNC_OFF};
|
|
|
|
if (!display_hint_sent) {
|
|
perform_hint_action(DISPLAY_STATE_HINT_ID,
|
|
resource_values, sizeof(resource_values)/sizeof(resource_values[0]));
|
|
display_hint_sent = 1;
|
|
}
|
|
} else if ((strncmp(governor, MSMDCVS_GOVERNOR, strlen(MSMDCVS_GOVERNOR)) == 0) &&
|
|
(strlen(governor) == strlen(MSMDCVS_GOVERNOR))) {
|
|
if (saved_interactive_mode == 1){
|
|
/* Display turned off. */
|
|
if (sysfs_read(DCVS_CPU0_SLACK_MAX_NODE, tmp_str, NODE_MAX - 1)) {
|
|
if (!slack_node_rw_failed) {
|
|
ALOGE("Failed to read from %s", DCVS_CPU0_SLACK_MAX_NODE);
|
|
}
|
|
|
|
rc = 1;
|
|
} else {
|
|
saved_dcvs_cpu0_slack_max = atoi(tmp_str);
|
|
}
|
|
|
|
if (sysfs_read(DCVS_CPU0_SLACK_MIN_NODE, tmp_str, NODE_MAX - 1)) {
|
|
if (!slack_node_rw_failed) {
|
|
ALOGE("Failed to read from %s", DCVS_CPU0_SLACK_MIN_NODE);
|
|
}
|
|
|
|
rc = 1;
|
|
} else {
|
|
saved_dcvs_cpu0_slack_min = atoi(tmp_str);
|
|
}
|
|
|
|
if (sysfs_read(MPDECISION_SLACK_MAX_NODE, tmp_str, NODE_MAX - 1)) {
|
|
if (!slack_node_rw_failed) {
|
|
ALOGE("Failed to read from %s", MPDECISION_SLACK_MAX_NODE);
|
|
}
|
|
|
|
rc = 1;
|
|
} else {
|
|
saved_mpdecision_slack_max = atoi(tmp_str);
|
|
}
|
|
|
|
if (sysfs_read(MPDECISION_SLACK_MIN_NODE, tmp_str, NODE_MAX - 1)) {
|
|
if(!slack_node_rw_failed) {
|
|
ALOGE("Failed to read from %s", MPDECISION_SLACK_MIN_NODE);
|
|
}
|
|
|
|
rc = 1;
|
|
} else {
|
|
saved_mpdecision_slack_min = atoi(tmp_str);
|
|
}
|
|
|
|
/* Write new values. */
|
|
if (saved_dcvs_cpu0_slack_max != -1) {
|
|
snprintf(tmp_str, NODE_MAX, "%d", 10 * saved_dcvs_cpu0_slack_max);
|
|
|
|
if (sysfs_write(DCVS_CPU0_SLACK_MAX_NODE, tmp_str) != 0) {
|
|
if (!slack_node_rw_failed) {
|
|
ALOGE("Failed to write to %s", DCVS_CPU0_SLACK_MAX_NODE);
|
|
}
|
|
|
|
rc = 1;
|
|
}
|
|
}
|
|
|
|
if (saved_dcvs_cpu0_slack_min != -1) {
|
|
snprintf(tmp_str, NODE_MAX, "%d", 10 * saved_dcvs_cpu0_slack_min);
|
|
|
|
if (sysfs_write(DCVS_CPU0_SLACK_MIN_NODE, tmp_str) != 0) {
|
|
if(!slack_node_rw_failed) {
|
|
ALOGE("Failed to write to %s", DCVS_CPU0_SLACK_MIN_NODE);
|
|
}
|
|
|
|
rc = 1;
|
|
}
|
|
}
|
|
|
|
if (saved_mpdecision_slack_max != -1) {
|
|
snprintf(tmp_str, NODE_MAX, "%d", 10 * saved_mpdecision_slack_max);
|
|
|
|
if (sysfs_write(MPDECISION_SLACK_MAX_NODE, tmp_str) != 0) {
|
|
if(!slack_node_rw_failed) {
|
|
ALOGE("Failed to write to %s", MPDECISION_SLACK_MAX_NODE);
|
|
}
|
|
|
|
rc = 1;
|
|
}
|
|
}
|
|
|
|
if (saved_mpdecision_slack_min != -1) {
|
|
snprintf(tmp_str, NODE_MAX, "%d", 10 * saved_mpdecision_slack_min);
|
|
|
|
if (sysfs_write(MPDECISION_SLACK_MIN_NODE, tmp_str) != 0) {
|
|
if(!slack_node_rw_failed) {
|
|
ALOGE("Failed to write to %s", MPDECISION_SLACK_MIN_NODE);
|
|
}
|
|
|
|
rc = 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
slack_node_rw_failed = rc;
|
|
}
|
|
} else {
|
|
/* Display on. */
|
|
if ((strncmp(governor, ONDEMAND_GOVERNOR, strlen(ONDEMAND_GOVERNOR)) == 0) &&
|
|
(strlen(governor) == strlen(ONDEMAND_GOVERNOR))) {
|
|
undo_hint_action(DISPLAY_STATE_HINT_ID);
|
|
display_hint_sent = 0;
|
|
} else if ((strncmp(governor, INTERACTIVE_GOVERNOR, strlen(INTERACTIVE_GOVERNOR)) == 0) &&
|
|
(strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) {
|
|
undo_hint_action(DISPLAY_STATE_HINT_ID);
|
|
display_hint_sent = 0;
|
|
} else if ((strncmp(governor, MSMDCVS_GOVERNOR, strlen(MSMDCVS_GOVERNOR)) == 0) &&
|
|
(strlen(governor) == strlen(MSMDCVS_GOVERNOR))) {
|
|
if (saved_interactive_mode == -1 || saved_interactive_mode == 0) {
|
|
/* Display turned on. Restore if possible. */
|
|
if (saved_dcvs_cpu0_slack_max != -1) {
|
|
snprintf(tmp_str, NODE_MAX, "%d", saved_dcvs_cpu0_slack_max);
|
|
|
|
if (sysfs_write(DCVS_CPU0_SLACK_MAX_NODE, tmp_str) != 0) {
|
|
if (!slack_node_rw_failed) {
|
|
ALOGE("Failed to write to %s", DCVS_CPU0_SLACK_MAX_NODE);
|
|
}
|
|
|
|
rc = 1;
|
|
}
|
|
}
|
|
|
|
if (saved_dcvs_cpu0_slack_min != -1) {
|
|
snprintf(tmp_str, NODE_MAX, "%d", saved_dcvs_cpu0_slack_min);
|
|
|
|
if (sysfs_write(DCVS_CPU0_SLACK_MIN_NODE, tmp_str) != 0) {
|
|
if (!slack_node_rw_failed) {
|
|
ALOGE("Failed to write to %s", DCVS_CPU0_SLACK_MIN_NODE);
|
|
}
|
|
|
|
rc = 1;
|
|
}
|
|
}
|
|
|
|
if (saved_mpdecision_slack_max != -1) {
|
|
snprintf(tmp_str, NODE_MAX, "%d", saved_mpdecision_slack_max);
|
|
|
|
if (sysfs_write(MPDECISION_SLACK_MAX_NODE, tmp_str) != 0) {
|
|
if (!slack_node_rw_failed) {
|
|
ALOGE("Failed to write to %s", MPDECISION_SLACK_MAX_NODE);
|
|
}
|
|
|
|
rc = 1;
|
|
}
|
|
}
|
|
|
|
if (saved_mpdecision_slack_min != -1) {
|
|
snprintf(tmp_str, NODE_MAX, "%d", saved_mpdecision_slack_min);
|
|
|
|
if (sysfs_write(MPDECISION_SLACK_MIN_NODE, tmp_str) != 0) {
|
|
if (!slack_node_rw_failed) {
|
|
ALOGE("Failed to write to %s", MPDECISION_SLACK_MIN_NODE);
|
|
}
|
|
|
|
rc = 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
slack_node_rw_failed = rc;
|
|
}
|
|
}
|
|
|
|
saved_interactive_mode = !!on;
|
|
}
|
|
|
|
|
|
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));
|
|
}
|