Skip to content

Commit 15a3d11

Browse files
committed
Merge branch 'sched-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip
* 'sched-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: sched: Increase SCHED_LOAD_SCALE resolution sched: Introduce SCHED_POWER_SCALE to scale cpu_power calculations sched: Cleanup set_load_weight()
2 parents 1f3a8e0 + c8b2811 commit 15a3d11

3 files changed

Lines changed: 82 additions & 43 deletions

File tree

‎include/linux/sched.h‎

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -786,17 +786,39 @@ enum cpu_idle_type {
786786
};
787787

788788
/*
789-
* sched-domains (multiprocessor balancing) declarations:
789+
* Increase resolution of nice-level calculations for 64-bit architectures.
790+
* The extra resolution improves shares distribution and load balancing of
791+
* low-weight task groups (eg. nice +19 on an autogroup), deeper taskgroup
792+
* hierarchies, especially on larger systems. This is not a user-visible change
793+
* and does not change the user-interface for setting shares/weights.
794+
*
795+
* We increase resolution only if we have enough bits to allow this increased
796+
* resolution (i.e. BITS_PER_LONG > 32). The costs for increasing resolution
797+
* when BITS_PER_LONG <= 32 are pretty high and the returns do not justify the
798+
* increased costs.
790799
*/
800+
#if BITS_PER_LONG > 32
801+
# define SCHED_LOAD_RESOLUTION 10
802+
# define scale_load(w) ((w) << SCHED_LOAD_RESOLUTION)
803+
# define scale_load_down(w) ((w) >> SCHED_LOAD_RESOLUTION)
804+
#else
805+
# define SCHED_LOAD_RESOLUTION 0
806+
# define scale_load(w) (w)
807+
# define scale_load_down(w) (w)
808+
#endif
791809

792-
/*
793-
* Increase resolution of nice-level calculations:
794-
*/
795-
#define SCHED_LOAD_SHIFT 10
810+
#define SCHED_LOAD_SHIFT (10 + SCHED_LOAD_RESOLUTION)
796811
#define SCHED_LOAD_SCALE (1L << SCHED_LOAD_SHIFT)
797812

798-
#define SCHED_LOAD_SCALE_FUZZ SCHED_LOAD_SCALE
813+
/*
814+
* Increase resolution of cpu_power calculations
815+
*/
816+
#define SCHED_POWER_SHIFT 10
817+
#define SCHED_POWER_SCALE (1L << SCHED_POWER_SHIFT)
799818

819+
/*
820+
* sched-domains (multiprocessor balancing) declarations:
821+
*/
800822
#ifdef CONFIG_SMP
801823
#define SD_LOAD_BALANCE 0x0001 /* Do load balancing on this domain. */
802824
#define SD_BALANCE_NEWIDLE 0x0002 /* Balance when about to become idle */

‎kernel/sched.c‎

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ static DEFINE_SPINLOCK(task_group_lock);
293293
* limitation from this.)
294294
*/
295295
#define MIN_SHARES 2
296-
#define MAX_SHARES (1UL << 18)
296+
#define MAX_SHARES (1UL << (18 + SCHED_LOAD_RESOLUTION))
297297

298298
static int root_task_group_load = ROOT_TASK_GROUP_LOAD;
299299
#endif
@@ -1330,13 +1330,25 @@ calc_delta_mine(unsigned long delta_exec, unsigned long weight,
13301330
{
13311331
u64 tmp;
13321332

1333-
tmp = (u64)delta_exec * weight;
1333+
/*
1334+
* weight can be less than 2^SCHED_LOAD_RESOLUTION for task group sched
1335+
* entities since MIN_SHARES = 2. Treat weight as 1 if less than
1336+
* 2^SCHED_LOAD_RESOLUTION.
1337+
*/
1338+
if (likely(weight > (1UL << SCHED_LOAD_RESOLUTION)))
1339+
tmp = (u64)delta_exec * scale_load_down(weight);
1340+
else
1341+
tmp = (u64)delta_exec;
13341342

13351343
if (!lw->inv_weight) {
1336-
if (BITS_PER_LONG > 32 && unlikely(lw->weight >= WMULT_CONST))
1344+
unsigned long w = scale_load_down(lw->weight);
1345+
1346+
if (BITS_PER_LONG > 32 && unlikely(w >= WMULT_CONST))
13371347
lw->inv_weight = 1;
1348+
else if (unlikely(!w))
1349+
lw->inv_weight = WMULT_CONST;
13381350
else
1339-
lw->inv_weight = WMULT_CONST / lw->weight;
1351+
lw->inv_weight = WMULT_CONST / w;
13401352
}
13411353

13421354
/*
@@ -1778,17 +1790,20 @@ static void dec_nr_running(struct rq *rq)
17781790

17791791
static void set_load_weight(struct task_struct *p)
17801792
{
1793+
int prio = p->static_prio - MAX_RT_PRIO;
1794+
struct load_weight *load = &p->se.load;
1795+
17811796
/*
17821797
* SCHED_IDLE tasks get minimal weight:
17831798
*/
17841799
if (p->policy == SCHED_IDLE) {
1785-
p->se.load.weight = WEIGHT_IDLEPRIO;
1786-
p->se.load.inv_weight = WMULT_IDLEPRIO;
1800+
load->weight = scale_load(WEIGHT_IDLEPRIO);
1801+
load->inv_weight = WMULT_IDLEPRIO;
17871802
return;
17881803
}
17891804

1790-
p->se.load.weight = prio_to_weight[p->static_prio - MAX_RT_PRIO];
1791-
p->se.load.inv_weight = prio_to_wmult[p->static_prio - MAX_RT_PRIO];
1805+
load->weight = scale_load(prio_to_weight[prio]);
1806+
load->inv_weight = prio_to_wmult[prio];
17921807
}
17931808

17941809
static void enqueue_task(struct rq *rq, struct task_struct *p, int flags)
@@ -6527,7 +6542,7 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level,
65276542
cpulist_scnprintf(str, sizeof(str), sched_group_cpus(group));
65286543

65296544
printk(KERN_CONT " %s", str);
6530-
if (group->cpu_power != SCHED_LOAD_SCALE) {
6545+
if (group->cpu_power != SCHED_POWER_SCALE) {
65316546
printk(KERN_CONT " (cpu_power = %d)",
65326547
group->cpu_power);
65336548
}
@@ -7902,7 +7917,7 @@ void __init sched_init(void)
79027917
#ifdef CONFIG_SMP
79037918
rq->sd = NULL;
79047919
rq->rd = NULL;
7905-
rq->cpu_power = SCHED_LOAD_SCALE;
7920+
rq->cpu_power = SCHED_POWER_SCALE;
79067921
rq->post_schedule = 0;
79077922
rq->active_balance = 0;
79087923
rq->next_balance = jiffies;
@@ -8806,14 +8821,14 @@ cpu_cgroup_exit(struct cgroup_subsys *ss, struct cgroup *cgrp,
88068821
static int cpu_shares_write_u64(struct cgroup *cgrp, struct cftype *cftype,
88078822
u64 shareval)
88088823
{
8809-
return sched_group_set_shares(cgroup_tg(cgrp), shareval);
8824+
return sched_group_set_shares(cgroup_tg(cgrp), scale_load(shareval));
88108825
}
88118826

88128827
static u64 cpu_shares_read_u64(struct cgroup *cgrp, struct cftype *cft)
88138828
{
88148829
struct task_group *tg = cgroup_tg(cgrp);
88158830

8816-
return (u64) tg->shares;
8831+
return (u64) scale_load_down(tg->shares);
88178832
}
88188833
#endif /* CONFIG_FAIR_GROUP_SCHED */
88198834

‎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)