exynos3: power: Tuning and cleanups

* Tune the governor for better power usage and interactivity
* Reset tuning parameters if governor changes
* Cleanup

Change-Id: Ibe60ece836a0e56ba58e109bbea26cbd54d75421
tirimbino
Steve Kondik 12 years ago committed by Gerrit Code Review
parent 79b8917c20
commit de4b10b242
  1. 67
      exynos3/s5pc110/power/power.c

@ -29,6 +29,8 @@
#define SCALING_GOVERNOR_PATH "/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor" #define SCALING_GOVERNOR_PATH "/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"
#define BOOSTPULSE_ONDEMAND "/sys/devices/system/cpu/cpufreq/ondemand/boostpulse" #define BOOSTPULSE_ONDEMAND "/sys/devices/system/cpu/cpufreq/ondemand/boostpulse"
#define BOOSTPULSE_INTERACTIVE "/sys/devices/system/cpu/cpufreq/interactive/boostpulse" #define BOOSTPULSE_INTERACTIVE "/sys/devices/system/cpu/cpufreq/interactive/boostpulse"
#define TIMER_RATE_SCREEN_ON "30000"
#define TIMER_RATE_SCREEN_OFF "150000"
struct s5pc110_power_module { struct s5pc110_power_module {
struct power_module base; struct power_module base;
@ -37,6 +39,8 @@ struct s5pc110_power_module {
int boostpulse_warned; int boostpulse_warned;
}; };
static char governor[20];
static int sysfs_read(char *path, char *s, int num_bytes) static int sysfs_read(char *path, char *s, int num_bytes)
{ {
char buf[80]; char buf[80];
@ -65,9 +69,30 @@ static int sysfs_read(char *path, char *s, int num_bytes)
return ret; return ret;
} }
static int get_scaling_governor(char governor[], int size) { static void sysfs_write(char *path, char *s)
{
char buf[80];
int len;
int fd = open(path, O_WRONLY);
if (fd < 0) {
strerror_r(errno, buf, sizeof(buf));
ALOGE("Error opening %s: %s\n", path, buf);
return;
}
len = write(fd, s, strlen(s));
if (len < 0) {
strerror_r(errno, buf, sizeof(buf));
ALOGE("Error writing to %s: %s\n", path, buf);
}
close(fd);
}
static int get_scaling_governor() {
if (sysfs_read(SCALING_GOVERNOR_PATH, governor, if (sysfs_read(SCALING_GOVERNOR_PATH, governor,
size) == -1) { sizeof(governor)) == -1) {
// Can't obtain the scaling governor. Return. // Can't obtain the scaling governor. Return.
return -1; return -1;
} else { } else {
@ -83,15 +108,35 @@ static int get_scaling_governor(char governor[], int size) {
return 0; return 0;
} }
static void s5pc110_power_set_interactive(struct power_module *module, int on)
{
if (strncmp(governor, "interactive", 11) == 0)
sysfs_write("/sys/devices/system/cpu/cpufreq/interactive/timer_rate",
on ? TIMER_RATE_SCREEN_ON : TIMER_RATE_SCREEN_OFF);
}
static void configure_governor()
{
s5pc110_power_set_interactive(NULL, 1);
if (strncmp(governor, "ondemand", 8) == 0) {
sysfs_write("/sys/devices/system/cpu/cpufreq/ondemand/up_threshold", "95");
sysfs_write("/sys/devices/system/cpu/cpufreq/ondemand/io_is_busy", "1");
sysfs_write("/sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor", "4");
} else if (strncmp(governor, "interactive", 11) == 0) {
sysfs_write("/sys/devices/system/cpu/cpufreq/interactive/min_sample_time", "90000");
sysfs_write("/sys/devices/system/cpu/cpufreq/interactive/above_hispeed_delay", "30000");
}
}
static int boostpulse_open(struct s5pc110_power_module *s5pc110) static int boostpulse_open(struct s5pc110_power_module *s5pc110)
{ {
char buf[80]; char buf[80];
char governor[80];
pthread_mutex_lock(&s5pc110->lock); pthread_mutex_lock(&s5pc110->lock);
if (s5pc110->boostpulse_fd < 0) { if (s5pc110->boostpulse_fd < 0) {
if (get_scaling_governor(governor, sizeof(governor)) < 0) { if (get_scaling_governor() < 0) {
ALOGE("Can't read scaling governor."); ALOGE("Can't read scaling governor.");
s5pc110->boostpulse_warned = 1; s5pc110->boostpulse_warned = 1;
} else { } else {
@ -104,8 +149,10 @@ static int boostpulse_open(struct s5pc110_power_module *s5pc110)
strerror_r(errno, buf, sizeof(buf)); strerror_r(errno, buf, sizeof(buf));
ALOGE("Error opening %s boostpulse interface: %s\n", governor, buf); ALOGE("Error opening %s boostpulse interface: %s\n", governor, buf);
s5pc110->boostpulse_warned = 1; s5pc110->boostpulse_warned = 1;
} else if (s5pc110->boostpulse_fd > 0) } else if (s5pc110->boostpulse_fd > 0) {
configure_governor();
ALOGD("Opened %s boostpulse interface", governor); ALOGD("Opened %s boostpulse interface", governor);
}
} }
} }
@ -152,14 +199,10 @@ static void s5pc110_power_hint(struct power_module *module, power_hint_t hint,
} }
} }
static void s5pc110_power_set_interactive(struct power_module *module, int on)
{
return;
}
static void s5pc110_power_init(struct power_module *module) static void s5pc110_power_init(struct power_module *module)
{ {
return; get_scaling_governor();
configure_governor();
} }
static struct hw_module_methods_t power_module_methods = { static struct hw_module_methods_t power_module_methods = {
@ -174,7 +217,7 @@ struct s5pc110_power_module HAL_MODULE_INFO_SYM = {
hal_api_version: HARDWARE_HAL_API_VERSION, hal_api_version: HARDWARE_HAL_API_VERSION,
id: POWER_HARDWARE_MODULE_ID, id: POWER_HARDWARE_MODULE_ID,
name: "S5PC110 Power HAL", name: "S5PC110 Power HAL",
author: "The Android Open Source Project", author: "The CyanogenMod Project",
methods: &power_module_methods, methods: &power_module_methods,
}, },
init: s5pc110_power_init, init: s5pc110_power_init,

Loading…
Cancel
Save