Skip to contentSkip to conversation

locking/mutex: initialize osq lock in __MUTEX_INITIALIZER()

PATCH In review Nikitas Angelinas 2 participants 3 messages Mar 29, 2021 – Apr 14, 2021 Locking primitives

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 locking/mutex: initialize osq lock in __MUTEX_INITIALIZER()

Since __MUTEX_INITIALIZER() is used on memory that is initialized to 0 anyway this change should not have an effect, but it seems better to initialize osq explicitly for completeness, as done in other macros and functions that initialize mutex and rwsem.

---
 include/linux/mutex.h | 8 ++++++++
 1 file changed, 8 insertions(+)
include/linux/mutex.h +8 -0
index 515cff7..bff47f8 100644
@@ -129,10 +129,18 @@ do {									\
 # define __DEP_MAP_MUTEX_INITIALIZER(lockname)
 #endif
 
+#ifdef CONFIG_MUTEX_SPIN_ON_OWNER
+# define __OSQ_MUTEX_INITIALIZER(lockname)			\
+		, .osq = OSQ_LOCK_UNLOCKED
+#else
+# define __OSQ_MUTEX_INITIALIZER(lockname)
+#endif
+
 #define __MUTEX_INITIALIZER(lockname) \
 		{ .owner = ATOMIC_LONG_INIT(0) \
 		, .wait_lock = __SPIN_LOCK_UNLOCKED(lockname.wait_lock) \
 		, .wait_list = LIST_HEAD_INIT(lockname.wait_list) \
+		__OSQ_MUTEX_INITIALIZER(lockname) \
 		__DEBUG_MUTEX_INITIALIZER(lockname) \
 		__DEP_MAP_MUTEX_INITIALIZER(lockname) }
 
Signature · 1 line
2.10.0
maintainer
#1 lore raw
Quoted 20 lines · Nikitas Angelinas

Since __MUTEX_INITIALIZER() is used on memory that is initialized to 0 anyway this change should not have an effect, but it seems better to initialize osq explicitly for completeness, as done in other macros and functions that initialize mutex and rwsem.

---
 include/linux/mutex.h | 8 ++++++++
 1 file changed, 8 insertions(+)
include/linux/mutex.h +2 -0
index 515cff7..bff47f8 100644
@@ -129,10 +129,18 @@ do {									\
 # define __DEP_MAP_MUTEX_INITIALIZER(lockname)
 #endif
 
+#ifdef CONFIG_MUTEX_SPIN_ON_OWNER
+# define __OSQ_MUTEX_INITIALIZER(lockname)			\

include/linux/mutex.h do { \ · line 143

Quoted 10 lines
include/linux/mutex.h +6 -0
+		, .osq = OSQ_LOCK_UNLOCKED
+#else
+# define __OSQ_MUTEX_INITIALIZER(lockname)
+#endif
+
 #define __MUTEX_INITIALIZER(lockname) \
 		{ .owner = ATOMIC_LONG_INIT(0) \
 		, .wait_lock = __SPIN_LOCK_UNLOCKED(lockname.wait_lock) \
 		, .wait_list = LIST_HEAD_INIT(lockname.wait_list) \
+		__OSQ_MUTEX_INITIALIZER(lockname) \

You don't need the lockname parameter for this macro.

Will

#2 lore raw
Quoted 34 lines · Will Deacon
Quoted 20 lines · Nikitas Angelinas

Since __MUTEX_INITIALIZER() is used on memory that is initialized to 0 anyway this change should not have an effect, but it seems better to initialize osq explicitly for completeness, as done in other macros and functions that initialize mutex and rwsem.

---
 include/linux/mutex.h | 8 ++++++++
 1 file changed, 8 insertions(+)
include/linux/mutex.h +2 -0
index 515cff7..bff47f8 100644
@@ -129,10 +129,18 @@ do {									\
 # define __DEP_MAP_MUTEX_INITIALIZER(lockname)
 #endif
 
+#ifdef CONFIG_MUTEX_SPIN_ON_OWNER
+# define __OSQ_MUTEX_INITIALIZER(lockname)			\

include/linux/mutex.h do { \ · line 143

Quoted 10 lines
include/linux/mutex.h +6 -0
+		, .osq = OSQ_LOCK_UNLOCKED
+#else
+# define __OSQ_MUTEX_INITIALIZER(lockname)
+#endif
+
 #define __MUTEX_INITIALIZER(lockname) \
 		{ .owner = ATOMIC_LONG_INIT(0) \
 		, .wait_lock = __SPIN_LOCK_UNLOCKED(lockname.wait_lock) \
 		, .wait_list = LIST_HEAD_INIT(lockname.wait_list) \
+		__OSQ_MUTEX_INITIALIZER(lockname) \

You don't need the lockname parameter for this macro.

Quoted 1 line

Will

Hi,

Please excuse this late reply.

I included the unnecessary lockname parameter as the counterpart macro in __RWSEM_INITIALIZER(), __RWSEM_OPT_INIT() and also __RWSEM_COUNT_INIT() do the same thing, thinking that was done on purpose, e.g. so that all macros used take a parameter in order to satisfy some dubious notion of symmetry; I realize this is not a good reason, of course.

I'll send a v2, possibly in a series with changes to the aforementioned bits in rwsem, fwiw.

Cheers,
Nikitas