Skip to content

Commit 4df714b

Browse files
wildea01ingomolnar
authored andcommitted
locking/atomic: Add atomic_cond_read_acquire()
smp_cond_load_acquire() provides a way to spin on a variable with acquire semantics until some conditional expression involving the variable is satisfied. Architectures such as arm64 can potentially enter a low-power state, waking up only when the value of the variable changes, which reduces the system impact of tight polling loops. This patch makes the same interface available to users of atomic_t, atomic64_t and atomic_long_t, rather than require messy accesses to the structure internals. 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-3-git-send-email-will.deacon@arm.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent e0d0228 commit 4df714b

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

‎include/asm-generic/atomic-long.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,7 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
243243
#define atomic_long_inc_not_zero(l) \
244244
ATOMIC_LONG_PFX(_inc_not_zero)((ATOMIC_LONG_PFX(_t) *)(l))
245245

246+
#define atomic_long_cond_read_acquire(v, c) \
247+
ATOMIC_LONG_PFX(_cond_read_acquire)((ATOMIC_LONG_PFX(_t) *)(v), (c))
248+
246249
#endif /* _ASM_GENERIC_ATOMIC_LONG_H */

‎include/linux/atomic.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,8 @@ static inline int atomic_dec_if_positive(atomic_t *v)
653653
}
654654
#endif
655655

656+
#define atomic_cond_read_acquire(v, c) smp_cond_load_acquire(&(v)->counter, (c))
657+
656658
#ifdef CONFIG_GENERIC_ATOMIC64
657659
#include <asm-generic/atomic64.h>
658660
#endif
@@ -1072,6 +1074,8 @@ static inline long long atomic64_fetch_andnot_release(long long i, atomic64_t *v
10721074
}
10731075
#endif
10741076

1077+
#define atomic64_cond_read_acquire(v, c) smp_cond_load_acquire(&(v)->counter, (c))
1078+
10751079
#include <asm-generic/atomic-long.h>
10761080

10771081
#endif /* _LINUX_ATOMIC_H */

0 commit comments

Comments
 (0)