diff options
author | Peter Zijlstra <a.p.zijlstra@chello.nl> | 2010-04-16 08:59:29 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2010-04-23 05:02:02 -0400 |
commit | 669c55e9f99b90e46eaa0f98a67ec53d46dc969a (patch) | |
tree | 9f60bcf779e5ec786c05b8053b59e091edcb418c | |
parent | 74f5187ac873042f502227701ed1727e7c5fbfa9 (diff) |
sched: Pre-compute cpumask_weight(sched_domain_span(sd))
Dave reported that his large SPARC machines spend lots of time in
hweight64(), try and optimize some of those needless cpumask_weight()
invocations (esp. with the large offstack cpumasks these are very
expensive indeed).
Reported-by: David Miller <davem@davemloft.net>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <new-submission>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r-- | include/linux/sched.h | 1 | ||||
-rw-r--r-- | kernel/sched.c | 3 | ||||
-rw-r--r-- | kernel/sched_fair.c | 12 |
3 files changed, 9 insertions, 7 deletions
diff --git a/include/linux/sched.h b/include/linux/sched.h index e3e900f318d7..dfea40574b2a 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h | |||
@@ -960,6 +960,7 @@ struct sched_domain { | |||
960 | char *name; | 960 | char *name; |
961 | #endif | 961 | #endif |
962 | 962 | ||
963 | unsigned int span_weight; | ||
963 | /* | 964 | /* |
964 | * Span of all CPUs in this domain. | 965 | * Span of all CPUs in this domain. |
965 | * | 966 | * |
diff --git a/kernel/sched.c b/kernel/sched.c index 0cc913a8554f..4956ed092838 100644 --- a/kernel/sched.c +++ b/kernel/sched.c | |||
@@ -6271,6 +6271,9 @@ cpu_attach_domain(struct sched_domain *sd, struct root_domain *rd, int cpu) | |||
6271 | struct rq *rq = cpu_rq(cpu); | 6271 | struct rq *rq = cpu_rq(cpu); |
6272 | struct sched_domain *tmp; | 6272 | struct sched_domain *tmp; |
6273 | 6273 | ||
6274 | for (tmp = sd; tmp; tmp = tmp->parent) | ||
6275 | tmp->span_weight = cpumask_weight(sched_domain_span(tmp)); | ||
6276 | |||
6274 | /* Remove the sched domains which do not contribute to scheduling. */ | 6277 | /* Remove the sched domains which do not contribute to scheduling. */ |
6275 | for (tmp = sd; tmp; ) { | 6278 | for (tmp = sd; tmp; ) { |
6276 | struct sched_domain *parent = tmp->parent; | 6279 | struct sched_domain *parent = tmp->parent; |
diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c index 88d3053ac7c2..0a413c7e3ab8 100644 --- a/kernel/sched_fair.c +++ b/kernel/sched_fair.c | |||
@@ -1508,9 +1508,7 @@ select_task_rq_fair(struct rq *rq, struct task_struct *p, int sd_flag, int wake_ | |||
1508 | * Pick the largest domain to update shares over | 1508 | * Pick the largest domain to update shares over |
1509 | */ | 1509 | */ |
1510 | tmp = sd; | 1510 | tmp = sd; |
1511 | if (affine_sd && (!tmp || | 1511 | if (affine_sd && (!tmp || affine_sd->span_weight > sd->span_weight)) |
1512 | cpumask_weight(sched_domain_span(affine_sd)) > | ||
1513 | cpumask_weight(sched_domain_span(sd)))) | ||
1514 | tmp = affine_sd; | 1512 | tmp = affine_sd; |
1515 | 1513 | ||
1516 | if (tmp) { | 1514 | if (tmp) { |
@@ -1554,10 +1552,10 @@ select_task_rq_fair(struct rq *rq, struct task_struct *p, int sd_flag, int wake_ | |||
1554 | 1552 | ||
1555 | /* Now try balancing at a lower domain level of new_cpu */ | 1553 | /* Now try balancing at a lower domain level of new_cpu */ |
1556 | cpu = new_cpu; | 1554 | cpu = new_cpu; |
1557 | weight = cpumask_weight(sched_domain_span(sd)); | 1555 | weight = sd->span_weight; |
1558 | sd = NULL; | 1556 | sd = NULL; |
1559 | for_each_domain(cpu, tmp) { | 1557 | for_each_domain(cpu, tmp) { |
1560 | if (weight <= cpumask_weight(sched_domain_span(tmp))) | 1558 | if (weight <= tmp->span_weight) |
1561 | break; | 1559 | break; |
1562 | if (tmp->flags & sd_flag) | 1560 | if (tmp->flags & sd_flag) |
1563 | sd = tmp; | 1561 | sd = tmp; |
@@ -2243,7 +2241,7 @@ unsigned long __weak arch_scale_freq_power(struct sched_domain *sd, int cpu) | |||
2243 | 2241 | ||
2244 | unsigned long default_scale_smt_power(struct sched_domain *sd, int cpu) | 2242 | unsigned long default_scale_smt_power(struct sched_domain *sd, int cpu) |
2245 | { | 2243 | { |
2246 | unsigned long weight = cpumask_weight(sched_domain_span(sd)); | 2244 | unsigned long weight = sd->span_weight; |
2247 | unsigned long smt_gain = sd->smt_gain; | 2245 | unsigned long smt_gain = sd->smt_gain; |
2248 | 2246 | ||
2249 | smt_gain /= weight; | 2247 | smt_gain /= weight; |
@@ -2276,7 +2274,7 @@ unsigned long scale_rt_power(int cpu) | |||
2276 | 2274 | ||
2277 | static void update_cpu_power(struct sched_domain *sd, int cpu) | 2275 | static void update_cpu_power(struct sched_domain *sd, int cpu) |
2278 | { | 2276 | { |
2279 | unsigned long weight = cpumask_weight(sched_domain_span(sd)); | 2277 | unsigned long weight = sd->span_weight; |
2280 | unsigned long power = SCHED_LOAD_SCALE; | 2278 | unsigned long power = SCHED_LOAD_SCALE; |
2281 | struct sched_group *sdg = sd->groups; | 2279 | struct sched_group *sdg = sd->groups; |
2282 | 2280 | ||