]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commitdiff
locking/qrwlock: Use 'struct qrwlock' instead of 'struct __qrwlock'
authorWill Deacon <will.deacon@arm.com>
Fri, 5 Jan 2018 01:48:33 +0000 (18:48 -0700)
committerKhalid Elmously <khalid.elmously@canonical.com>
Fri, 16 Feb 2018 17:40:13 +0000 (12:40 -0500)
BugLink: https://bugs.launchpad.net/bugs/1732238
There's no good reason to keep the internal structure of struct qrwlock
hidden from qrwlock.h, particularly as it's actually needed for unlock
and ends up being abstracted independently behind the __qrwlock_write_byte()
function.

Stop pretending we can hide this stuff, and move the __qrwlock definition
into qrwlock, removing the __qrwlock_write_byte() nastiness and using the
same struct definition everywhere instead.

Signed-off-by: Will Deacon <will.deacon@arm.com>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Jeremy.Linton@arm.com
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Waiman Long <longman@redhat.com>
Cc: linux-arm-kernel@lists.infradead.org
Link: http://lkml.kernel.org/r/1507810851-306-2-git-send-email-will.deacon@arm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
(cherry picked from commit e0d02285f16e8d5810f3d5d5e8a5886ca0015d3b)
Signed-off-by: dann frazier <dann.frazier@canonical.com>
Acked-by: Seth Forshee <seth.forshee@canonical.com>
Acked-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
include/asm-generic/qrwlock.h
include/asm-generic/qrwlock_types.h
kernel/locking/qrwlock.c

index 7d026bf277131f7bc4c79529cc26488e3a8281ee..5a571469f32405acd1fe81e82c2cb4a45f9469ac 100644 (file)
@@ -146,23 +146,13 @@ static inline void queued_read_unlock(struct qrwlock *lock)
        (void)atomic_sub_return_release(_QR_BIAS, &lock->cnts);
 }
 
-/**
- * __qrwlock_write_byte - retrieve the write byte address of a queue rwlock
- * @lock : Pointer to queue rwlock structure
- * Return: the write byte address of a queue rwlock
- */
-static inline u8 *__qrwlock_write_byte(struct qrwlock *lock)
-{
-       return (u8 *)lock + 3 * IS_BUILTIN(CONFIG_CPU_BIG_ENDIAN);
-}
-
 /**
  * queued_write_unlock - release write lock of a queue rwlock
  * @lock : Pointer to queue rwlock structure
  */
 static inline void queued_write_unlock(struct qrwlock *lock)
 {
-       smp_store_release(__qrwlock_write_byte(lock), 0);
+       smp_store_release(&lock->wmode, 0);
 }
 
 /*
index 0abc6b6062fbb1c203bed0f025e05e82ac3eea24..507f2dc51bba98f6f3d3d0f93f58940af9ece784 100644 (file)
@@ -9,12 +9,23 @@
  */
 
 typedef struct qrwlock {
-       atomic_t                cnts;
+       union {
+               atomic_t cnts;
+               struct {
+#ifdef __LITTLE_ENDIAN
+                       u8 wmode;       /* Writer mode   */
+                       u8 rcnts[3];    /* Reader counts */
+#else
+                       u8 rcnts[3];    /* Reader counts */
+                       u8 wmode;       /* Writer mode   */
+#endif
+               };
+       };
        arch_spinlock_t         wait_lock;
 } arch_rwlock_t;
 
 #define        __ARCH_RW_LOCK_UNLOCKED {               \
-       .cnts = ATOMIC_INIT(0),                 \
+       { .cnts = ATOMIC_INIT(0), },            \
        .wait_lock = __ARCH_SPIN_LOCK_UNLOCKED, \
 }
 
index 2655f26ec882689f42d2ba7831209f166ce45869..1af791e3734893789682b8eed1b9cdf0c2ae10da 100644 (file)
 #include <linux/spinlock.h>
 #include <asm/qrwlock.h>
 
-/*
- * This internal data structure is used for optimizing access to some of
- * the subfields within the atomic_t cnts.
- */
-struct __qrwlock {
-       union {
-               atomic_t cnts;
-               struct {
-#ifdef __LITTLE_ENDIAN
-                       u8 wmode;       /* Writer mode   */
-                       u8 rcnts[3];    /* Reader counts */
-#else
-                       u8 rcnts[3];    /* Reader counts */
-                       u8 wmode;       /* Writer mode   */
-#endif
-               };
-       };
-       arch_spinlock_t lock;
-};
-
 /**
  * rspin_until_writer_unlock - inc reader count & spin until writer is gone
  * @lock  : Pointer to queue rwlock structure
@@ -125,10 +105,8 @@ void queued_write_lock_slowpath(struct qrwlock *lock)
         * or wait for a previous writer to go away.
         */
        for (;;) {
-               struct __qrwlock *l = (struct __qrwlock *)lock;
-
-               if (!READ_ONCE(l->wmode) &&
-                  (cmpxchg_relaxed(&l->wmode, 0, _QW_WAITING) == 0))
+               if (!READ_ONCE(lock->wmode) &&
+                  (cmpxchg_relaxed(&lock->wmode, 0, _QW_WAITING) == 0))
                        break;
 
                cpu_relax();