Skip to content

Commit 1399fa7

Browse files
Nikhil RaoIngo Molnar
authored andcommitted
sched: Introduce SCHED_POWER_SCALE to scale cpu_power calculations
SCHED_LOAD_SCALE is used to increase nice resolution and to scale cpu_power calculations in the scheduler. This patch introduces SCHED_POWER_SCALE and converts all uses of SCHED_LOAD_SCALE for scaling cpu_power to use SCHED_POWER_SCALE instead. This is a preparatory patch for increasing the resolution of SCHED_LOAD_SCALE, and there is no need to increase resolution for cpu_power calculations. Signed-off-by: Nikhil Rao <ncrao@google.com> Acked-by: Peter Zijlstra <peterz@infradead.org> Cc: Nikunj A. Dadhania <nikunj@linux.vnet.ibm.com> Cc: Srivatsa Vaddagiri <vatsa@linux.vnet.ibm.com> Cc: Stephan Barwolf <stephan.baerwolf@tu-ilmenau.de> Cc: Mike Galbraith <efault@gmx.de> Link: http://lkml.kernel.org/r/1305738580-9924-3-git-send-email-ncrao@google.com Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent f05998d commit 1399fa7

3 files changed

Lines changed: 37 additions & 32 deletions

File tree

‎include/linux/sched.h‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -787,18 +787,21 @@ enum cpu_idle_type {
787787
CPU_MAX_IDLE_TYPES
788788
};
789789

790-
/*
791-
* sched-domains (multiprocessor balancing) declarations:
792-
*/
793-
794790
/*
795791
* Increase resolution of nice-level calculations:
796792
*/
797793
#define SCHED_LOAD_SHIFT 10
798794
#define SCHED_LOAD_SCALE (1L << SCHED_LOAD_SHIFT)
799795

800-
#define SCHED_LOAD_SCALE_FUZZ SCHED_LOAD_SCALE
796+
/*
797+
* Increase resolution of cpu_power calculations
798+
*/
799+
#define SCHED_POWER_SHIFT 10
800+
#define SCHED_POWER_SCALE (1L << SCHED_POWER_SHIFT)
801801

802+
/*
803+
* sched-domains (multiprocessor balancing) declarations:
804+
*/
802805
#ifdef CONFIG_SMP
803806
#define SD_LOAD_BALANCE 0x0001 /* Do load balancing on this domain. */
804807
#define SD_BALANCE_NEWIDLE 0x0002 /* Balance when about to become idle */

‎kernel/sched.c‎

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

65326532
printk(KERN_CONT " %s", str);
6533-
if (group->cpu_power != SCHED_LOAD_SCALE) {
6533+
if (group->cpu_power != SCHED_POWER_SCALE) {
65346534
printk(KERN_CONT " (cpu_power = %d)",
65356535
group->cpu_power);
65366536
}
@@ -7905,7 +7905,7 @@ void __init sched_init(void)
79057905
#ifdef CONFIG_SMP
79067906
rq->sd = NULL;
79077907
rq->rd = NULL;
7908-
rq->cpu_power = SCHED_LOAD_SCALE;
7908+
rq->cpu_power = SCHED_POWER_SCALE;
79097909
rq->post_schedule = 0;
79107910
rq->active_balance = 0;
79117911
rq->next_balance = jiffies;

‎kernel/sched_fair.c‎

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,7 +1584,7 @@ find_idlest_group(struct sched_domain *sd, struct task_struct *p,
15841584
}
15851585

15861586
/* Adjust by relative CPU power of the group */
1587-
avg_load = (avg_load * SCHED_LOAD_SCALE) / group->cpu_power;
1587+
avg_load = (avg_load * SCHED_POWER_SCALE) / group->cpu_power;
15881588

15891589
if (local_group) {
15901590
this_load = avg_load;
@@ -1722,7 +1722,7 @@ select_task_rq_fair(struct task_struct *p, int sd_flag, int wake_flags)
17221722
nr_running += cpu_rq(i)->cfs.nr_running;
17231723
}
17241724

1725-
capacity = DIV_ROUND_CLOSEST(power, SCHED_LOAD_SCALE);
1725+
capacity = DIV_ROUND_CLOSEST(power, SCHED_POWER_SCALE);
17261726

17271727
if (tmp->flags & SD_POWERSAVINGS_BALANCE)
17281728
nr_running /= 2;
@@ -2570,7 +2570,7 @@ static inline int check_power_save_busiest_group(struct sd_lb_stats *sds,
25702570

25712571
unsigned long default_scale_freq_power(struct sched_domain *sd, int cpu)
25722572
{
2573-
return SCHED_LOAD_SCALE;
2573+
return SCHED_POWER_SCALE;
25742574
}
25752575

25762576
unsigned long __weak arch_scale_freq_power(struct sched_domain *sd, int cpu)
@@ -2607,18 +2607,18 @@ unsigned long scale_rt_power(int cpu)
26072607
available = total - rq->rt_avg;
26082608
}
26092609

2610-
if (unlikely((s64)total < SCHED_LOAD_SCALE))
2611-
total = SCHED_LOAD_SCALE;
2610+
if (unlikely((s64)total < SCHED_POWER_SCALE))
2611+
total = SCHED_POWER_SCALE;
26122612

2613-
total >>= SCHED_LOAD_SHIFT;
2613+
total >>= SCHED_POWER_SHIFT;
26142614

26152615
return div_u64(available, total);
26162616
}
26172617

26182618
static void update_cpu_power(struct sched_domain *sd, int cpu)
26192619
{
26202620
unsigned long weight = sd->span_weight;
2621-
unsigned long power = SCHED_LOAD_SCALE;
2621+
unsigned long power = SCHED_POWER_SCALE;
26222622
struct sched_group *sdg = sd->groups;
26232623

26242624
if ((sd->flags & SD_SHARE_CPUPOWER) && weight > 1) {
@@ -2627,7 +2627,7 @@ static void update_cpu_power(struct sched_domain *sd, int cpu)
26272627
else
26282628
power *= default_scale_smt_power(sd, cpu);
26292629

2630-
power >>= SCHED_LOAD_SHIFT;
2630+
power >>= SCHED_POWER_SHIFT;
26312631
}
26322632

26332633
sdg->cpu_power_orig = power;
@@ -2637,10 +2637,10 @@ static void update_cpu_power(struct sched_domain *sd, int cpu)
26372637
else
26382638
power *= default_scale_freq_power(sd, cpu);
26392639

2640-
power >>= SCHED_LOAD_SHIFT;
2640+
power >>= SCHED_POWER_SHIFT;
26412641

26422642
power *= scale_rt_power(cpu);
2643-
power >>= SCHED_LOAD_SHIFT;
2643+
power >>= SCHED_POWER_SHIFT;
26442644

26452645
if (!power)
26462646
power = 1;
@@ -2682,7 +2682,7 @@ static inline int
26822682
fix_small_capacity(struct sched_domain *sd, struct sched_group *group)
26832683
{
26842684
/*
2685-
* Only siblings can have significantly less than SCHED_LOAD_SCALE
2685+
* Only siblings can have significantly less than SCHED_POWER_SCALE
26862686
*/
26872687
if (!(sd->flags & SD_SHARE_CPUPOWER))
26882688
return 0;
@@ -2770,7 +2770,7 @@ static inline void update_sg_lb_stats(struct sched_domain *sd,
27702770
}
27712771

27722772
/* Adjust by relative CPU power of the group */
2773-
sgs->avg_load = (sgs->group_load * SCHED_LOAD_SCALE) / group->cpu_power;
2773+
sgs->avg_load = (sgs->group_load*SCHED_POWER_SCALE) / group->cpu_power;
27742774

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

2790-
sgs->group_capacity = DIV_ROUND_CLOSEST(group->cpu_power, SCHED_LOAD_SCALE);
2790+
sgs->group_capacity = DIV_ROUND_CLOSEST(group->cpu_power,
2791+
SCHED_POWER_SCALE);
27912792
if (!sgs->group_capacity)
27922793
sgs->group_capacity = fix_small_capacity(sd, group);
27932794
sgs->group_weight = group->group_weight;
@@ -2961,7 +2962,7 @@ static int check_asym_packing(struct sched_domain *sd,
29612962
return 0;
29622963

29632964
*imbalance = DIV_ROUND_CLOSEST(sds->max_load * sds->busiest->cpu_power,
2964-
SCHED_LOAD_SCALE);
2965+
SCHED_POWER_SCALE);
29652966
return 1;
29662967
}
29672968

@@ -2990,7 +2991,7 @@ static inline void fix_small_imbalance(struct sd_lb_stats *sds,
29902991
cpu_avg_load_per_task(this_cpu);
29912992

29922993
scaled_busy_load_per_task = sds->busiest_load_per_task
2993-
* SCHED_LOAD_SCALE;
2994+
* SCHED_POWER_SCALE;
29942995
scaled_busy_load_per_task /= sds->busiest->cpu_power;
29952996

29962997
if (sds->max_load - sds->this_load + scaled_busy_load_per_task >=
@@ -3009,26 +3010,26 @@ static inline void fix_small_imbalance(struct sd_lb_stats *sds,
30093010
min(sds->busiest_load_per_task, sds->max_load);
30103011
pwr_now += sds->this->cpu_power *
30113012
min(sds->this_load_per_task, sds->this_load);
3012-
pwr_now /= SCHED_LOAD_SCALE;
3013+
pwr_now /= SCHED_POWER_SCALE;
30133014

30143015
/* Amount of load we'd subtract */
3015-
tmp = (sds->busiest_load_per_task * SCHED_LOAD_SCALE) /
3016+
tmp = (sds->busiest_load_per_task * SCHED_POWER_SCALE) /
30163017
sds->busiest->cpu_power;
30173018
if (sds->max_load > tmp)
30183019
pwr_move += sds->busiest->cpu_power *
30193020
min(sds->busiest_load_per_task, sds->max_load - tmp);
30203021

30213022
/* Amount of load we'd add */
30223023
if (sds->max_load * sds->busiest->cpu_power <
3023-
sds->busiest_load_per_task * SCHED_LOAD_SCALE)
3024+
sds->busiest_load_per_task * SCHED_POWER_SCALE)
30243025
tmp = (sds->max_load * sds->busiest->cpu_power) /
30253026
sds->this->cpu_power;
30263027
else
3027-
tmp = (sds->busiest_load_per_task * SCHED_LOAD_SCALE) /
3028+
tmp = (sds->busiest_load_per_task * SCHED_POWER_SCALE) /
30283029
sds->this->cpu_power;
30293030
pwr_move += sds->this->cpu_power *
30303031
min(sds->this_load_per_task, sds->this_load + tmp);
3031-
pwr_move /= SCHED_LOAD_SCALE;
3032+
pwr_move /= SCHED_POWER_SCALE;
30323033

30333034
/* Move if we gain throughput */
30343035
if (pwr_move > pwr_now)
@@ -3070,7 +3071,7 @@ static inline void calculate_imbalance(struct sd_lb_stats *sds, int this_cpu,
30703071
load_above_capacity = (sds->busiest_nr_running -
30713072
sds->busiest_group_capacity);
30723073

3073-
load_above_capacity *= (SCHED_LOAD_SCALE * SCHED_LOAD_SCALE);
3074+
load_above_capacity *= (SCHED_LOAD_SCALE * SCHED_POWER_SCALE);
30743075

30753076
load_above_capacity /= sds->busiest->cpu_power;
30763077
}
@@ -3090,7 +3091,7 @@ static inline void calculate_imbalance(struct sd_lb_stats *sds, int this_cpu,
30903091
/* How much load to actually move to equalise the imbalance */
30913092
*imbalance = min(max_pull * sds->busiest->cpu_power,
30923093
(sds->avg_load - sds->this_load) * sds->this->cpu_power)
3093-
/ SCHED_LOAD_SCALE;
3094+
/ SCHED_POWER_SCALE;
30943095

30953096
/*
30963097
* if *imbalance is less than the average load per runnable task
@@ -3159,7 +3160,7 @@ find_busiest_group(struct sched_domain *sd, int this_cpu,
31593160
if (!sds.busiest || sds.busiest_nr_running == 0)
31603161
goto out_balanced;
31613162

3162-
sds.avg_load = (SCHED_LOAD_SCALE * sds.total_load) / sds.total_pwr;
3163+
sds.avg_load = (SCHED_POWER_SCALE * sds.total_load) / sds.total_pwr;
31633164

31643165
/*
31653166
* If the busiest group is imbalanced the below checks don't
@@ -3238,7 +3239,8 @@ find_busiest_queue(struct sched_domain *sd, struct sched_group *group,
32383239

32393240
for_each_cpu(i, sched_group_cpus(group)) {
32403241
unsigned long power = power_of(i);
3241-
unsigned long capacity = DIV_ROUND_CLOSEST(power, SCHED_LOAD_SCALE);
3242+
unsigned long capacity = DIV_ROUND_CLOSEST(power,
3243+
SCHED_POWER_SCALE);
32423244
unsigned long wl;
32433245

32443246
if (!capacity)
@@ -3263,7 +3265,7 @@ find_busiest_queue(struct sched_domain *sd, struct sched_group *group,
32633265
* the load can be moved away from the cpu that is potentially
32643266
* running at a lower capacity.
32653267
*/
3266-
wl = (wl * SCHED_LOAD_SCALE) / power;
3268+
wl = (wl * SCHED_POWER_SCALE) / power;
32673269

32683270
if (wl > max_load) {
32693271
max_load = wl;

0 commit comments

Comments
 (0)