mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: linux-kernel@vger.kernel.org
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Maarten Lankhorst <maarten.lankhorst@canonical.com>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Subject: [PATCH 1/3] locking: ww_mutex: add one level of indirection for access of the lock
Date: Fri, 27 Feb 2015 17:57:07 +0100	[thread overview]
Message-ID: <1425056229-22326-2-git-send-email-bigeasy@linutronix.de> (raw)
In-Reply-To: <1425056229-22326-1-git-send-email-bigeasy@linutronix.de>

This level of indirection is one step towards replacing the "mutex" with
a different kind of locking mechanism.
The new functions of the form "__.*_lock" provide access to whatever is
hidden behind the "base" member in ww-mutex's struct

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 include/linux/ww_mutex.h | 48 ++++++++++++++++++++++++++++++++++++------
 lib/locking-selftest.c   | 54 ++++++++++++++++++++++++------------------------
 2 files changed, 69 insertions(+), 33 deletions(-)

diff --git a/include/linux/ww_mutex.h b/include/linux/ww_mutex.h
index 760399a470bd..6e5d5ee3138d 100644
--- a/include/linux/ww_mutex.h
+++ b/include/linux/ww_mutex.h
@@ -72,6 +72,42 @@ struct ww_mutex {
 #define DEFINE_WW_MUTEX(mutexname, ww_class) \
 	struct ww_mutex mutexname = __WW_MUTEX_INITIALIZER(mutexname, ww_class)
 
+static inline void __ww_mutex_init(struct mutex *lock,
+				   struct ww_class *ww_class)
+{
+	__mutex_init(lock, ww_class->mutex_name, &ww_class->mutex_key);
+}
+
+static inline void __ww_mutex_lock_lock(struct mutex *lock)
+{
+	mutex_lock(lock);
+}
+
+static inline int __ww_mutex_lock_interruptible_lock(struct mutex *lock)
+{
+	return mutex_lock_interruptible(lock);
+}
+
+static inline int __ww_mutex_trylock_lock(struct mutex *lock)
+{
+	return mutex_trylock(lock);
+}
+
+static inline void __ww_mutex_destroy_lock(struct mutex *lock)
+{
+	mutex_destroy(lock);
+}
+
+static inline bool __ww_mutex_is_locked_lock(struct mutex *lock)
+{
+	return mutex_is_locked(lock);
+}
+
+static inline void __ww_mutex_unlock_lock(struct mutex *lock)
+{
+	mutex_unlock(lock);
+}
+
 /**
  * ww_mutex_init - initialize the w/w mutex
  * @lock: the mutex to be initialized
@@ -85,7 +121,7 @@ struct ww_mutex {
 static inline void ww_mutex_init(struct ww_mutex *lock,
 				 struct ww_class *ww_class)
 {
-	__mutex_init(&lock->base, ww_class->mutex_name, &ww_class->mutex_key);
+	__ww_mutex_init(&lock->base, ww_class);
 	lock->ctx = NULL;
 #ifdef CONFIG_DEBUG_MUTEXES
 	lock->ww_class = ww_class;
@@ -225,7 +261,7 @@ static inline int ww_mutex_lock(struct ww_mutex *lock, struct ww_acquire_ctx *ct
 	if (ctx)
 		return __ww_mutex_lock(lock, ctx);
 
-	mutex_lock(&lock->base);
+	__ww_mutex_lock_lock(&lock->base);
 	return 0;
 }
 
@@ -265,7 +301,7 @@ static inline int __must_check ww_mutex_lock_interruptible(struct ww_mutex *lock
 	if (ctx)
 		return __ww_mutex_lock_interruptible(lock, ctx);
 	else
-		return mutex_lock_interruptible(&lock->base);
+		return __ww_mutex_lock_interruptible_lock(&lock->base);
 }
 
 /**
@@ -348,7 +384,7 @@ extern void ww_mutex_unlock(struct ww_mutex *lock);
  */
 static inline int __must_check ww_mutex_trylock(struct ww_mutex *lock)
 {
-	return mutex_trylock(&lock->base);
+	return __ww_mutex_trylock_lock(&lock->base);
 }
 
 /***
@@ -361,7 +397,7 @@ static inline int __must_check ww_mutex_trylock(struct ww_mutex *lock)
  */
 static inline void ww_mutex_destroy(struct ww_mutex *lock)
 {
-	mutex_destroy(&lock->base);
+	__ww_mutex_destroy_lock(&lock->base);
 }
 
 /**
@@ -372,7 +408,7 @@ static inline void ww_mutex_destroy(struct ww_mutex *lock)
  */
 static inline bool ww_mutex_is_locked(struct ww_mutex *lock)
 {
-	return mutex_is_locked(&lock->base);
+	return __ww_mutex_is_locked_lock(&lock->base);
 }
 
 #endif
diff --git a/lib/locking-selftest.c b/lib/locking-selftest.c
index 872a15a2a637..2c35e38b4013 100644
--- a/lib/locking-selftest.c
+++ b/lib/locking-selftest.c
@@ -1179,15 +1179,15 @@ static void ww_test_normal(void)
 
 	/* mutex_lock (and indirectly, mutex_lock_nested) */
 	o.ctx = (void *)~0UL;
-	mutex_lock(&o.base);
-	mutex_unlock(&o.base);
+	__ww_mutex_lock_lock(&o.base);
+	__ww_mutex_unlock_lock(&o.base);
 	WARN_ON(o.ctx != (void *)~0UL);
 
 	/* mutex_lock_interruptible (and *_nested) */
 	o.ctx = (void *)~0UL;
-	ret = mutex_lock_interruptible(&o.base);
+	ret = __ww_mutex_lock_interruptible_lock(&o.base);
 	if (!ret)
-		mutex_unlock(&o.base);
+		__ww_mutex_unlock_lock(&o.base);
 	else
 		WARN_ON(1);
 	WARN_ON(o.ctx != (void *)~0UL);
@@ -1196,33 +1196,33 @@ static void ww_test_normal(void)
 	o.ctx = (void *)~0UL;
 	ret = mutex_lock_killable(&o.base);
 	if (!ret)
-		mutex_unlock(&o.base);
+		__ww_mutex_unlock_lock(&o.base);
 	else
 		WARN_ON(1);
 	WARN_ON(o.ctx != (void *)~0UL);
 
 	/* trylock, succeeding */
 	o.ctx = (void *)~0UL;
-	ret = mutex_trylock(&o.base);
+	ret = __ww_mutex_trylock_lock(&o.base);
 	WARN_ON(!ret);
 	if (ret)
-		mutex_unlock(&o.base);
+		__ww_mutex_unlock_lock(&o.base);
 	else
 		WARN_ON(1);
 	WARN_ON(o.ctx != (void *)~0UL);
 
 	/* trylock, failing */
 	o.ctx = (void *)~0UL;
-	mutex_lock(&o.base);
-	ret = mutex_trylock(&o.base);
+	__ww_mutex_lock_lock(&o.base);
+	ret = __ww_mutex_trylock_lock(&o.base);
 	WARN_ON(ret);
-	mutex_unlock(&o.base);
+	__ww_mutex_unlock_lock(&o.base);
 	WARN_ON(o.ctx != (void *)~0UL);
 
 	/* nest_lock */
 	o.ctx = (void *)~0UL;
 	mutex_lock_nest_lock(&o.base, &t);
-	mutex_unlock(&o.base);
+	__ww_mutex_unlock_lock(&o.base);
 	WARN_ON(o.ctx != (void *)~0UL);
 }
 
@@ -1299,7 +1299,7 @@ static void ww_test_edeadlk_normal(void)
 {
 	int ret;
 
-	mutex_lock(&o2.base);
+	__ww_mutex_lock_lock(&o2.base);
 	o2.ctx = &t2;
 	mutex_release(&o2.base.dep_map, 1, _THIS_IP_);
 
@@ -1315,7 +1315,7 @@ static void ww_test_edeadlk_normal(void)
 
 	o2.ctx = NULL;
 	mutex_acquire(&o2.base.dep_map, 0, 1, _THIS_IP_);
-	mutex_unlock(&o2.base);
+	__ww_mutex_unlock_lock(&o2.base);
 	WWU(&o);
 
 	WWL(&o2, &t);
@@ -1325,7 +1325,7 @@ static void ww_test_edeadlk_normal_slow(void)
 {
 	int ret;
 
-	mutex_lock(&o2.base);
+	__ww_mutex_lock_lock(&o2.base);
 	mutex_release(&o2.base.dep_map, 1, _THIS_IP_);
 	o2.ctx = &t2;
 
@@ -1341,7 +1341,7 @@ static void ww_test_edeadlk_normal_slow(void)
 
 	o2.ctx = NULL;
 	mutex_acquire(&o2.base.dep_map, 0, 1, _THIS_IP_);
-	mutex_unlock(&o2.base);
+	__ww_mutex_unlock_lock(&o2.base);
 	WWU(&o);
 
 	ww_mutex_lock_slow(&o2, &t);
@@ -1351,7 +1351,7 @@ static void ww_test_edeadlk_no_unlock(void)
 {
 	int ret;
 
-	mutex_lock(&o2.base);
+	__ww_mutex_lock_lock(&o2.base);
 	o2.ctx = &t2;
 	mutex_release(&o2.base.dep_map, 1, _THIS_IP_);
 
@@ -1367,7 +1367,7 @@ static void ww_test_edeadlk_no_unlock(void)
 
 	o2.ctx = NULL;
 	mutex_acquire(&o2.base.dep_map, 0, 1, _THIS_IP_);
-	mutex_unlock(&o2.base);
+	__ww_mutex_unlock_lock(&o2.base);
 
 	WWL(&o2, &t);
 }
@@ -1376,7 +1376,7 @@ static void ww_test_edeadlk_no_unlock_slow(void)
 {
 	int ret;
 
-	mutex_lock(&o2.base);
+	__ww_mutex_lock_lock(&o2.base);
 	mutex_release(&o2.base.dep_map, 1, _THIS_IP_);
 	o2.ctx = &t2;
 
@@ -1392,7 +1392,7 @@ static void ww_test_edeadlk_no_unlock_slow(void)
 
 	o2.ctx = NULL;
 	mutex_acquire(&o2.base.dep_map, 0, 1, _THIS_IP_);
-	mutex_unlock(&o2.base);
+	__ww_mutex_unlock_lock(&o2.base);
 
 	ww_mutex_lock_slow(&o2, &t);
 }
@@ -1401,7 +1401,7 @@ static void ww_test_edeadlk_acquire_more(void)
 {
 	int ret;
 
-	mutex_lock(&o2.base);
+	__ww_mutex_lock_lock(&o2.base);
 	mutex_release(&o2.base.dep_map, 1, _THIS_IP_);
 	o2.ctx = &t2;
 
@@ -1422,7 +1422,7 @@ static void ww_test_edeadlk_acquire_more_slow(void)
 {
 	int ret;
 
-	mutex_lock(&o2.base);
+	__ww_mutex_lock_lock(&o2.base);
 	mutex_release(&o2.base.dep_map, 1, _THIS_IP_);
 	o2.ctx = &t2;
 
@@ -1443,11 +1443,11 @@ static void ww_test_edeadlk_acquire_more_edeadlk(void)
 {
 	int ret;
 
-	mutex_lock(&o2.base);
+	__ww_mutex_lock_lock(&o2.base);
 	mutex_release(&o2.base.dep_map, 1, _THIS_IP_);
 	o2.ctx = &t2;
 
-	mutex_lock(&o3.base);
+	__ww_mutex_lock_lock(&o3.base);
 	mutex_release(&o3.base.dep_map, 1, _THIS_IP_);
 	o3.ctx = &t2;
 
@@ -1469,11 +1469,11 @@ static void ww_test_edeadlk_acquire_more_edeadlk_slow(void)
 {
 	int ret;
 
-	mutex_lock(&o2.base);
+	__ww_mutex_lock_lock(&o2.base);
 	mutex_release(&o2.base.dep_map, 1, _THIS_IP_);
 	o2.ctx = &t2;
 
-	mutex_lock(&o3.base);
+	__ww_mutex_lock_lock(&o3.base);
 	mutex_release(&o3.base.dep_map, 1, _THIS_IP_);
 	o3.ctx = &t2;
 
@@ -1494,7 +1494,7 @@ static void ww_test_edeadlk_acquire_wrong(void)
 {
 	int ret;
 
-	mutex_lock(&o2.base);
+	__ww_mutex_lock_lock(&o2.base);
 	mutex_release(&o2.base.dep_map, 1, _THIS_IP_);
 	o2.ctx = &t2;
 
@@ -1519,7 +1519,7 @@ static void ww_test_edeadlk_acquire_wrong_slow(void)
 {
 	int ret;
 
-	mutex_lock(&o2.base);
+	__ww_mutex_lock_lock(&o2.base);
 	mutex_release(&o2.base.dep_map, 1, _THIS_IP_);
 	o2.ctx = &t2;
 
-- 
2.1.4


  reply	other threads:[~2015-02-27 16:57 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-27 16:57 rt_mutex based ww_mutex implementation Sebastian Andrzej Siewior
2015-02-27 16:57 ` Sebastian Andrzej Siewior [this message]
2015-02-27 18:20   ` [PATCH 1/3] locking: ww_mutex: add one level of indirection for access of the lock Maarten Lankhorst
2015-02-27 18:57     ` Sebastian Andrzej Siewior
2015-02-27 16:57 ` [PATCH 2/3] locking: ww_mutex: Allow to use rt_mutex instead of mutex for the baselock Sebastian Andrzej Siewior
2015-03-02  3:20   ` Mike Galbraith
2015-03-02  8:46     ` Maarten Lankhorst
2015-03-02 12:50       ` Mike Galbraith
2015-03-06 12:14       ` Sebastian Andrzej Siewior
2015-03-06 12:16         ` Maarten Lankhorst
2015-03-06 12:36           ` Sebastian Andrzej Siewior
2015-03-06 17:50             ` Mike Galbraith
2015-03-09 10:00               ` Sebastian Andrzej Siewior
2015-03-09 10:51                 ` Mike Galbraith
2015-03-09 11:07                   ` Sebastian Andrzej Siewior
2015-03-09 11:29                     ` Mike Galbraith
2015-03-09 13:21                       ` Sebastian Andrzej Siewior
2015-03-09 22:27                         ` Paul E. McKenney
2015-03-10 12:30   ` Peter Zijlstra
2015-03-10 12:37   ` Peter Zijlstra
2015-03-10 12:39     ` Peter Zijlstra
2015-03-10 14:10     ` Maarten Lankhorst
2015-03-10 15:28       ` Peter Zijlstra
2015-03-10 18:21         ` Maarten Lankhorst
2015-03-10 12:43   ` Peter Zijlstra
2015-03-10 12:46   ` Peter Zijlstra
2015-02-27 16:57 ` [PATCH 3/3] locking: rtmutex: set state back to running on error Sebastian Andrzej Siewior
2015-02-28 10:00   ` [tip:locking/urgent] locking/rtmutex: Set " tip-bot for Sebastian Andrzej Siewior
2015-03-01  5:35   ` [PATCH 3/3] locking: rtmutex: set " Mike Galbraith
2015-03-01  8:48   ` [tip:locking/urgent] locking/rtmutex: Set " tip-bot for Sebastian Andrzej Siewior

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=1425056229-22326-2-git-send-email-bigeasy@linutronix.de \
    --to=bigeasy@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@canonical.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    /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®