[RFC PATCH v2 3/5] sched: collect statistics required for powersavebalance

From: Vaidyanathan Srinivasan
Date: Thu Oct 09 2008 - 08:06:26 EST


Update sched domain level statistics with the minimum load and
group leader who can pull more tasks. Also suggest a powersave
movement if the domain is otherwise balanced.

Signed-off-by: Vaidyanathan Srinivasan <svaidy@xxxxxxxxxxxxxxxxxx>
---

kernel/sched.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 96 insertions(+), 0 deletions(-)

diff --git a/kernel/sched.c b/kernel/sched.c
index cfd83d9..c99b5bd 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -3229,6 +3229,102 @@ void update_sd_loads(struct sd_loads *sdl, struct group_loads *gl)
}
}

+#if defined(CONFIG_SCHED_MC) || defined(CONFIG_SCHED_SMT)
+void update_powersavings_group_loads(struct sd_loads *sdl,
+ struct group_loads *gl,
+ enum cpu_idle_type idle)
+{
+ int group_capacity = gl->group->__cpu_power / SCHED_LOAD_SCALE;
+
+ /*
+ * Busy processors will not participate in power savings
+ * balance.
+ */
+ if (idle == CPU_NOT_IDLE ||
+ !(sdl->sd->flags & SD_POWERSAVINGS_BALANCE))
+ return;
+
+ /*
+ * If the this group is idle or completely loaded, then there
+ * is no opportunity to do power savings balance with this group
+ */
+ if (gl->nr_running >= group_capacity || gl->nr_running == 0)
+ return;
+
+ /*
+ * Calculate the group which has the least non-idle load.
+ * This is the group from where we need to pick up the load
+ * for saving power
+ */
+ if (!sdl->min_load_group.group)
+ sdl->min_load_group = *gl;
+ else {
+ if (gl->nr_running < sdl->min_load_group.nr_running)
+ sdl->min_load_group = *gl;
+ /* If the loads are equal, then prefer the cpu with
+ * less logical number
+ */
+ else if (gl->nr_running == sdl->min_load_group.nr_running &&
+ first_cpu(gl->group->cpumask) <
+ first_cpu(sdl->min_load_group.group->cpumask))
+ sdl->min_load_group = *gl;
+ }
+
+ /*
+ * Calculate the group which is almost near its
+ * capacity but still has some space to pick up some load
+ * from other group and save more power
+ */
+
+ if (gl->nr_running > 0 && gl->nr_running <= group_capacity - 1) {
+ if (!sdl->power_save_leader_group.group)
+ sdl->power_save_leader_group = *gl;
+ else {
+ if (gl->nr_running >
+ sdl->power_save_leader_group.nr_running)
+ sdl->power_save_leader_group = *gl;
+ else if (gl->nr_running ==
+ sdl->power_save_leader_group.nr_running &&
+ first_cpu(gl->group->cpumask) <
+ first_cpu(sdl->min_load_group.group->cpumask))
+ sdl->power_save_leader_group = *gl;
+ }
+ }
+}
+
+static struct sched_group *powersavings_balance_group(struct sd_loads *sdl,
+ struct group_loads *gl, enum cpu_idle_type idle,
+ unsigned long *imbalance)
+{
+ *imbalance = 0;
+ if (idle == CPU_NOT_IDLE || !(sdl->sd->flags & SD_POWERSAVINGS_BALANCE))
+ return NULL;
+
+ if (sdl->local.group == sdl->power_save_leader_group.group &&
+ sdl->power_save_leader_group.group !=
+ sdl->min_load_group.group) {
+ *imbalance = sdl->min_load_group.avg_load_per_task;
+ return sdl->min_load_group.group;
+ }
+
+ return NULL;
+}
+#else
+void update_powersavings_group_loads(struct sd_loads *sdl,
+ struct group_loads *gl, enum cpu_idle_type idle)
+{
+ return;
+}
+
+static struct sched_group *powersavings_balance_group(struct sd_loads *sdl,
+ struct group_loads *gl, enum cpu_idle_type idle,
+ unsigned long *imbalance)
+{
+ *imbalance = 0;
+ return NULL;
+}
+#endif
+
/*
* find_busiest_group finds and returns the busiest CPU group within the
* domain. It calculates and returns the amount of weighted load which

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/