aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavidlohr Bueso <dave@stgolabs.net>2016-06-28 17:56:51 -0400
committerIngo Molnar <mingo@kernel.org>2016-07-07 03:16:20 -0400
commitf06628638cf6e75f179742b6c1b35076965b9fdd (patch)
tree7dbd4970a827063cfcb866b8bd298a0a5b05ee19
parent36e91aa2628e46c2146049eee8b9b7f773b0ffc3 (diff)
locking/atomic: Introduce inc/dec variants for the atomic_fetch_$op() API
With the inclusion of atomic FETCH-OP variants, many places in the kernel can make use of atomic_fetch_$op() to avoid the callers that need to compute the value/state _before_ the operation. Peter Zijlstra laid out the machinery but we are still missing the simpler dec,inc() calls (which future patches will make use of). This patch only deals with the generic code, as at least right now no arch actually implement them -- which is similar to what the OP-RETURN primitives currently do. Signed-off-by: Davidlohr Bueso <dbueso@suse.de> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: James.Bottomley@HansenPartnership.com Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: awalls@md.metrocast.net Cc: bp@alien8.de Cc: cw00.choi@samsung.com Cc: davem@davemloft.net Cc: dledford@redhat.com Cc: dougthompson@xmission.com Cc: gregkh@linuxfoundation.org Cc: hans.verkuil@cisco.com Cc: heiko.carstens@de.ibm.com Cc: jikos@kernel.org Cc: kys@microsoft.com Cc: mchehab@osg.samsung.com Cc: pfg@sgi.com Cc: schwidefsky@de.ibm.com Cc: sean.hefty@intel.com Cc: sumit.semwal@linaro.org Link: http://lkml.kernel.org/r/20160628215651.GA20048@linux-80c1.suse Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--include/asm-generic/atomic-long.h22
-rw-r--r--include/linux/atomic.h128
2 files changed, 150 insertions, 0 deletions
diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
index 2d0d3cf791ab..288cc9e96395 100644
--- a/include/asm-generic/atomic-long.h
+++ b/include/asm-generic/atomic-long.h
@@ -146,6 +146,28 @@ ATOMIC_LONG_FETCH_OP(xor, _relaxed)
146ATOMIC_LONG_FETCH_OP(xor, _acquire) 146ATOMIC_LONG_FETCH_OP(xor, _acquire)
147ATOMIC_LONG_FETCH_OP(xor, _release) 147ATOMIC_LONG_FETCH_OP(xor, _release)
148 148
149#undef ATOMIC_LONG_FETCH_OP
150
151#define ATOMIC_LONG_FETCH_INC_DEC_OP(op, mo) \
152static inline long \
153atomic_long_fetch_##op##mo(atomic_long_t *l) \
154{ \
155 ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; \
156 \
157 return (long)ATOMIC_LONG_PFX(_fetch_##op##mo)(v); \
158}
159
160ATOMIC_LONG_FETCH_INC_DEC_OP(inc,)
161ATOMIC_LONG_FETCH_INC_DEC_OP(inc, _relaxed)
162ATOMIC_LONG_FETCH_INC_DEC_OP(inc, _acquire)
163ATOMIC_LONG_FETCH_INC_DEC_OP(inc, _release)
164ATOMIC_LONG_FETCH_INC_DEC_OP(dec,)
165ATOMIC_LONG_FETCH_INC_DEC_OP(dec, _relaxed)
166ATOMIC_LONG_FETCH_INC_DEC_OP(dec, _acquire)
167ATOMIC_LONG_FETCH_INC_DEC_OP(dec, _release)
168
169#undef ATOMIC_LONG_FETCH_INC_DEC_OP
170
149#define ATOMIC_LONG_OP(op) \ 171#define ATOMIC_LONG_OP(op) \
150static __always_inline void \ 172static __always_inline void \
151atomic_long_##op(long i, atomic_long_t *l) \ 173atomic_long_##op(long i, atomic_long_t *l) \
diff --git a/include/linux/atomic.h b/include/linux/atomic.h
index 12d910d61b83..e71835bf60a9 100644
--- a/include/linux/atomic.h
+++ b/include/linux/atomic.h
@@ -188,6 +188,38 @@
188#endif 188#endif
189#endif /* atomic_fetch_add_relaxed */ 189#endif /* atomic_fetch_add_relaxed */
190 190
191/* atomic_fetch_inc_relaxed */
192#ifndef atomic_fetch_inc_relaxed
193
194#ifndef atomic_fetch_inc
195#define atomic_fetch_inc(v) atomic_fetch_add(1, (v))
196#define atomic_fetch_inc_relaxed(v) atomic_fetch_add_relaxed(1, (v))
197#define atomic_fetch_inc_acquire(v) atomic_fetch_add_acquire(1, (v))
198#define atomic_fetch_inc_release(v) atomic_fetch_add_release(1, (v))
199#else /* atomic_fetch_inc */
200#define atomic_fetch_inc_relaxed atomic_fetch_inc
201#define atomic_fetch_inc_acquire atomic_fetch_inc
202#define atomic_fetch_inc_release atomic_fetch_inc
203#endif /* atomic_fetch_inc */
204
205#else /* atomic_fetch_inc_relaxed */
206
207#ifndef atomic_fetch_inc_acquire
208#define atomic_fetch_inc_acquire(...) \
209 __atomic_op_acquire(atomic_fetch_inc, __VA_ARGS__)
210#endif
211
212#ifndef atomic_fetch_inc_release
213#define atomic_fetch_inc_release(...) \
214 __atomic_op_release(atomic_fetch_inc, __VA_ARGS__)
215#endif
216
217#ifndef atomic_fetch_inc
218#define atomic_fetch_inc(...) \
219 __atomic_op_fence(atomic_fetch_inc, __VA_ARGS__)
220#endif
221#endif /* atomic_fetch_inc_relaxed */
222
191/* atomic_fetch_sub_relaxed */ 223/* atomic_fetch_sub_relaxed */
192#ifndef atomic_fetch_sub_relaxed 224#ifndef atomic_fetch_sub_relaxed
193#define atomic_fetch_sub_relaxed atomic_fetch_sub 225#define atomic_fetch_sub_relaxed atomic_fetch_sub
@@ -212,6 +244,38 @@
212#endif 244#endif
213#endif /* atomic_fetch_sub_relaxed */ 245#endif /* atomic_fetch_sub_relaxed */
214 246
247/* atomic_fetch_dec_relaxed */
248#ifndef atomic_fetch_dec_relaxed
249
250#ifndef atomic_fetch_dec
251#define atomic_fetch_dec(v) atomic_fetch_sub(1, (v))
252#define atomic_fetch_dec_relaxed(v) atomic_fetch_sub_relaxed(1, (v))
253#define atomic_fetch_dec_acquire(v) atomic_fetch_sub_acquire(1, (v))
254#define atomic_fetch_dec_release(v) atomic_fetch_sub_release(1, (v))
255#else /* atomic_fetch_dec */
256#define atomic_fetch_dec_relaxed atomic_fetch_dec
257#define atomic_fetch_dec_acquire atomic_fetch_dec
258#define atomic_fetch_dec_release atomic_fetch_dec
259#endif /* atomic_fetch_dec */
260
261#else /* atomic_fetch_dec_relaxed */
262
263#ifndef atomic_fetch_dec_acquire
264#define atomic_fetch_dec_acquire(...) \
265 __atomic_op_acquire(atomic_fetch_dec, __VA_ARGS__)
266#endif
267
268#ifndef atomic_fetch_dec_release
269#define atomic_fetch_dec_release(...) \
270 __atomic_op_release(atomic_fetch_dec, __VA_ARGS__)
271#endif
272
273#ifndef atomic_fetch_dec
274#define atomic_fetch_dec(...) \
275 __atomic_op_fence(atomic_fetch_dec, __VA_ARGS__)
276#endif
277#endif /* atomic_fetch_dec_relaxed */
278
215/* atomic_fetch_or_relaxed */ 279/* atomic_fetch_or_relaxed */
216#ifndef atomic_fetch_or_relaxed 280#ifndef atomic_fetch_or_relaxed
217#define atomic_fetch_or_relaxed atomic_fetch_or 281#define atomic_fetch_or_relaxed atomic_fetch_or
@@ -697,6 +761,38 @@ static inline int atomic_dec_if_positive(atomic_t *v)
697#endif 761#endif
698#endif /* atomic64_fetch_add_relaxed */ 762#endif /* atomic64_fetch_add_relaxed */
699 763
764/* atomic64_fetch_inc_relaxed */
765#ifndef atomic64_fetch_inc_relaxed
766
767#ifndef atomic64_fetch_inc
768#define atomic64_fetch_inc(v) atomic64_fetch_add(1, (v))
769#define atomic64_fetch_inc_relaxed(v) atomic64_fetch_add_relaxed(1, (v))
770#define atomic64_fetch_inc_acquire(v) atomic64_fetch_add_acquire(1, (v))
771#define atomic64_fetch_inc_release(v) atomic64_fetch_add_release(1, (v))
772#else /* atomic64_fetch_inc */
773#define atomic64_fetch_inc_relaxed atomic64_fetch_inc
774#define atomic64_fetch_inc_acquire atomic64_fetch_inc
775#define atomic64_fetch_inc_release atomic64_fetch_inc
776#endif /* atomic64_fetch_inc */
777
778#else /* atomic64_fetch_inc_relaxed */
779
780#ifndef atomic64_fetch_inc_acquire
781#define atomic64_fetch_inc_acquire(...) \
782 __atomic_op_acquire(atomic64_fetch_inc, __VA_ARGS__)
783#endif
784
785#ifndef atomic64_fetch_inc_release
786#define atomic64_fetch_inc_release(...) \
787 __atomic_op_release(atomic64_fetch_inc, __VA_ARGS__)
788#endif
789
790#ifndef atomic64_fetch_inc
791#define atomic64_fetch_inc(...) \
792 __atomic_op_fence(atomic64_fetch_inc, __VA_ARGS__)
793#endif
794#endif /* atomic64_fetch_inc_relaxed */
795
700/* atomic64_fetch_sub_relaxed */ 796/* atomic64_fetch_sub_relaxed */
701#ifndef atomic64_fetch_sub_relaxed 797#ifndef atomic64_fetch_sub_relaxed
702#define atomic64_fetch_sub_relaxed atomic64_fetch_sub 798#define atomic64_fetch_sub_relaxed atomic64_fetch_sub
@@ -721,6 +817,38 @@ static inline int atomic_dec_if_positive(atomic_t *v)
721#endif 817#endif
722#endif /* atomic64_fetch_sub_relaxed */ 818#endif /* atomic64_fetch_sub_relaxed */
723 819
820/* atomic64_fetch_dec_relaxed */
821#ifndef atomic64_fetch_dec_relaxed
822
823#ifndef atomic64_fetch_dec
824#define atomic64_fetch_dec(v) atomic64_fetch_sub(1, (v))
825#define atomic64_fetch_dec_relaxed(v) atomic64_fetch_sub_relaxed(1, (v))
826#define atomic64_fetch_dec_acquire(v) atomic64_fetch_sub_acquire(1, (v))
827#define atomic64_fetch_dec_release(v) atomic64_fetch_sub_release(1, (v))
828#else /* atomic64_fetch_dec */
829#define atomic64_fetch_dec_relaxed atomic64_fetch_dec
830#define atomic64_fetch_dec_acquire atomic64_fetch_dec
831#define atomic64_fetch_dec_release atomic64_fetch_dec
832#endif /* atomic64_fetch_dec */
833
834#else /* atomic64_fetch_dec_relaxed */
835
836#ifndef atomic64_fetch_dec_acquire
837#define atomic64_fetch_dec_acquire(...) \
838 __atomic_op_acquire(atomic64_fetch_dec, __VA_ARGS__)
839#endif
840
841#ifndef atomic64_fetch_dec_release
842#define atomic64_fetch_dec_release(...) \
843 __atomic_op_release(atomic64_fetch_dec, __VA_ARGS__)
844#endif
845
846#ifndef atomic64_fetch_dec
847#define atomic64_fetch_dec(...) \
848 __atomic_op_fence(atomic64_fetch_dec, __VA_ARGS__)
849#endif
850#endif /* atomic64_fetch_dec_relaxed */
851
724/* atomic64_fetch_or_relaxed */ 852/* atomic64_fetch_or_relaxed */
725#ifndef atomic64_fetch_or_relaxed 853#ifndef atomic64_fetch_or_relaxed
726#define atomic64_fetch_or_relaxed atomic64_fetch_or 854#define atomic64_fetch_or_relaxed atomic64_fetch_or