From: Michael Wang <wangyun@linux.vnet.ibm.com>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Paul Turner <pjt@google.com>, Mike Galbraith <efault@gmx.de>,
Andrew Morton <akpm@linux-foundation.org>,
Tejun Heo <tj@kernel.org>,
"Nikunj A. Dadhania" <nikunj@linux.vnet.ibm.com>,
Namhyung Kim <namhyung@kernel.org>, Ram Pai <linuxram@us.ibm.com>
Subject: [RFC PATCH v2 2/3] sched: build schedule balance map
Date: Thu, 17 Jan 2013 13:48:21 +0800 [thread overview]
Message-ID: <50F790A5.10107@linux.vnet.ibm.com> (raw)
In-Reply-To: <50F79047.1080907@linux.vnet.ibm.com>
This patch will build schedule balance map as designed, now
cpu_sbm->sd[f][l] can directly locate the sd of cpu on level 'l'
with flag 'f' supported.
In order to quickly locate the lower sd while changing the base cpu,
the level with empty sd in map will be filled with the lower sd.
Signed-off-by: Michael Wang <wangyun@linux.vnet.ibm.com>
---
kernel/sched/core.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 70 insertions(+), 0 deletions(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 092c801..0c63303 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -5578,6 +5578,62 @@ static void update_top_cache_domain(int cpu)
static int sbm_max_level;
DEFINE_PER_CPU_SHARED_ALIGNED(struct sched_balance_map, sbm_array);
+static void build_sched_balance_map(int cpu)
+{
+ struct sched_balance_map *sbm = &per_cpu(sbm_array, cpu);
+ struct sched_domain *sd = cpu_rq(cpu)->sd;
+ struct sched_domain *top_sd = NULL;
+ int i, type, level = 0;
+
+ memset(sbm->top_level, 0, sizeof((*sbm).top_level));
+ memset(sbm->affine_map, 0, sizeof((*sbm).affine_map));
+ for (type = 0; type < SBM_MAX_TYPE; type++) {
+ memset(sbm->sd[type], 0,
+ sizeof(struct sched_domain *) * sbm_max_level);
+ }
+
+ while (sd) {
+ if (!(sd->flags & SD_LOAD_BALANCE))
+ continue;
+
+ if (sd->flags & SD_BALANCE_EXEC) {
+ sbm->top_level[SBM_EXEC_TYPE] = sd->level;
+ sbm->sd[SBM_EXEC_TYPE][sd->level] = sd;
+ }
+
+ if (sd->flags & SD_BALANCE_FORK) {
+ sbm->top_level[SBM_FORK_TYPE] = sd->level;
+ sbm->sd[SBM_FORK_TYPE][sd->level] = sd;
+ }
+
+ if (sd->flags & SD_BALANCE_WAKE) {
+ sbm->top_level[SBM_WAKE_TYPE] = sd->level;
+ sbm->sd[SBM_WAKE_TYPE][sd->level] = sd;
+ }
+
+ if (sd->flags & SD_WAKE_AFFINE) {
+ for_each_cpu(i, sched_domain_span(sd)) {
+ if (!sbm->affine_map[i])
+ sbm->affine_map[i] = sd;
+ }
+ }
+
+ sd = sd->parent;
+ }
+
+ /*
+ * fill the hole to get lower level sd easily.
+ */
+ for (type = 0; type < SBM_MAX_TYPE; type++) {
+ level = sbm->top_level[type];
+ top_sd = sbm->sd[type][level];
+ if ((++level != sbm_max_level) && top_sd) {
+ for (; level < sbm_max_level; level++)
+ sbm->sd[type][level] = top_sd;
+ }
+ }
+}
+
/*
* Attach the domain 'sd' to 'cpu' as its base domain. Callers must
* hold the hotplug lock.
@@ -5587,6 +5643,9 @@ cpu_attach_domain(struct sched_domain *sd, struct root_domain *rd, int cpu)
{
struct rq *rq = cpu_rq(cpu);
struct sched_domain *tmp;
+ struct sched_balance_map *sbm = &per_cpu(sbm_array, cpu);
+
+ rcu_assign_pointer(rq->sbm, NULL);
/* Remove the sched domains which do not contribute to scheduling. */
for (tmp = sd; tmp; ) {
@@ -5619,6 +5678,17 @@ cpu_attach_domain(struct sched_domain *sd, struct root_domain *rd, int cpu)
destroy_sched_domains(tmp, cpu);
update_top_cache_domain(cpu);
+
+ /* disable sbm if initialization failed or sd detached. */
+ if (!sbm_max_level || !sd)
+ return;
+
+ /*
+ * synchronize_rcu() is unnecessary here since
+ * destroy_sched_domains() already do the work.
+ */
+ build_sched_balance_map(cpu);
+ rcu_assign_pointer(rq->sbm, sbm);
}
/* cpus with isolated domains */
--
1.7.4.1
next prev parent reply other threads:[~2013-01-17 5:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-17 5:46 [RFC PATCH v2 0/3] sched: simplify the select_task_rq_fair() Michael Wang
2013-01-17 5:47 ` [RFC PATCH v2 1/3] sched: schedule balance map foundation Michael Wang
2013-01-17 5:48 ` Michael Wang [this message]
2013-01-17 5:49 ` [RFC PATCH v2 3/3] sched: simplify select_task_rq_fair() with schedule balance map Michael Wang
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=50F790A5.10107@linux.vnet.ibm.com \
--to=wangyun@linux.vnet.ibm.com \
--cc=a.p.zijlstra@chello.nl \
--cc=akpm@linux-foundation.org \
--cc=efault@gmx.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxram@us.ibm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=nikunj@linux.vnet.ibm.com \
--cc=pjt@google.com \
--cc=tj@kernel.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;
as well as URLs for NNTP newsgroup(s).