Skip to content

Commit

Permalink
cpufreq: interactive: change speed according to current speed and tar…
Browse files Browse the repository at this point in the history
…get load

Add a target_load attribute that specifies how aggressively the governor is
to adjust speed to meet the observed load.  New target speed is calculated
as the current actual speed (may be higher than target speed on SMP) times
the CPU load (as a fraction) divided by target load (fraction).

cpufreq_frequency_table_target() call use CPUFREQ_RELATION_L to set
the next higher speed rather than next lower speed.

Change-Id: If432451da82f5fed12e15c9421d7d27792376150
Signed-off-by: Todd Poynor <[email protected]>
  • Loading branch information
toddpoynor authored and Jay Wu committed Dec 15, 2012
1 parent 960258e commit a231fb3
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions drivers/cpufreq/cpufreq_interactive.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ static int boostpulse_duration;
#define DEFAULT_GO_HISPEED_LOAD 85
static unsigned long go_hispeed_load;

/* Target load. Lower values result in higher CPU speeds. */
#define DEFAULT_TARGET_LOAD 90
static unsigned long target_load = DEFAULT_TARGET_LOAD;

/*
* The minimum amount of time to spend at a frequency before we can ramp down.
*/
Expand Down Expand Up @@ -198,7 +202,7 @@ static void cpufreq_interactive_timer(unsigned long data)
hispeed_freq < pcpu->policy->max) {
new_freq = hispeed_freq;
} else {
new_freq = pcpu->policy->max * cpu_load / 100;
new_freq = pcpu->policy->cur * cpu_load / target_load;

if (new_freq < hispeed_freq)
new_freq = hispeed_freq;
Expand All @@ -215,14 +219,14 @@ static void cpufreq_interactive_timer(unsigned long data)
}
}
} else {
new_freq = hispeed_freq * cpu_load / 100;
new_freq = pcpu->policy->cur * cpu_load / target_load;
}

if (new_freq <= hispeed_freq)
pcpu->hispeed_validate_time = pcpu->timer_run_time;

if (cpufreq_frequency_table_target(pcpu->policy, pcpu->freq_table,
new_freq, CPUFREQ_RELATION_H,
new_freq, CPUFREQ_RELATION_L,
&index)) {
goto rearm;
}
Expand Down Expand Up @@ -478,6 +482,30 @@ static void cpufreq_interactive_boost(void)
wake_up_process(speedchange_task);
}

static ssize_t show_target_load(
struct kobject *kobj, struct attribute *attr, char *buf)
{
return sprintf(buf, "%lu\n", target_load);
}

static ssize_t store_target_load(
struct kobject *kobj, struct attribute *attr, const char *buf,
size_t count)
{
int ret;
unsigned long val;

ret = strict_strtoul(buf, 0, &val);
if (ret < 0)
return ret;
target_load = val;
return count;
}

static struct global_attr target_load_attr =
__ATTR(target_load, S_IRUGO | S_IWUSR,
show_target_load, store_target_load);

static ssize_t show_hispeed_freq(struct kobject *kobj,
struct attribute *attr, char *buf)
{
Expand Down Expand Up @@ -645,6 +673,7 @@ static struct global_attr boostpulse =
__ATTR(boostpulse, 0200, NULL, store_boostpulse);

static struct attribute *interactive_attributes[] = {
&target_load_attr.attr,
&hispeed_freq_attr.attr,
&go_hispeed_load_attr.attr,
&above_hispeed_delay.attr,
Expand Down

0 comments on commit a231fb3

Please sign in to comment.