All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/4] locking: Some locking code cleanups
@ 2024-02-22 15:05 Waiman Long
  2024-02-22 15:05 ` [PATCH v2 1/4] locking/qspinlock: Fix 'wait_early' set but not used warning Waiman Long
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Waiman Long @ 2024-02-22 15:05 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Will Deacon, Boqun Feng,
	Andrew Morton
  Cc: linux-kernel, George Stark, Waiman Long

 v2:
  - Add Boqun's "Reviewed-by" tags & twist the mutex patch as suggested
    by him.

This series contains a number of cleanup locking patches.

Waiman Long (4):
  locking/qspinlock: Fix 'wait_early' set but not used warning
  locking/mutex: Clean up mutex.h
  locking/rwsem: Clarify that RWSEM_READER_OWNED is just a hint
  locking/rwsem: Make DEBUG_RWSEMS and PREEMPT_RT mutually exclusive

 include/linux/mutex.h               | 8 ++------
 kernel/locking/qspinlock_paravirt.h | 2 +-
 kernel/locking/rwsem.c              | 6 +++---
 lib/Kconfig.debug                   | 4 ++--
 4 files changed, 8 insertions(+), 12 deletions(-)

-- 
2.39.3


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v2 1/4] locking/qspinlock: Fix 'wait_early' set but not used warning
  2024-02-22 15:05 [PATCH v2 0/4] locking: Some locking code cleanups Waiman Long
@ 2024-02-22 15:05 ` Waiman Long
  2024-02-28 12:53   ` [tip: locking/core] " tip-bot2 for Waiman Long
  2024-02-22 15:05 ` [PATCH v2 2/4] locking/mutex: Clean up mutex.h Waiman Long
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 11+ messages in thread
From: Waiman Long @ 2024-02-22 15:05 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Will Deacon, Boqun Feng,
	Andrew Morton
  Cc: linux-kernel, George Stark, Waiman Long, kernel test robot

When CONFIG_LOCK_EVENT_COUNTS is off, the wait_early variable will be
set but not used. This is expected. Recent compilers will not generate
wait_early code in this case.

Add the __maybe_unused attribute to wait_early for suppressing this
W=1 warning.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202312260422.f4pK3f9m-lkp@intel.com/
Signed-off-by: Waiman Long <longman@redhat.com>
Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
---
 kernel/locking/qspinlock_paravirt.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/locking/qspinlock_paravirt.h b/kernel/locking/qspinlock_paravirt.h
index 6a0184e9c234..ae2b12f68b90 100644
--- a/kernel/locking/qspinlock_paravirt.h
+++ b/kernel/locking/qspinlock_paravirt.h
@@ -294,8 +294,8 @@ static void pv_wait_node(struct mcs_spinlock *node, struct mcs_spinlock *prev)
 {
 	struct pv_node *pn = (struct pv_node *)node;
 	struct pv_node *pp = (struct pv_node *)prev;
+	bool __maybe_unused wait_early;
 	int loop;
-	bool wait_early;
 
 	for (;;) {
 		for (wait_early = false, loop = SPIN_THRESHOLD; loop; loop--) {
-- 
2.39.3


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 2/4] locking/mutex: Clean up mutex.h
  2024-02-22 15:05 [PATCH v2 0/4] locking: Some locking code cleanups Waiman Long
  2024-02-22 15:05 ` [PATCH v2 1/4] locking/qspinlock: Fix 'wait_early' set but not used warning Waiman Long
@ 2024-02-22 15:05 ` Waiman Long
  2024-02-28 12:53   ` [tip: locking/core] locking/mutex: Simplify <linux/mutex.h> tip-bot2 for Waiman Long
  2024-02-22 15:05 ` [PATCH v2 3/4] locking/rwsem: Clarify that RWSEM_READER_OWNED is just a hint Waiman Long
  2024-02-22 15:05 ` [PATCH v2 4/4] locking/rwsem: Make DEBUG_RWSEMS and PREEMPT_RT mutually exclusive Waiman Long
  3 siblings, 1 reply; 11+ messages in thread
From: Waiman Long @ 2024-02-22 15:05 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Will Deacon, Boqun Feng,
	Andrew Morton
  Cc: linux-kernel, George Stark, Waiman Long

CONFIG_DEBUG_MUTEXES and CONFIG_PREEMPT_RT are mutually exclusive. They
can't be both set at the same time.  Move up the mutex_destroy() function
declaration and the __DEBUG_MUTEX_INITIALIZER() macro above the "#ifndef
CONFIG_PREEMPT_RT" section to eliminate duplicated mutex_destroy()
declaration.

Also remove the duplicated mutex_trylock() function declaration in the
CONFIG_PREEMPT_RT section.

Signed-off-by: Waiman Long <longman@redhat.com>
Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
---
 include/linux/mutex.h | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/include/linux/mutex.h b/include/linux/mutex.h
index 7e208d46ba5b..67edc4ca2bee 100644
--- a/include/linux/mutex.h
+++ b/include/linux/mutex.h
@@ -32,11 +32,9 @@
 # define __DEP_MAP_MUTEX_INITIALIZER(lockname)
 #endif
 
-#ifndef CONFIG_PREEMPT_RT
-
 #ifdef CONFIG_DEBUG_MUTEXES
 
-#define __DEBUG_MUTEX_INITIALIZER(lockname)				\
+# define __DEBUG_MUTEX_INITIALIZER(lockname)				\
 	, .magic = &lockname
 
 extern void mutex_destroy(struct mutex *lock);
@@ -49,6 +47,7 @@ static inline void mutex_destroy(struct mutex *lock) {}
 
 #endif
 
+#ifndef CONFIG_PREEMPT_RT
 /**
  * mutex_init - initialize the mutex
  * @mutex: the mutex to be initialized
@@ -101,9 +100,6 @@ extern bool mutex_is_locked(struct mutex *lock);
 
 extern void __mutex_rt_init(struct mutex *lock, const char *name,
 			    struct lock_class_key *key);
-extern int mutex_trylock(struct mutex *lock);
-
-static inline void mutex_destroy(struct mutex *lock) { }
 
 #define mutex_is_locked(l)	rt_mutex_base_is_locked(&(l)->rtmutex)
 
-- 
2.39.3


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 3/4] locking/rwsem: Clarify that RWSEM_READER_OWNED is just a hint
  2024-02-22 15:05 [PATCH v2 0/4] locking: Some locking code cleanups Waiman Long
  2024-02-22 15:05 ` [PATCH v2 1/4] locking/qspinlock: Fix 'wait_early' set but not used warning Waiman Long
  2024-02-22 15:05 ` [PATCH v2 2/4] locking/mutex: Clean up mutex.h Waiman Long
@ 2024-02-22 15:05 ` Waiman Long
  2024-02-28 12:53   ` [tip: locking/core] " tip-bot2 for Waiman Long
  2024-02-22 15:05 ` [PATCH v2 4/4] locking/rwsem: Make DEBUG_RWSEMS and PREEMPT_RT mutually exclusive Waiman Long
  3 siblings, 1 reply; 11+ messages in thread
From: Waiman Long @ 2024-02-22 15:05 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Will Deacon, Boqun Feng,
	Andrew Morton
  Cc: linux-kernel, George Stark, Waiman Long

Clarify in the comments that the RWSEM_READER_OWNED bit in the owner
field is just a hint, not an authoritative state of the rwsem.

Signed-off-by: Waiman Long <longman@redhat.com>
Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
---
 kernel/locking/rwsem.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c
index 2340b6d90ec6..c6d17aee4209 100644
--- a/kernel/locking/rwsem.c
+++ b/kernel/locking/rwsem.c
@@ -35,7 +35,7 @@
 /*
  * The least significant 2 bits of the owner value has the following
  * meanings when set.
- *  - Bit 0: RWSEM_READER_OWNED - The rwsem is owned by readers
+ *  - Bit 0: RWSEM_READER_OWNED - rwsem may be owned by readers (just a hint)
  *  - Bit 1: RWSEM_NONSPINNABLE - Cannot spin on a reader-owned lock
  *
  * When the rwsem is reader-owned and a spinning writer has timed out,
@@ -1002,8 +1002,8 @@ rwsem_down_read_slowpath(struct rw_semaphore *sem, long count, unsigned int stat
 
 	/*
 	 * To prevent a constant stream of readers from starving a sleeping
-	 * waiter, don't attempt optimistic lock stealing if the lock is
-	 * currently owned by readers.
+	 * writer, don't attempt optimistic lock stealing if the lock is
+	 * very likely owned by readers.
 	 */
 	if ((atomic_long_read(&sem->owner) & RWSEM_READER_OWNED) &&
 	    (rcnt > 1) && !(count & RWSEM_WRITER_LOCKED))
-- 
2.39.3


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 4/4] locking/rwsem: Make DEBUG_RWSEMS and PREEMPT_RT mutually exclusive
  2024-02-22 15:05 [PATCH v2 0/4] locking: Some locking code cleanups Waiman Long
                   ` (2 preceding siblings ...)
  2024-02-22 15:05 ` [PATCH v2 3/4] locking/rwsem: Clarify that RWSEM_READER_OWNED is just a hint Waiman Long
@ 2024-02-22 15:05 ` Waiman Long
  2024-02-28 12:53   ` [tip: locking/core] " tip-bot2 for Waiman Long
  3 siblings, 1 reply; 11+ messages in thread
From: Waiman Long @ 2024-02-22 15:05 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Will Deacon, Boqun Feng,
	Andrew Morton
  Cc: linux-kernel, George Stark, Waiman Long

The debugging code enabled by CONFIG_DEBUG_RWSEMS will only be
compiled in when CONFIG_PREEMPT_RT isn't set. There is no point to
allow CONFIG_DEBUG_RWSEMS to be set in a kernel configuration where
CONFIG_PREEMPT_RT is also set. Make them mutually exclusive.

Signed-off-by: Waiman Long <longman@redhat.com>
Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
---
 lib/Kconfig.debug | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 975a07f9f1cc..cb695bc76d30 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1303,7 +1303,7 @@ config PROVE_LOCKING
 	select DEBUG_SPINLOCK
 	select DEBUG_MUTEXES if !PREEMPT_RT
 	select DEBUG_RT_MUTEXES if RT_MUTEXES
-	select DEBUG_RWSEMS
+	select DEBUG_RWSEMS if !PREEMPT_RT
 	select DEBUG_WW_MUTEX_SLOWPATH
 	select DEBUG_LOCK_ALLOC
 	select PREEMPT_COUNT if !ARCH_NO_PREEMPT
@@ -1426,7 +1426,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
 
 config DEBUG_RWSEMS
 	bool "RW Semaphore debugging: basic checks"
-	depends on DEBUG_KERNEL
+	depends on DEBUG_KERNEL && !PREEMPT_RT
 	help
 	  This debugging feature allows mismatched rw semaphore locks
 	  and unlocks to be detected and reported.
-- 
2.39.3


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [tip: locking/core] locking/rwsem: Make DEBUG_RWSEMS and PREEMPT_RT mutually exclusive
  2024-02-22 15:05 ` [PATCH v2 4/4] locking/rwsem: Make DEBUG_RWSEMS and PREEMPT_RT mutually exclusive Waiman Long
@ 2024-02-28 12:53   ` tip-bot2 for Waiman Long
  0 siblings, 0 replies; 11+ messages in thread
From: tip-bot2 for Waiman Long @ 2024-02-28 12:53 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Waiman Long, Ingo Molnar, Boqun Feng, Thomas Gleixner, x86,
	linux-kernel

The following commit has been merged into the locking/core branch of tip:

Commit-ID:     f22f71322a18e90e127f2fc2c11cc2d5191bc4c6
Gitweb:        https://git.kernel.org/tip/f22f71322a18e90e127f2fc2c11cc2d5191bc4c6
Author:        Waiman Long <longman@redhat.com>
AuthorDate:    Thu, 22 Feb 2024 10:05:40 -05:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Wed, 28 Feb 2024 13:08:38 +01:00

locking/rwsem: Make DEBUG_RWSEMS and PREEMPT_RT mutually exclusive

The debugging code enabled by CONFIG_DEBUG_RWSEMS=y will only be
compiled in when CONFIG_PREEMPT_RT isn't set. There is no point to
allow CONFIG_DEBUG_RWSEMS to be set in a kernel configuration where
CONFIG_PREEMPT_RT is also set. Make them mutually exclusive.

Signed-off-by: Waiman Long <longman@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20240222150540.79981-5-longman@redhat.com
---
 lib/Kconfig.debug | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 975a07f..cb695bc 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1303,7 +1303,7 @@ config PROVE_LOCKING
 	select DEBUG_SPINLOCK
 	select DEBUG_MUTEXES if !PREEMPT_RT
 	select DEBUG_RT_MUTEXES if RT_MUTEXES
-	select DEBUG_RWSEMS
+	select DEBUG_RWSEMS if !PREEMPT_RT
 	select DEBUG_WW_MUTEX_SLOWPATH
 	select DEBUG_LOCK_ALLOC
 	select PREEMPT_COUNT if !ARCH_NO_PREEMPT
@@ -1426,7 +1426,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
 
 config DEBUG_RWSEMS
 	bool "RW Semaphore debugging: basic checks"
-	depends on DEBUG_KERNEL
+	depends on DEBUG_KERNEL && !PREEMPT_RT
 	help
 	  This debugging feature allows mismatched rw semaphore locks
 	  and unlocks to be detected and reported.

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [tip: locking/core] locking/rwsem: Clarify that RWSEM_READER_OWNED is just a hint
  2024-02-22 15:05 ` [PATCH v2 3/4] locking/rwsem: Clarify that RWSEM_READER_OWNED is just a hint Waiman Long
@ 2024-02-28 12:53   ` tip-bot2 for Waiman Long
  0 siblings, 0 replies; 11+ messages in thread
From: tip-bot2 for Waiman Long @ 2024-02-28 12:53 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Waiman Long, Ingo Molnar, Boqun Feng, x86, linux-kernel

The following commit has been merged into the locking/core branch of tip:

Commit-ID:     d566c78659eccf085f905fd266fc461de92eaa8f
Gitweb:        https://git.kernel.org/tip/d566c78659eccf085f905fd266fc461de92eaa8f
Author:        Waiman Long <longman@redhat.com>
AuthorDate:    Thu, 22 Feb 2024 10:05:39 -05:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Wed, 28 Feb 2024 13:08:38 +01:00

locking/rwsem: Clarify that RWSEM_READER_OWNED is just a hint

Clarify in the comments that the RWSEM_READER_OWNED bit in the owner
field is just a hint, not an authoritative state of the rwsem.

Signed-off-by: Waiman Long <longman@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20240222150540.79981-4-longman@redhat.com
---
 kernel/locking/rwsem.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c
index 2340b6d..c6d17ae 100644
--- a/kernel/locking/rwsem.c
+++ b/kernel/locking/rwsem.c
@@ -35,7 +35,7 @@
 /*
  * The least significant 2 bits of the owner value has the following
  * meanings when set.
- *  - Bit 0: RWSEM_READER_OWNED - The rwsem is owned by readers
+ *  - Bit 0: RWSEM_READER_OWNED - rwsem may be owned by readers (just a hint)
  *  - Bit 1: RWSEM_NONSPINNABLE - Cannot spin on a reader-owned lock
  *
  * When the rwsem is reader-owned and a spinning writer has timed out,
@@ -1002,8 +1002,8 @@ rwsem_down_read_slowpath(struct rw_semaphore *sem, long count, unsigned int stat
 
 	/*
 	 * To prevent a constant stream of readers from starving a sleeping
-	 * waiter, don't attempt optimistic lock stealing if the lock is
-	 * currently owned by readers.
+	 * writer, don't attempt optimistic lock stealing if the lock is
+	 * very likely owned by readers.
 	 */
 	if ((atomic_long_read(&sem->owner) & RWSEM_READER_OWNED) &&
 	    (rcnt > 1) && !(count & RWSEM_WRITER_LOCKED))

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [tip: locking/core] locking/mutex: Simplify <linux/mutex.h>
  2024-02-22 15:05 ` [PATCH v2 2/4] locking/mutex: Clean up mutex.h Waiman Long
@ 2024-02-28 12:53   ` tip-bot2 for Waiman Long
  0 siblings, 0 replies; 11+ messages in thread
From: tip-bot2 for Waiman Long @ 2024-02-28 12:53 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Waiman Long, Ingo Molnar, Boqun Feng, x86, linux-kernel

The following commit has been merged into the locking/core branch of tip:

Commit-ID:     d6cac0b6b0115fd0a5f51a49401473626e4e4fe7
Gitweb:        https://git.kernel.org/tip/d6cac0b6b0115fd0a5f51a49401473626e4e4fe7
Author:        Waiman Long <longman@redhat.com>
AuthorDate:    Thu, 22 Feb 2024 10:05:38 -05:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Wed, 28 Feb 2024 13:08:37 +01:00

locking/mutex: Simplify <linux/mutex.h>

CONFIG_DEBUG_MUTEXES and CONFIG_PREEMPT_RT are mutually exclusive. They
can't be both set at the same time.  Move up the mutex_destroy() function
declaration and the __DEBUG_MUTEX_INITIALIZER() macro above the "#ifndef
CONFIG_PREEMPT_RT" section to eliminate duplicated mutex_destroy()
declaration.

Also remove the duplicated mutex_trylock() function declaration in the
CONFIG_PREEMPT_RT section.

Signed-off-by: Waiman Long <longman@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20240222150540.79981-3-longman@redhat.com
---
 include/linux/mutex.h | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/include/linux/mutex.h b/include/linux/mutex.h
index 7e208d4..67edc4c 100644
--- a/include/linux/mutex.h
+++ b/include/linux/mutex.h
@@ -32,11 +32,9 @@
 # define __DEP_MAP_MUTEX_INITIALIZER(lockname)
 #endif
 
-#ifndef CONFIG_PREEMPT_RT
-
 #ifdef CONFIG_DEBUG_MUTEXES
 
-#define __DEBUG_MUTEX_INITIALIZER(lockname)				\
+# define __DEBUG_MUTEX_INITIALIZER(lockname)				\
 	, .magic = &lockname
 
 extern void mutex_destroy(struct mutex *lock);
@@ -49,6 +47,7 @@ static inline void mutex_destroy(struct mutex *lock) {}
 
 #endif
 
+#ifndef CONFIG_PREEMPT_RT
 /**
  * mutex_init - initialize the mutex
  * @mutex: the mutex to be initialized
@@ -101,9 +100,6 @@ extern bool mutex_is_locked(struct mutex *lock);
 
 extern void __mutex_rt_init(struct mutex *lock, const char *name,
 			    struct lock_class_key *key);
-extern int mutex_trylock(struct mutex *lock);
-
-static inline void mutex_destroy(struct mutex *lock) { }
 
 #define mutex_is_locked(l)	rt_mutex_base_is_locked(&(l)->rtmutex)
 

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [tip: locking/core] locking/qspinlock: Fix 'wait_early' set but not used warning
  2024-02-22 15:05 ` [PATCH v2 1/4] locking/qspinlock: Fix 'wait_early' set but not used warning Waiman Long
@ 2024-02-28 12:53   ` tip-bot2 for Waiman Long
  2024-03-11 10:57     ` Ingo Molnar
  0 siblings, 1 reply; 11+ messages in thread
From: tip-bot2 for Waiman Long @ 2024-02-28 12:53 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: kernel test robot, Waiman Long, Ingo Molnar, Boqun Feng,
	Linus Torvalds, x86, linux-kernel

The following commit has been merged into the locking/core branch of tip:

Commit-ID:     ca4bc2e07b716509fd279d2b449bb42f4263a9c8
Gitweb:        https://git.kernel.org/tip/ca4bc2e07b716509fd279d2b449bb42f4263a9c8
Author:        Waiman Long <longman@redhat.com>
AuthorDate:    Thu, 22 Feb 2024 10:05:37 -05:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Wed, 28 Feb 2024 13:08:37 +01:00

locking/qspinlock: Fix 'wait_early' set but not used warning

When CONFIG_LOCK_EVENT_COUNTS is off, the wait_early variable will be
set but not used. This is expected. Recent compilers will not generate
wait_early code in this case.

Add the __maybe_unused attribute to wait_early for suppressing this
W=1 warning.

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Waiman Long <longman@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20240222150540.79981-2-longman@redhat.com

Closes: https://lore.kernel.org/oe-kbuild-all/202312260422.f4pK3f9m-lkp@intel.com/
---
 kernel/locking/qspinlock_paravirt.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/locking/qspinlock_paravirt.h b/kernel/locking/qspinlock_paravirt.h
index 6a0184e..ae2b12f 100644
--- a/kernel/locking/qspinlock_paravirt.h
+++ b/kernel/locking/qspinlock_paravirt.h
@@ -294,8 +294,8 @@ static void pv_wait_node(struct mcs_spinlock *node, struct mcs_spinlock *prev)
 {
 	struct pv_node *pn = (struct pv_node *)node;
 	struct pv_node *pp = (struct pv_node *)prev;
+	bool __maybe_unused wait_early;
 	int loop;
-	bool wait_early;
 
 	for (;;) {
 		for (wait_early = false, loop = SPIN_THRESHOLD; loop; loop--) {

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [tip: locking/core] locking/qspinlock: Fix 'wait_early' set but not used warning
  2024-02-28 12:53   ` [tip: locking/core] " tip-bot2 for Waiman Long
@ 2024-03-11 10:57     ` Ingo Molnar
  2024-03-11 13:45       ` Waiman Long
  0 siblings, 1 reply; 11+ messages in thread
From: Ingo Molnar @ 2024-03-11 10:57 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-tip-commits, kernel test robot, Waiman Long, Boqun Feng,
	Linus Torvalds, x86


* tip-bot2 for Waiman Long <tip-bot2@linutronix.de> wrote:

> The following commit has been merged into the locking/core branch of tip:
> 
> Commit-ID:     ca4bc2e07b716509fd279d2b449bb42f4263a9c8
> Gitweb:        https://git.kernel.org/tip/ca4bc2e07b716509fd279d2b449bb42f4263a9c8
> Author:        Waiman Long <longman@redhat.com>
> AuthorDate:    Thu, 22 Feb 2024 10:05:37 -05:00
> Committer:     Ingo Molnar <mingo@kernel.org>
> CommitterDate: Wed, 28 Feb 2024 13:08:37 +01:00
> 
> locking/qspinlock: Fix 'wait_early' set but not used warning
> 
> When CONFIG_LOCK_EVENT_COUNTS is off, the wait_early variable will be
> set but not used. This is expected. Recent compilers will not generate
> wait_early code in this case.
> 
> Add the __maybe_unused attribute to wait_early for suppressing this
> W=1 warning.
> 
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Waiman Long <longman@redhat.com>
> Signed-off-by: Ingo Molnar <mingo@kernel.org>
> Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
> Cc: Linus Torvalds <torvalds@linux-foundation.org>
> Link: https://lore.kernel.org/r/20240222150540.79981-2-longman@redhat.com
> 
> Closes: https://lore.kernel.org/oe-kbuild-all/202312260422.f4pK3f9m-lkp@intel.com/
> ---
>  kernel/locking/qspinlock_paravirt.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/locking/qspinlock_paravirt.h b/kernel/locking/qspinlock_paravirt.h
> index 6a0184e..ae2b12f 100644
> --- a/kernel/locking/qspinlock_paravirt.h
> +++ b/kernel/locking/qspinlock_paravirt.h
> @@ -294,8 +294,8 @@ static void pv_wait_node(struct mcs_spinlock *node, struct mcs_spinlock *prev)
>  {
>  	struct pv_node *pn = (struct pv_node *)node;
>  	struct pv_node *pp = (struct pv_node *)prev;
> +	bool __maybe_unused wait_early;
>  	int loop;
> -	bool wait_early;

On a second thought, shouldn't this be solved via lockevent_cond_inc()'s
!CONFIG_LOCK_EVENT_COUNTS stub explicitly marking the variable as used, via 
!something like:

   #define lockevent_cond_inc(ev, c)		do { (void)(c); } while (0)

or so, instead of uglifying the usage site?

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [tip: locking/core] locking/qspinlock: Fix 'wait_early' set but not used warning
  2024-03-11 10:57     ` Ingo Molnar
@ 2024-03-11 13:45       ` Waiman Long
  0 siblings, 0 replies; 11+ messages in thread
From: Waiman Long @ 2024-03-11 13:45 UTC (permalink / raw)
  To: Ingo Molnar, linux-kernel
  Cc: linux-tip-commits, kernel test robot, Boqun Feng, Linus Torvalds,
	x86

On 3/11/24 06:57, Ingo Molnar wrote:
> * tip-bot2 for Waiman Long <tip-bot2@linutronix.de> wrote:
>
>> The following commit has been merged into the locking/core branch of tip:
>>
>> Commit-ID:     ca4bc2e07b716509fd279d2b449bb42f4263a9c8
>> Gitweb:        https://git.kernel.org/tip/ca4bc2e07b716509fd279d2b449bb42f4263a9c8
>> Author:        Waiman Long <longman@redhat.com>
>> AuthorDate:    Thu, 22 Feb 2024 10:05:37 -05:00
>> Committer:     Ingo Molnar <mingo@kernel.org>
>> CommitterDate: Wed, 28 Feb 2024 13:08:37 +01:00
>>
>> locking/qspinlock: Fix 'wait_early' set but not used warning
>>
>> When CONFIG_LOCK_EVENT_COUNTS is off, the wait_early variable will be
>> set but not used. This is expected. Recent compilers will not generate
>> wait_early code in this case.
>>
>> Add the __maybe_unused attribute to wait_early for suppressing this
>> W=1 warning.
>>
>> Reported-by: kernel test robot <lkp@intel.com>
>> Signed-off-by: Waiman Long <longman@redhat.com>
>> Signed-off-by: Ingo Molnar <mingo@kernel.org>
>> Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
>> Cc: Linus Torvalds <torvalds@linux-foundation.org>
>> Link: https://lore.kernel.org/r/20240222150540.79981-2-longman@redhat.com
>>
>> Closes: https://lore.kernel.org/oe-kbuild-all/202312260422.f4pK3f9m-lkp@intel.com/
>> ---
>>   kernel/locking/qspinlock_paravirt.h | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/kernel/locking/qspinlock_paravirt.h b/kernel/locking/qspinlock_paravirt.h
>> index 6a0184e..ae2b12f 100644
>> --- a/kernel/locking/qspinlock_paravirt.h
>> +++ b/kernel/locking/qspinlock_paravirt.h
>> @@ -294,8 +294,8 @@ static void pv_wait_node(struct mcs_spinlock *node, struct mcs_spinlock *prev)
>>   {
>>   	struct pv_node *pn = (struct pv_node *)node;
>>   	struct pv_node *pp = (struct pv_node *)prev;
>> +	bool __maybe_unused wait_early;
>>   	int loop;
>> -	bool wait_early;
> On a second thought, shouldn't this be solved via lockevent_cond_inc()'s
> !CONFIG_LOCK_EVENT_COUNTS stub explicitly marking the variable as used, via
> !something like:
>
>     #define lockevent_cond_inc(ev, c)		do { (void)(c); } while (0)
>
> or so, instead of uglifying the usage site?

Right, that should work too. Thanks for the suggestion. I will post 
another to do that.

Cheers,
Longman


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-03-11 13:46 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-22 15:05 [PATCH v2 0/4] locking: Some locking code cleanups Waiman Long
2024-02-22 15:05 ` [PATCH v2 1/4] locking/qspinlock: Fix 'wait_early' set but not used warning Waiman Long
2024-02-28 12:53   ` [tip: locking/core] " tip-bot2 for Waiman Long
2024-03-11 10:57     ` Ingo Molnar
2024-03-11 13:45       ` Waiman Long
2024-02-22 15:05 ` [PATCH v2 2/4] locking/mutex: Clean up mutex.h Waiman Long
2024-02-28 12:53   ` [tip: locking/core] locking/mutex: Simplify <linux/mutex.h> tip-bot2 for Waiman Long
2024-02-22 15:05 ` [PATCH v2 3/4] locking/rwsem: Clarify that RWSEM_READER_OWNED is just a hint Waiman Long
2024-02-28 12:53   ` [tip: locking/core] " tip-bot2 for Waiman Long
2024-02-22 15:05 ` [PATCH v2 4/4] locking/rwsem: Make DEBUG_RWSEMS and PREEMPT_RT mutually exclusive Waiman Long
2024-02-28 12:53   ` [tip: locking/core] " tip-bot2 for Waiman Long

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.