From: Preeti U Murthy <preeti@linux.vnet.ibm.com>
To: alex.shi@intel.com, vincent.guittot@linaro.org,
peterz@infradead.org, pjt@google.com, efault@gmx.de,
rjw@rjwysocki.net, morten.rasmussen@arm.com,
svaidy@linux.vnet.ibm.com, arjan@linux.intel.com,
mingo@kernel.org
Cc: nicolas.pitre@linaro.org, len.brown@intel.com,
yuyang.du@intel.com, linaro-kernel@lists.linaro.org,
daniel.lezcano@linaro.org, corbet@lwn.net,
catalin.marinas@arm.com, markgross@thegnar.org,
sundar.iyer@intel.com, linux-kernel@vger.kernel.org,
dietmar.eggemann@arm.com, Lorenzo.Pieralisi@arm.com,
mike.turquette@linaro.org, akpm@linux-foundation.org,
paulmck@linux.vnet.ibm.com, tglx@linutronix.de
Subject: [RFC PATCH V2 18/19] sched: lazy power balance
Date: Mon, 11 Aug 2014 17:19:34 +0530 [thread overview]
Message-ID: <20140811114916.32407.88823.stgit@preeti.in.ibm.com> (raw)
In-Reply-To: <20140811114501.32407.61304.stgit@preeti.in.ibm.com>
From: Alex Shi <alex.shi@intel.com>
When active task number in sched domain waves around the power friendly
scheduling creteria, scheduling will thresh between the power friendly
balance and performance balance, bring unnecessary task migration.
The typical benchmark is 'make -j x'.
To remove such issue, introduce a u64 perf_lb_record variable to record
performance load balance history. If there is no performance LB for
continuing 32 times load balancing, or no LB for 8 times max_interval ms,
or only 4 times performance LB in last 64 times load balancing, then we
accept a power friendly LB. Otherwise, give up this time power friendly
LB chance, do nothing.
With this patch, the worst case for power scheduling -- kbuild, gets
similar performance/watts value among different policy.
Signed-off-by: Alex Shi <alex.shi@intel.com>
[Added CONFIG_SCHED_POWER switch to enable this patch]
Signed-off-by: Preeti U Murthy <preeti@linux.vnet.ibm.com>
---
include/linux/sched.h | 4 ++-
kernel/sched/fair.c | 70 +++++++++++++++++++++++++++++++++++++++++--------
2 files changed, 61 insertions(+), 13 deletions(-)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 009da6a..990b6b9 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -938,7 +938,9 @@ struct sched_domain {
unsigned long last_balance; /* init to jiffies. units in jiffies */
unsigned int balance_interval; /* initialise to 1. units in ms. */
unsigned int nr_balance_failed; /* initialise to 0 */
-
+#ifdef CONFIG_SCHED_POWER
+ u64 perf_lb_record; /* performance balance record */
+#endif
/* idle_balance() stats */
u64 max_newidle_lb_cost;
unsigned long next_decay_max_lb_cost;
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 2e64e96..c49ee6c 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -6743,6 +6743,62 @@ static inline void calculate_imbalance(struct lb_env *env, struct sd_lb_stats *s
return fix_small_imbalance(env, sds);
}
+#ifdef CONFIG_SCHED_POWER
+#define PERF_LB_HH_MASK 0xffffffff00000000ULL
+#define PERF_LB_LH_MASK 0xffffffffULL
+
+/**
+ * need_perf_balance - Check if the performance load balance needed
+ * in the sched_domain.
+ *
+ * @env: The load balancing environment.
+ * @sds: Variable containing the statistics of the sched_domain
+ */
+static int need_perf_balance(struct lb_env *env, struct sd_lb_stats *sds)
+{
+ env->sd->perf_lb_record <<= 1;
+
+ if (env->flags & LBF_PERF_BAL) {
+ env->sd->perf_lb_record |= 0x1;
+ return 1;
+ }
+
+ /*
+ * The situation isn't eligible for performance balance. If this_cpu
+ * is not eligible or the timing is not suitable for lazy powersaving
+ * balance, we will stop both powersaving and performance balance.
+ */
+ if (env->flags & LBF_POWER_BAL && sds->local == sds->group_leader
+ && sds->group_leader != sds->group_min) {
+ int interval;
+
+ /* powersaving balance interval set as 8 * max_interval */
+ interval = msecs_to_jiffies(8 * env->sd->max_interval);
+ if (time_after(jiffies, env->sd->last_balance + interval))
+ env->sd->perf_lb_record = 0;
+
+ /*
+ * A eligible timing is no performance balance in last 32
+ * balance and performance balance is no more than 4 times
+ * in last 64 balance, or no balance in powersaving interval
+ * time.
+ */
+ if ((hweight64(env->sd->perf_lb_record & PERF_LB_HH_MASK) <= 4)
+ && !(env->sd->perf_lb_record & PERF_LB_LH_MASK)) {
+
+ env->imbalance = sds->min_load_per_task;
+ return 0;
+ }
+
+ }
+
+ /* give up this time power balancing, do nothing */
+ env->flags &= ~LBF_POWER_BAL;
+ sds->group_min = NULL;
+ return 0;
+}
+#endif
+
/******* find_busiest_group() helpers end here *********************/
/**
@@ -6776,18 +6832,8 @@ static struct sched_group *find_busiest_group(struct lb_env *env)
update_sd_lb_stats(env, &sds);
#ifdef CONFIG_SCHED_POWER
- 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;
- }
+ if (!need_perf_balance(env, &sds))
+ return sds.group_min;
#endif
local = &sds.local_stat;
busiest = &sds.busiest_stat;
next prev parent reply other threads:[~2014-08-11 11:50 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-11 11:48 [RFC PATCH V2 17/19] sched: power aware load balance Preeti U Murthy
2014-08-11 11:49 ` Preeti U Murthy [this message]
2014-08-11 11:50 ` [RFC PATCH V2 19/19] sched: don't do power balance on share cpu power domain Preeti U Murthy
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=20140811114916.32407.88823.stgit@preeti.in.ibm.com \
--to=preeti@linux.vnet.ibm.com \
--cc=Lorenzo.Pieralisi@arm.com \
--cc=akpm@linux-foundation.org \
--cc=alex.shi@intel.com \
--cc=arjan@linux.intel.com \
--cc=catalin.marinas@arm.com \
--cc=corbet@lwn.net \
--cc=daniel.lezcano@linaro.org \
--cc=dietmar.eggemann@arm.com \
--cc=efault@gmx.de \
--cc=len.brown@intel.com \
--cc=linaro-kernel@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=markgross@thegnar.org \
--cc=mike.turquette@linaro.org \
--cc=mingo@kernel.org \
--cc=morten.rasmussen@arm.com \
--cc=nicolas.pitre@linaro.org \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=pjt@google.com \
--cc=rjw@rjwysocki.net \
--cc=sundar.iyer@intel.com \
--cc=svaidy@linux.vnet.ibm.com \
--cc=tglx@linutronix.de \
--cc=vincent.guittot@linaro.org \
--cc=yuyang.du@intel.com \
/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®