From 7075241133d606a11966eb9517bc727c4b7115ae Mon Sep 17 00:00:00 2001 From: nico Date: Thu, 13 Dec 2018 05:58:17 +0000 Subject: power: Find online CPU core and get scaling governor Change-Id: I90aed1aaee8d3819d1de921674da924efd0a6c4f --- power-660.c | 24 ++++++------------------ power-8916.c | 13 +++---------- power-8937.c | 24 ++++++------------------ power-8952.c | 24 ++++++------------------ power-8953.c | 24 ++++++------------------ power-common.h | 1 - utils.c | 25 ++++++++++++------------- 7 files changed, 39 insertions(+), 96 deletions(-) diff --git a/power-660.c b/power-660.c index 7c274af..00d50c5 100644 --- a/power-660.c +++ b/power-660.c @@ -91,15 +91,9 @@ int set_interactive_override(int on) { ALOGI("Got set_interactive hint"); - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU0) == -1) { - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU1) == -1) { - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU2) == -1) { - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU3) == -1) { - ALOGE("Can't obtain scaling governor."); - return HINT_HANDLED; - } - } - } + if (get_scaling_governor(governor, sizeof(governor)) == -1) { + ALOGE("Can't obtain scaling governor."); + return HINT_HANDLED; } if (!on) { @@ -154,15 +148,9 @@ static void process_video_encode_hint(void* metadata) { ALOGI("Got process_video_encode_hint"); - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU0) == -1) { - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU1) == -1) { - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU2) == -1) { - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU3) == -1) { - ALOGE("Can't obtain scaling governor."); - // return HINT_HANDLED; - } - } - } + if (get_scaling_governor(governor, sizeof(governor)) == -1) { + ALOGE("Can't obtain scaling governor."); + // return HINT_HANDLED; } /* Initialize encode metadata struct fields. */ diff --git a/power-8916.c b/power-8916.c index 1ad6ab9..af32609 100644 --- a/power-8916.c +++ b/power-8916.c @@ -96,16 +96,9 @@ int set_interactive_override(int on) { char governor[80]; char tmp_str[NODE_MAX]; - ALOGI("Got set_interactive hint"); - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU0) == -1) { - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU1) == -1) { - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU2) == -1) { - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU3) == -1) { - ALOGE("Can't obtain scaling governor."); - return HINT_HANDLED; - } - } - } + if (get_scaling_governor(governor, sizeof(governor)) == -1) { + ALOGE("Can't obtain scaling governor."); + return HINT_HANDLED; } if (!on) { diff --git a/power-8937.c b/power-8937.c index e2610d9..2cbdc71 100644 --- a/power-8937.c +++ b/power-8937.c @@ -97,15 +97,9 @@ int set_interactive_override(int on) { ALOGI("Got set_interactive hint"); - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU0) == -1) { - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU1) == -1) { - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU2) == -1) { - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU3) == -1) { - ALOGE("Can't obtain scaling governor."); - return HINT_HANDLED; - } - } - } + if (get_scaling_governor(governor, sizeof(governor)) == -1) { + ALOGE("Can't obtain scaling governor."); + return HINT_HANDLED; } if (!on) { @@ -165,15 +159,9 @@ static void process_video_encode_hint(void* metadata) { ALOGI("Got process_video_encode_hint"); - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU0) == -1) { - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU1) == -1) { - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU2) == -1) { - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU3) == -1) { - ALOGE("Can't obtain scaling governor."); - return; - } - } - } + if (get_scaling_governor(governor, sizeof(governor)) == -1) { + ALOGE("Can't obtain scaling governor."); + return; } /* Initialize encode metadata struct fields. */ diff --git a/power-8952.c b/power-8952.c index f023243..a11d809 100644 --- a/power-8952.c +++ b/power-8952.c @@ -88,15 +88,9 @@ int set_interactive_override(int on) { ALOGI("Got set_interactive hint"); - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU0) == -1) { - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU1) == -1) { - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU2) == -1) { - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU3) == -1) { - ALOGE("Can't obtain scaling governor."); - return HINT_HANDLED; - } - } - } + if (get_scaling_governor(governor, sizeof(governor)) == -1) { + ALOGE("Can't obtain scaling governor."); + return HINT_HANDLED; } if (!on) { @@ -127,15 +121,9 @@ static void process_video_encode_hint(void* metadata) { ALOGI("Got process_video_encode_hint"); - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU0) == -1) { - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU1) == -1) { - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU2) == -1) { - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU3) == -1) { - ALOGE("Can't obtain scaling governor."); - return; - } - } - } + if (get_scaling_governor(governor, sizeof(governor)) == -1) { + ALOGE("Can't obtain scaling governor."); + return; } /* Initialize encode metadata struct fields. */ diff --git a/power-8953.c b/power-8953.c index 38ee3cb..76569b5 100644 --- a/power-8953.c +++ b/power-8953.c @@ -99,15 +99,9 @@ int set_interactive_override(int on) { ALOGI("Got set_interactive hint"); - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU0) == -1) { - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU1) == -1) { - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU2) == -1) { - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU3) == -1) { - ALOGE("Can't obtain scaling governor."); - return HINT_HANDLED; - } - } - } + if (get_scaling_governor(governor, sizeof(governor)) == -1) { + ALOGE("Can't obtain scaling governor."); + return HINT_HANDLED; } if (!on) { @@ -168,15 +162,9 @@ static void process_video_encode_hint(void* metadata) { ALOGI("Got process_video_encode_hint"); - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU0) == -1) { - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU1) == -1) { - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU2) == -1) { - if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU3) == -1) { - ALOGE("Can't obtain scaling governor."); - // return HINT_HANDLED; - } - } - } + if (get_scaling_governor(governor, sizeof(governor)) == -1) { + ALOGE("Can't obtain scaling governor."); + // return HINT_HANDLED; } /* Initialize encode metadata struct fields. */ diff --git a/power-common.h b/power-common.h index 2707a64..c989e97 100644 --- a/power-common.h +++ b/power-common.h @@ -35,7 +35,6 @@ extern "C" { #define NODE_MAX (64) -#define SCALING_GOVERNOR_PATH "/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor" #define SCALING_MIN_FREQ "/sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq" #define INTERACTIVE_GOVERNOR "interactive" #define SCHEDUTIL_GOVERNOR "schedutil" diff --git a/utils.c b/utils.c index ec9d1e8..295b7dd 100644 --- a/utils.c +++ b/utils.c @@ -46,10 +46,14 @@ #define SOC_ID_0 "/sys/devices/soc0/soc_id" #define SOC_ID_1 "/sys/devices/system/soc/soc0/id" -const char* scaling_gov_path[4] = {"/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor", +const char* scaling_gov_path[8] = {"/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor", "/sys/devices/system/cpu/cpu1/cpufreq/scaling_governor", "/sys/devices/system/cpu/cpu2/cpufreq/scaling_governor", - "/sys/devices/system/cpu/cpu3/cpufreq/scaling_governor"}; + "/sys/devices/system/cpu/cpu3/cpufreq/scaling_governor", + "/sys/devices/system/cpu/cpu4/cpufreq/scaling_governor", + "/sys/devices/system/cpu/cpu5/cpufreq/scaling_governor", + "/sys/devices/system/cpu/cpu6/cpufreq/scaling_governor", + "/sys/devices/system/cpu/cpu7/cpufreq/scaling_governor"}; #define PERF_HAL_PATH "libqti-perfd-client.so" static void* qcopt_handle; @@ -170,19 +174,14 @@ int sysfs_write(const char* path, char* s) { } int get_scaling_governor(char governor[], int size) { - if (sysfs_read(SCALING_GOVERNOR_PATH, governor, size) == -1) { - // Can't obtain the scaling governor. Return. - return -1; - } else { - // Strip newline at the end. - int len = strlen(governor); - - len--; - - while (len >= 0 && (governor[len] == '\n' || governor[len] == '\r')) governor[len--] = '\0'; + for (size_t i = 0; i < ARRAY_SIZE(scaling_gov_path); i++) { + if (get_scaling_governor_check_cores(governor, size, i) == 0) { + // Obtained the scaling governor. Return. + return 0; + } } - return 0; + return -1; } int get_scaling_governor_check_cores(char governor[], int size, int core_num) { -- cgit v1.2.3