linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tip-bot for Jason Low <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: mingo@kernel.org, konrad.wilk@oracle.com,
	torvalds@linux-foundation.org, peterz@infradead.org,
	jason.low2@hp.com, riel@redhat.com, rostedt@goodmis.org,
	akpm@linux-foundation.org, tglx@linutronix.de,
	david@fromorbit.com, davidlohr@hp.com, scott.norton@hp.com,
	linux-kernel@vger.kernel.org, hpa@zytor.com, waiman.long@hp.com,
	tim.c.chen@linux.intel.com, paulmck@linux.vnet.ibm.com,
	aswin@hp.com
Subject: [tip:locking/urgent] locking/spinlocks/mcs: Micro-optimize osq_unlock()
Date: Wed, 16 Jul 2014 12:21:15 -0700	[thread overview]
Message-ID: <tip-33ecd2083a9560fbc1ef1b1279ef3ecb4c012a4f@git.kernel.org> (raw)
In-Reply-To: <1405358872-3732-5-git-send-email-jason.low2@hp.com>

Commit-ID:  33ecd2083a9560fbc1ef1b1279ef3ecb4c012a4f
Gitweb:     http://git.kernel.org/tip/33ecd2083a9560fbc1ef1b1279ef3ecb4c012a4f
Author:     Jason Low <jason.low2@hp.com>
AuthorDate: Mon, 14 Jul 2014 10:27:51 -0700
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 16 Jul 2014 13:28:06 +0200

locking/spinlocks/mcs: Micro-optimize osq_unlock()

In the unlock function of the cancellable MCS spinlock, the first
thing we do is to retrive the current CPU's osq node. However, due to
the changes made in the previous patch, in the common case where the
lock is not contended, we wouldn't need to access the current CPU's
osq node anymore.

This patch optimizes this by only retriving this CPU's osq node
after we attempt the initial cmpxchg to unlock the osq and found
that its contended.

Signed-off-by: Jason Low <jason.low2@hp.com>
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Cc: Scott Norton <scott.norton@hp.com>
Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Waiman Long <waiman.long@hp.com>
Cc: Davidlohr Bueso <davidlohr@hp.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Tim Chen <tim.c.chen@linux.intel.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Aswin Chandramouleeswaran <aswin@hp.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: http://lkml.kernel.org/r/1405358872-3732-5-git-send-email-jason.low2@hp.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/locking/mcs_spinlock.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c
index 32fc16c..be9ee15 100644
--- a/kernel/locking/mcs_spinlock.c
+++ b/kernel/locking/mcs_spinlock.c
@@ -182,8 +182,7 @@ unqueue:
 
 void osq_unlock(struct optimistic_spin_queue *lock)
 {
-	struct optimistic_spin_node *node = this_cpu_ptr(&osq_node);
-	struct optimistic_spin_node *next;
+	struct optimistic_spin_node *node, *next;
 	int curr = encode_cpu(smp_processor_id());
 
 	/*
@@ -195,6 +194,7 @@ void osq_unlock(struct optimistic_spin_queue *lock)
 	/*
 	 * Second most likely case.
 	 */
+	node = this_cpu_ptr(&osq_node);
 	next = xchg(&node->next, NULL);
 	if (next) {
 		ACCESS_ONCE(next->locked) = 1;

  reply	other threads:[~2014-07-16 19:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-14 17:27 [PATCH v2 0/5] MCS spinlocks: Cancellable MCS spinlock rework Jason Low
2014-07-14 17:27 ` [PATCH v2 1/5] MCS spinlocks: Rename optimistic_spin_queue to optimistic_spin_node Jason Low
2014-07-16 19:20   ` [tip:locking/urgent] locking/spinlocks/mcs: Rename optimistic_spin_queue() to optimistic_spin_node() tip-bot for Jason Low
2014-07-14 17:27 ` [PATCH v2 2/5] MCS spinlocks: Convert osq lock to atomic_t to reduce overhead Jason Low
2014-07-16 19:20   ` [tip:locking/urgent] locking/spinlocks/mcs: " tip-bot for Jason Low
2014-07-14 17:27 ` [PATCH v2 3/5] MCS spinlocks: Introduce and use init macro and function for osq locks Jason Low
2014-07-16 19:21   ` [tip:locking/urgent] locking/spinlocks/mcs: " tip-bot for Jason Low
2014-07-14 17:27 ` [PATCH v2 4/5] MCS spinlocks: Micro-optimize osq_unlock() Jason Low
2014-07-16 19:21   ` tip-bot for Jason Low [this message]
2014-07-14 17:27 ` [PATCH v2 5/5] rwsem: Reduce the size of struct rw_semaphore Jason Low
2014-07-16 19:24   ` [tip:locking/urgent] locking/rwsem: " tip-bot for Jason Low

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=tip-33ecd2083a9560fbc1ef1b1279ef3ecb4c012a4f@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=akpm@linux-foundation.org \
    --cc=aswin@hp.com \
    --cc=david@fromorbit.com \
    --cc=davidlohr@hp.com \
    --cc=hpa@zytor.com \
    --cc=jason.low2@hp.com \
    --cc=konrad.wilk@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=riel@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=scott.norton@hp.com \
    --cc=tglx@linutronix.de \
    --cc=tim.c.chen@linux.intel.com \
    --cc=torvalds@linux-foundation.org \
    --cc=waiman.long@hp.com \
    /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;
as well as URLs for NNTP newsgroup(s).