Skip to content

Commit e0f5f3a

Browse files
deggemaningomolnar
authored andcommitted
sched/fair: Make load tracking frequency scale-invariant
Apply frequency scaling correction factor to per-entity load tracking to make it frequency invariant. Currently, load appears bigger when the CPU is running slower which affects load-balancing decisions. Each segment of the sched_avg.load_sum geometric series is now scaled by the current frequency so that the sched_avg.load_avg of each sched entity will be invariant from frequency scaling. Moreover, cfs_rq.runnable_load_sum is scaled by the current frequency as well. Signed-off-by: Dietmar Eggemann <dietmar.eggemann@arm.com> Signed-off-by: Morten Rasmussen <morten.rasmussen@arm.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Vincent Guittot <vincent.guittot@linaro.org> Cc: Dietmar Eggemann <Dietmar.Eggemann@arm.com> Cc: Juri Lelli <Juri.Lelli@arm.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: daniel.lezcano@linaro.org Cc: mturquette@baylibre.com Cc: pang.xunlei@zte.com.cn Cc: rjw@rjwysocki.net Cc: sgurrappadi@nvidia.com Cc: yuyang.du@intel.com Link: http://lkml.kernel.org/r/1439569394-11974-2-git-send-email-morten.rasmussen@arm.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 2a59572 commit e0f5f3a

2 files changed

Lines changed: 20 additions & 13 deletions

File tree

‎include/linux/sched.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,9 +1177,9 @@ struct load_weight {
11771177

11781178
/*
11791179
* The load_avg/util_avg accumulates an infinite geometric series.
1180-
* 1) load_avg factors the amount of time that a sched_entity is
1181-
* runnable on a rq into its weight. For cfs_rq, it is the aggregated
1182-
* such weights of all runnable and blocked sched_entities.
1180+
* 1) load_avg factors frequency scaling into the amount of time that a
1181+
* sched_entity is runnable on a rq into its weight. For cfs_rq, it is the
1182+
* aggregated such weights of all runnable and blocked sched_entities.
11831183
* 2) util_avg factors frequency scaling into the amount of time
11841184
* that a sched_entity is running on a CPU, in the range [0..SCHED_LOAD_SCALE].
11851185
* For cfs_rq, it is the aggregated such times of all runnable and

‎kernel/sched/fair.c‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2515,6 +2515,8 @@ static u32 __compute_runnable_contrib(u64 n)
25152515
return contrib + runnable_avg_yN_sum[n];
25162516
}
25172517

2518+
#define scale(v, s) ((v)*(s) >> SCHED_CAPACITY_SHIFT)
2519+
25182520
/*
25192521
* We can represent the historical contribution to runnable average as the
25202522
* coefficients of a geometric series. To do this we sub-divide our runnable
@@ -2547,9 +2549,9 @@ static __always_inline int
25472549
__update_load_avg(u64 now, int cpu, struct sched_avg *sa,
25482550
unsigned long weight, int running, struct cfs_rq *cfs_rq)
25492551
{
2550-
u64 delta, periods;
2552+
u64 delta, scaled_delta, periods;
25512553
u32 contrib;
2552-
int delta_w, decayed = 0;
2554+
int delta_w, scaled_delta_w, decayed = 0;
25532555
unsigned long scale_freq = arch_scale_freq_capacity(NULL, cpu);
25542556

25552557
delta = now - sa->last_update_time;
@@ -2585,13 +2587,16 @@ __update_load_avg(u64 now, int cpu, struct sched_avg *sa,
25852587
* period and accrue it.
25862588
*/
25872589
delta_w = 1024 - delta_w;
2590+
scaled_delta_w = scale(delta_w, scale_freq);
25882591
if (weight) {
2589-
sa->load_sum += weight * delta_w;
2590-
if (cfs_rq)
2591-
cfs_rq->runnable_load_sum += weight * delta_w;
2592+
sa->load_sum += weight * scaled_delta_w;
2593+
if (cfs_rq) {
2594+
cfs_rq->runnable_load_sum +=
2595+
weight * scaled_delta_w;
2596+
}
25922597
}
25932598
if (running)
2594-
sa->util_sum += delta_w * scale_freq >> SCHED_CAPACITY_SHIFT;
2599+
sa->util_sum += scaled_delta_w;
25952600

25962601
delta -= delta_w;
25972602

@@ -2608,23 +2613,25 @@ __update_load_avg(u64 now, int cpu, struct sched_avg *sa,
26082613

26092614
/* Efficiently calculate \sum (1..n_period) 1024*y^i */
26102615
contrib = __compute_runnable_contrib(periods);
2616+
contrib = scale(contrib, scale_freq);
26112617
if (weight) {
26122618
sa->load_sum += weight * contrib;
26132619
if (cfs_rq)
26142620
cfs_rq->runnable_load_sum += weight * contrib;
26152621
}
26162622
if (running)
2617-
sa->util_sum += contrib * scale_freq >> SCHED_CAPACITY_SHIFT;
2623+
sa->util_sum += contrib;
26182624
}
26192625

26202626
/* Remainder of delta accrued against u_0` */
2627+
scaled_delta = scale(delta, scale_freq);
26212628
if (weight) {
2622-
sa->load_sum += weight * delta;
2629+
sa->load_sum += weight * scaled_delta;
26232630
if (cfs_rq)
2624-
cfs_rq->runnable_load_sum += weight * delta;
2631+
cfs_rq->runnable_load_sum += weight * scaled_delta;
26252632
}
26262633
if (running)
2627-
sa->util_sum += delta * scale_freq >> SCHED_CAPACITY_SHIFT;
2634+
sa->util_sum += scaled_delta;
26282635

26292636
sa->period_contrib += delta;
26302637

0 commit comments

Comments
 (0)