From: Gregory Haskins <ghaskins@novell.com>
To: mingo@elte.hu, tglx@linutronix.de, rostedt@goodmis.org,
linux-rt-users@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, sdietrich@novell.com,
pmorreale@novell.com, mkohari@novell.com, ghaskins@novell.com
Subject: [PATCH 2/5] sched: make task->oncpu available in all configurations
Date: Tue, 20 May 2008 10:49:20 -0400 [thread overview]
Message-ID: <20080520144920.15992.40920.stgit@novell1.haskins.net> (raw)
In-Reply-To: <20080520143954.15992.85900.stgit@novell1.haskins.net>
We will use this later in the series to eliminate the need for a function
call.
Signed-off-by: Gregory Haskins <ghaskins@novell.com>
---
include/linux/sched.h | 2 --
kernel/sched.c | 35 ++++++++++++++++++++++++-----------
2 files changed, 24 insertions(+), 13 deletions(-)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index ec94970..70175e0 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1080,10 +1080,8 @@ struct task_struct {
int lock_depth; /* BKL lock depth */
#ifdef CONFIG_SMP
-#ifdef __ARCH_WANT_UNLOCKED_CTXSW
int oncpu;
#endif
-#endif
int prio, static_prio, normal_prio;
#ifdef CONFIG_PREEMPT_RCU_BOOST
diff --git a/kernel/sched.c b/kernel/sched.c
index 4428916..03cb222 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -699,18 +699,39 @@ static inline int task_current(struct rq *rq, struct task_struct *p)
return rq->curr == p;
}
-#ifndef __ARCH_WANT_UNLOCKED_CTXSW
static inline int task_running(struct rq *rq, struct task_struct *p)
{
+#ifdef CONFIG_SMP
+ return p->oncpu;
+#else
return task_current(rq, p);
+#endif
}
+#ifndef __ARCH_WANT_UNLOCKED_CTXSW
static inline void prepare_lock_switch(struct rq *rq, struct task_struct *next)
{
+#ifdef CONFIG_SMP
+ /*
+ * We can optimise this out completely for !SMP, because the
+ * SMP rebalancing from interrupt is the only thing that cares
+ * here.
+ */
+ next->oncpu = 1;
+#endif
}
static inline void finish_lock_switch(struct rq *rq, struct task_struct *prev)
{
+#ifdef CONFIG_SMP
+ /*
+ * After ->oncpu is cleared, the task can be moved to a different CPU.
+ * We must ensure this doesn't happen until the switch is completely
+ * finished.
+ */
+ smp_wmb();
+ prev->oncpu = 0;
+#endif
#ifdef CONFIG_DEBUG_SPINLOCK
/* this is a valid case when another task releases the spinlock */
rq->lock.owner = current;
@@ -726,14 +747,6 @@ static inline void finish_lock_switch(struct rq *rq, struct task_struct *prev)
}
#else /* __ARCH_WANT_UNLOCKED_CTXSW */
-static inline int task_running(struct rq *rq, struct task_struct *p)
-{
-#ifdef CONFIG_SMP
- return p->oncpu;
-#else
- return task_current(rq, p);
-#endif
-}
static inline void prepare_lock_switch(struct rq *rq, struct task_struct *next)
{
@@ -2082,7 +2095,7 @@ void sched_fork(struct task_struct *p, int clone_flags)
if (likely(sched_info_on()))
memset(&p->sched_info, 0, sizeof(p->sched_info));
#endif
-#if defined(CONFIG_SMP) && defined(__ARCH_WANT_UNLOCKED_CTXSW)
+#if defined(CONFIG_SMP)
p->oncpu = 0;
#endif
#ifdef CONFIG_PREEMPT
@@ -5684,7 +5697,7 @@ void __cpuinit init_idle(struct task_struct *idle, int cpu)
spin_lock_irqsave(&rq->lock, flags);
rq->curr = rq->idle = idle;
-#if defined(CONFIG_SMP) && defined(__ARCH_WANT_UNLOCKED_CTXSW)
+#if defined(CONFIG_SMP)
idle->oncpu = 1;
#endif
spin_unlock_irqrestore(&rq->lock, flags);
next prev parent reply other threads:[~2008-05-20 15:22 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-20 14:49 [PATCH 0/5] RT: adaptive-lock enhancements Gregory Haskins
2008-05-20 14:49 ` [PATCH 1/5] optimize rt lock wakeup Gregory Haskins
2008-05-20 14:49 ` Gregory Haskins [this message]
2008-05-20 14:49 ` [PATCH 3/5] rtmutex: use task->oncpu to save a call Gregory Haskins
2008-05-20 14:49 ` [PATCH 4/5] adjust pi_lock usage in wakeup Gregory Haskins
2008-05-20 14:49 ` [PATCH 5/5] remove the extra call to try_to_take_lock Gregory Haskins
2008-05-24 3:02 ` Steven Rostedt
2008-05-24 3:30 ` Gregory Haskins
2008-05-24 14:11 ` Peter W. Morreale
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=20080520144920.15992.40920.stgit@novell1.haskins.net \
--to=ghaskins@novell.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=mkohari@novell.com \
--cc=pmorreale@novell.com \
--cc=rostedt@goodmis.org \
--cc=sdietrich@novell.com \
--cc=tglx@linutronix.de \
/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®