diff options
author | Davidlohr Bueso <dave@stgolabs.net> | 2015-02-02 01:16:24 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2015-02-04 01:57:42 -0500 |
commit | afffc6c1805d98e08e778cddb644a666e78cfcfd (patch) | |
tree | 86ad29607790194934447f45787de73314bd5397 | |
parent | 73105994c57d06e40a33ab5a716db04e898b4c05 (diff) |
locking/rtmutex: Optimize setting task running after being blocked
We explicitly mark the task running after returning from
a __rt_mutex_slowlock() call, which does the actual sleeping
via wait-wake-trylocking. As such, this patch does two things:
(1) refactors the code so that setting current to TASK_RUNNING
is done by __rt_mutex_slowlock(), and not by the callers. The
downside to this is that it becomes a bit unclear when at what
point we block. As such I've added a comment that the task
blocks when calling __rt_mutex_slowlock() so readers can figure
out when it is running again.
(2) relaxes setting current's state through __set_current_state(),
instead of it's more expensive barrier alternative. There was no
need for the implied barrier as we're obviously not planning on
blocking.
Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: http://lkml.kernel.org/r/1422857784.18096.1.camel@stgolabs.net
Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r-- | kernel/locking/rtmutex.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c index 7c98873a3077..3059bc2f022d 100644 --- a/kernel/locking/rtmutex.c +++ b/kernel/locking/rtmutex.c | |||
@@ -1130,6 +1130,7 @@ __rt_mutex_slowlock(struct rt_mutex *lock, int state, | |||
1130 | set_current_state(state); | 1130 | set_current_state(state); |
1131 | } | 1131 | } |
1132 | 1132 | ||
1133 | __set_current_state(TASK_RUNNING); | ||
1133 | return ret; | 1134 | return ret; |
1134 | } | 1135 | } |
1135 | 1136 | ||
@@ -1188,10 +1189,9 @@ rt_mutex_slowlock(struct rt_mutex *lock, int state, | |||
1188 | ret = task_blocks_on_rt_mutex(lock, &waiter, current, chwalk); | 1189 | ret = task_blocks_on_rt_mutex(lock, &waiter, current, chwalk); |
1189 | 1190 | ||
1190 | if (likely(!ret)) | 1191 | if (likely(!ret)) |
1192 | /* sleep on the mutex */ | ||
1191 | ret = __rt_mutex_slowlock(lock, state, timeout, &waiter); | 1193 | ret = __rt_mutex_slowlock(lock, state, timeout, &waiter); |
1192 | 1194 | ||
1193 | set_current_state(TASK_RUNNING); | ||
1194 | |||
1195 | if (unlikely(ret)) { | 1195 | if (unlikely(ret)) { |
1196 | remove_waiter(lock, &waiter); | 1196 | remove_waiter(lock, &waiter); |
1197 | rt_mutex_handle_deadlock(ret, chwalk, &waiter); | 1197 | rt_mutex_handle_deadlock(ret, chwalk, &waiter); |
@@ -1626,10 +1626,9 @@ int rt_mutex_finish_proxy_lock(struct rt_mutex *lock, | |||
1626 | 1626 | ||
1627 | set_current_state(TASK_INTERRUPTIBLE); | 1627 | set_current_state(TASK_INTERRUPTIBLE); |
1628 | 1628 | ||
1629 | /* sleep on the mutex */ | ||
1629 | ret = __rt_mutex_slowlock(lock, TASK_INTERRUPTIBLE, to, waiter); | 1630 | ret = __rt_mutex_slowlock(lock, TASK_INTERRUPTIBLE, to, waiter); |
1630 | 1631 | ||
1631 | set_current_state(TASK_RUNNING); | ||
1632 | |||
1633 | if (unlikely(ret)) | 1632 | if (unlikely(ret)) |
1634 | remove_waiter(lock, waiter); | 1633 | remove_waiter(lock, waiter); |
1635 | 1634 | ||