linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Davidlohr Bueso <dave@stgolabs.net>
To: Peter Zijlstra <peterz@infradead.org>
Cc: mingo@kernel.org, davem@davemloft.net, cw00.choi@samsung.com,
	dougthompson@xmission.com, bp@alien8.de, mchehab@osg.samsung.com,
	gregkh@linuxfoundation.org, pfg@sgi.com, jikos@kernel.org,
	hans.verkuil@cisco.com, awalls@md.metrocast.net,
	dledford@redhat.com, sean.hefty@intel.com, kys@microsoft.com,
	heiko.carstens@de.ibm.com, James.Bottomley@HansenPartnership.com,
	sumit.semwal@linaro.org, schwidefsky@de.ibm.com,
	linux-kernel@vger.kernel.org, Davidlohr Bueso <dbueso@suse.de>
Subject: [PATCH -v4 01/12] locking/atomic: Introduce inc/dec calls for FETCH-OP flavors
Date: Tue, 28 Jun 2016 14:56:51 -0700	[thread overview]
Message-ID: <20160628215651.GA20048@linux-80c1.suse> (raw)
In-Reply-To: <20160624184857.GD30154@twins.programming.kicks-ass.net>

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 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>
---

 include/asm-generic/atomic-long.h |  22 +++++++
 include/linux/atomic.h            | 128 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 150 insertions(+)

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)
 ATOMIC_LONG_FETCH_OP(xor, _acquire)
 ATOMIC_LONG_FETCH_OP(xor, _release)
 
+#undef ATOMIC_LONG_FETCH_OP
+
+#define ATOMIC_LONG_FETCH_INC_DEC_OP(op, mo)					\
+static inline long							\
+atomic_long_fetch_##op##mo(atomic_long_t *l)				\
+{									\
+	ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l;		\
+									\
+	return (long)ATOMIC_LONG_PFX(_fetch_##op##mo)(v);		\
+}
+
+ATOMIC_LONG_FETCH_INC_DEC_OP(inc,)
+ATOMIC_LONG_FETCH_INC_DEC_OP(inc, _relaxed)
+ATOMIC_LONG_FETCH_INC_DEC_OP(inc, _acquire)
+ATOMIC_LONG_FETCH_INC_DEC_OP(inc, _release)
+ATOMIC_LONG_FETCH_INC_DEC_OP(dec,)
+ATOMIC_LONG_FETCH_INC_DEC_OP(dec, _relaxed)
+ATOMIC_LONG_FETCH_INC_DEC_OP(dec, _acquire)
+ATOMIC_LONG_FETCH_INC_DEC_OP(dec, _release)
+
+#undef ATOMIC_LONG_FETCH_INC_DEC_OP
+
 #define ATOMIC_LONG_OP(op)						\
 static __always_inline void						\
 atomic_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 @@
 #endif
 #endif /* atomic_fetch_add_relaxed */
 
+/* atomic_fetch_inc_relaxed */
+#ifndef atomic_fetch_inc_relaxed
+
+#ifndef atomic_fetch_inc
+#define atomic_fetch_inc(v)	        atomic_fetch_add(1, (v))
+#define atomic_fetch_inc_relaxed(v)	atomic_fetch_add_relaxed(1, (v))
+#define atomic_fetch_inc_acquire(v)	atomic_fetch_add_acquire(1, (v))
+#define atomic_fetch_inc_release(v)	atomic_fetch_add_release(1, (v))
+#else /* atomic_fetch_inc */
+#define atomic_fetch_inc_relaxed	atomic_fetch_inc
+#define atomic_fetch_inc_acquire	atomic_fetch_inc
+#define atomic_fetch_inc_release	atomic_fetch_inc
+#endif /* atomic_fetch_inc */
+
+#else /* atomic_fetch_inc_relaxed */
+
+#ifndef atomic_fetch_inc_acquire
+#define atomic_fetch_inc_acquire(...)					\
+	__atomic_op_acquire(atomic_fetch_inc, __VA_ARGS__)
+#endif
+
+#ifndef atomic_fetch_inc_release
+#define atomic_fetch_inc_release(...)					\
+	__atomic_op_release(atomic_fetch_inc, __VA_ARGS__)
+#endif
+
+#ifndef atomic_fetch_inc
+#define atomic_fetch_inc(...)						\
+	__atomic_op_fence(atomic_fetch_inc, __VA_ARGS__)
+#endif
+#endif /* atomic_fetch_inc_relaxed */
+
 /* atomic_fetch_sub_relaxed */
 #ifndef atomic_fetch_sub_relaxed
 #define atomic_fetch_sub_relaxed	atomic_fetch_sub
@@ -212,6 +244,38 @@
 #endif
 #endif /* atomic_fetch_sub_relaxed */
 
+/* atomic_fetch_dec_relaxed */
+#ifndef atomic_fetch_dec_relaxed
+
+#ifndef atomic_fetch_dec
+#define atomic_fetch_dec(v)	        atomic_fetch_sub(1, (v))
+#define atomic_fetch_dec_relaxed(v)	atomic_fetch_sub_relaxed(1, (v))
+#define atomic_fetch_dec_acquire(v)	atomic_fetch_sub_acquire(1, (v))
+#define atomic_fetch_dec_release(v)	atomic_fetch_sub_release(1, (v))
+#else /* atomic_fetch_dec */
+#define atomic_fetch_dec_relaxed	atomic_fetch_dec
+#define atomic_fetch_dec_acquire	atomic_fetch_dec
+#define atomic_fetch_dec_release	atomic_fetch_dec
+#endif /* atomic_fetch_dec */
+
+#else /* atomic_fetch_dec_relaxed */
+
+#ifndef atomic_fetch_dec_acquire
+#define atomic_fetch_dec_acquire(...)					\
+	__atomic_op_acquire(atomic_fetch_dec, __VA_ARGS__)
+#endif
+
+#ifndef atomic_fetch_dec_release
+#define atomic_fetch_dec_release(...)					\
+	__atomic_op_release(atomic_fetch_dec, __VA_ARGS__)
+#endif
+
+#ifndef atomic_fetch_dec
+#define atomic_fetch_dec(...)						\
+	__atomic_op_fence(atomic_fetch_dec, __VA_ARGS__)
+#endif
+#endif /* atomic_fetch_dec_relaxed */
+
 /* atomic_fetch_or_relaxed */
 #ifndef atomic_fetch_or_relaxed
 #define atomic_fetch_or_relaxed	atomic_fetch_or
@@ -697,6 +761,38 @@ static inline int atomic_dec_if_positive(atomic_t *v)
 #endif
 #endif /* atomic64_fetch_add_relaxed */
 
+/* atomic64_fetch_inc_relaxed */
+#ifndef atomic64_fetch_inc_relaxed
+
+#ifndef atomic64_fetch_inc
+#define atomic64_fetch_inc(v)		atomic64_fetch_add(1, (v))
+#define atomic64_fetch_inc_relaxed(v)	atomic64_fetch_add_relaxed(1, (v))
+#define atomic64_fetch_inc_acquire(v)	atomic64_fetch_add_acquire(1, (v))
+#define atomic64_fetch_inc_release(v)	atomic64_fetch_add_release(1, (v))
+#else /* atomic64_fetch_inc */
+#define atomic64_fetch_inc_relaxed	atomic64_fetch_inc
+#define atomic64_fetch_inc_acquire	atomic64_fetch_inc
+#define atomic64_fetch_inc_release	atomic64_fetch_inc
+#endif /* atomic64_fetch_inc */
+
+#else /* atomic64_fetch_inc_relaxed */
+
+#ifndef atomic64_fetch_inc_acquire
+#define atomic64_fetch_inc_acquire(...)					\
+	__atomic_op_acquire(atomic64_fetch_inc, __VA_ARGS__)
+#endif
+
+#ifndef atomic64_fetch_inc_release
+#define atomic64_fetch_inc_release(...)					\
+	__atomic_op_release(atomic64_fetch_inc, __VA_ARGS__)
+#endif
+
+#ifndef atomic64_fetch_inc
+#define atomic64_fetch_inc(...)						\
+	__atomic_op_fence(atomic64_fetch_inc, __VA_ARGS__)
+#endif
+#endif /* atomic64_fetch_inc_relaxed */
+
 /* atomic64_fetch_sub_relaxed */
 #ifndef atomic64_fetch_sub_relaxed
 #define atomic64_fetch_sub_relaxed	atomic64_fetch_sub
@@ -721,6 +817,38 @@ static inline int atomic_dec_if_positive(atomic_t *v)
 #endif
 #endif /* atomic64_fetch_sub_relaxed */
 
+/* atomic64_fetch_dec_relaxed */
+#ifndef atomic64_fetch_dec_relaxed
+
+#ifndef atomic64_fetch_dec
+#define atomic64_fetch_dec(v)		atomic64_fetch_sub(1, (v))
+#define atomic64_fetch_dec_relaxed(v)	atomic64_fetch_sub_relaxed(1, (v))
+#define atomic64_fetch_dec_acquire(v)	atomic64_fetch_sub_acquire(1, (v))
+#define atomic64_fetch_dec_release(v)	atomic64_fetch_sub_release(1, (v))
+#else /* atomic64_fetch_dec */
+#define atomic64_fetch_dec_relaxed	atomic64_fetch_dec
+#define atomic64_fetch_dec_acquire	atomic64_fetch_dec
+#define atomic64_fetch_dec_release	atomic64_fetch_dec
+#endif /* atomic64_fetch_dec */
+
+#else /* atomic64_fetch_dec_relaxed */
+
+#ifndef atomic64_fetch_dec_acquire
+#define atomic64_fetch_dec_acquire(...)					\
+	__atomic_op_acquire(atomic64_fetch_dec, __VA_ARGS__)
+#endif
+
+#ifndef atomic64_fetch_dec_release
+#define atomic64_fetch_dec_release(...)					\
+	__atomic_op_release(atomic64_fetch_dec, __VA_ARGS__)
+#endif
+
+#ifndef atomic64_fetch_dec
+#define atomic64_fetch_dec(...)						\
+	__atomic_op_fence(atomic64_fetch_dec, __VA_ARGS__)
+#endif
+#endif /* atomic64_fetch_dec_relaxed */
+
 /* atomic64_fetch_or_relaxed */
 #ifndef atomic64_fetch_or_relaxed
 #define atomic64_fetch_or_relaxed	atomic64_fetch_or
-- 
2.6.6

  reply	other threads:[~2016-06-28 21:57 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-20 20:05 [PATCH -tip 00/12] locking/atomics: Add and use inc,dec calls for FETCH-OP flavors Davidlohr Bueso
2016-06-20 20:05 ` [PATCH 01/12] locking/atomic: Introduce inc/dec " Davidlohr Bueso
2016-06-21  7:28   ` Peter Zijlstra
2016-06-21 13:33   ` [PATCH v2 " Davidlohr Bueso
2016-06-21 16:36     ` Davidlohr Bueso
2016-06-23  9:09       ` Peter Zijlstra
2016-06-24 16:34         ` Davidlohr Bueso
2016-06-24 18:48           ` Peter Zijlstra
2016-06-28 21:56             ` Davidlohr Bueso [this message]
2016-07-07  8:33               ` [tip:locking/core] locking/atomic: Introduce inc/dec variants for the atomic_fetch_$op() API tip-bot for Davidlohr Bueso
2016-06-20 20:05 ` [PATCH 02/12] net/neighbour: Employ atomic_fetch_inc() Davidlohr Bueso
2016-06-20 20:05 ` [PATCH 03/12] PM,devfreq: " Davidlohr Bueso
2016-07-02  5:04   ` Chanwoo Choi
2016-06-20 20:05 ` [PATCH 04/12] EDAC: " Davidlohr Bueso
2016-06-21 13:59   ` Borislav Petkov
2016-06-20 20:05 ` [PATCH 05/12] tty/serial: " Davidlohr Bueso
2016-06-20 20:05 ` [PATCH 06/12] HID,wacom: " Davidlohr Bueso
2016-06-22  8:10   ` Jiri Kosina
2016-06-20 20:05 ` [PATCH 07/12] drivers/media: " Davidlohr Bueso
2016-07-13 16:07   ` Mauro Carvalho Chehab
2016-06-20 20:06 ` [PATCH 08/12] infiniband: " Davidlohr Bueso
2016-06-20 20:06 ` [PATCH 09/12] drivers/hv: " Davidlohr Bueso
2016-06-20 20:06 ` [PATCH 10/12] s390/scm_block: " Davidlohr Bueso
2016-06-20 20:06 ` [PATCH 11/12] scsi: " Davidlohr Bueso
2016-06-20 20:06 ` [PATCH 12/12] dma-buf/fence: Employ atomic_fetch_add Davidlohr Bueso
2016-06-24 16:46 ` [PATCH -tip 00/12] locking/atomics: Add and use inc,dec calls for FETCH-OP flavors James Bottomley
2016-06-24 17:30   ` Davidlohr Bueso
2016-06-24 17:44     ` James Bottomley
2016-06-24 20:35       ` Davidlohr Bueso
2016-06-24 17:45     ` KY Srinivasan
2016-06-24 19:35       ` Davidlohr Bueso
2016-06-24 19:17   ` Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160628215651.GA20048@linux-80c1.suse \
    --to=dave@stgolabs.net \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=awalls@md.metrocast.net \
    --cc=bp@alien8.de \
    --cc=cw00.choi@samsung.com \
    --cc=davem@davemloft.net \
    --cc=dbueso@suse.de \
    --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=linux-kernel@vger.kernel.org \
    --cc=mchehab@osg.samsung.com \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=pfg@sgi.com \
    --cc=schwidefsky@de.ibm.com \
    --cc=sean.hefty@intel.com \
    --cc=sumit.semwal@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).