[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20071121044416.6315.71088.stgit@novell1.haskins.net>
Date: Tue, 20 Nov 2007 23:44:16 -0500
From: Gregory Haskins <ghaskins@...ell.com>
To: LKML <linux-kernel@...r.kernel.org>,
Steven Rostedt <srostedt@...hat.com>
Cc: Christoph Lameter <clameter@....com>,
Peter Zijlstra <a.p.zijlstra@...llo.nl>,
Ingo Molnar <mingo@...e.hu>,
Gregory Haskins <ghaskins@...ell.com>
Subject: [PATCH 3/4] RT: Only balance our RT tasks within our root-domain
We move the rt-overload data as the first global to per-domain
reclassification. This limits the scope of overload related cache-line
bouncing to stay with a specified partition instead of affecting all
cpus in the system.
Finally, we limit the scope of find_lowest_cpu searches to the domain
instead of the entire system. Note that we would always respect domain
boundaries even without this patch, but we first would scan potentially
all cpus before whittling the list down. Now we can avoid looking at
RQs that are out of scope, again reducing cache-line hits.
Note: In some cases, task->cpus_allowed will effectively reduce our search
to within our domain. However, I believe there are cases where the
cpus_allowed mask may be all ones and therefore we err on the side of
caution. If it can be optimized later, so be it.
Signed-off-by: Gregory Haskins <ghaskins@...ell.com>
CC: Christoph Lameter <clameter@....com>
---
kernel/sched.c | 2 ++
kernel/sched_rt.c | 65 +++++++++++++++++++++++++++++++++++------------------
2 files changed, 45 insertions(+), 22 deletions(-)
diff --git a/kernel/sched.c b/kernel/sched.c
index fb619fb..578c186 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -281,6 +281,8 @@ struct rt_rq {
struct root_domain {
atomic_t refcount;
cpumask_t span;
+ cpumask_t rto_mask;
+ atomic_t rto_count;
};
struct root_domain def_root_domain;
diff --git a/kernel/sched_rt.c b/kernel/sched_rt.c
index fbf4fb1..3495762 100644
--- a/kernel/sched_rt.c
+++ b/kernel/sched_rt.c
@@ -4,20 +4,18 @@
*/
#ifdef CONFIG_SMP
-static cpumask_t rt_overload_mask;
-static atomic_t rto_count;
-static inline int rt_overloaded(void)
+
+static inline int rt_overloaded(struct rq *rq)
{
- return atomic_read(&rto_count);
+ return atomic_read(&rq->rd->rto_count);
}
-static inline cpumask_t *rt_overload(void)
+static inline cpumask_t *rt_overload(struct rq *rq)
{
- return &rt_overload_mask;
+ return &rq->rd->rto_mask;
}
static inline void rt_set_overload(struct rq *rq)
{
- rq->rt.overloaded = 1;
- cpu_set(rq->cpu, rt_overload_mask);
+ cpu_set(rq->cpu, rq->rd->rto_mask);
/*
* Make sure the mask is visible before we set
* the overload count. That is checked to determine
@@ -26,22 +24,25 @@ static inline void rt_set_overload(struct rq *rq)
* updated yet.
*/
wmb();
- atomic_inc(&rto_count);
+ atomic_inc(&rq->rd->rto_count);
}
static inline void rt_clear_overload(struct rq *rq)
{
/* the order here really doesn't matter */
- atomic_dec(&rto_count);
- cpu_clear(rq->cpu, rt_overload_mask);
- rq->rt.overloaded = 0;
+ atomic_dec(&rq->rd->rto_count);
+ cpu_clear(rq->cpu, rq->rd->rto_mask);
}
static void update_rt_migration(struct rq *rq)
{
- if (rq->rt.rt_nr_migratory && (rq->rt.rt_nr_running > 1))
+ if (rq->rt.rt_nr_migratory && (rq->rt.rt_nr_running > 1)) {
rt_set_overload(rq);
- else
+ rq->rt.overloaded = 1;
+ } else {
rt_clear_overload(rq);
+ rq->rt.overloaded = 0;
+ }
+
}
#endif /* CONFIG_SMP */
@@ -304,6 +305,15 @@ static int find_lowest_cpus(struct task_struct *task, cpumask_t *lowest_mask)
cpus_and(*lowest_mask, cpu_online_map, task->cpus_allowed);
/*
+ * Yes, I know doing two cpus_and() kind of sucks, especially on
+ * those very large SMP systems. We are going for correctness now,
+ * optimization later. A later patch will add rd->online to cache
+ * the subset of rd->span that are online and then we can collapse
+ * these two mask operations into one
+ */
+ cpus_and(*lowest_mask, *lowest_mask, task_rq(task)->rd->span);
+
+ /*
* Scan each rq for the lowest prio.
*/
for_each_cpu_mask(cpu, *lowest_mask) {
@@ -584,18 +594,12 @@ static int pull_rt_task(struct rq *this_rq)
assert_spin_locked(&this_rq->lock);
- /*
- * If cpusets are used, and we have overlapping
- * run queue cpusets, then this algorithm may not catch all.
- * This is just the price you pay on trying to keep
- * dirtying caches down on large SMP machines.
- */
- if (likely(!rt_overloaded()))
+ if (likely(!rt_overloaded(this_rq)))
return 0;
next = pick_next_task_rt(this_rq);
- rto_cpumask = rt_overload();
+ rto_cpumask = rt_overload(this_rq);
for_each_cpu_mask(cpu, *rto_cpumask) {
if (this_cpu == cpu)
@@ -814,6 +818,20 @@ static void task_tick_rt(struct rq *rq, struct task_struct *p)
}
}
+/* Assumes rq->lock is held */
+static void join_domain_rt(struct rq *rq)
+{
+ if (rq->rt.overloaded)
+ rt_set_overload(rq);
+}
+
+/* Assumes rq->lock is held */
+static void leave_domain_rt(struct rq *rq)
+{
+ if (rq->rt.overloaded)
+ rt_clear_overload(rq);
+}
+
static void set_curr_task_rt(struct rq *rq)
{
struct task_struct *p = rq->curr;
@@ -843,4 +861,7 @@ const struct sched_class rt_sched_class = {
.set_curr_task = set_curr_task_rt,
.task_tick = task_tick_rt,
+
+ .join_domain = join_domain_rt,
+ .leave_domain = leave_domain_rt,
};
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists