Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4db2ce01 authored by David S. Miller's avatar David S. Miller
Browse files

[LIB]: Consolidate _atomic_dec_and_lock()



Several implementations were essentialy a common piece of C code using
the cmpxchg() macro.  Put the implementation in one spot that everyone
can share, and convert sparc64 over to using this.

Alpha is the lone arch-specific implementation, which codes up a
special fast path for the common case in order to avoid GP reloading
which a pure C version would require.

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4a805e86
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -908,11 +908,6 @@ config IRQBALANCE
 	  The default yes will allow the kernel to do irq load balancing.
	  Saying no will keep the kernel from doing irq load balancing.

config HAVE_DEC_LOCK
	bool
	depends on (SMP || PREEMPT) && X86_CMPXCHG
	default y

# turning this on wastes a bunch of space.
# Summit needs it only when NUMA is on
config BOOT_IOREMAP
+0 −1
Original line number Diff line number Diff line
@@ -7,4 +7,3 @@ lib-y = checksum.o delay.o usercopy.o getuser.o putuser.o memcpy.o strstr.o \
	bitops.o

lib-$(CONFIG_X86_USE_3DNOW) += mmx.o
lib-$(CONFIG_HAVE_DEC_LOCK) += dec_and_lock.o

arch/i386/lib/dec_and_lock.c

deleted100644 → 0
+0 −42
Original line number Diff line number Diff line
/*
 * x86 version of "atomic_dec_and_lock()" using
 * the atomic "cmpxchg" instruction.
 *
 * (For CPU's lacking cmpxchg, we use the slow
 * generic version, and this one never even gets
 * compiled).
 */

#include <linux/spinlock.h>
#include <linux/module.h>
#include <asm/atomic.h>

int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock)
{
	int counter;
	int newcount;

repeat:
	counter = atomic_read(atomic);
	newcount = counter-1;

	if (!newcount)
		goto slow_path;

	asm volatile("lock; cmpxchgl %1,%2"
		:"=a" (newcount)
		:"r" (newcount), "m" (atomic->counter), "0" (counter));

	/* If the above failed, "eax" will have changed */
	if (newcount != counter)
		goto repeat;
	return 0;

slow_path:
	spin_lock(lock);
	if (atomic_dec_and_test(atomic))
		return 1;
	spin_unlock(lock);
	return 0;
}
EXPORT_SYMBOL(_atomic_dec_and_lock);
+0 −5
Original line number Diff line number Diff line
@@ -298,11 +298,6 @@ config PREEMPT

source "mm/Kconfig"

config HAVE_DEC_LOCK
	bool
	depends on (SMP || PREEMPT)
	default y

config IA32_SUPPORT
	bool "Support for Linux/x86 binaries"
	help
+0 −1
Original line number Diff line number Diff line
@@ -15,7 +15,6 @@ lib-$(CONFIG_ITANIUM) += copy_page.o copy_user.o memcpy.o
lib-$(CONFIG_MCKINLEY)	+= copy_page_mck.o memcpy_mck.o
lib-$(CONFIG_PERFMON)	+= carta_random.o
lib-$(CONFIG_MD_RAID5)	+= xor.o
lib-$(CONFIG_HAVE_DEC_LOCK) += dec_and_lock.o

AFLAGS___divdi3.o	=
AFLAGS___udivdi3.o	= -DUNSIGNED
Loading