[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <tip-a338ecb07a338c9a8b0ca0010e862ebe598b1551@git.kernel.org>
Date: Tue, 16 Apr 2019 03:03:17 -0700
From: tip-bot for Waiman Long <tipbot@...or.com>
To: linux-tip-commits@...r.kernel.org
Cc: paulmck@...ux.vnet.ibm.com, hpa@...or.com, a.p.zijlstra@...llo.nl,
bp@...en8.de, dave@...olabs.net, mingo@...nel.org,
torvalds@...ux-foundation.org, akpm@...ux-foundation.org,
longman@...hat.com, peterz@...radead.org, dbueso@...e.de,
tglx@...utronix.de, will.deacon@....com,
linux-kernel@...r.kernel.org, tim.c.chen@...ux.intel.com,
arnd@...db.de
Subject: [tip:locking/core] locking/rwsem: Micro-optimize
rwsem_try_read_lock_unqueued()
Commit-ID: a338ecb07a338c9a8b0ca0010e862ebe598b1551
Gitweb: https://git.kernel.org/tip/a338ecb07a338c9a8b0ca0010e862ebe598b1551
Author: Waiman Long <longman@...hat.com>
AuthorDate: Thu, 4 Apr 2019 13:43:13 -0400
Committer: Ingo Molnar <mingo@...nel.org>
CommitDate: Wed, 10 Apr 2019 10:56:01 +0200
locking/rwsem: Micro-optimize rwsem_try_read_lock_unqueued()
The atomic_long_cmpxchg_acquire() in rwsem_try_read_lock_unqueued() is
replaced by atomic_long_try_cmpxchg_acquire() to simpify the code and
generate slightly better assembly code.
There is no functional change.
Signed-off-by: Waiman Long <longman@...hat.com>
Acked-by: Peter Zijlstra <a.p.zijlstra@...llo.nl>
Acked-by: Will Deacon <will.deacon@....com>
Acked-by: Davidlohr Bueso <dbueso@...e.de>
Cc: Andrew Morton <akpm@...ux-foundation.org>
Cc: Arnd Bergmann <arnd@...db.de>
Cc: Borislav Petkov <bp@...en8.de>
Cc: Davidlohr Bueso <dave@...olabs.net>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Paul E. McKenney <paulmck@...ux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@...radead.org>
Cc: Thomas Gleixner <tglx@...utronix.de>
Cc: Tim Chen <tim.c.chen@...ux.intel.com>
Link: http://lkml.kernel.org/r/20190404174320.22416-5-longman@redhat.com
Signed-off-by: Ingo Molnar <mingo@...nel.org>
---
kernel/locking/rwsem-xadd.c | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/kernel/locking/rwsem-xadd.c b/kernel/locking/rwsem-xadd.c
index c213869e1aa7..f6198e1a58f6 100644
--- a/kernel/locking/rwsem-xadd.c
+++ b/kernel/locking/rwsem-xadd.c
@@ -259,21 +259,16 @@ static inline bool rwsem_try_write_lock(long count, struct rw_semaphore *sem)
*/
static inline bool rwsem_try_write_lock_unqueued(struct rw_semaphore *sem)
{
- long old, count = atomic_long_read(&sem->count);
+ long count = atomic_long_read(&sem->count);
- while (true) {
- if (!(count == 0 || count == RWSEM_WAITING_BIAS))
- return false;
-
- old = atomic_long_cmpxchg_acquire(&sem->count, count,
- count + RWSEM_ACTIVE_WRITE_BIAS);
- if (old == count) {
+ while (!count || count == RWSEM_WAITING_BIAS) {
+ if (atomic_long_try_cmpxchg_acquire(&sem->count, &count,
+ count + RWSEM_ACTIVE_WRITE_BIAS)) {
rwsem_set_owner(sem);
return true;
}
-
- count = old;
}
+ return false;
}
static inline bool owner_on_cpu(struct task_struct *owner)
Powered by blists - more mailing lists