From: Alex Shi <alex.shi@intel.com>
To: mingo@redhat.com, peterz@infradead.org, tglx@linutronix.de,
akpm@linux-foundation.org, arjan@linux.intel.com, bp@alien8.de,
pjt@google.com, namhyung@kernel.org, efault@gmx.de,
morten.rasmussen@arm.com
Cc: vincent.guittot@linaro.org, gregkh@linuxfoundation.org,
preeti@linux.vnet.ibm.com, viresh.kumar@linaro.org,
linux-kernel@vger.kernel.org, alex.shi@intel.com,
len.brown@intel.com, rafael.j.wysocki@intel.com, jkosina@suse.cz,
clark.williams@gmail.com, tony.luck@intel.com,
keescook@chromium.org, mgorman@suse.de, riel@redhat.com
Subject: [patch v7 18/21] sched: power aware load balance
Date: Thu, 4 Apr 2013 10:00:59 +0800 [thread overview]
Message-ID: <1365040862-8390-19-git-send-email-alex.shi@intel.com> (raw)
In-Reply-To: <1365040862-8390-1-git-send-email-alex.shi@intel.com>
This patch enabled the power aware consideration in load balance.
As mentioned in the power aware scheduler proposal, Power aware
scheduling has 2 assumptions:
1, race to idle is helpful for power saving
2, less active sched_groups will reduce power consumption
The first assumption make performance policy take over scheduling when
any scheduler group is busy.
The second assumption make power aware scheduling try to pack disperse
tasks into fewer groups.
The enabling logical summary here:
1, Collect power aware scheduler statistics during performance load
balance statistics collection.
2, If the balance cpu is eligible for power load balance, just do it
and forget performance load balance. If the domain is suitable for
power balance, but the cpu is inappropriate(idle or full), stop both
power/performance balance in this domain.
3, If using performance balance policy or using power balance but any
group is busy, do performance balance.
Above logical is mainly implemented in update_sd_lb_power_stats(). It
decides if a domain is suitable for power aware scheduling. If so,
it will fill the dst group and source group accordingly.
This patch reused some of Suresh's power saving load balance code.
Signed-off-by: Alex Shi <alex.shi@intel.com>
---
kernel/sched/fair.c | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 118 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 9326c22..0682472 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -18,6 +18,9 @@
*
* Adaptive scheduling granularity, math enhancements by Peter Zijlstra
* Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra <pzijlstr@redhat.com>
+ *
+ * Powersaving balance policy added by Alex Shi
+ * Copyright (C) 2013 Intel, Alex Shi <alex.shi@intel.com>
*/
#include <linux/latencytop.h>
@@ -4398,6 +4401,101 @@ static unsigned long task_h_load(struct task_struct *p)
/********** Helpers for find_busiest_group ************************/
/**
+ * init_sd_lb_power_stats - Initialize power savings statistics for
+ * the given sched_domain, during load balancing.
+ *
+ * @env: The load balancing environment.
+ * @sds: Variable containing the statistics for sd.
+ */
+static inline void init_sd_lb_power_stats(struct lb_env *env,
+ struct sd_lb_stats *sds)
+{
+ if (sched_balance_policy == SCHED_POLICY_PERFORMANCE ||
+ env->idle == CPU_NOT_IDLE) {
+ env->flags &= ~LBF_POWER_BAL;
+ env->flags |= LBF_PERF_BAL;
+ return;
+ }
+ env->flags &= ~LBF_PERF_BAL;
+ env->flags |= LBF_POWER_BAL;
+ sds->min_util = UINT_MAX;
+ sds->leader_util = 0;
+}
+
+/**
+ * update_sd_lb_power_stats - Update the power saving stats for a
+ * sched_domain while performing load balancing.
+ *
+ * @env: The load balancing environment.
+ * @group: sched_group belonging to the sched_domain under consideration.
+ * @sds: Variable containing the statistics of the sched_domain
+ * @local_group: Does group contain the CPU for which we're performing
+ * load balancing?
+ * @sgs: Variable containing the statistics of the group.
+ */
+static inline void update_sd_lb_power_stats(struct lb_env *env,
+ struct sched_group *group, struct sd_lb_stats *sds,
+ int local_group, struct sg_lb_stats *sgs)
+{
+ unsigned long threshold_util;
+
+ if (env->flags & LBF_PERF_BAL)
+ return;
+
+ threshold_util = sgs->group_weight * FULL_UTIL;
+
+ /*
+ * If the local group is idle or full loaded
+ * no need to do power savings balance at this domain
+ */
+ if (local_group && (!sgs->sum_nr_running ||
+ sgs->group_util + FULL_UTIL > threshold_util))
+ env->flags &= ~LBF_POWER_BAL;
+
+ /* Do performance load balance if any group overload */
+ if (sgs->group_util > threshold_util) {
+ env->flags |= LBF_PERF_BAL;
+ env->flags &= ~LBF_POWER_BAL;
+ }
+
+ /*
+ * If a group is idle,
+ * don't include that group in power savings calculations
+ */
+ if (!(env->flags & LBF_POWER_BAL) || !sgs->sum_nr_running)
+ 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 ((sgs->group_util < sds->min_util) ||
+ (sgs->group_util == sds->min_util &&
+ group_first_cpu(group) > group_first_cpu(sds->group_min))) {
+ sds->group_min = group;
+ sds->min_util = sgs->group_util;
+ sds->min_load_per_task = sgs->sum_weighted_load /
+ sgs->sum_nr_running;
+ }
+
+ /*
+ * 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 (sgs->group_util + FULL_UTIL > threshold_util)
+ return;
+
+ if (sgs->group_util > sds->leader_util ||
+ (sgs->group_util == sds->leader_util && sds->group_leader &&
+ group_first_cpu(group) < group_first_cpu(sds->group_leader))) {
+ sds->group_leader = group;
+ sds->leader_util = sgs->group_util;
+ }
+}
+
+/**
* get_sd_load_idx - Obtain the load index for a given sched domain.
* @sd: The sched_domain whose load_idx is to be obtained.
* @idle: The Idle status of the CPU for whose sd load_icx is obtained.
@@ -4634,6 +4732,10 @@ static inline void update_sg_lb_stats(struct lb_env *env,
sgs->group_load += load;
sgs->sum_nr_running += nr_running;
sgs->sum_weighted_load += weighted_cpuload(i);
+
+ /* add scaled rq utilization */
+ sgs->group_util += max_rq_util(i);
+
if (idle_cpu(i))
sgs->idle_cpus++;
}
@@ -4742,6 +4844,7 @@ static inline void update_sd_lb_stats(struct lb_env *env,
if (child && child->flags & SD_PREFER_SIBLING)
prefer_sibling = 1;
+ init_sd_lb_power_stats(env, sds);
load_idx = get_sd_load_idx(env->sd, env->idle);
do {
@@ -4793,6 +4896,7 @@ static inline void update_sd_lb_stats(struct lb_env *env,
sds->group_imb = sgs.group_imb;
}
+ update_sd_lb_power_stats(env, sg, sds, local_group, &sgs);
sg = sg->next;
} while (sg != env->sd->groups);
}
@@ -5010,6 +5114,19 @@ find_busiest_group(struct lb_env *env, int *balance)
*/
update_sd_lb_stats(env, balance, &sds);
+ if (!(env->flags & LBF_POWER_BAL) && !(env->flags & LBF_PERF_BAL))
+ return NULL;
+
+ if (env->flags & LBF_POWER_BAL) {
+ if (sds.this == sds.group_leader &&
+ sds.group_leader != sds.group_min) {
+ env->imbalance = sds.min_load_per_task;
+ return sds.group_min;
+ }
+ env->flags &= ~LBF_POWER_BAL;
+ return NULL;
+ }
+
/*
* this_cpu is not the appropriate cpu to perform load balancing at
* this level.
@@ -5187,7 +5304,7 @@ static int load_balance(int this_cpu, struct rq *this_rq,
.idle = idle,
.loop_break = sched_nr_migrate_break,
.cpus = cpus,
- .flags = LBF_PERF_BAL,
+ .flags = LBF_POWER_BAL,
};
cpumask_copy(cpus, cpu_active_mask);
@@ -6265,7 +6382,6 @@ void unregister_fair_sched_group(struct task_group *tg, int cpu) { }
#endif /* CONFIG_FAIR_GROUP_SCHED */
-
static unsigned int get_rr_interval_fair(struct rq *rq, struct task_struct *task)
{
struct sched_entity *se = &task->se;
--
1.7.12
next prev parent reply other threads:[~2013-04-04 2:02 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-04 2:00 [patch v7 0/21] sched: power aware scheduling Alex Shi
2013-04-04 2:00 ` [patch v7 01/21] Revert "sched: Introduce temporary FAIR_GROUP_SCHED dependency for load-tracking" Alex Shi
2013-04-04 2:00 ` [patch v7 02/21] sched: set initial value of runnable avg for new forked task Alex Shi
2013-05-06 3:24 ` Preeti U Murthy
2013-04-04 2:00 ` [patch v7 03/21] sched: add sched balance policies in kernel Alex Shi
2013-04-04 2:00 ` [patch v7 04/21] sched: add sysfs interface for sched_balance_policy selection Alex Shi
2013-04-04 2:00 ` [patch v7 05/21] sched: log the cpu utilization at rq Alex Shi
2013-05-06 3:26 ` Preeti U Murthy
2013-05-06 5:22 ` Alex Shi
2013-05-06 12:03 ` Phil Carmody
2013-05-06 12:35 ` Alex Shi
2013-05-06 21:19 ` Paul Turner
2013-04-04 2:00 ` [patch v7 06/21] sched: add new sg/sd_lb_stats fields for incoming fork/exec/wake balancing Alex Shi
2013-04-04 2:00 ` [patch v7 07/21] sched: move sg/sd_lb_stats struct ahead Alex Shi
2013-04-04 2:00 ` [patch v7 08/21] sched: scale_rt_power rename and meaning change Alex Shi
2013-04-04 2:00 ` [patch v7 09/21] sched: get rq potential maximum utilization Alex Shi
2013-04-04 2:00 ` [patch v7 10/21] sched: add power aware scheduling in fork/exec/wake Alex Shi
2013-04-04 2:00 ` [patch v7 11/21] sched: add sched_burst_threshold_ns as wakeup burst indicator Alex Shi
2013-04-04 2:00 ` [patch v7 12/21] sched: using avg_idle to detect bursty wakeup Alex Shi
2013-04-04 2:00 ` [patch v7 13/21] sched: packing transitory tasks in wakeup power balancing Alex Shi
2013-04-04 2:00 ` [patch v7 14/21] sched: add power/performance balance allow flag Alex Shi
2013-04-04 2:00 ` [patch v7 15/21] sched: pull all tasks from source group Alex Shi
2013-04-04 5:59 ` Namhyung Kim
2013-04-06 11:49 ` Alex Shi
2013-04-04 2:00 ` [patch v7 16/21] sched: no balance for prefer_sibling in power scheduling Alex Shi
2013-05-06 3:26 ` Preeti U Murthy
2013-04-04 2:00 ` [patch v7 17/21] sched: add new members of sd_lb_stats Alex Shi
2013-04-04 2:00 ` Alex Shi [this message]
2013-04-04 2:01 ` [patch v7 19/21] sched: lazy power balance Alex Shi
2013-04-04 2:01 ` [patch v7 20/21] sched: don't do power balance on share cpu power domain Alex Shi
2013-04-08 3:17 ` Preeti U Murthy
2013-04-08 3:25 ` Preeti U Murthy
2013-04-08 4:19 ` Alex Shi
2013-04-04 2:01 ` [patch v7 21/21] sched: make sure select_tas_rq_fair get a cpu Alex Shi
2013-04-11 21:02 ` [patch v7 0/21] sched: power aware scheduling Len Brown
2013-04-12 8:46 ` Alex Shi
2013-04-12 16:23 ` Borislav Petkov
2013-04-12 16:48 ` Mike Galbraith
2013-04-12 17:12 ` Borislav Petkov
2013-04-14 1:36 ` Alex Shi
2013-04-17 21:53 ` Len Brown
2013-04-18 1:51 ` Mike Galbraith
2013-04-26 15:11 ` Mike Galbraith
2013-04-30 5:16 ` Mike Galbraith
2013-04-30 8:30 ` Mike Galbraith
2013-04-30 8:41 ` Ingo Molnar
2013-04-30 9:35 ` Mike Galbraith
2013-04-30 9:49 ` Mike Galbraith
2013-04-30 9:56 ` Mike Galbraith
2013-05-17 8:06 ` Preeti U Murthy
2013-05-20 1:01 ` Alex Shi
2013-05-20 2:30 ` Preeti U Murthy
2013-04-14 1:28 ` Alex Shi
2013-04-14 5:10 ` Alex Shi
2013-04-14 15:59 ` Borislav Petkov
2013-04-15 6:04 ` Alex Shi
2013-04-15 6:16 ` Alex Shi
2013-04-15 9:52 ` Borislav Petkov
2013-04-15 13:50 ` Alex Shi
2013-04-15 23:12 ` Borislav Petkov
2013-04-16 0:22 ` Alex Shi
2013-04-16 10:24 ` Borislav Petkov
2013-04-17 1:18 ` Alex Shi
2013-04-17 7:38 ` Borislav Petkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1365040862-8390-19-git-send-email-alex.shi@intel.com \
--to=alex.shi@intel.com \
--cc=akpm@linux-foundation.org \
--cc=arjan@linux.intel.com \
--cc=bp@alien8.de \
--cc=clark.williams@gmail.com \
--cc=efault@gmx.de \
--cc=gregkh@linuxfoundation.org \
--cc=jkosina@suse.cz \
--cc=keescook@chromium.org \
--cc=len.brown@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=morten.rasmussen@arm.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=pjt@google.com \
--cc=preeti@linux.vnet.ibm.com \
--cc=rafael.j.wysocki@intel.com \
--cc=riel@redhat.com \
--cc=tglx@linutronix.de \
--cc=tony.luck@intel.com \
--cc=vincent.guittot@linaro.org \
--cc=viresh.kumar@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®