mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-15 15:15:47 +00:00
d89c70356a
When CONFIG_GENERIC_LOCKBEAK=y, locking structures grow an extra int ->break_lock field which is used to implement raw_spin_is_contended() by setting the field to 1 when waiting on a lock and clearing it to zero when holding a lock. However, there are a few problems with this approach: - There is a write-write race between a CPU successfully taking the lock (and subsequently writing break_lock = 0) and a waiter waiting on the lock (and subsequently writing break_lock = 1). This could result in a contended lock being reported as uncontended and vice-versa. - On machines with store buffers, nothing guarantees that the writes to break_lock are visible to other CPUs at any particular time. - READ_ONCE/WRITE_ONCE are not used, so the field is potentially susceptible to harmful compiler optimisations, Consequently, the usefulness of this field is unclear and we'd be better off removing it and allowing architectures to implement raw_spin_is_contended() by providing a definition of arch_spin_is_contended(), as they can when CONFIG_GENERIC_LOCKBREAK=n. Signed-off-by: Will Deacon <will.deacon@arm.com> Acked-by: Peter Zijlstra <peterz@infradead.org> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Sebastian Ott <sebott@linux.vnet.ibm.com> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/1511894539-7988-3-git-send-email-will.deacon@arm.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
45 lines
1.1 KiB
C
45 lines
1.1 KiB
C
#ifndef __LINUX_RWLOCK_TYPES_H
|
|
#define __LINUX_RWLOCK_TYPES_H
|
|
|
|
/*
|
|
* include/linux/rwlock_types.h - generic rwlock type definitions
|
|
* and initializers
|
|
*
|
|
* portions Copyright 2005, Red Hat, Inc., Ingo Molnar
|
|
* Released under the General Public License (GPL).
|
|
*/
|
|
typedef struct {
|
|
arch_rwlock_t raw_lock;
|
|
#ifdef CONFIG_DEBUG_SPINLOCK
|
|
unsigned int magic, owner_cpu;
|
|
void *owner;
|
|
#endif
|
|
#ifdef CONFIG_DEBUG_LOCK_ALLOC
|
|
struct lockdep_map dep_map;
|
|
#endif
|
|
} rwlock_t;
|
|
|
|
#define RWLOCK_MAGIC 0xdeaf1eed
|
|
|
|
#ifdef CONFIG_DEBUG_LOCK_ALLOC
|
|
# define RW_DEP_MAP_INIT(lockname) .dep_map = { .name = #lockname }
|
|
#else
|
|
# define RW_DEP_MAP_INIT(lockname)
|
|
#endif
|
|
|
|
#ifdef CONFIG_DEBUG_SPINLOCK
|
|
#define __RW_LOCK_UNLOCKED(lockname) \
|
|
(rwlock_t) { .raw_lock = __ARCH_RW_LOCK_UNLOCKED, \
|
|
.magic = RWLOCK_MAGIC, \
|
|
.owner = SPINLOCK_OWNER_INIT, \
|
|
.owner_cpu = -1, \
|
|
RW_DEP_MAP_INIT(lockname) }
|
|
#else
|
|
#define __RW_LOCK_UNLOCKED(lockname) \
|
|
(rwlock_t) { .raw_lock = __ARCH_RW_LOCK_UNLOCKED, \
|
|
RW_DEP_MAP_INIT(lockname) }
|
|
#endif
|
|
|
|
#define DEFINE_RWLOCK(x) rwlock_t x = __RW_LOCK_UNLOCKED(x)
|
|
|
|
#endif /* __LINUX_RWLOCK_TYPES_H */
|