mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH REPOST] locking/local_lock: Make the empty local_lock_*() function a macro.
@ 2022-02-08 17:08 Sebastian Andrzej Siewior
  2022-02-09 21:08 ` Davidlohr Bueso
  2022-02-11 11:16 ` [tip: locking/core] " tip-bot2 for Sebastian Andrzej Siewior
  0 siblings, 2 replies; 3+ messages in thread
From: Sebastian Andrzej Siewior @ 2022-02-08 17:08 UTC (permalink / raw)
  To: linux-kernel
  Cc: Peter Zijlstra, Waiman Long, Ingo Molnar, Will Deacon, Thomas Gleixner

It has been said that local_lock() does not add any overhead compared to
preempt_disable() in a !LOCKDEP configuration. A micro benchmark showed
an unexpected result which can be reduced to the fact that local_lock()
was not entirely optimized away.
In the !LOCKDEP configuration local_lock_acquire() is an empty static
inline function. On x86 the this_cpu_ptr() argument of that function is
fully evaluated leading to an additional mov+add instructions which are
not needed and not used.

Replace the static inline function with a macro. The typecheck() macro
ensures that the argument is of proper type while the resulting
disassembly shows no traces of this_cpu_ptr().

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Reviewed-by: Waiman Long <longman@redhat.com>
---
Repost of
   https://lkml.kernel.org/r/20220105202623.1118172-1-bigeasy@linutronix.de

 include/linux/local_lock_internal.h |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

--- a/include/linux/local_lock_internal.h
+++ b/include/linux/local_lock_internal.h
@@ -44,9 +44,9 @@ static inline void local_lock_debug_init
 }
 #else /* CONFIG_DEBUG_LOCK_ALLOC */
 # define LOCAL_LOCK_DEBUG_INIT(lockname)
-static inline void local_lock_acquire(local_lock_t *l) { }
-static inline void local_lock_release(local_lock_t *l) { }
-static inline void local_lock_debug_init(local_lock_t *l) { }
+# define local_lock_acquire(__ll)  do { typecheck(local_lock_t *, __ll); } while (0)
+# define local_lock_release(__ll)  do { typecheck(local_lock_t *, __ll); } while (0)
+# define local_lock_debug_init(__ll)  do { typecheck(local_lock_t *, __ll); } while (0)
 #endif /* !CONFIG_DEBUG_LOCK_ALLOC */
 
 #define INIT_LOCAL_LOCK(lockname)	{ LOCAL_LOCK_DEBUG_INIT(lockname) }

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

* Re: [PATCH REPOST] locking/local_lock: Make the empty local_lock_*() function a macro.
  2022-02-08 17:08 [PATCH REPOST] locking/local_lock: Make the empty local_lock_*() function a macro Sebastian Andrzej Siewior
@ 2022-02-09 21:08 ` Davidlohr Bueso
  2022-02-11 11:16 ` [tip: locking/core] " tip-bot2 for Sebastian Andrzej Siewior
  1 sibling, 0 replies; 3+ messages in thread
From: Davidlohr Bueso @ 2022-02-09 21:08 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior
  Cc: linux-kernel, Peter Zijlstra, Waiman Long, Ingo Molnar,
	Will Deacon, Thomas Gleixner

On Tue, 08 Feb 2022, Sebastian Andrzej Siewior wrote:

>It has been said that local_lock() does not add any overhead compared to
>preempt_disable() in a !LOCKDEP configuration. A micro benchmark showed
>an unexpected result which can be reduced to the fact that local_lock()
>was not entirely optimized away.
>In the !LOCKDEP configuration local_lock_acquire() is an empty static
>inline function. On x86 the this_cpu_ptr() argument of that function is
>fully evaluated leading to an additional mov+add instructions which are
>not needed and not used.
>
>Replace the static inline function with a macro. The typecheck() macro
>ensures that the argument is of proper type while the resulting
>disassembly shows no traces of this_cpu_ptr().
>
>Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
>Reviewed-by: Waiman Long <longman@redhat.com>

Reviewed-by: Davidlohr Bueso <dbueso@suse.de>

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

* [tip: locking/core] locking/local_lock: Make the empty local_lock_*() function a macro.
  2022-02-08 17:08 [PATCH REPOST] locking/local_lock: Make the empty local_lock_*() function a macro Sebastian Andrzej Siewior
  2022-02-09 21:08 ` Davidlohr Bueso
@ 2022-02-11 11:16 ` tip-bot2 for Sebastian Andrzej Siewior
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Sebastian Andrzej Siewior @ 2022-02-11 11:16 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Sebastian Andrzej Siewior, Peter Zijlstra (Intel),
	Waiman Long, x86, linux-kernel

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

Commit-ID:     9983a9d577db415c41099a20a5637ab25dd3c240
Gitweb:        https://git.kernel.org/tip/9983a9d577db415c41099a20a5637ab25dd3c240
Author:        Sebastian Andrzej Siewior <bigeasy@linutronix.de>
AuthorDate:    Tue, 08 Feb 2022 18:08:02 +01:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Fri, 11 Feb 2022 12:13:56 +01:00

locking/local_lock: Make the empty local_lock_*() function a macro.

It has been said that local_lock() does not add any overhead compared to
preempt_disable() in a !LOCKDEP configuration. A micro benchmark showed
an unexpected result which can be reduced to the fact that local_lock()
was not entirely optimized away.
In the !LOCKDEP configuration local_lock_acquire() is an empty static
inline function. On x86 the this_cpu_ptr() argument of that function is
fully evaluated leading to an additional mov+add instructions which are
not needed and not used.

Replace the static inline function with a macro. The typecheck() macro
ensures that the argument is of proper type while the resulting
disassembly shows no traces of this_cpu_ptr().

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Waiman Long <longman@redhat.com>
Link: https://lkml.kernel.org/r/YgKjciR60fZft2l4@linutronix.de
---
 include/linux/local_lock_internal.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/linux/local_lock_internal.h b/include/linux/local_lock_internal.h
index 975e33b..6d635e8 100644
--- a/include/linux/local_lock_internal.h
+++ b/include/linux/local_lock_internal.h
@@ -44,9 +44,9 @@ static inline void local_lock_debug_init(local_lock_t *l)
 }
 #else /* CONFIG_DEBUG_LOCK_ALLOC */
 # define LOCAL_LOCK_DEBUG_INIT(lockname)
-static inline void local_lock_acquire(local_lock_t *l) { }
-static inline void local_lock_release(local_lock_t *l) { }
-static inline void local_lock_debug_init(local_lock_t *l) { }
+# define local_lock_acquire(__ll)  do { typecheck(local_lock_t *, __ll); } while (0)
+# define local_lock_release(__ll)  do { typecheck(local_lock_t *, __ll); } while (0)
+# define local_lock_debug_init(__ll)  do { typecheck(local_lock_t *, __ll); } while (0)
 #endif /* !CONFIG_DEBUG_LOCK_ALLOC */
 
 #define INIT_LOCAL_LOCK(lockname)	{ LOCAL_LOCK_DEBUG_INIT(lockname) }

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

end of thread, other threads:[~2022-02-11 11:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-08 17:08 [PATCH REPOST] locking/local_lock: Make the empty local_lock_*() function a macro Sebastian Andrzej Siewior
2022-02-09 21:08 ` Davidlohr Bueso
2022-02-11 11:16 ` [tip: locking/core] " tip-bot2 for Sebastian Andrzej Siewior

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®