From e2d45c4536c92d13fece0d8915c8a8cbbace3fa2 Mon Sep 17 00:00:00 2001 From: lambdadroid Date: Wed, 2 Aug 2017 14:50:44 +0200 Subject: [PATCH] Add performance profile support (#17) --- power/power.c | 82 ++++++++++++++++++++++++++++++++++++++- rootdir/init.power.rc | 6 +++ rootdir/init.thermal.rc | 6 --- rootdir/ueventd.me176c.rc | 8 ++-- 4 files changed, 91 insertions(+), 11 deletions(-) diff --git a/power/power.c b/power/power.c index 5f63013..b772db2 100644 --- a/power/power.c +++ b/power/power.c @@ -7,6 +7,30 @@ #include #include +enum { + PROFILE_POWER_SAVE = 0, + PROFILE_BALANCED, + PROFILE_HIGH_PERFORMANCE, + PROFILE_BIAS_POWER_SAVE, + PROFILE_BIAS_PERFORMANCE, + PROFILE_COUNT +}; + +#define CPU_COUNT 4 + +#define INTEL_PSTATE_GOVERNOR_CONTROL "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor" +#define INTEL_PSTATE_GOVERNOR_POWER_SAVE "powersave" +#define INTEL_PSTATE_GOVERNOR_PERFORMANCE "performance" + +#define INTEL_PSTATE_MAX_PERF_CONTROL "/sys/devices/system/cpu/intel_pstate/max_perf_pct" +#define MAX_PERF_DEFAULT "100" +#define MAX_PERF_POWER_SAVE "75" +#define MAX_PERF_BIAS_POWER_SAVE "90" + +#define INTEL_PSTATE_TURBO_CONTROL "/sys/devices/system/cpu/intel_pstate/no_turbo" +#define TURBO_ON "0" +#define TURBO_OFF "1" + #define TOUCHSCREEN_POWER_CONTROL_PATH "/sys/bus/i2c/devices/i2c-GDIX1001:00/power/control" #define BATTERY_POWER_CONTROL_PATH "/sys/bus/i2c/devices/i2c-UPIG3105:00/power/control" @@ -36,6 +60,16 @@ static void sysfs_write(const char *path, const char *text) { close(fd); } +static void intel_pstate_set_governor(const char *governor) { + char path[sizeof(INTEL_PSTATE_GOVERNOR_CONTROL)]; + + int i; + for (i = 0; i < CPU_COUNT; ++i) { + sprintf(path, INTEL_PSTATE_GOVERNOR_CONTROL, i); + sysfs_write(path, governor); + } +} + static void power_init(struct power_module *module) { module; } @@ -47,9 +81,44 @@ static void power_set_interactive(struct power_module *module, int on) { update_battery_state(on); } +static void power_set_profile(int profile) { + switch (profile) { + case PROFILE_POWER_SAVE: + intel_pstate_set_governor(INTEL_PSTATE_GOVERNOR_POWER_SAVE); + sysfs_write(INTEL_PSTATE_MAX_PERF_CONTROL, MAX_PERF_POWER_SAVE); + sysfs_write(INTEL_PSTATE_TURBO_CONTROL, TURBO_OFF); + break; + case PROFILE_BALANCED: + intel_pstate_set_governor(INTEL_PSTATE_GOVERNOR_POWER_SAVE); + sysfs_write(INTEL_PSTATE_MAX_PERF_CONTROL, MAX_PERF_DEFAULT); + sysfs_write(INTEL_PSTATE_TURBO_CONTROL, TURBO_OFF); + break; + case PROFILE_HIGH_PERFORMANCE: + intel_pstate_set_governor(INTEL_PSTATE_GOVERNOR_PERFORMANCE); + sysfs_write(INTEL_PSTATE_MAX_PERF_CONTROL, MAX_PERF_DEFAULT); + sysfs_write(INTEL_PSTATE_TURBO_CONTROL, TURBO_ON); + break; + case PROFILE_BIAS_POWER_SAVE: + intel_pstate_set_governor(INTEL_PSTATE_GOVERNOR_POWER_SAVE); + sysfs_write(INTEL_PSTATE_MAX_PERF_CONTROL, MAX_PERF_BIAS_POWER_SAVE); + sysfs_write(INTEL_PSTATE_TURBO_CONTROL, TURBO_OFF); + break; + case PROFILE_BIAS_PERFORMANCE: + intel_pstate_set_governor(INTEL_PSTATE_GOVERNOR_PERFORMANCE); + sysfs_write(INTEL_PSTATE_MAX_PERF_CONTROL, MAX_PERF_DEFAULT); + sysfs_write(INTEL_PSTATE_TURBO_CONTROL, TURBO_OFF); + break; + default: + ALOGE("Invalid performance profile: %d\n", profile); + } +} + static void power_hint(struct power_module *module, power_hint_t hint, void *data) { module; switch (hint) { + case POWER_HINT_SET_PROFILE: + power_set_profile(*(int*) data); + break; case POWER_HINT_DISABLE_TOUCH: update_touchscreen_state(!data); break; @@ -58,6 +127,16 @@ static void power_hint(struct power_module *module, power_hint_t hint, void *dat } } +static int power_get_feature(struct power_module *module, feature_t feature) { + module; + switch (feature) { + case POWER_FEATURE_SUPPORTED_PROFILES: + return PROFILE_COUNT; + default: + return -1; + } +} + static struct hw_module_methods_t power_module_methods = { .open = NULL, }; @@ -65,7 +144,7 @@ static struct hw_module_methods_t power_module_methods = { struct power_module HAL_MODULE_INFO_SYM = { .common = { .tag = HARDWARE_MODULE_TAG, - .module_api_version = POWER_MODULE_API_VERSION_0_2, + .module_api_version = POWER_MODULE_API_VERSION_0_3, .hal_api_version = HARDWARE_HAL_API_VERSION, .id = POWER_HARDWARE_MODULE_ID, .name = "ME176C Power", @@ -76,4 +155,5 @@ struct power_module HAL_MODULE_INFO_SYM = { .init = power_init, .setInteractive = power_set_interactive, .powerHint = power_hint, + .getFeature = power_get_feature, }; diff --git a/rootdir/init.power.rc b/rootdir/init.power.rc index 2535fe1..c854df1 100644 --- a/rootdir/init.power.rc +++ b/rootdir/init.power.rc @@ -1,3 +1,9 @@ +on early-init + chown system system /sys/devices/system/cpu/intel_pstate/max_perf_pct + chmod 0644 /sys/devices/system/cpu/intel_pstate/max_perf_pct + chown system system /sys/devices/system/cpu/intel_pstate/no_turbo + chmod 0644 /sys/devices/system/cpu/intel_pstate/no_turbo + on init # Block Bluetooth and GPS (unsupported) write /sys/class/rfkill/rfkill0/soft 1 diff --git a/rootdir/init.thermal.rc b/rootdir/init.thermal.rc index 9308867..bd912e3 100644 --- a/rootdir/init.thermal.rc +++ b/rootdir/init.thermal.rc @@ -1,9 +1,3 @@ -on early-init - chown system system /sys/devices/system/cpu/intel_pstate/max_perf_pct - chmod 0644 /sys/devices/system/cpu/intel_pstate/max_perf_pct - chown system system /sys/devices/system/cpu/intel_pstate/no_turbo - chmod 0644 /sys/devices/system/cpu/intel_pstate/no_turbo - service thermald /system/bin/thermald -p 5 class core critical diff --git a/rootdir/ueventd.me176c.rc b/rootdir/ueventd.me176c.rc index db5c8bc..3e46f5d 100644 --- a/rootdir/ueventd.me176c.rc +++ b/rootdir/ueventd.me176c.rc @@ -1,5 +1,3 @@ -/sys/devices/system/cpu/cpu* online 0664 system system - # Graphics /dev/dri 0666 root graphics /dev/dri/card0 0666 root graphics @@ -8,8 +6,10 @@ /dev/dri/controlD64 0660 root graphics # Power -/sys/devices/platform* i2c-GDIX1001:00/power/control 0644 system system -/sys/devices/platform* i2c-UPIG3105:00/power/control 0644 system system +/sys/devices/system/cpu/cpu* online 0664 system system +/sys/devices/system/cpu/cpu* cpufreq/scaling_governor 0644 system system +/sys/devices/platform* i2c-GDIX1001:00/power/control 0644 system system +/sys/devices/platform* i2c-UPIG3105:00/power/control 0644 system system # Backlight /sys/devices/pci* intel_backlight/brightness 0664 system system