Skip to content

Commit ca8ce3d

Browse files
Nicolas Pitreingomolnar
authored andcommitted
sched: Final power vs. capacity cleanups
It is better not to think about compute capacity as being equivalent to "CPU power". The upcoming "power aware" scheduler work may create confusion with the notion of energy consumption if "power" is used too liberally. This contains the architecture visible changes. Incidentally, only ARM takes advantage of the available pow^H^H^Hcapacity scaling hooks and therefore those changes outside kernel/sched/ are confined to one ARM specific file. The default arch_scale_smt_power() hook is not overridden by anyone. Replacements are as follows: arch_scale_freq_power --> arch_scale_freq_capacity arch_scale_smt_power --> arch_scale_smt_capacity SCHED_POWER_SCALE --> SCHED_CAPACITY_SCALE SCHED_POWER_SHIFT --> SCHED_CAPACITY_SHIFT The local usage of "power" in arch/arm/kernel/topology.c is also changed to "capacity" as appropriate. Signed-off-by: Nicolas Pitre <nico@linaro.org> Signed-off-by: Peter Zijlstra <peterz@infradead.org> Cc: Vincent Guittot <vincent.guittot@linaro.org> Cc: Daniel Lezcano <daniel.lezcano@linaro.org> Cc: Morten Rasmussen <morten.rasmussen@arm.com> Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net> Cc: linaro-kernel@lists.linaro.org Cc: Arnd Bergmann <arnd@arndb.de> Cc: Dietmar Eggemann <dietmar.eggemann@arm.com> Cc: Grant Likely <grant.likely@linaro.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Mark Brown <broonie@linaro.org> Cc: Rob Herring <robh+dt@kernel.org> Cc: Russell King <linux@arm.linux.org.uk> Cc: Sudeep KarkadaNagesha <sudeep.karkadanagesha@arm.com> Cc: Vincent Guittot <vincent.guittot@linaro.org> Cc: devicetree@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Link: http://lkml.kernel.org/n/tip-48zba9qbznvglwelgq2cfygh@git.kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent ced549f commit ca8ce3d

4 files changed

Lines changed: 63 additions & 62 deletions

File tree

‎arch/arm/kernel/topology.c‎

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,30 @@
2626
#include <asm/topology.h>
2727

2828
/*
29-
* cpu power scale management
29+
* cpu capacity scale management
3030
*/
3131

3232
/*
33-
* cpu power table
33+
* cpu capacity table
3434
* This per cpu data structure describes the relative capacity of each core.
3535
* On a heteregenous system, cores don't have the same computation capacity
36-
* and we reflect that difference in the cpu_power field so the scheduler can
37-
* take this difference into account during load balance. A per cpu structure
38-
* is preferred because each CPU updates its own cpu_power field during the
39-
* load balance except for idle cores. One idle core is selected to run the
40-
* rebalance_domains for all idle cores and the cpu_power can be updated
41-
* during this sequence.
36+
* and we reflect that difference in the cpu_capacity field so the scheduler
37+
* can take this difference into account during load balance. A per cpu
38+
* structure is preferred because each CPU updates its own cpu_capacity field
39+
* during the load balance except for idle cores. One idle core is selected
40+
* to run the rebalance_domains for all idle cores and the cpu_capacity can be
41+
* updated during this sequence.
4242
*/
4343
static DEFINE_PER_CPU(unsigned long, cpu_scale);
4444

45-
unsigned long arch_scale_freq_power(struct sched_domain *sd, int cpu)
45+
unsigned long arch_scale_freq_capacity(struct sched_domain *sd, int cpu)
4646
{
4747
return per_cpu(cpu_scale, cpu);
4848
}
4949

50-
static void set_power_scale(unsigned int cpu, unsigned long power)
50+
static void set_capacity_scale(unsigned int cpu, unsigned long capacity)
5151
{
52-
per_cpu(cpu_scale, cpu) = power;
52+
per_cpu(cpu_scale, cpu) = capacity;
5353
}
5454

5555
#ifdef CONFIG_OF
@@ -62,11 +62,11 @@ struct cpu_efficiency {
6262
* Table of relative efficiency of each processors
6363
* The efficiency value must fit in 20bit and the final
6464
* cpu_scale value must be in the range
65-
* 0 < cpu_scale < 3*SCHED_POWER_SCALE/2
65+
* 0 < cpu_scale < 3*SCHED_CAPACITY_SCALE/2
6666
* in order to return at most 1 when DIV_ROUND_CLOSEST
6767
* is used to compute the capacity of a CPU.
6868
* Processors that are not defined in the table,
69-
* use the default SCHED_POWER_SCALE value for cpu_scale.
69+
* use the default SCHED_CAPACITY_SCALE value for cpu_scale.
7070
*/
7171
static const struct cpu_efficiency table_efficiency[] = {
7272
{"arm,cortex-a15", 3891},
@@ -83,9 +83,9 @@ static unsigned long middle_capacity = 1;
8383
* Iterate all CPUs' descriptor in DT and compute the efficiency
8484
* (as per table_efficiency). Also calculate a middle efficiency
8585
* as close as possible to (max{eff_i} - min{eff_i}) / 2
86-
* This is later used to scale the cpu_power field such that an
87-
* 'average' CPU is of middle power. Also see the comments near
88-
* table_efficiency[] and update_cpu_power().
86+
* This is later used to scale the cpu_capacity field such that an
87+
* 'average' CPU is of middle capacity. Also see the comments near
88+
* table_efficiency[] and update_cpu_capacity().
8989
*/
9090
static void __init parse_dt_topology(void)
9191
{
@@ -141,15 +141,15 @@ static void __init parse_dt_topology(void)
141141
* cpu_scale because all CPUs have the same capacity. Otherwise, we
142142
* compute a middle_capacity factor that will ensure that the capacity
143143
* of an 'average' CPU of the system will be as close as possible to
144-
* SCHED_POWER_SCALE, which is the default value, but with the
144+
* SCHED_CAPACITY_SCALE, which is the default value, but with the
145145
* constraint explained near table_efficiency[].
146146
*/
147147
if (4*max_capacity < (3*(max_capacity + min_capacity)))
148148
middle_capacity = (min_capacity + max_capacity)
149-
>> (SCHED_POWER_SHIFT+1);
149+
>> (SCHED_CAPACITY_SHIFT+1);
150150
else
151151
middle_capacity = ((max_capacity / 3)
152-
>> (SCHED_POWER_SHIFT-1)) + 1;
152+
>> (SCHED_CAPACITY_SHIFT-1)) + 1;
153153

154154
}
155155

@@ -158,20 +158,20 @@ static void __init parse_dt_topology(void)
158158
* boot. The update of all CPUs is in O(n^2) for heteregeneous system but the
159159
* function returns directly for SMP system.
160160
*/
161-
static void update_cpu_power(unsigned int cpu)
161+
static void update_cpu_capacity(unsigned int cpu)
162162
{
163163
if (!cpu_capacity(cpu))
164164
return;
165165

166-
set_power_scale(cpu, cpu_capacity(cpu) / middle_capacity);
166+
set_capacity_scale(cpu, cpu_capacity(cpu) / middle_capacity);
167167

168-
printk(KERN_INFO "CPU%u: update cpu_power %lu\n",
169-
cpu, arch_scale_freq_power(NULL, cpu));
168+
printk(KERN_INFO "CPU%u: update cpu_capacity %lu\n",
169+
cpu, arch_scale_freq_capacity(NULL, cpu));
170170
}
171171

172172
#else
173173
static inline void parse_dt_topology(void) {}
174-
static inline void update_cpu_power(unsigned int cpuid) {}
174+
static inline void update_cpu_capacity(unsigned int cpuid) {}
175175
#endif
176176

177177
/*
@@ -267,7 +267,7 @@ void store_cpu_topology(unsigned int cpuid)
267267

268268
update_siblings_masks(cpuid);
269269

270-
update_cpu_power(cpuid);
270+
update_cpu_capacity(cpuid);
271271

272272
printk(KERN_INFO "CPU%u: thread %d, cpu %d, socket %d, mpidr %x\n",
273273
cpuid, cpu_topology[cpuid].thread_id,
@@ -297,7 +297,7 @@ void __init init_cpu_topology(void)
297297
{
298298
unsigned int cpu;
299299

300-
/* init core mask and power*/
300+
/* init core mask and capacity */
301301
for_each_possible_cpu(cpu) {
302302
struct cputopo_arm *cpu_topo = &(cpu_topology[cpu]);
303303

@@ -307,7 +307,7 @@ void __init init_cpu_topology(void)
307307
cpumask_clear(&cpu_topo->core_sibling);
308308
cpumask_clear(&cpu_topo->thread_sibling);
309309

310-
set_power_scale(cpu, SCHED_POWER_SCALE);
310+
set_capacity_scale(cpu, SCHED_CAPACITY_SCALE);
311311
}
312312
smp_wmb();
313313

‎include/linux/sched.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -854,10 +854,10 @@ enum cpu_idle_type {
854854
};
855855

856856
/*
857-
* Increase resolution of cpu_power calculations
857+
* Increase resolution of cpu_capacity calculations
858858
*/
859-
#define SCHED_POWER_SHIFT 10
860-
#define SCHED_POWER_SCALE (1L << SCHED_POWER_SHIFT)
859+
#define SCHED_CAPACITY_SHIFT 10
860+
#define SCHED_CAPACITY_SCALE (1L << SCHED_CAPACITY_SHIFT)
861861

862862
/*
863863
* sched-domains (multiprocessor balancing) declarations:

‎kernel/sched/core.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5249,7 +5249,7 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level,
52495249
cpulist_scnprintf(str, sizeof(str), sched_group_cpus(group));
52505250

52515251
printk(KERN_CONT " %s", str);
5252-
if (group->sgc->capacity != SCHED_POWER_SCALE) {
5252+
if (group->sgc->capacity != SCHED_CAPACITY_SCALE) {
52535253
printk(KERN_CONT " (cpu_capacity = %d)",
52545254
group->sgc->capacity);
52555255
}
@@ -5715,7 +5715,7 @@ build_overlap_sched_groups(struct sched_domain *sd, int cpu)
57155715
* domains and no possible iteration will get us here, we won't
57165716
* die on a /0 trap.
57175717
*/
5718-
sg->sgc->capacity = SCHED_POWER_SCALE * cpumask_weight(sg_span);
5718+
sg->sgc->capacity = SCHED_CAPACITY_SCALE * cpumask_weight(sg_span);
57195719
sg->sgc->capacity_orig = sg->sgc->capacity;
57205720

57215721
/*
@@ -6921,7 +6921,7 @@ void __init sched_init(void)
69216921
#ifdef CONFIG_SMP
69226922
rq->sd = NULL;
69236923
rq->rd = NULL;
6924-
rq->cpu_capacity = SCHED_POWER_SCALE;
6924+
rq->cpu_capacity = SCHED_CAPACITY_SCALE;
69256925
rq->post_schedule = 0;
69266926
rq->active_balance = 0;
69276927
rq->next_balance = jiffies;

‎kernel/sched/fair.c‎

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,9 +1062,9 @@ static void update_numa_stats(struct numa_stats *ns, int nid)
10621062
if (!cpus)
10631063
return;
10641064

1065-
ns->load = (ns->load * SCHED_POWER_SCALE) / ns->compute_capacity;
1065+
ns->load = (ns->load * SCHED_CAPACITY_SCALE) / ns->compute_capacity;
10661066
ns->task_capacity =
1067-
DIV_ROUND_CLOSEST(ns->compute_capacity, SCHED_POWER_SCALE);
1067+
DIV_ROUND_CLOSEST(ns->compute_capacity, SCHED_CAPACITY_SCALE);
10681068
ns->has_free_capacity = (ns->nr_running < ns->task_capacity);
10691069
}
10701070

@@ -4370,7 +4370,7 @@ find_idlest_group(struct sched_domain *sd, struct task_struct *p,
43704370
}
43714371

43724372
/* Adjust by relative CPU capacity of the group */
4373-
avg_load = (avg_load * SCHED_POWER_SCALE) / group->sgc->capacity;
4373+
avg_load = (avg_load * SCHED_CAPACITY_SCALE) / group->sgc->capacity;
43744374

43754375
if (local_group) {
43764376
this_load = avg_load;
@@ -5609,10 +5609,10 @@ static inline int get_sd_load_idx(struct sched_domain *sd,
56095609

56105610
static unsigned long default_scale_capacity(struct sched_domain *sd, int cpu)
56115611
{
5612-
return SCHED_POWER_SCALE;
5612+
return SCHED_CAPACITY_SCALE;
56135613
}
56145614

5615-
unsigned long __weak arch_scale_freq_power(struct sched_domain *sd, int cpu)
5615+
unsigned long __weak arch_scale_freq_capacity(struct sched_domain *sd, int cpu)
56165616
{
56175617
return default_scale_capacity(sd, cpu);
56185618
}
@@ -5627,7 +5627,7 @@ static unsigned long default_scale_smt_capacity(struct sched_domain *sd, int cpu
56275627
return smt_gain;
56285628
}
56295629

5630-
unsigned long __weak arch_scale_smt_power(struct sched_domain *sd, int cpu)
5630+
unsigned long __weak arch_scale_smt_capacity(struct sched_domain *sd, int cpu)
56315631
{
56325632
return default_scale_smt_capacity(sd, cpu);
56335633
}
@@ -5658,40 +5658,40 @@ static unsigned long scale_rt_capacity(int cpu)
56585658
available = total - avg;
56595659
}
56605660

5661-
if (unlikely((s64)total < SCHED_POWER_SCALE))
5662-
total = SCHED_POWER_SCALE;
5661+
if (unlikely((s64)total < SCHED_CAPACITY_SCALE))
5662+
total = SCHED_CAPACITY_SCALE;
56635663

5664-
total >>= SCHED_POWER_SHIFT;
5664+
total >>= SCHED_CAPACITY_SHIFT;
56655665

56665666
return div_u64(available, total);
56675667
}
56685668

56695669
static void update_cpu_capacity(struct sched_domain *sd, int cpu)
56705670
{
56715671
unsigned long weight = sd->span_weight;
5672-
unsigned long capacity = SCHED_POWER_SCALE;
5672+
unsigned long capacity = SCHED_CAPACITY_SCALE;
56735673
struct sched_group *sdg = sd->groups;
56745674

56755675
if ((sd->flags & SD_SHARE_CPUPOWER) && weight > 1) {
56765676
if (sched_feat(ARCH_POWER))
5677-
capacity *= arch_scale_smt_power(sd, cpu);
5677+
capacity *= arch_scale_smt_capacity(sd, cpu);
56785678
else
56795679
capacity *= default_scale_smt_capacity(sd, cpu);
56805680

5681-
capacity >>= SCHED_POWER_SHIFT;
5681+
capacity >>= SCHED_CAPACITY_SHIFT;
56825682
}
56835683

56845684
sdg->sgc->capacity_orig = capacity;
56855685

56865686
if (sched_feat(ARCH_POWER))
5687-
capacity *= arch_scale_freq_power(sd, cpu);
5687+
capacity *= arch_scale_freq_capacity(sd, cpu);
56885688
else
56895689
capacity *= default_scale_capacity(sd, cpu);
56905690

5691-
capacity >>= SCHED_POWER_SHIFT;
5691+
capacity >>= SCHED_CAPACITY_SHIFT;
56925692

56935693
capacity *= scale_rt_capacity(cpu);
5694-
capacity >>= SCHED_POWER_SHIFT;
5694+
capacity >>= SCHED_CAPACITY_SHIFT;
56955695

56965696
if (!capacity)
56975697
capacity = 1;
@@ -5780,7 +5780,7 @@ static inline int
57805780
fix_small_capacity(struct sched_domain *sd, struct sched_group *group)
57815781
{
57825782
/*
5783-
* Only siblings can have significantly less than SCHED_POWER_SCALE
5783+
* Only siblings can have significantly less than SCHED_CAPACITY_SCALE
57845784
*/
57855785
if (!(sd->flags & SD_SHARE_CPUPOWER))
57865786
return 0;
@@ -5845,11 +5845,11 @@ static inline int sg_capacity_factor(struct lb_env *env, struct sched_group *gro
58455845
cpus = group->group_weight;
58465846

58475847
/* smt := ceil(cpus / capacity), assumes: 1 < smt_capacity < 2 */
5848-
smt = DIV_ROUND_UP(SCHED_POWER_SCALE * cpus, capacity_orig);
5848+
smt = DIV_ROUND_UP(SCHED_CAPACITY_SCALE * cpus, capacity_orig);
58495849
capacity_factor = cpus / smt; /* cores */
58505850

58515851
capacity_factor = min_t(unsigned,
5852-
capacity_factor, DIV_ROUND_CLOSEST(capacity, SCHED_POWER_SCALE));
5852+
capacity_factor, DIV_ROUND_CLOSEST(capacity, SCHED_CAPACITY_SCALE));
58535853
if (!capacity_factor)
58545854
capacity_factor = fix_small_capacity(env->sd, group);
58555855

@@ -5895,7 +5895,7 @@ static inline void update_sg_lb_stats(struct lb_env *env,
58955895

58965896
/* Adjust by relative CPU capacity of the group */
58975897
sgs->group_capacity = group->sgc->capacity;
5898-
sgs->avg_load = (sgs->group_load*SCHED_POWER_SCALE) / sgs->group_capacity;
5898+
sgs->avg_load = (sgs->group_load*SCHED_CAPACITY_SCALE) / sgs->group_capacity;
58995899

59005900
if (sgs->sum_nr_running)
59015901
sgs->load_per_task = sgs->sum_weighted_load / sgs->sum_nr_running;
@@ -6089,7 +6089,7 @@ static int check_asym_packing(struct lb_env *env, struct sd_lb_stats *sds)
60896089

60906090
env->imbalance = DIV_ROUND_CLOSEST(
60916091
sds->busiest_stat.avg_load * sds->busiest_stat.group_capacity,
6092-
SCHED_POWER_SCALE);
6092+
SCHED_CAPACITY_SCALE);
60936093

60946094
return 1;
60956095
}
@@ -6118,7 +6118,7 @@ void fix_small_imbalance(struct lb_env *env, struct sd_lb_stats *sds)
61186118
imbn = 1;
61196119

61206120
scaled_busy_load_per_task =
6121-
(busiest->load_per_task * SCHED_POWER_SCALE) /
6121+
(busiest->load_per_task * SCHED_CAPACITY_SCALE) /
61226122
busiest->group_capacity;
61236123

61246124
if (busiest->avg_load + scaled_busy_load_per_task >=
@@ -6137,7 +6137,7 @@ void fix_small_imbalance(struct lb_env *env, struct sd_lb_stats *sds)
61376137
min(busiest->load_per_task, busiest->avg_load);
61386138
capa_now += local->group_capacity *
61396139
min(local->load_per_task, local->avg_load);
6140-
capa_now /= SCHED_POWER_SCALE;
6140+
capa_now /= SCHED_CAPACITY_SCALE;
61416141

61426142
/* Amount of load we'd subtract */
61436143
if (busiest->avg_load > scaled_busy_load_per_task) {
@@ -6148,16 +6148,16 @@ void fix_small_imbalance(struct lb_env *env, struct sd_lb_stats *sds)
61486148

61496149
/* Amount of load we'd add */
61506150
if (busiest->avg_load * busiest->group_capacity <
6151-
busiest->load_per_task * SCHED_POWER_SCALE) {
6151+
busiest->load_per_task * SCHED_CAPACITY_SCALE) {
61526152
tmp = (busiest->avg_load * busiest->group_capacity) /
61536153
local->group_capacity;
61546154
} else {
6155-
tmp = (busiest->load_per_task * SCHED_POWER_SCALE) /
6155+
tmp = (busiest->load_per_task * SCHED_CAPACITY_SCALE) /
61566156
local->group_capacity;
61576157
}
61586158
capa_move += local->group_capacity *
61596159
min(local->load_per_task, local->avg_load + tmp);
6160-
capa_move /= SCHED_POWER_SCALE;
6160+
capa_move /= SCHED_CAPACITY_SCALE;
61616161

61626162
/* Move if we gain throughput */
61636163
if (capa_move > capa_now)
@@ -6207,7 +6207,7 @@ static inline void calculate_imbalance(struct lb_env *env, struct sd_lb_stats *s
62076207
load_above_capacity =
62086208
(busiest->sum_nr_running - busiest->group_capacity_factor);
62096209

6210-
load_above_capacity *= (SCHED_LOAD_SCALE * SCHED_POWER_SCALE);
6210+
load_above_capacity *= (SCHED_LOAD_SCALE * SCHED_CAPACITY_SCALE);
62116211
load_above_capacity /= busiest->group_capacity;
62126212
}
62136213

@@ -6225,7 +6225,7 @@ static inline void calculate_imbalance(struct lb_env *env, struct sd_lb_stats *s
62256225
env->imbalance = min(
62266226
max_pull * busiest->group_capacity,
62276227
(sds->avg_load - local->avg_load) * local->group_capacity
6228-
) / SCHED_POWER_SCALE;
6228+
) / SCHED_CAPACITY_SCALE;
62296229

62306230
/*
62316231
* if *imbalance is less than the average load per runnable task
@@ -6279,7 +6279,8 @@ static struct sched_group *find_busiest_group(struct lb_env *env)
62796279
if (!sds.busiest || busiest->sum_nr_running == 0)
62806280
goto out_balanced;
62816281

6282-
sds.avg_load = (SCHED_POWER_SCALE * sds.total_load) / sds.total_capacity;
6282+
sds.avg_load = (SCHED_CAPACITY_SCALE * sds.total_load)
6283+
/ sds.total_capacity;
62836284

62846285
/*
62856286
* If the busiest group is imbalanced the below checks don't
@@ -6378,7 +6379,7 @@ static struct rq *find_busiest_queue(struct lb_env *env,
63786379
continue;
63796380

63806381
capacity = capacity_of(i);
6381-
capacity_factor = DIV_ROUND_CLOSEST(capacity, SCHED_POWER_SCALE);
6382+
capacity_factor = DIV_ROUND_CLOSEST(capacity, SCHED_CAPACITY_SCALE);
63826383
if (!capacity_factor)
63836384
capacity_factor = fix_small_capacity(env->sd, group);
63846385

0 commit comments

Comments
 (0)