* [PATCH v2 1/2] ia64: implement atomic64_dec_if_positive
[not found] <1473702432-8116-1-git-send-email-vgupta@synopsys.com>
@ 2016-09-12 17:47 ` Vineet Gupta
2016-09-12 18:26 ` Luck, Tony
0 siblings, 1 reply; 2+ messages in thread
From: Vineet Gupta @ 2016-09-12 17:47 UTC (permalink / raw)
To: Tony Luck, Fenghua Yu, Ingo Molnar, Peter Zijlstra
Cc: linux-kernel, linux-snps-arc, Vineet Gupta, linux-ia64
This is based on s390 version and needed to get rid of
CONFIG_ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
Cc: Tony Luck <tony.luck@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: linux-ia64@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
---
arch/ia64/include/asm/atomic.h | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
index f565ad376142..65d4bb2b6685 100644
--- a/arch/ia64/include/asm/atomic.h
+++ b/arch/ia64/include/asm/atomic.h
@@ -269,6 +269,22 @@ static __inline__ long atomic64_add_unless(atomic64_t *v, long a, long u)
#define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
+static __inline__ long atomic64_dec_if_positive(atomic64_t *v)
+{
+ long c, old, dec;
+ c = atomic64_read(v);
+ for (;;) {
+ dec = c - 1;
+ if (unlikely(dec < 0))
+ break;
+ old = atomic64_cmpxchg((v), c, dec);
+ if (likely(old = c))
+ break;
+ c = old;
+ }
+ return dec;
+}
+
/*
* Atomically add I to V and return TRUE if the resulting value is
* negative.
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* RE: [PATCH v2 1/2] ia64: implement atomic64_dec_if_positive
2016-09-12 17:47 ` [PATCH v2 1/2] ia64: implement atomic64_dec_if_positive Vineet Gupta
@ 2016-09-12 18:26 ` Luck, Tony
0 siblings, 0 replies; 2+ messages in thread
From: Luck, Tony @ 2016-09-12 18:26 UTC (permalink / raw)
To: Vineet Gupta, Yu, Fenghua, Ingo Molnar, Peter Zijlstra
Cc: linux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org,
linux-ia64@vger.kernel.org
+static __inline__ long atomic64_dec_if_positive(atomic64_t *v)
+{
+ long c, old, dec;
+ c = atomic64_read(v);
+ for (;;) {
+ dec = c - 1;
+ if (unlikely(dec < 0))
+ break;
+ old = atomic64_cmpxchg((v), c, dec);
+ if (likely(old = c))
+ break;
+ c = old;
+ }
+ return dec;
+}
I was about to say "add a cpu_relax()" in the bottom of that loop. But none of the other
atomic ops that spin on a cmpxchg do that ... so:
Acked-by: Tony Luck <tony.luck@intel.com>
-Tony
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-09-12 18:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1473702432-8116-1-git-send-email-vgupta@synopsys.com>
2016-09-12 17:47 ` [PATCH v2 1/2] ia64: implement atomic64_dec_if_positive Vineet Gupta
2016-09-12 18:26 ` Luck, Tony
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox