mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] rtmutex: rt_mutex_slowlock() is mostly called as TASK_INTERRUPTIBLE
@ 2017-01-19 16:32 Steven Rostedt (VMware)
  2017-01-30 11:53 ` [tip:locking/core] locking/rtmutex: Flip unlikely() branch to likely() in __rt_mutex_slowlock() tip-bot for Steven Rostedt (VMware)
  0 siblings, 1 reply; 2+ messages in thread
From: Steven Rostedt (VMware) @ 2017-01-19 16:32 UTC (permalink / raw)
  To: LKML; +Cc: Thomas Gleixner, Peter Zijlstra, Ingo Molnar, Andrew Morton

Running my likely/unlikely profiler for 3 weeks on two production
machines, I discovered that the unlikely() test in
__rt_mutex_slowlock() checking if state is TASK_INTERRUPTIBLE is hit
100% of the time, making it a very likely case.

The reason is, on a vanilla kernel, the majority case of calling
rt_mutex() is from the futex code. This code is always called as
TASK_INTERRUPTIBLE. In the -rt patch, this code is commonly called when
PREEMPT_RT is enabled with TASK_UNINTERRUPTIBLE. But that's not the
likely scenario.

The rt_mutex() code should be optimized for the common vanilla case,
and that is from a futex, with TASK_INTERRUPTIBLE as the state.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c
index 1ec0f48..8de6288 100644
--- a/kernel/locking/rtmutex.c
+++ b/kernel/locking/rtmutex.c
@@ -1115,7 +1115,7 @@ __rt_mutex_slowlock(struct rt_mutex *lock, int state,
 		 * TASK_INTERRUPTIBLE checks for signals and
 		 * timeout. Ignored otherwise.
 		 */
-		if (unlikely(state == TASK_INTERRUPTIBLE)) {
+		if (likely(state == TASK_INTERRUPTIBLE)) {
 			/* Signal pending? */
 			if (signal_pending(current))
 				ret = -EINTR;

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [tip:locking/core] locking/rtmutex: Flip unlikely() branch to likely() in __rt_mutex_slowlock()
  2017-01-19 16:32 [PATCH] rtmutex: rt_mutex_slowlock() is mostly called as TASK_INTERRUPTIBLE Steven Rostedt (VMware)
@ 2017-01-30 11:53 ` tip-bot for Steven Rostedt (VMware)
  0 siblings, 0 replies; 2+ messages in thread
From: tip-bot for Steven Rostedt (VMware) @ 2017-01-30 11:53 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: akpm, hpa, linux-kernel, torvalds, mingo, tglx, rostedt, peterz

Commit-ID:  4009f4b3a9d8b74547269f293e6a920adf278996
Gitweb:     http://git.kernel.org/tip/4009f4b3a9d8b74547269f293e6a920adf278996
Author:     Steven Rostedt (VMware) <rostedt@goodmis.org>
AuthorDate: Thu, 19 Jan 2017 11:32:34 -0500
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Mon, 30 Jan 2017 11:42:59 +0100

locking/rtmutex: Flip unlikely() branch to likely() in __rt_mutex_slowlock()

Running my likely/unlikely profiler for 3 weeks on two production
machines, I discovered that the unlikely() test in
__rt_mutex_slowlock() checking if state is TASK_INTERRUPTIBLE is hit
100% of the time, making it a very likely case.

The reason is, on a vanilla kernel, the majority case of calling
rt_mutex() is from the futex code. This code is always called as
TASK_INTERRUPTIBLE. In the -rt patch, this code is commonly called when
PREEMPT_RT is enabled with TASK_UNINTERRUPTIBLE. But that's not the
likely scenario.

The rt_mutex() code should be optimized for the common vanilla case,
and that is from a futex, with TASK_INTERRUPTIBLE as the state.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/20170119113234.1efeedd1@gandalf.local.home
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/locking/rtmutex.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c
index 2f443ed..d340be3 100644
--- a/kernel/locking/rtmutex.c
+++ b/kernel/locking/rtmutex.c
@@ -1179,7 +1179,7 @@ __rt_mutex_slowlock(struct rt_mutex *lock, int state,
 		 * TASK_INTERRUPTIBLE checks for signals and
 		 * timeout. Ignored otherwise.
 		 */
-		if (unlikely(state == TASK_INTERRUPTIBLE)) {
+		if (likely(state == TASK_INTERRUPTIBLE)) {
 			/* Signal pending? */
 			if (signal_pending(current))
 				ret = -EINTR;

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-01-30 11:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-19 16:32 [PATCH] rtmutex: rt_mutex_slowlock() is mostly called as TASK_INTERRUPTIBLE Steven Rostedt (VMware)
2017-01-30 11:53 ` [tip:locking/core] locking/rtmutex: Flip unlikely() branch to likely() in __rt_mutex_slowlock() tip-bot for Steven Rostedt (VMware)

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®