Commit b3a2a05f authored by Mark Rutland's avatar Mark Rutland Committed by Ingo Molnar
Browse files

atomics/treewide: Make conditional inc/dec ops optional



The conditional inc/dec ops differ for atomic_t and atomic64_t:

- atomic_inc_unless_positive() is optional for atomic_t, and doesn't exist for atomic64_t.
- atomic_dec_unless_negative() is optional for atomic_t, and doesn't exist for atomic64_t.
- atomic_dec_if_positive is optional for atomic_t, and is mandatory for atomic64_t.

Let's make these consistently optional for both. At the same time, let's
clean up the existing fallbacks to use atomic_try_cmpxchg().

The instrumented atomics are updated accordingly.

There should be no functional change as a result of this patch.

Signed-off-by: default avatarMark Rutland <mark.rutland@arm.com>
Reviewed-by: default avatarWill Deacon <will.deacon@arm.com>
Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/lkml/20180621121321.4761-18-mark.rutland@arm.com


Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 9837559d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -296,5 +296,6 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
	smp_mb();
	return old - 1;
}
#define atomic64_dec_if_positive atomic64_dec_if_positive

#endif /* _ALPHA_ATOMIC_H */
+1 −0
Original line number Diff line number Diff line
@@ -517,6 +517,7 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)

	return val;
}
#define atomic64_dec_if_positive atomic64_dec_if_positive

/**
 * atomic64_fetch_add_unless - add unless the number is a given value
+1 −0
Original line number Diff line number Diff line
@@ -474,6 +474,7 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)

	return result;
}
#define atomic64_dec_if_positive atomic64_dec_if_positive

static inline long long atomic64_fetch_add_unless(atomic64_t *v, long long a,
						  long long u)
+2 −0
Original line number Diff line number Diff line
@@ -159,5 +159,7 @@

#define atomic64_andnot			atomic64_andnot

#define atomic64_dec_if_positive	atomic64_dec_if_positive

#endif
#endif
+0 −16
Original line number Diff line number Diff line
@@ -215,22 +215,6 @@ ATOMIC64_FETCH_OP(xor, ^)
	(cmpxchg(&((v)->counter), old, new))
#define atomic64_xchg(v, new) (xchg(&((v)->counter), new))

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

#define atomic_add(i,v)			(void)atomic_add_return((i), (v))
#define atomic_sub(i,v)			(void)atomic_sub_return((i), (v))

Loading