Skip to content

Commit

Permalink
exynos3: power: Tuning and cleanups
Browse files Browse the repository at this point in the history
* Tune the governor for better power usage and interactivity
* Reset tuning parameters if governor changes
* Cleanup

Change-Id: Ibe60ece836a0e56ba58e109bbea26cbd54d75421
  • Loading branch information
hyperb1iss authored and Gerrit Code Review committed Feb 19, 2013
1 parent 79b8917 commit de4b10b
Showing 1 changed file with 55 additions and 12 deletions.
67 changes: 55 additions & 12 deletions exynos3/s5pc110/power/power.c
Expand Up @@ -29,6 +29,8 @@
#define SCALING_GOVERNOR_PATH "/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"
#define BOOSTPULSE_ONDEMAND "/sys/devices/system/cpu/cpufreq/ondemand/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 power_module base;
Expand All @@ -37,6 +39,8 @@ struct s5pc110_power_module {
int boostpulse_warned;
};

static char governor[20];

static int sysfs_read(char *path, char *s, int num_bytes)
{
char buf[80];
Expand Down Expand Up @@ -65,9 +69,30 @@ static int sysfs_read(char *path, char *s, int num_bytes)
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,
size) == -1) {
sizeof(governor)) == -1) {
// Can't obtain the scaling governor. Return.
return -1;
} else {
Expand All @@ -83,15 +108,35 @@ static int get_scaling_governor(char governor[], int size) {
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)
{
char buf[80];
char governor[80];

pthread_mutex_lock(&s5pc110->lock);

if (s5pc110->boostpulse_fd < 0) {
if (get_scaling_governor(governor, sizeof(governor)) < 0) {
if (get_scaling_governor() < 0) {
ALOGE("Can't read scaling governor.");
s5pc110->boostpulse_warned = 1;
} else {
Expand All @@ -104,8 +149,10 @@ static int boostpulse_open(struct s5pc110_power_module *s5pc110)
strerror_r(errno, buf, sizeof(buf));
ALOGE("Error opening %s boostpulse interface: %s\n", governor, buf);
s5pc110->boostpulse_warned = 1;
} else if (s5pc110->boostpulse_fd > 0)
} else if (s5pc110->boostpulse_fd > 0) {
configure_governor();
ALOGD("Opened %s boostpulse interface", governor);
}
}
}

Expand Down Expand Up @@ -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)
{
return;
get_scaling_governor();
configure_governor();
}

static struct hw_module_methods_t power_module_methods = {
Expand All @@ -174,7 +217,7 @@ struct s5pc110_power_module HAL_MODULE_INFO_SYM = {
hal_api_version: HARDWARE_HAL_API_VERSION,
id: POWER_HARDWARE_MODULE_ID,
name: "S5PC110 Power HAL",
author: "The Android Open Source Project",
author: "The CyanogenMod Project",
methods: &power_module_methods,
},
init: s5pc110_power_init,
Expand Down

0 comments on commit de4b10b

Please sign in to comment.