sched: cpufreq: use rt_avg as estimate of required RT CPU capacity

A policy of going to fmax on any RT activity will be detrimental
for power on many platforms. Often RT accounts for only a small amount
of CPU activity so sending the CPU frequency to fmax is overkill. Worse
still, some platforms may not be able to even complete the CPU frequency
change before the RT activity has already completed.

Cpufreq governors have not treated RT activity this way in the past so
it is not part of the expected semantics of the RT scheduling class. The
DL class offers guarantees about task completion and could be used for
this purpose.

Modify the schedutil algorithm to instead use rt_avg as an estimate of
RT utilization of the CPU.

Based on previous work by Vincent Guittot <vincent.guittot@linaro.org>.

Change-Id: I1ed605a3e2512a94d34217a8e57c3fd97cca60be
Signed-off-by: Steve Muckle <smuckle@linaro.org>
This commit is contained in:
Steve Muckle
2016-08-25 15:59:17 -07:00
committed by Amit Pundir
parent 83ad45692d
commit 8c7730ea97
2 changed files with 21 additions and 14 deletions

View File

@@ -3295,8 +3295,6 @@ static inline unsigned long rlimit_max(unsigned int limit)
#define SCHED_CPUFREQ_DL (1U << 1)
#define SCHED_CPUFREQ_IOWAIT (1U << 2)
#define SCHED_CPUFREQ_RT_DL (SCHED_CPUFREQ_RT | SCHED_CPUFREQ_DL)
#ifdef CONFIG_CPU_FREQ
struct update_util_data {
void (*func)(struct update_util_data *data, u64 time, unsigned int flags);

View File

@@ -156,15 +156,24 @@ static unsigned int get_next_freq(struct sugov_cpu *sg_cpu, unsigned long util,
return cpufreq_driver_resolve_freq(policy, freq);
}
static void sugov_get_util(unsigned long *util, unsigned long *max)
static void sugov_get_util(unsigned long *util, unsigned long *max, u64 time)
{
struct rq *rq = this_rq();
unsigned long cfs_max;
int cpu = smp_processor_id();
struct rq *rq = cpu_rq(cpu);
unsigned long max_cap, rt;
s64 delta;
cfs_max = arch_scale_cpu_capacity(NULL, smp_processor_id());
max_cap = arch_scale_cpu_capacity(NULL, cpu);
*util = min(rq->cfs.avg.util_avg, cfs_max);
*max = cfs_max;
sched_avg_update(rq);
delta = time - rq->age_stamp;
if (unlikely(delta < 0))
delta = 0;
rt = div64_u64(rq->rt_avg, sched_avg_period() + delta);
rt = (rt * max_cap) >> SCHED_CAPACITY_SHIFT;
*util = min(rq->cfs.avg.util_avg + rt, max_cap);
*max = max_cap;
}
static void sugov_set_iowait_boost(struct sugov_cpu *sg_cpu, u64 time,
@@ -212,10 +221,10 @@ static void sugov_update_single(struct update_util_data *hook, u64 time,
if (!sugov_should_update_freq(sg_policy, time))
return;
if (flags & SCHED_CPUFREQ_RT_DL) {
if (flags & SCHED_CPUFREQ_DL) {
next_f = policy->cpuinfo.max_freq;
} else {
sugov_get_util(&util, &max);
sugov_get_util(&util, &max, time);
sugov_iowait_boost(sg_cpu, &util, &max);
next_f = get_next_freq(sg_cpu, util, max);
}
@@ -232,7 +241,7 @@ static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu,
u64 last_freq_update_time = sg_policy->last_freq_update_time;
unsigned int j;
if (flags & SCHED_CPUFREQ_RT_DL)
if (flags & SCHED_CPUFREQ_DL)
return max_f;
sugov_iowait_boost(sg_cpu, &util, &max);
@@ -258,7 +267,7 @@ static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu,
j_sg_cpu->iowait_boost = 0;
continue;
}
if (j_sg_cpu->flags & SCHED_CPUFREQ_RT_DL)
if (j_sg_cpu->flags & SCHED_CPUFREQ_DL)
return max_f;
j_util = j_sg_cpu->util;
@@ -282,7 +291,7 @@ static void sugov_update_shared(struct update_util_data *hook, u64 time,
unsigned long util, max;
unsigned int next_f;
sugov_get_util(&util, &max);
sugov_get_util(&util, &max, time);
raw_spin_lock(&sg_policy->update_lock);
@@ -590,7 +599,7 @@ static int sugov_start(struct cpufreq_policy *policy)
if (policy_is_shared(policy)) {
sg_cpu->util = 0;
sg_cpu->max = 0;
sg_cpu->flags = SCHED_CPUFREQ_RT;
sg_cpu->flags = SCHED_CPUFREQ_DL;
sg_cpu->last_update = 0;
sg_cpu->cached_raw_freq = 0;
sg_cpu->iowait_boost = 0;