2009-09-01 08:53:27

by Peter Zijlstra

[permalink] [raw]
Subject: [RFC][PATCH 5/8] sched: dynamic cpu_power

Recompute the cpu_power for each cpu during load-balance

Signed-off-by: Peter Zijlstra <[email protected]>
---
kernel/sched.c | 38 +++++++++++++++++++++++++++++++++++---
1 file changed, 35 insertions(+), 3 deletions(-)

Index: linux-2.6/kernel/sched.c
===================================================================
--- linux-2.6.orig/kernel/sched.c
+++ linux-2.6/kernel/sched.c
@@ -3691,14 +3691,46 @@ static inline int check_power_save_busie
}
#endif /* CONFIG_SCHED_MC || CONFIG_SCHED_SMT */

-static void update_sched_power(struct sched_domain *sd)
+unsigned long __weak arch_smt_gain(struct sched_domain *sd, int cpu)
+{
+ unsigned long weight = cpumask_weight(sched_domain_span(sd));
+ unsigned long smt_gain = sd->smt_gain;
+
+ smt_gain /= weight;
+
+ return smt_gain;
+}
+
+static void update_cpu_power(struct sched_domain *sd, int cpu)
+{
+ unsigned long weight = cpumask_weight(sched_domain_span(sd));
+ unsigned long power = SCHED_LOAD_SCALE;
+ struct sched_group *sdg = sd->groups;
+ unsigned long old = sdg->__cpu_power;
+
+ /* here we could scale based on cpufreq */
+
+ if ((sd->flags & SD_SHARE_CPUPOWER) && weight > 1) {
+ power *= arch_smt_gain(sd, cpu);
+ power >>= SCHED_LOAD_SHIFT;
+ }
+
+ /* here we could scale based on RT time */
+
+ if (power != old) {
+ sdg->__cpu_power = power;
+ sdg->reciprocal_cpu_power = reciprocal_value(power);
+ }
+}
+
+static void update_group_power(struct sched_domain *sd, int cpu)
{
struct sched_domain *child = sd->child;
struct sched_group *group, *sdg = sd->groups;
unsigned long power = sdg->__cpu_power;

if (!child) {
- /* compute cpu power for this cpu */
+ update_cpu_power(sd, cpu);
return;
}

@@ -3743,7 +3775,7 @@ static inline void update_sg_lb_stats(st
if (local_group) {
balance_cpu = group_first_cpu(group);
if (balance_cpu == this_cpu)
- update_sched_power(sd);
+ update_group_power(sd, this_cpu);
}

/* Tally up the load of all CPUs in the group */

--


Subject: Re: [RFC][PATCH 5/8] sched: dynamic cpu_power

On Tue, Sep 01, 2009 at 10:34:36AM +0200, Peter Zijlstra wrote:
> Recompute the cpu_power for each cpu during load-balance

This patch rocks! Atleast in theory, it does :-)

>
> Signed-off-by: Peter Zijlstra <[email protected]>
> ---
> kernel/sched.c | 38 +++++++++++++++++++++++++++++++++++---
> 1 file changed, 35 insertions(+), 3 deletions(-)
>
> Index: linux-2.6/kernel/sched.c
> ===================================================================
> --- linux-2.6.orig/kernel/sched.c
> +++ linux-2.6/kernel/sched.c
> @@ -3691,14 +3691,46 @@ static inline int check_power_save_busie
> }
> #endif /* CONFIG_SCHED_MC || CONFIG_SCHED_SMT */
>
> -static void update_sched_power(struct sched_domain *sd)
> +unsigned long __weak arch_smt_gain(struct sched_domain *sd, int cpu)
> +{
> + unsigned long weight = cpumask_weight(sched_domain_span(sd));
> + unsigned long smt_gain = sd->smt_gain;
> +
> + smt_gain /= weight;
> +
> + return smt_gain;
> +}
> +
> +static void update_cpu_power(struct sched_domain *sd, int cpu)
> +{
> + unsigned long weight = cpumask_weight(sched_domain_span(sd));
> + unsigned long power = SCHED_LOAD_SCALE;
> + struct sched_group *sdg = sd->groups;
> + unsigned long old = sdg->__cpu_power;
> +
> + /* here we could scale based on cpufreq */
> +
> + if ((sd->flags & SD_SHARE_CPUPOWER) && weight > 1) {
> + power *= arch_smt_gain(sd, cpu);
> + power >>= SCHED_LOAD_SHIFT;
> + }
> +
> + /* here we could scale based on RT time */
> +
> + if (power != old) {
> + sdg->__cpu_power = power;
> + sdg->reciprocal_cpu_power = reciprocal_value(power);
> + }
> +}
> +
> +static void update_group_power(struct sched_domain *sd, int cpu)
> {
> struct sched_domain *child = sd->child;
> struct sched_group *group, *sdg = sd->groups;
> unsigned long power = sdg->__cpu_power;
>
> if (!child) {
> - /* compute cpu power for this cpu */
> + update_cpu_power(sd, cpu);
> return;
> }
>
> @@ -3743,7 +3775,7 @@ static inline void update_sg_lb_stats(st
> if (local_group) {
> balance_cpu = group_first_cpu(group);
> if (balance_cpu == this_cpu)
> - update_sched_power(sd);
> + update_group_power(sd, this_cpu);
> }
>
> /* Tally up the load of all CPUs in the group */
>
> --

--
Thanks and Regards
gautham

2009-09-04 08:56:28

by Peter Zijlstra

[permalink] [raw]
Subject: [tip:sched/balancing] sched: Implement dynamic cpu_power

Commit-ID: ab29230e673c646292c90c8b9d378b9562145af0
Gitweb: http://git.kernel.org/tip/ab29230e673c646292c90c8b9d378b9562145af0
Author: Peter Zijlstra <[email protected]>
AuthorDate: Tue, 1 Sep 2009 10:34:36 +0200
Committer: Ingo Molnar <[email protected]>
CommitDate: Fri, 4 Sep 2009 10:09:54 +0200

sched: Implement dynamic cpu_power

Recompute the cpu_power for each cpu during load-balance.

Signed-off-by: Peter Zijlstra <[email protected]>
Tested-by: Andreas Herrmann <[email protected]>
Acked-by: Andreas Herrmann <[email protected]>
Acked-by: Gautham R Shenoy <[email protected]>
Cc: Balbir Singh <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>


---
kernel/sched.c | 38 +++++++++++++++++++++++++++++++++++---
1 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/kernel/sched.c b/kernel/sched.c
index 5511226..036600f 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -3699,14 +3699,46 @@ static inline int check_power_save_busiest_group(struct sd_lb_stats *sds,
}
#endif /* CONFIG_SCHED_MC || CONFIG_SCHED_SMT */

-static void update_sched_power(struct sched_domain *sd)
+unsigned long __weak arch_smt_gain(struct sched_domain *sd, int cpu)
+{
+ unsigned long weight = cpumask_weight(sched_domain_span(sd));
+ unsigned long smt_gain = sd->smt_gain;
+
+ smt_gain /= weight;
+
+ return smt_gain;
+}
+
+static void update_cpu_power(struct sched_domain *sd, int cpu)
+{
+ unsigned long weight = cpumask_weight(sched_domain_span(sd));
+ unsigned long power = SCHED_LOAD_SCALE;
+ struct sched_group *sdg = sd->groups;
+ unsigned long old = sdg->__cpu_power;
+
+ /* here we could scale based on cpufreq */
+
+ if ((sd->flags & SD_SHARE_CPUPOWER) && weight > 1) {
+ power *= arch_smt_gain(sd, cpu);
+ power >>= SCHED_LOAD_SHIFT;
+ }
+
+ /* here we could scale based on RT time */
+
+ if (power != old) {
+ sdg->__cpu_power = power;
+ sdg->reciprocal_cpu_power = reciprocal_value(power);
+ }
+}
+
+static void update_group_power(struct sched_domain *sd, int cpu)
{
struct sched_domain *child = sd->child;
struct sched_group *group, *sdg = sd->groups;
unsigned long power = sdg->__cpu_power;

if (!child) {
- /* compute cpu power for this cpu */
+ update_cpu_power(sd, cpu);
return;
}

@@ -3749,7 +3781,7 @@ static inline void update_sg_lb_stats(struct sched_domain *sd,
if (local_group) {
balance_cpu = group_first_cpu(group);
if (balance_cpu == this_cpu)
- update_sched_power(sd);
+ update_group_power(sd, this_cpu);
}

/* Tally up the load of all CPUs in the group */