Skip to content
This repository has been archived by the owner on Nov 26, 2022. It is now read-only.

Commit

Permalink
Add performance profile support (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephan-gh committed Aug 2, 2017
1 parent 8872623 commit e2d45c4
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 11 deletions.
82 changes: 81 additions & 1 deletion power/power.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,30 @@
#include <hardware/power.h>
#include <cutils/log.h>

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"

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand All @@ -58,14 +127,24 @@ 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,
};

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",
Expand All @@ -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,
};
6 changes: 6 additions & 0 deletions rootdir/init.power.rc
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 0 additions & 6 deletions rootdir/init.thermal.rc
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions rootdir/ueventd.me176c.rc
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down

0 comments on commit e2d45c4

Please sign in to comment.