mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nicolas Pitre <nico@cam.org>
To: Ingo Molnar <mingo@elte.hu>
Cc: Christoph Hellwig <hch@infradead.org>,
	lkml <linux-kernel@vger.kernel.org>,
	Linus Torvalds <torvalds@osdl.org>, Andrew Morton <akpm@osdl.org>,
	Arjan van de Ven <arjanv@infradead.org>,
	Jes Sorensen <jes@trained-monkey.org>,
	Zwane Mwaikambo <zwane@arm.linux.org.uk>,
	Oleg Nesterov <oleg@tv-sign.ru>,
	David Howells <dhowells@redhat.com>,
	Alan Cox <alan@lxorguk.ukuu.org.uk>,
	Benjamin LaHaise <bcrl@kvack.org>,
	Steven Rostedt <rostedt@goodmis.org>, Andi Kleen <ak@suse.de>
Subject: [patch 2/2] mutex subsystem: use the per architecture fast path lock_unlock defines
Date: Thu, 22 Dec 2005 16:40:44 -0500 (EST)	[thread overview]
Message-ID: <Pine.LNX.4.64.0512221637570.26663@localhost.localdomain> (raw)
In-Reply-To: <Pine.LNX.4.64.0512221613010.26663@localhost.localdomain>


This switch the core over to the architecture defined fast path locking 
primitives.  It also adds __mutex_lock_interruptible_noinline and 
friends.

Index: linux-2.6/kernel/mutex.c
===================================================================
--- linux-2.6.orig/kernel/mutex.c
+++ linux-2.6/kernel/mutex.c
@@ -266,13 +266,8 @@ __mutex_lock_interruptible_nonatomic(str
  */
 int fastcall mutex_trylock(struct mutex *lock)
 {
-#ifdef __HAVE_ARCH_CMPXCHG
 	if (atomic_cmpxchg(&lock->count, 1, 0) == 1)
 		return 1;
-#else
-	if (atomic_dec_return(&lock->count) == 0)
-		return 1;
-#endif
 	return 0;
 }
 
@@ -316,13 +311,14 @@ static inline void __mutex_unlock_nonato
 	 * Waiters take care of themselves and stay in flight until
 	 * necessary.
 	 *
-	 * (in the xchg based implementation the fastpath has set the
+	 * (depending on the implementation the fastpath has set the
 	 *  count to 1 already, so we must not set it here, because we
 	 *  dont own the lock anymore. In the debug case we must set
 	 *  the lock inside the spinlock.)
 	 */
-#if !defined(CONFIG_MUTEX_XCHG_ALGORITHM) && !defined(CONFIG_DEBUG_MUTEXES)
-	atomic_set(&lock->count, 1);
+#if !defined(CONFIG_DEBUG_MUTEXES)
+	if (__mutex_slowpath_needs_unlock())
+		atomic_set(&lock->count, 1);
 #endif
 	spin_lock_mutex(&lock->wait_lock);
 #ifdef CONFIG_DEBUG_MUTEXES
@@ -349,21 +345,12 @@ static inline void __mutex_unlock_nonato
 static __sched void FASTCALL(__mutex_lock_noinline(atomic_t *lock_count));
 
 /*
- * Some architectures do not have fast dec_and_test atomic primitives,
- * for them we are providing an atomic_xchg() based mutex implementation,
- * if they enable CONFIG_MUTEX_XCHG_ALGORITHM.
- *
  * The locking fastpath is the 1->0 transition from 'unlocked' into
  * 'locked' state:
  */
 static inline void __mutex_lock_atomic(struct mutex *lock)
 {
-#ifdef CONFIG_MUTEX_XCHG_ALGORITHM
-	if (unlikely(atomic_xchg(&lock->count, 0) != 1))
-		__mutex_lock_noinline(&lock->count);
-#else
-	atomic_dec_call_if_negative(&lock->count, __mutex_lock_noinline);
-#endif
+	__mutex_fastpath_lock(&lock->count, __mutex_lock_noinline);
 }
 
 /*
@@ -383,16 +370,23 @@ static inline void __mutex_lock(struct m
 	__mutex_lock_atomic(lock);
 }
 
+static __sched int FASTCALL(__mutex_lock_interruptible_noinline(atomic_t *lock_count));
+
+static int __mutex_lock_interruptible_atomic(struct mutex *lock)
+{
+	__mutex_fastpath_lock_retval(&lock->count, __mutex_lock_interruptible_noinline);
+}
+
+static int fastcall __sched __mutex_lock_interruptible_noinline(atomic_t *lock_count)
+{
+	struct mutex *lock = container_of(lock_count, struct mutex, count);
+
+	return __mutex_lock_interruptible_nonatomic(lock);
+}
+
 static inline int __mutex_lock_interruptible(struct mutex *lock)
 {
-#ifdef CONFIG_MUTEX_XCHG_ALGORITHM
-	if (unlikely(atomic_xchg(&lock->count, 0) != 1))
-		return __mutex_lock_interruptible_nonatomic(lock);
-#else
-	if (unlikely(atomic_dec_return(&lock->count) < 0))
-		return __mutex_lock_interruptible_nonatomic(lock);
-#endif
-	return 0;
+	__mutex_lock_interruptible_atomic(lock);
 }
 
 static void __sched FASTCALL(__mutex_unlock_noinline(atomic_t *lock_count));
@@ -403,12 +397,7 @@ static void __sched FASTCALL(__mutex_unl
  */
 static inline void __mutex_unlock_atomic(struct mutex *lock)
 {
-#ifdef CONFIG_MUTEX_XCHG_ALGORITHM
-	if (unlikely(atomic_xchg(&lock->count, 1) != 0))
-		__mutex_unlock_noinline(&lock->count);
-#else
-	atomic_inc_call_if_nonpositive(&lock->count, __mutex_unlock_noinline);
-#endif
+	__mutex_fastpath_unlock(&lock->count, __mutex_unlock_noinline);
 }
 
 static void fastcall __sched __mutex_unlock_noinline(atomic_t *lock_count)
Index: linux-2.6/include/linux/mutex.h
===================================================================
--- linux-2.6.orig/include/linux/mutex.h
+++ linux-2.6/include/linux/mutex.h
@@ -12,6 +12,7 @@
  */
 #include <linux/list.h>
 #include <linux/spinlock_types.h>
+#include <asm/mutex.h>
 
 #include <asm/atomic.h>
 

  parent reply	other threads:[~2005-12-22 21:41 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-12-22 11:41 [patch 0/9] mutex subsystem, -V4 Ingo Molnar
2005-12-22 11:53 ` Christoph Hellwig
2005-12-22 12:45   ` Ingo Molnar
2005-12-22 15:34   ` Nicolas Pitre
2005-12-22 15:40     ` Ingo Molnar
2005-12-22 16:32       ` Nicolas Pitre
2005-12-22 16:44         ` Ingo Molnar
2005-12-22 16:58           ` Russell King
2005-12-22 21:04             ` Ingo Molnar
2005-12-22 21:26               ` Russell King
2005-12-22 21:27               ` Nicolas Pitre
2005-12-22 21:37                 ` [patch 1/2] mutex subsystem: basic per arch fast path primitives Nicolas Pitre
2005-12-22 21:53                   ` Christoph Hellwig
2005-12-22 21:40                 ` Nicolas Pitre [this message]
2005-12-22 21:54                 ` [patch 0/9] mutex subsystem, -V4 Ingo Molnar
2005-12-22 16:58           ` Nicolas Pitre
2005-12-22 17:20     ` Christoph Hellwig
2005-12-22 17:33     ` Steven Rostedt
2005-12-22 18:24       ` Nicolas Pitre
2005-12-22 11:54 ` Andrew Morton
2005-12-22 12:20   ` Ingo Molnar
2005-12-22 13:07     ` Andrew Morton
2005-12-22 13:23       ` Arjan van de Ven
2005-12-22 13:44         ` Andrew Morton
2005-12-22 14:11           ` Alan Cox
2005-12-22 23:30             ` Andrew Morton
2005-12-22 23:34               ` Christoph Hellwig
     [not found]                 ` <32801.10.10.10.28.1135295357.squirrel@linux1>
2005-12-22 23:49                   ` Sean
2005-12-22 23:53                     ` Randy.Dunlap
     [not found]                       ` <50572.10.10.10.28.1135296023.squirrel@linux1>
2005-12-23  0:00                         ` Sean
2005-12-23  0:00                       ` Steven Rostedt
     [not found]                 ` <20051222221311.2f6056ec.akpm@osdl.org>
2005-12-23 14:24                   ` Nicolas Pitre
2005-12-23 14:51                     ` Andrew Morton
2005-12-23 14:57                       ` Russell King
2005-12-23 15:04                         ` Xavier Bestel
2005-12-23 15:27                           ` Andrew Morton
2005-12-23 15:00                       ` Steven Rostedt
2006-01-03 17:54                       ` Abhijit Bhopatkar
2005-12-25 16:08                 ` Roman Zippel
2005-12-25 22:54                   ` Ingo Molnar
2005-12-26 21:49                     ` Roman Zippel
2005-12-25 23:04                   ` Andrew Morton
2005-12-25 23:22                     ` Ingo Molnar
2005-12-26 10:35                       ` Andrew Morton
2005-12-26 10:42                         ` Arjan van de Ven
2005-12-26 11:11                           ` Andrew Morton
2005-12-26 17:15                             ` Mike Galbraith
2005-12-26 17:44                               ` Lee Revell
2005-12-27  0:32                             ` David Lang
2005-12-26 18:15                           ` Linus Torvalds
2005-12-27 14:42                         ` Ingo Molnar
2005-12-27 23:02                           ` Andrew Morton
2005-12-26  0:33                     ` Moore's law (was Re: [patch 0/9] mutex subsystem, -V4) Pavel Machek
2006-01-05 15:30                       ` Andi Kleen
2006-01-05 19:08                         ` Pavel Machek
2005-12-26 15:29                     ` [patch 0/9] mutex subsystem, -V4 Nicolas Pitre
2005-12-22 15:46           ` Thomas Gleixner
2005-12-22 17:40             ` Linus Torvalds
2005-12-22 20:09               ` Steven Rostedt
2005-12-22 17:17           ` Christoph Hellwig
2005-12-22 15:19       ` Nicolas Pitre
2005-12-22 21:43       ` Paul Mackerras

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=Pine.LNX.4.64.0512221637570.26663@localhost.localdomain \
    --to=nico@cam.org \
    --cc=ak@suse.de \
    --cc=akpm@osdl.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=arjanv@infradead.org \
    --cc=bcrl@kvack.org \
    --cc=dhowells@redhat.com \
    --cc=hch@infradead.org \
    --cc=jes@trained-monkey.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=oleg@tv-sign.ru \
    --cc=rostedt@goodmis.org \
    --cc=torvalds@osdl.org \
    --cc=zwane@arm.linux.org.uk \
    /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®