]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
locking/rwsem: Remove rwsem-spinlock.c & use rwsem-xadd.c for all archs
authorWaiman Long <longman@redhat.com>
Fri, 22 Mar 2019 14:30:07 +0000 (10:30 -0400)
committerIngo Molnar <mingo@kernel.org>
Wed, 3 Apr 2019 12:50:52 +0000 (14:50 +0200)
Currently, we have two different implementation of rwsem:

 1) CONFIG_RWSEM_GENERIC_SPINLOCK (rwsem-spinlock.c)
 2) CONFIG_RWSEM_XCHGADD_ALGORITHM (rwsem-xadd.c)

As we are going to use a single generic implementation for rwsem-xadd.c
and no architecture-specific code will be needed, there is no point
in keeping two different implementations of rwsem. In most cases, the
performance of rwsem-spinlock.c will be worse. It also doesn't get all
the performance tuning and optimizations that had been implemented in
rwsem-xadd.c over the years.

For simplication, we are going to remove rwsem-spinlock.c and make all
architectures use a single implementation of rwsem - rwsem-xadd.c.

All references to RWSEM_GENERIC_SPINLOCK and RWSEM_XCHGADD_ALGORITHM
in the code are removed.

Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Waiman Long <longman@redhat.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tim Chen <tim.c.chen@linux.intel.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-c6x-dev@linux-c6x.org
Cc: linux-m68k@lists.linux-m68k.org
Cc: linux-riscv@lists.infradead.org
Cc: linux-um@lists.infradead.org
Cc: linux-xtensa@linux-xtensa.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: nios2-dev@lists.rocketboards.org
Cc: openrisc@lists.librecores.org
Cc: uclinux-h8-devel@lists.sourceforge.jp
Link: https://lkml.kernel.org/r/20190322143008.21313-3-longman@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
31 files changed:
arch/alpha/Kconfig
arch/arc/Kconfig
arch/arm/Kconfig
arch/arm64/Kconfig
arch/c6x/Kconfig
arch/csky/Kconfig
arch/h8300/Kconfig
arch/hexagon/Kconfig
arch/ia64/Kconfig
arch/m68k/Kconfig
arch/microblaze/Kconfig
arch/mips/Kconfig
arch/nds32/Kconfig
arch/nios2/Kconfig
arch/openrisc/Kconfig
arch/parisc/Kconfig
arch/powerpc/Kconfig
arch/riscv/Kconfig
arch/s390/Kconfig
arch/sh/Kconfig
arch/sparc/Kconfig
arch/unicore32/Kconfig
arch/x86/Kconfig
arch/x86/um/Kconfig
arch/xtensa/Kconfig
include/linux/rwsem-spinlock.h [deleted file]
include/linux/rwsem.h
kernel/Kconfig.locks
kernel/locking/Makefile
kernel/locking/rwsem-spinlock.c [deleted file]
kernel/locking/rwsem.h

index 584a6e1148539682a34a4c480c3f5252ee169267..27c871227eee93634615d395cce5d77ffc96c040 100644 (file)
@@ -49,13 +49,6 @@ config MMU
        bool
        default y
 
-config RWSEM_GENERIC_SPINLOCK
-       bool
-
-config RWSEM_XCHGADD_ALGORITHM
-       bool
-       default y
-
 config ARCH_HAS_ILOG2_U32
        bool
        default n
index c781e45d1d9953267b977bc094e0d1acde0ee623..23e063df5d2cf1233665b575193e9c5e7e227e52 100644 (file)
@@ -63,9 +63,6 @@ config SCHED_OMIT_FRAME_POINTER
 config GENERIC_CSUM
        def_bool y
 
-config RWSEM_GENERIC_SPINLOCK
-       def_bool y
-
 config ARCH_DISCONTIGMEM_ENABLE
        def_bool n
 
index 850b4805e2d171436e539b326867d6ce08a6f9d6..c8b03e1c6c2a45cbfd03a70772d7fe1c4b7b0ca2 100644 (file)
@@ -178,10 +178,6 @@ config TRACE_IRQFLAGS_SUPPORT
        bool
        default !CPU_V7M
 
-config RWSEM_XCHGADD_ALGORITHM
-       bool
-       default y
-
 config ARCH_HAS_ILOG2_U32
        bool
 
index 7e34b9eba5de151572ba479d73ccf82ba18e8beb..c62b9db2b5e889fb55b6a90d6bac48e22df0834d 100644 (file)
@@ -237,9 +237,6 @@ config LOCKDEP_SUPPORT
 config TRACE_IRQFLAGS_SUPPORT
        def_bool y
 
-config RWSEM_XCHGADD_ALGORITHM
-       def_bool y
-
 config GENERIC_BUG
        def_bool y
        depends on BUG
index e5cd3c5f8399ce1cb055315083db5b2f4873a1fe..ed92b5840c0a8281c5c899adfd117e1f74a94edb 100644 (file)
@@ -27,9 +27,6 @@ config MMU
 config FPU
        def_bool n
 
-config RWSEM_GENERIC_SPINLOCK
-       def_bool y
-
 config GENERIC_CALIBRATE_DELAY
        def_bool y
 
index 725a115759c97695eec204f2c15ca399eab234ee..6555d178113221412b1c0f3dbd0ff09c63bb99a6 100644 (file)
@@ -92,9 +92,6 @@ config GENERIC_HWEIGHT
 config MMU
        def_bool y
 
-config RWSEM_GENERIC_SPINLOCK
-       def_bool y
-
 config STACKTRACE_SUPPORT
        def_bool y
 
index c071da34e0817be181e82ac3d7a9ca7eea85450c..61c01db6c29230ca8b60ffc64d00179ccc579b24 100644 (file)
@@ -27,9 +27,6 @@ config H8300
 config CPU_BIG_ENDIAN
        def_bool y
 
-config RWSEM_GENERIC_SPINLOCK
-       def_bool y
-
 config GENERIC_HWEIGHT
        def_bool y
 
index ac441680dcc06acddcfdf717b1828c2cdc1962d8..3e54a53208d58ad7c7587dcc88920a692c5d2634 100644 (file)
@@ -65,12 +65,6 @@ config GENERIC_CSUM
 config GENERIC_IRQ_PROBE
        def_bool y
 
-config RWSEM_GENERIC_SPINLOCK
-       def_bool n
-
-config RWSEM_XCHGADD_ALGORITHM
-       def_bool y
-
 config GENERIC_HWEIGHT
        def_bool y
 
index 8d7396bd1790319eb7fa9a10b671d2b922081b36..73a26f04644e3e27a17c1fc1ab4145f22f6d520c 100644 (file)
@@ -83,10 +83,6 @@ config STACKTRACE_SUPPORT
 config GENERIC_LOCKBREAK
        def_bool n
 
-config RWSEM_XCHGADD_ALGORITHM
-       bool
-       default y
-
 config HUGETLB_PAGE_SIZE_VARIABLE
        bool
        depends on HUGETLB_PAGE
index b54206408f91b9693581c9b6a139324a659cf361..f5661f48019c6062f714bb7a426332b006fce9e6 100644 (file)
@@ -32,13 +32,6 @@ config M68K
 config CPU_BIG_ENDIAN
        def_bool y
 
-config RWSEM_GENERIC_SPINLOCK
-       bool
-       default y
-
-config RWSEM_XCHGADD_ALGORITHM
-       bool
-
 config ARCH_HAS_ILOG2_U32
        bool
 
index a51b965b3b82359f5feb15aaef1529cdbaa0f32a..a7a9a9d59f65e1a71071d68d17caa139aa6d41af 100644 (file)
@@ -58,15 +58,9 @@ config CPU_LITTLE_ENDIAN
 
 endchoice
 
-config RWSEM_GENERIC_SPINLOCK
-       def_bool y
-
 config ZONE_DMA
        def_bool y
 
-config RWSEM_XCHGADD_ALGORITHM
-       bool
-
 config ARCH_HAS_ILOG2_U32
        def_bool n
 
index 4a5f5b0ee9a9e7d9988321e452bf87a7e13be9ab..b9c48b27162dc111aa6fee50d057f2cc4bee368d 100644 (file)
@@ -1037,13 +1037,6 @@ source "arch/mips/paravirt/Kconfig"
 
 endmenu
 
-config RWSEM_GENERIC_SPINLOCK
-       bool
-       default y
-
-config RWSEM_XCHGADD_ALGORITHM
-       bool
-
 config GENERIC_HWEIGHT
        bool
        default y
index addb7f5f52645c75e83025f075d2878efd186d02..55559ca0efe404ce78d7039f9fa09a72df7c0ad3 100644 (file)
@@ -60,9 +60,6 @@ config GENERIC_LOCKBREAK
         def_bool y
        depends on PREEMPT
 
-config RWSEM_GENERIC_SPINLOCK
-       def_bool y
-
 config TRACE_IRQFLAGS_SUPPORT
        def_bool y
 
index 4ef15a61b7bc33ee199a84fb6c8ef36be2a9deac..56685fd45ed004dcdbe337a04ff7dff40991fac8 100644 (file)
@@ -40,9 +40,6 @@ config NO_IOPORT_MAP
 config FPU
        def_bool n
 
-config RWSEM_GENERIC_SPINLOCK
-       def_bool y
-
 config TRACE_IRQFLAGS_SUPPORT
        def_bool n
 
index a5e361fbb75a01400681b6238b21a7eea18b9607..683511b8c9df8d4d00f33820e1e5087a8997da20 100644 (file)
@@ -43,12 +43,6 @@ config CPU_BIG_ENDIAN
 config MMU
        def_bool y
 
-config RWSEM_GENERIC_SPINLOCK
-       def_bool y
-
-config RWSEM_XCHGADD_ALGORITHM
-       def_bool n
-
 config GENERIC_HWEIGHT
        def_bool y
 
index c8e621296092d83751ecdec774fb46aa430c6c04..f1ed8ddfe48697b0fa02810fbcb22763d1bd1302 100644 (file)
@@ -75,12 +75,6 @@ config GENERIC_LOCKBREAK
        default y
        depends on SMP && PREEMPT
 
-config RWSEM_GENERIC_SPINLOCK
-       def_bool y
-
-config RWSEM_XCHGADD_ALGORITHM
-       bool
-
 config ARCH_HAS_ILOG2_U32
        bool
        default n
index 2d0be82c30619bd405949b64c2847603caf5a67d..e5dd6aafaf68e637427daad53ffaa0be8103fb42 100644 (file)
@@ -103,13 +103,6 @@ config LOCKDEP_SUPPORT
        bool
        default y
 
-config RWSEM_GENERIC_SPINLOCK
-       bool
-
-config RWSEM_XCHGADD_ALGORITHM
-       bool
-       default y
-
 config GENERIC_LOCKBREAK
        bool
        default y
index eb56c82d8aa14caf0e6f5507102dd22fb208b9ac..0582260fb6c20f31a68075c217382d30b4a0852c 100644 (file)
@@ -69,9 +69,6 @@ config STACKTRACE_SUPPORT
 config TRACE_IRQFLAGS_SUPPORT
        def_bool y
 
-config RWSEM_GENERIC_SPINLOCK
-       def_bool y
-
 config GENERIC_BUG
        def_bool y
        depends on BUG
index b6e3d0653002af7a8eb20b5a0f3e0d8b27ba0b16..c9300b43719569d7d948aa876759a4d9b116428e 100644 (file)
@@ -14,12 +14,6 @@ config LOCKDEP_SUPPORT
 config STACKTRACE_SUPPORT
        def_bool y
 
-config RWSEM_GENERIC_SPINLOCK
-       bool
-
-config RWSEM_XCHGADD_ALGORITHM
-       def_bool y
-
 config ARCH_HAS_ILOG2_U32
        def_bool n
 
index b1c91ea9a958e939da0a91d720346f6d229a384c..0be08d586d40c64ee7db194210048a7724480ba6 100644 (file)
@@ -90,12 +90,6 @@ config ARCH_DEFCONFIG
        default "arch/sh/configs/shx3_defconfig" if SUPERH32
        default "arch/sh/configs/cayman_defconfig" if SUPERH64
 
-config RWSEM_GENERIC_SPINLOCK
-       def_bool y
-
-config RWSEM_XCHGADD_ALGORITHM
-       bool
-
 config GENERIC_BUG
        def_bool y
        depends on BUG && SUPERH32
index 40f8f4f73fe8fea23c31b73d9e4441dbd67fabf1..16b620237816175dc071e1fc2240adda13b670f7 100644 (file)
@@ -191,14 +191,6 @@ config NR_CPUS
 
 source "kernel/Kconfig.hz"
 
-config RWSEM_GENERIC_SPINLOCK
-       bool
-       default y if SPARC32
-
-config RWSEM_XCHGADD_ALGORITHM
-       bool
-       default y if SPARC64
-
 config GENERIC_HWEIGHT
        bool
        default y
index 817d82608712ab6f603edd6514c16c2744b08584..0d5869c9bf0398b419fdfad5e678ca8d47a37dbf 100644 (file)
@@ -38,12 +38,6 @@ config STACKTRACE_SUPPORT
 config LOCKDEP_SUPPORT
        def_bool y
 
-config RWSEM_GENERIC_SPINLOCK
-       def_bool y
-
-config RWSEM_XCHGADD_ALGORITHM
-       bool
-
 config ARCH_HAS_ILOG2_U32
        bool
 
index 5ad92419be19c5d67fae37158bac2b93e105d1bc..84b184e016cd47eccf57a7907d50a59ce8088bfc 100644 (file)
@@ -268,9 +268,6 @@ config ARCH_MAY_HAVE_PC_FDC
        def_bool y
        depends on ISA_DMA_API
 
-config RWSEM_XCHGADD_ALGORITHM
-       def_bool y
-
 config GENERIC_CALIBRATE_DELAY
        def_bool y
 
index a9e80e44178c7818cdf03ae07fb66128c028f003..a8985e1f7432f394ca1aac200ba23e8c416dd1cc 100644 (file)
@@ -32,12 +32,6 @@ config ARCH_DEFCONFIG
        default "arch/um/configs/i386_defconfig" if X86_32
        default "arch/um/configs/x86_64_defconfig" if X86_64
 
-config RWSEM_XCHGADD_ALGORITHM
-       def_bool 64BIT
-
-config RWSEM_GENERIC_SPINLOCK
-       def_bool !RWSEM_XCHGADD_ALGORITHM
-
 config 3_LEVEL_PGTABLES
        bool "Three-level pagetables" if !64BIT
        default 64BIT
index 4b9aafe766c58870d285975bdb3339b70628c827..35c8d91e61069df2101eeea4c01eb41648aa91cd 100644 (file)
@@ -46,9 +46,6 @@ config XTENSA
          with reasonable minimum requirements.  The Xtensa Linux project has
          a home page at <http://www.linux-xtensa.org/>.
 
-config RWSEM_XCHGADD_ALGORITHM
-       def_bool y
-
 config GENERIC_HWEIGHT
        def_bool y
 
diff --git a/include/linux/rwsem-spinlock.h b/include/linux/rwsem-spinlock.h
deleted file mode 100644 (file)
index e475683..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/* rwsem-spinlock.h: fallback C implementation
- *
- * Copyright (c) 2001   David Howells (dhowells@redhat.com).
- * - Derived partially from ideas by Andrea Arcangeli <andrea@suse.de>
- * - Derived also from comments by Linus
- */
-
-#ifndef _LINUX_RWSEM_SPINLOCK_H
-#define _LINUX_RWSEM_SPINLOCK_H
-
-#ifndef _LINUX_RWSEM_H
-#error "please don't include linux/rwsem-spinlock.h directly, use linux/rwsem.h instead"
-#endif
-
-#ifdef __KERNEL__
-/*
- * the rw-semaphore definition
- * - if count is 0 then there are no active readers or writers
- * - if count is +ve then that is the number of active readers
- * - if count is -1 then there is one active writer
- * - if wait_list is not empty, then there are processes waiting for the semaphore
- */
-struct rw_semaphore {
-       __s32                   count;
-       raw_spinlock_t          wait_lock;
-       struct list_head        wait_list;
-#ifdef CONFIG_DEBUG_LOCK_ALLOC
-       struct lockdep_map dep_map;
-#endif
-};
-
-#define RWSEM_UNLOCKED_VALUE           0x00000000
-
-extern void __down_read(struct rw_semaphore *sem);
-extern int __must_check __down_read_killable(struct rw_semaphore *sem);
-extern int __down_read_trylock(struct rw_semaphore *sem);
-extern void __down_write(struct rw_semaphore *sem);
-extern int __must_check __down_write_killable(struct rw_semaphore *sem);
-extern int __down_write_trylock(struct rw_semaphore *sem);
-extern void __up_read(struct rw_semaphore *sem);
-extern void __up_write(struct rw_semaphore *sem);
-extern void __downgrade_write(struct rw_semaphore *sem);
-extern int rwsem_is_locked(struct rw_semaphore *sem);
-
-#endif /* __KERNEL__ */
-#endif /* _LINUX_RWSEM_SPINLOCK_H */
index 6e56006b2cb6b7017c712cc76fe6e2cbeb61e247..0fc41062c6495ce1191051947ebe669866ea0aac 100644 (file)
 
 struct rw_semaphore;
 
-#ifdef CONFIG_RWSEM_GENERIC_SPINLOCK
-#include <linux/rwsem-spinlock.h> /* use a generic implementation */
-#define __RWSEM_INIT_COUNT(name)       .count = RWSEM_UNLOCKED_VALUE
-#else
 /* All arch specific implementations share the same struct */
 struct rw_semaphore {
        atomic_long_t count;
@@ -65,7 +61,6 @@ static inline int rwsem_is_locked(struct rw_semaphore *sem)
 
 #define RWSEM_UNLOCKED_VALUE           0L
 #define __RWSEM_INIT_COUNT(name)       .count = ATOMIC_LONG_INIT(RWSEM_UNLOCKED_VALUE)
-#endif
 
 /* Common initializer macros and functions */
 
index fbba478ae52294f5306818deb15a9259b0132d53..e335953fa70407c39b18243f9aad7d1634e9b68a 100644 (file)
@@ -229,7 +229,7 @@ config MUTEX_SPIN_ON_OWNER
 
 config RWSEM_SPIN_ON_OWNER
        def_bool y
-       depends on SMP && RWSEM_XCHGADD_ALGORITHM && ARCH_SUPPORTS_ATOMIC_RMW
+       depends on SMP && ARCH_SUPPORTS_ATOMIC_RMW
 
 config LOCK_SPIN_ON_OWNER
        def_bool y
index 392c7f23af7651a52dda141740d890b77114cab6..1af83e9ce57d5f4b3c685998e6197ac5141955f5 100644 (file)
@@ -3,7 +3,7 @@
 # and is generally not a function of system call inputs.
 KCOV_INSTRUMENT                := n
 
-obj-y += mutex.o semaphore.o rwsem.o percpu-rwsem.o
+obj-y += mutex.o semaphore.o rwsem.o percpu-rwsem.o rwsem-xadd.o
 
 ifdef CONFIG_FUNCTION_TRACER
 CFLAGS_REMOVE_lockdep.o = $(CC_FLAGS_FTRACE)
@@ -25,8 +25,6 @@ obj-$(CONFIG_RT_MUTEXES) += rtmutex.o
 obj-$(CONFIG_DEBUG_RT_MUTEXES) += rtmutex-debug.o
 obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock.o
 obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock_debug.o
-obj-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o
-obj-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem-xadd.o
 obj-$(CONFIG_QUEUED_RWLOCKS) += qrwlock.o
 obj-$(CONFIG_LOCK_TORTURE_TEST) += locktorture.o
 obj-$(CONFIG_WW_MUTEX_SELFTEST) += test-ww_mutex.o
diff --git a/kernel/locking/rwsem-spinlock.c b/kernel/locking/rwsem-spinlock.c
deleted file mode 100644 (file)
index a7ffb2a..0000000
+++ /dev/null
@@ -1,339 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/* rwsem-spinlock.c: R/W semaphores: contention handling functions for
- * generic spinlock implementation
- *
- * Copyright (c) 2001   David Howells (dhowells@redhat.com).
- * - Derived partially from idea by Andrea Arcangeli <andrea@suse.de>
- * - Derived also from comments by Linus
- */
-#include <linux/rwsem.h>
-#include <linux/sched/signal.h>
-#include <linux/sched/debug.h>
-#include <linux/export.h>
-
-enum rwsem_waiter_type {
-       RWSEM_WAITING_FOR_WRITE,
-       RWSEM_WAITING_FOR_READ
-};
-
-struct rwsem_waiter {
-       struct list_head list;
-       struct task_struct *task;
-       enum rwsem_waiter_type type;
-};
-
-int rwsem_is_locked(struct rw_semaphore *sem)
-{
-       int ret = 1;
-       unsigned long flags;
-
-       if (raw_spin_trylock_irqsave(&sem->wait_lock, flags)) {
-               ret = (sem->count != 0);
-               raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
-       }
-       return ret;
-}
-EXPORT_SYMBOL(rwsem_is_locked);
-
-/*
- * initialise the semaphore
- */
-void __init_rwsem(struct rw_semaphore *sem, const char *name,
-                 struct lock_class_key *key)
-{
-#ifdef CONFIG_DEBUG_LOCK_ALLOC
-       /*
-        * Make sure we are not reinitializing a held semaphore:
-        */
-       debug_check_no_locks_freed((void *)sem, sizeof(*sem));
-       lockdep_init_map(&sem->dep_map, name, key, 0);
-#endif
-       sem->count = 0;
-       raw_spin_lock_init(&sem->wait_lock);
-       INIT_LIST_HEAD(&sem->wait_list);
-}
-EXPORT_SYMBOL(__init_rwsem);
-
-/*
- * handle the lock release when processes blocked on it that can now run
- * - if we come here, then:
- *   - the 'active count' _reached_ zero
- *   - the 'waiting count' is non-zero
- * - the spinlock must be held by the caller
- * - woken process blocks are discarded from the list after having task zeroed
- * - writers are only woken if wakewrite is non-zero
- */
-static inline struct rw_semaphore *
-__rwsem_do_wake(struct rw_semaphore *sem, int wakewrite)
-{
-       struct rwsem_waiter *waiter;
-       struct task_struct *tsk;
-       int woken;
-
-       waiter = list_entry(sem->wait_list.next, struct rwsem_waiter, list);
-
-       if (waiter->type == RWSEM_WAITING_FOR_WRITE) {
-               if (wakewrite)
-                       /* Wake up a writer. Note that we do not grant it the
-                        * lock - it will have to acquire it when it runs. */
-                       wake_up_process(waiter->task);
-               goto out;
-       }
-
-       /* grant an infinite number of read locks to the front of the queue */
-       woken = 0;
-       do {
-               struct list_head *next = waiter->list.next;
-
-               list_del(&waiter->list);
-               tsk = waiter->task;
-               /*
-                * Make sure we do not wakeup the next reader before
-                * setting the nil condition to grant the next reader;
-                * otherwise we could miss the wakeup on the other
-                * side and end up sleeping again. See the pairing
-                * in rwsem_down_read_failed().
-                */
-               smp_mb();
-               waiter->task = NULL;
-               wake_up_process(tsk);
-               put_task_struct(tsk);
-               woken++;
-               if (next == &sem->wait_list)
-                       break;
-               waiter = list_entry(next, struct rwsem_waiter, list);
-       } while (waiter->type != RWSEM_WAITING_FOR_WRITE);
-
-       sem->count += woken;
-
- out:
-       return sem;
-}
-
-/*
- * wake a single writer
- */
-static inline struct rw_semaphore *
-__rwsem_wake_one_writer(struct rw_semaphore *sem)
-{
-       struct rwsem_waiter *waiter;
-
-       waiter = list_entry(sem->wait_list.next, struct rwsem_waiter, list);
-       wake_up_process(waiter->task);
-
-       return sem;
-}
-
-/*
- * get a read lock on the semaphore
- */
-int __sched __down_read_common(struct rw_semaphore *sem, int state)
-{
-       struct rwsem_waiter waiter;
-       unsigned long flags;
-
-       raw_spin_lock_irqsave(&sem->wait_lock, flags);
-
-       if (sem->count >= 0 && list_empty(&sem->wait_list)) {
-               /* granted */
-               sem->count++;
-               raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
-               goto out;
-       }
-
-       /* set up my own style of waitqueue */
-       waiter.task = current;
-       waiter.type = RWSEM_WAITING_FOR_READ;
-       get_task_struct(current);
-
-       list_add_tail(&waiter.list, &sem->wait_list);
-
-       /* wait to be given the lock */
-       for (;;) {
-               if (!waiter.task)
-                       break;
-               if (signal_pending_state(state, current))
-                       goto out_nolock;
-               set_current_state(state);
-               raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
-               schedule();
-               raw_spin_lock_irqsave(&sem->wait_lock, flags);
-       }
-
-       raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
- out:
-       return 0;
-
-out_nolock:
-       /*
-        * We didn't take the lock, so that there is a writer, which
-        * is owner or the first waiter of the sem. If it's a waiter,
-        * it will be woken by current owner. Not need to wake anybody.
-        */
-       list_del(&waiter.list);
-       raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
-       return -EINTR;
-}
-
-void __sched __down_read(struct rw_semaphore *sem)
-{
-       __down_read_common(sem, TASK_UNINTERRUPTIBLE);
-}
-
-int __sched __down_read_killable(struct rw_semaphore *sem)
-{
-       return __down_read_common(sem, TASK_KILLABLE);
-}
-
-/*
- * trylock for reading -- returns 1 if successful, 0 if contention
- */
-int __down_read_trylock(struct rw_semaphore *sem)
-{
-       unsigned long flags;
-       int ret = 0;
-
-
-       raw_spin_lock_irqsave(&sem->wait_lock, flags);
-
-       if (sem->count >= 0 && list_empty(&sem->wait_list)) {
-               /* granted */
-               sem->count++;
-               ret = 1;
-       }
-
-       raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
-
-       return ret;
-}
-
-/*
- * get a write lock on the semaphore
- */
-int __sched __down_write_common(struct rw_semaphore *sem, int state)
-{
-       struct rwsem_waiter waiter;
-       unsigned long flags;
-       int ret = 0;
-
-       raw_spin_lock_irqsave(&sem->wait_lock, flags);
-
-       /* set up my own style of waitqueue */
-       waiter.task = current;
-       waiter.type = RWSEM_WAITING_FOR_WRITE;
-       list_add_tail(&waiter.list, &sem->wait_list);
-
-       /* wait for someone to release the lock */
-       for (;;) {
-               /*
-                * That is the key to support write lock stealing: allows the
-                * task already on CPU to get the lock soon rather than put
-                * itself into sleep and waiting for system woke it or someone
-                * else in the head of the wait list up.
-                */
-               if (sem->count == 0)
-                       break;
-               if (signal_pending_state(state, current))
-                       goto out_nolock;
-
-               set_current_state(state);
-               raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
-               schedule();
-               raw_spin_lock_irqsave(&sem->wait_lock, flags);
-       }
-       /* got the lock */
-       sem->count = -1;
-       list_del(&waiter.list);
-
-       raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
-
-       return ret;
-
-out_nolock:
-       list_del(&waiter.list);
-       if (!list_empty(&sem->wait_list) && sem->count >= 0)
-               __rwsem_do_wake(sem, 0);
-       raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
-
-       return -EINTR;
-}
-
-void __sched __down_write(struct rw_semaphore *sem)
-{
-       __down_write_common(sem, TASK_UNINTERRUPTIBLE);
-}
-
-int __sched __down_write_killable(struct rw_semaphore *sem)
-{
-       return __down_write_common(sem, TASK_KILLABLE);
-}
-
-/*
- * trylock for writing -- returns 1 if successful, 0 if contention
- */
-int __down_write_trylock(struct rw_semaphore *sem)
-{
-       unsigned long flags;
-       int ret = 0;
-
-       raw_spin_lock_irqsave(&sem->wait_lock, flags);
-
-       if (sem->count == 0) {
-               /* got the lock */
-               sem->count = -1;
-               ret = 1;
-       }
-
-       raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
-
-       return ret;
-}
-
-/*
- * release a read lock on the semaphore
- */
-void __up_read(struct rw_semaphore *sem)
-{
-       unsigned long flags;
-
-       raw_spin_lock_irqsave(&sem->wait_lock, flags);
-
-       if (--sem->count == 0 && !list_empty(&sem->wait_list))
-               sem = __rwsem_wake_one_writer(sem);
-
-       raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
-}
-
-/*
- * release a write lock on the semaphore
- */
-void __up_write(struct rw_semaphore *sem)
-{
-       unsigned long flags;
-
-       raw_spin_lock_irqsave(&sem->wait_lock, flags);
-
-       sem->count = 0;
-       if (!list_empty(&sem->wait_list))
-               sem = __rwsem_do_wake(sem, 1);
-
-       raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
-}
-
-/*
- * downgrade a write lock into a read lock
- * - just wake up any readers at the front of the queue
- */
-void __downgrade_write(struct rw_semaphore *sem)
-{
-       unsigned long flags;
-
-       raw_spin_lock_irqsave(&sem->wait_lock, flags);
-
-       sem->count = 1;
-       if (!list_empty(&sem->wait_list))
-               sem = __rwsem_do_wake(sem, 0);
-
-       raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
-}
-
index 067e265fa5c1df5da7efef44554247c7d2260282..45ee00236e0398ebe82174cb10dc42e3191f6743 100644 (file)
@@ -153,7 +153,6 @@ static inline void rwsem_clear_reader_owned(struct rw_semaphore *sem)
 }
 #endif
 
-#ifdef CONFIG_RWSEM_XCHGADD_ALGORITHM
 /*
  * lock for reading
  */
@@ -260,5 +259,3 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
        if (tmp < 0)
                rwsem_downgrade_wake(sem);
 }
-
-#endif /* CONFIG_RWSEM_XCHGADD_ALGORITHM */