Skip to content

Commit 9c3f75c

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
sched: Break out cpu_power from the sched_group structure
In order to prepare for non-unique sched_groups per domain, we need to carry the cpu_power elsewhere, so put a level of indirection in. Reported-and-tested-by: Anton Blanchard <anton@samba.org> Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Andrew Morton <akpm@linux-foundation.org> Link: http://lkml.kernel.org/n/tip-qkho2byuhe4482fuknss40ad@git.kernel.org Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent e6625fa commit 9c3f75c

3 files changed

Lines changed: 58 additions & 34 deletions

File tree

‎include/linux/sched.h‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -893,16 +893,20 @@ static inline int sd_power_saving_flags(void)
893893
return 0;
894894
}
895895

896-
struct sched_group {
897-
struct sched_group *next; /* Must be a circular list */
898-
atomic_t ref;
899-
896+
struct sched_group_power {
900897
/*
901898
* CPU power of this group, SCHED_LOAD_SCALE being max power for a
902899
* single CPU.
903900
*/
904-
unsigned int cpu_power, cpu_power_orig;
901+
unsigned int power, power_orig;
902+
};
903+
904+
struct sched_group {
905+
struct sched_group *next; /* Must be a circular list */
906+
atomic_t ref;
907+
905908
unsigned int group_weight;
909+
struct sched_group_power *sgp;
906910

907911
/*
908912
* The CPUs this group covers.

‎kernel/sched.c‎

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6557,7 +6557,7 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level,
65576557
break;
65586558
}
65596559

6560-
if (!group->cpu_power) {
6560+
if (!group->sgp->power) {
65616561
printk(KERN_CONT "\n");
65626562
printk(KERN_ERR "ERROR: domain->cpu_power not "
65636563
"set\n");
@@ -6581,9 +6581,9 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level,
65816581
cpulist_scnprintf(str, sizeof(str), sched_group_cpus(group));
65826582

65836583
printk(KERN_CONT " %s", str);
6584-
if (group->cpu_power != SCHED_POWER_SCALE) {
6584+
if (group->sgp->power != SCHED_POWER_SCALE) {
65856585
printk(KERN_CONT " (cpu_power = %d)",
6586-
group->cpu_power);
6586+
group->sgp->power);
65876587
}
65886588

65896589
group = group->next;
@@ -6777,8 +6777,10 @@ static struct root_domain *alloc_rootdomain(void)
67776777
static void free_sched_domain(struct rcu_head *rcu)
67786778
{
67796779
struct sched_domain *sd = container_of(rcu, struct sched_domain, rcu);
6780-
if (atomic_dec_and_test(&sd->groups->ref))
6780+
if (atomic_dec_and_test(&sd->groups->ref)) {
6781+
kfree(sd->groups->sgp);
67816782
kfree(sd->groups);
6783+
}
67826784
kfree(sd);
67836785
}
67846786

@@ -6945,6 +6947,7 @@ int sched_smt_power_savings = 0, sched_mc_power_savings = 0;
69456947
struct sd_data {
69466948
struct sched_domain **__percpu sd;
69476949
struct sched_group **__percpu sg;
6950+
struct sched_group_power **__percpu sgp;
69486951
};
69496952

69506953
struct s_data {
@@ -6981,8 +6984,10 @@ static int get_group(int cpu, struct sd_data *sdd, struct sched_group **sg)
69816984
if (child)
69826985
cpu = cpumask_first(sched_domain_span(child));
69836986

6984-
if (sg)
6987+
if (sg) {
69856988
*sg = *per_cpu_ptr(sdd->sg, cpu);
6989+
(*sg)->sgp = *per_cpu_ptr(sdd->sgp, cpu);
6990+
}
69866991

69876992
return cpu;
69886993
}
@@ -7020,7 +7025,7 @@ build_sched_groups(struct sched_domain *sd)
70207025
continue;
70217026

70227027
cpumask_clear(sched_group_cpus(sg));
7023-
sg->cpu_power = 0;
7028+
sg->sgp->power = 0;
70247029

70257030
for_each_cpu(j, span) {
70267031
if (get_group(j, sdd, NULL) != group)
@@ -7185,6 +7190,7 @@ static void claim_allocations(int cpu, struct sched_domain *sd)
71857190
if (cpu == cpumask_first(sched_group_cpus(sg))) {
71867191
WARN_ON_ONCE(*per_cpu_ptr(sdd->sg, cpu) != sg);
71877192
*per_cpu_ptr(sdd->sg, cpu) = NULL;
7193+
*per_cpu_ptr(sdd->sgp, cpu) = NULL;
71887194
}
71897195
}
71907196

@@ -7234,9 +7240,14 @@ static int __sdt_alloc(const struct cpumask *cpu_map)
72347240
if (!sdd->sg)
72357241
return -ENOMEM;
72367242

7243+
sdd->sgp = alloc_percpu(struct sched_group_power *);
7244+
if (!sdd->sgp)
7245+
return -ENOMEM;
7246+
72377247
for_each_cpu(j, cpu_map) {
72387248
struct sched_domain *sd;
72397249
struct sched_group *sg;
7250+
struct sched_group_power *sgp;
72407251

72417252
sd = kzalloc_node(sizeof(struct sched_domain) + cpumask_size(),
72427253
GFP_KERNEL, cpu_to_node(j));
@@ -7251,6 +7262,13 @@ static int __sdt_alloc(const struct cpumask *cpu_map)
72517262
return -ENOMEM;
72527263

72537264
*per_cpu_ptr(sdd->sg, j) = sg;
7265+
7266+
sgp = kzalloc_node(sizeof(struct sched_group_power),
7267+
GFP_KERNEL, cpu_to_node(j));
7268+
if (!sgp)
7269+
return -ENOMEM;
7270+
7271+
*per_cpu_ptr(sdd->sgp, j) = sgp;
72547272
}
72557273
}
72567274

@@ -7268,9 +7286,11 @@ static void __sdt_free(const struct cpumask *cpu_map)
72687286
for_each_cpu(j, cpu_map) {
72697287
kfree(*per_cpu_ptr(sdd->sd, j));
72707288
kfree(*per_cpu_ptr(sdd->sg, j));
7289+
kfree(*per_cpu_ptr(sdd->sgp, j));
72717290
}
72727291
free_percpu(sdd->sd);
72737292
free_percpu(sdd->sg);
7293+
free_percpu(sdd->sgp);
72747294
}
72757295
}
72767296

‎kernel/sched_fair.c‎

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,7 +1585,7 @@ find_idlest_group(struct sched_domain *sd, struct task_struct *p,
15851585
}
15861586

15871587
/* Adjust by relative CPU power of the group */
1588-
avg_load = (avg_load * SCHED_POWER_SCALE) / group->cpu_power;
1588+
avg_load = (avg_load * SCHED_POWER_SCALE) / group->sgp->power;
15891589

15901590
if (local_group) {
15911591
this_load = avg_load;
@@ -2631,7 +2631,7 @@ static void update_cpu_power(struct sched_domain *sd, int cpu)
26312631
power >>= SCHED_POWER_SHIFT;
26322632
}
26332633

2634-
sdg->cpu_power_orig = power;
2634+
sdg->sgp->power_orig = power;
26352635

26362636
if (sched_feat(ARCH_POWER))
26372637
power *= arch_scale_freq_power(sd, cpu);
@@ -2647,7 +2647,7 @@ static void update_cpu_power(struct sched_domain *sd, int cpu)
26472647
power = 1;
26482648

26492649
cpu_rq(cpu)->cpu_power = power;
2650-
sdg->cpu_power = power;
2650+
sdg->sgp->power = power;
26512651
}
26522652

26532653
static void update_group_power(struct sched_domain *sd, int cpu)
@@ -2665,11 +2665,11 @@ static void update_group_power(struct sched_domain *sd, int cpu)
26652665

26662666
group = child->groups;
26672667
do {
2668-
power += group->cpu_power;
2668+
power += group->sgp->power;
26692669
group = group->next;
26702670
} while (group != child->groups);
26712671

2672-
sdg->cpu_power = power;
2672+
sdg->sgp->power = power;
26732673
}
26742674

26752675
/*
@@ -2691,7 +2691,7 @@ fix_small_capacity(struct sched_domain *sd, struct sched_group *group)
26912691
/*
26922692
* If ~90% of the cpu_power is still there, we're good.
26932693
*/
2694-
if (group->cpu_power * 32 > group->cpu_power_orig * 29)
2694+
if (group->sgp->power * 32 > group->sgp->power_orig * 29)
26952695
return 1;
26962696

26972697
return 0;
@@ -2771,7 +2771,7 @@ static inline void update_sg_lb_stats(struct sched_domain *sd,
27712771
}
27722772

27732773
/* Adjust by relative CPU power of the group */
2774-
sgs->avg_load = (sgs->group_load*SCHED_POWER_SCALE) / group->cpu_power;
2774+
sgs->avg_load = (sgs->group_load*SCHED_POWER_SCALE) / group->sgp->power;
27752775

27762776
/*
27772777
* Consider the group unbalanced when the imbalance is larger
@@ -2788,7 +2788,7 @@ static inline void update_sg_lb_stats(struct sched_domain *sd,
27882788
if ((max_cpu_load - min_cpu_load) >= avg_load_per_task && max_nr_running > 1)
27892789
sgs->group_imb = 1;
27902790

2791-
sgs->group_capacity = DIV_ROUND_CLOSEST(group->cpu_power,
2791+
sgs->group_capacity = DIV_ROUND_CLOSEST(group->sgp->power,
27922792
SCHED_POWER_SCALE);
27932793
if (!sgs->group_capacity)
27942794
sgs->group_capacity = fix_small_capacity(sd, group);
@@ -2877,7 +2877,7 @@ static inline void update_sd_lb_stats(struct sched_domain *sd, int this_cpu,
28772877
return;
28782878

28792879
sds->total_load += sgs.group_load;
2880-
sds->total_pwr += sg->cpu_power;
2880+
sds->total_pwr += sg->sgp->power;
28812881

28822882
/*
28832883
* In case the child domain prefers tasks go to siblings
@@ -2962,7 +2962,7 @@ static int check_asym_packing(struct sched_domain *sd,
29622962
if (this_cpu > busiest_cpu)
29632963
return 0;
29642964

2965-
*imbalance = DIV_ROUND_CLOSEST(sds->max_load * sds->busiest->cpu_power,
2965+
*imbalance = DIV_ROUND_CLOSEST(sds->max_load * sds->busiest->sgp->power,
29662966
SCHED_POWER_SCALE);
29672967
return 1;
29682968
}
@@ -2993,7 +2993,7 @@ static inline void fix_small_imbalance(struct sd_lb_stats *sds,
29932993

29942994
scaled_busy_load_per_task = sds->busiest_load_per_task
29952995
* SCHED_POWER_SCALE;
2996-
scaled_busy_load_per_task /= sds->busiest->cpu_power;
2996+
scaled_busy_load_per_task /= sds->busiest->sgp->power;
29972997

29982998
if (sds->max_load - sds->this_load + scaled_busy_load_per_task >=
29992999
(scaled_busy_load_per_task * imbn)) {
@@ -3007,28 +3007,28 @@ static inline void fix_small_imbalance(struct sd_lb_stats *sds,
30073007
* moving them.
30083008
*/
30093009

3010-
pwr_now += sds->busiest->cpu_power *
3010+
pwr_now += sds->busiest->sgp->power *
30113011
min(sds->busiest_load_per_task, sds->max_load);
3012-
pwr_now += sds->this->cpu_power *
3012+
pwr_now += sds->this->sgp->power *
30133013
min(sds->this_load_per_task, sds->this_load);
30143014
pwr_now /= SCHED_POWER_SCALE;
30153015

30163016
/* Amount of load we'd subtract */
30173017
tmp = (sds->busiest_load_per_task * SCHED_POWER_SCALE) /
3018-
sds->busiest->cpu_power;
3018+
sds->busiest->sgp->power;
30193019
if (sds->max_load > tmp)
3020-
pwr_move += sds->busiest->cpu_power *
3020+
pwr_move += sds->busiest->sgp->power *
30213021
min(sds->busiest_load_per_task, sds->max_load - tmp);
30223022

30233023
/* Amount of load we'd add */
3024-
if (sds->max_load * sds->busiest->cpu_power <
3024+
if (sds->max_load * sds->busiest->sgp->power <
30253025
sds->busiest_load_per_task * SCHED_POWER_SCALE)
3026-
tmp = (sds->max_load * sds->busiest->cpu_power) /
3027-
sds->this->cpu_power;
3026+
tmp = (sds->max_load * sds->busiest->sgp->power) /
3027+
sds->this->sgp->power;
30283028
else
30293029
tmp = (sds->busiest_load_per_task * SCHED_POWER_SCALE) /
3030-
sds->this->cpu_power;
3031-
pwr_move += sds->this->cpu_power *
3030+
sds->this->sgp->power;
3031+
pwr_move += sds->this->sgp->power *
30323032
min(sds->this_load_per_task, sds->this_load + tmp);
30333033
pwr_move /= SCHED_POWER_SCALE;
30343034

@@ -3074,7 +3074,7 @@ static inline void calculate_imbalance(struct sd_lb_stats *sds, int this_cpu,
30743074

30753075
load_above_capacity *= (SCHED_LOAD_SCALE * SCHED_POWER_SCALE);
30763076

3077-
load_above_capacity /= sds->busiest->cpu_power;
3077+
load_above_capacity /= sds->busiest->sgp->power;
30783078
}
30793079

30803080
/*
@@ -3090,8 +3090,8 @@ static inline void calculate_imbalance(struct sd_lb_stats *sds, int this_cpu,
30903090
max_pull = min(sds->max_load - sds->avg_load, load_above_capacity);
30913091

30923092
/* How much load to actually move to equalise the imbalance */
3093-
*imbalance = min(max_pull * sds->busiest->cpu_power,
3094-
(sds->avg_load - sds->this_load) * sds->this->cpu_power)
3093+
*imbalance = min(max_pull * sds->busiest->sgp->power,
3094+
(sds->avg_load - sds->this_load) * sds->this->sgp->power)
30953095
/ SCHED_POWER_SCALE;
30963096

30973097
/*

0 commit comments

Comments
 (0)