Skip to content

Commit e0d0228

Browse files
wildea01Ingo Molnar
authored andcommitted
locking/qrwlock: Use 'struct qrwlock' instead of 'struct __qrwlock'
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>
1 parent 5a8897c commit e0d0228

File tree

3 files changed

+16
-37
lines changed

3 files changed

+16
-37
lines changed

include/asm-generic/qrwlock.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,23 +128,13 @@ static inline void queued_read_unlock(struct qrwlock *lock)
128128
(void)atomic_sub_return_release(_QR_BIAS, &lock->cnts);
129129
}
130130

131-
/**
132-
* __qrwlock_write_byte - retrieve the write byte address of a queue rwlock
133-
* @lock : Pointer to queue rwlock structure
134-
* Return: the write byte address of a queue rwlock
135-
*/
136-
static inline u8 *__qrwlock_write_byte(struct qrwlock *lock)
137-
{
138-
return (u8 *)lock + 3 * IS_BUILTIN(CONFIG_CPU_BIG_ENDIAN);
139-
}
140-
141131
/**
142132
* queued_write_unlock - release write lock of a queue rwlock
143133
* @lock : Pointer to queue rwlock structure
144134
*/
145135
static inline void queued_write_unlock(struct qrwlock *lock)
146136
{
147-
smp_store_release(__qrwlock_write_byte(lock), 0);
137+
smp_store_release(&lock->wmode, 0);
148138
}
149139

150140
/*

include/asm-generic/qrwlock_types.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,23 @@
99
*/
1010

1111
typedef struct qrwlock {
12-
atomic_t cnts;
12+
union {
13+
atomic_t cnts;
14+
struct {
15+
#ifdef __LITTLE_ENDIAN
16+
u8 wmode; /* Writer mode */
17+
u8 rcnts[3]; /* Reader counts */
18+
#else
19+
u8 rcnts[3]; /* Reader counts */
20+
u8 wmode; /* Writer mode */
21+
#endif
22+
};
23+
};
1324
arch_spinlock_t wait_lock;
1425
} arch_rwlock_t;
1526

1627
#define __ARCH_RW_LOCK_UNLOCKED { \
17-
.cnts = ATOMIC_INIT(0), \
28+
{ .cnts = ATOMIC_INIT(0), }, \
1829
.wait_lock = __ARCH_SPIN_LOCK_UNLOCKED, \
1930
}
2031

kernel/locking/qrwlock.c

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,6 @@
2323
#include <linux/spinlock.h>
2424
#include <asm/qrwlock.h>
2525

26-
/*
27-
* This internal data structure is used for optimizing access to some of
28-
* the subfields within the atomic_t cnts.
29-
*/
30-
struct __qrwlock {
31-
union {
32-
atomic_t cnts;
33-
struct {
34-
#ifdef __LITTLE_ENDIAN
35-
u8 wmode; /* Writer mode */
36-
u8 rcnts[3]; /* Reader counts */
37-
#else
38-
u8 rcnts[3]; /* Reader counts */
39-
u8 wmode; /* Writer mode */
40-
#endif
41-
};
42-
};
43-
arch_spinlock_t lock;
44-
};
45-
4626
/**
4727
* rspin_until_writer_unlock - inc reader count & spin until writer is gone
4828
* @lock : Pointer to queue rwlock structure
@@ -125,10 +105,8 @@ void queued_write_lock_slowpath(struct qrwlock *lock)
125105
* or wait for a previous writer to go away.
126106
*/
127107
for (;;) {
128-
struct __qrwlock *l = (struct __qrwlock *)lock;
129-
130-
if (!READ_ONCE(l->wmode) &&
131-
(cmpxchg_relaxed(&l->wmode, 0, _QW_WAITING) == 0))
108+
if (!READ_ONCE(lock->wmode) &&
109+
(cmpxchg_relaxed(&lock->wmode, 0, _QW_WAITING) == 0))
132110
break;
133111

134112
cpu_relax();

0 commit comments

Comments
 (0)