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 1/5] optimize rt lock wakeup
Date: Tue, 20 May 2008 10:49:15 -0400 [thread overview]
Message-ID: <20080520144915.15992.57013.stgit@novell1.haskins.net> (raw)
In-Reply-To: <20080520143954.15992.85900.stgit@novell1.haskins.net>
It is redundant to wake the grantee task if it is already running, and
the call to wake_up_process is relatively expensive. If we can safely
skip it we can measurably improve the performance of the adaptive-locks.
Credit goes to Peter Morreale for the general idea.
Signed-off-by: Gregory Haskins <ghaskins@novell.com>
Signed-off-by: Peter Morreale <pmorreale@novell.com>
---
kernel/rtmutex.c | 45 ++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 40 insertions(+), 5 deletions(-)
diff --git a/kernel/rtmutex.c b/kernel/rtmutex.c
index 6c1debb..8ae9de3 100644
--- a/kernel/rtmutex.c
+++ b/kernel/rtmutex.c
@@ -522,6 +522,41 @@ static void wakeup_next_waiter(struct rt_mutex *lock, int savestate)
pendowner = waiter->task;
waiter->task = NULL;
+ /*
+ * Do the wakeup before the ownership change to give any spinning
+ * waiter grantees a headstart over the other threads that will
+ * trigger once owner changes.
+ */
+ if (!savestate)
+ wake_up_process(pendowner);
+ else {
+ /*
+ * We can skip the actual (expensive) wakeup if the
+ * waiter is already running, but we have to be careful
+ * of race conditions because they may be about to sleep.
+ *
+ * The waiter-side protocol has the following pattern:
+ * 1: Set state != RUNNING
+ * 2: Conditionally sleep if waiter->task != NULL;
+ *
+ * And the owner-side has the following:
+ * A: Set waiter->task = NULL
+ * B: Conditionally wake if the state != RUNNING
+ *
+ * As long as we ensure 1->2 order, and A->B order, we
+ * will never miss a wakeup.
+ *
+ * Therefore, this barrier ensures that waiter->task = NULL
+ * is visible before we test the pendowner->state. The
+ * corresponding barrier is in the sleep logic.
+ */
+ smp_mb();
+
+ /* If !RUNNING && !RUNNING_MUTEX */
+ if (pendowner->state & ~TASK_RUNNING_MUTEX)
+ wake_up_process_mutex(pendowner);
+ }
+
rt_mutex_set_owner(lock, pendowner, RT_MUTEX_OWNER_PENDING);
spin_unlock(¤t->pi_lock);
@@ -548,11 +583,6 @@ static void wakeup_next_waiter(struct rt_mutex *lock, int savestate)
plist_add(&next->pi_list_entry, &pendowner->pi_waiters);
}
spin_unlock(&pendowner->pi_lock);
-
- if (savestate)
- wake_up_process_mutex(pendowner);
- else
- wake_up_process(pendowner);
}
/*
@@ -803,6 +833,11 @@ rt_spin_lock_slowlock(struct rt_mutex *lock)
if (adaptive_wait(&waiter, orig_owner)) {
update_current(TASK_UNINTERRUPTIBLE, &saved_state);
+ /*
+ * The xchg() in update_current() is an implicit
+ * barrier which we rely upon to ensure current->state
+ * is visible before we test waiter.task.
+ */
if (waiter.task)
schedule_rt_mutex(lock);
}
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 ` Gregory Haskins [this message]
2008-05-20 14:49 ` [PATCH 2/5] sched: make task->oncpu available in all configurations Gregory Haskins
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=20080520144915.15992.57013.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®