[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1425056229-22326-2-git-send-email-bigeasy@linutronix.de>
Date: Fri, 27 Feb 2015 17:57:07 +0100
From: Sebastian Andrzej Siewior <bigeasy@...utronix.de>
To: linux-kernel@...r.kernel.org
Cc: Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>,
Maarten Lankhorst <maarten.lankhorst@...onical.com>,
Sebastian Andrzej Siewior <bigeasy@...utronix.de>
Subject: [PATCH 1/3] locking: ww_mutex: add one level of indirection for access of the lock
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@...utronix.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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists