Skip to content

Commit f74445b

Browse files
mrutland-armingomolnar
authored andcommitted
atomics/treewide: Remove atomic_inc_not_zero_hint()
While documentation suggests atomic_inc_not_zero_hint() will perform better than atomic_inc_not_zero(), this is unlikely to be the case. No architectures implement atomic_inc_not_zero_hint() directly, and thus it either falls back to atomic_inc_not_zero(), or a loop using atomic_cmpxchg(). Whenever the hint does not match the value in memory, the repeated use of atomic_cmpxchg() will be more expensive than the read that atomic_inc_not_zero_hint() attempts to avoid. For architectures with LL/SC atomics, a read cannot be avoided, and it would always be better to use atomic_inc_not_zero() directly. For other architectures, their own atomic_inc_not_zero() is likely to be more optimal than an atomic_cmpxchg() loop regardless. Generally, atomic_inc_not_zero_hint() is liable to perform worse than atomic_inc_not_zero(). Further, atomic_inc_not_zero_hint() only exists for atomic_t, and not atomic64_t or atomic_long_t, and there is only one user in the kernel tree. Given all this, let's remove atomic_inc_not_zero_hint(), and migrate the existing user over to atomic_inc_not_zero(). There should be no functional change as a result of this patch. Signed-off-by: Mark Rutland <mark.rutland@arm.com> Reviewed-by: Will Deacon <will.deacon@arm.com> Acked-by: Peter 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-4-mark.rutland@arm.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 8b47038 commit f74445b

2 files changed

Lines changed: 1 addition & 33 deletions

File tree

‎include/linux/atomic.h‎

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -571,38 +571,6 @@ static inline int atomic_fetch_andnot_release(int i, atomic_t *v)
571571
}
572572
#endif
573573

574-
/**
575-
* atomic_inc_not_zero_hint - increment if not null
576-
* @v: pointer of type atomic_t
577-
* @hint: probable value of the atomic before the increment
578-
*
579-
* This version of atomic_inc_not_zero() gives a hint of probable
580-
* value of the atomic. This helps processor to not read the memory
581-
* before doing the atomic read/modify/write cycle, lowering
582-
* number of bus transactions on some arches.
583-
*
584-
* Returns: 0 if increment was not done, 1 otherwise.
585-
*/
586-
#ifndef atomic_inc_not_zero_hint
587-
static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
588-
{
589-
int val, c = hint;
590-
591-
/* sanity test, should be removed by compiler if hint is a constant */
592-
if (!hint)
593-
return atomic_inc_not_zero(v);
594-
595-
do {
596-
val = atomic_cmpxchg(v, c, c + 1);
597-
if (val == c)
598-
return 1;
599-
c = val;
600-
} while (c);
601-
602-
return 0;
603-
}
604-
#endif
605-
606574
#ifndef atomic_inc_unless_negative
607575
static inline int atomic_inc_unless_negative(atomic_t *p)
608576
{

‎net/atm/pppoatm.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ static int pppoatm_may_send(struct pppoatm_vcc *pvcc, int size)
244244
* the packet count limit, so...
245245
*/
246246
if (atm_may_send(pvcc->atmvcc, size) &&
247-
atomic_inc_not_zero_hint(&pvcc->inflight, NONE_INFLIGHT))
247+
atomic_inc_not_zero(&pvcc->inflight))
248248
return 1;
249249

250250
/*

0 commit comments

Comments
 (0)