Updated generic semaphore patch set
Subsystems (15)
I've pushed out a new version of the semaphore tree. I'll send the new patches as a reply to this mail.
git://git.kernel.org/pub/scm/linux/kernel/git/willy/misc.git semaphore-20080314
Changes:
- Dropped all the asm/semaphore.h changes. They're just causing conflicts for linux-next, and while Stephen assures me that fixing them up is trivial and he doesn't mind, I'd rather not burn him out prematurely. I still intend to push them, but they don't need to be part of linux-next, IMO.
- Split the addition of down_killable() out of the main patch. It's logically separate (adding a new interface), and it was sheer laziness to not split it out in the first place.
- New functionality! down_timeout(). Just look at the mess in acpi/osl.c where it tries to emulate it. It's very little extra code to add it to kernel/semaphore.c, so I thought it was a good idea.
- Simplify the implementation. Dave Howells said the current algorithm makes his head hurt, and in retrospect, perhaps I was just trying to be too clever.
- Fix the lockdep bug (thanks to Peter Zijlstra)
- Remove an unsightly and unnecessary unlikely() (thanks to Harvey Harrison)
- Fix the down() while interrupts disabled bug (thanks to Ingo Molnar) (I may have posted this one before. Not sure.)
I've tested the end result of this with Dave Howells' synchro-test module and not found any problems.
If you prefer, you can also find the patches at
http://git.kernel.org/?p=linux/kernel/git/willy/misc.git;a=shortlog;h=semaphore-20080314
Signature · 4 lines
Intel are signing my paycheques ... these opinions are still mine "Bill, look, we understand that you're interested in selling us this operating system, but compare it to ours. We can't possibly take such a retrograde step."
From: Harvey Harrison <[email protected]>
Subject: [PATCH] semaphore: eliminate forward declarations
Move the internal helper functions before their use and remove the forward declarations.
---
This is a pretty trivial thing...other than this looks good to me.
kernel/semaphore.c | 156 +++++++++++++++++++++++++--------------------------- 1 files changed, 75 insertions(+), 81 deletions(-)
kernel/semaphore.c +75 -81
@@ -22,11 +22,81 @@* semaphore. If it's zero, there may be tasks waiting on the list. */ -static noinline void __down(struct semaphore *sem); -static noinline int __down_interruptible(struct semaphore *sem); -static noinline int __down_killable(struct semaphore *sem); -static noinline int __down_timeout(struct semaphore *sem, long jiffies); -static noinline void __up(struct semaphore *sem); +/* Functions for the contended case */ + +struct semaphore_waiter { +struct list_head list; +struct task_struct *task; +int up; +}; + +/* +* Because this function is inlined, the 'state' parameter will be +* constant, and thus optimised away by the compiler. Likewise the +* 'timeout' parameter for the cases without timeouts. +*/ +static inline int __sched __down_common(struct semaphore *sem, long state, +long timeout) +{ +struct task_struct *task = current; +struct semaphore_waiter waiter; + +list_add_tail (&waiter.list, &sem->wait_list); + waiter.task = task; + waiter.up =0 ; + +for (;;) { +if (state ==TASK_INTERRUPTIBLE &&signal_pending (task)) + goto interrupted; +if (state ==TASK_KILLABLE &&fatal_signal_pending (task)) + goto interrupted; +if (timeout <=0 ) + goto timed_out; +__set_task_state (task, state); +spin_unlock_irq (&sem->lock); + timeout =schedule_timeout (timeout); +spin_lock_irq (&sem->lock); +if (waiter.up) +return 0 ; + } + + timed_out: +list_del (&waiter.list); +return -ETIME ; + + interrupted: +list_del (&waiter.list); +return -EINTR ; +} + +static noinline void __sched __down(struct semaphore *sem) +{ +__down_common (sem,TASK_UNINTERRUPTIBLE ,MAX_SCHEDULE_TIMEOUT ); +} + +static noinline int __sched __down_interruptible(struct semaphore *sem) +{ +return __down_common (sem,TASK_INTERRUPTIBLE ,MAX_SCHEDULE_TIMEOUT ); +} + +static noinline int __sched __down_killable(struct semaphore *sem) +{ +return __down_common (sem,TASK_KILLABLE ,MAX_SCHEDULE_TIMEOUT ); +} + +static noinline int __sched __down_timeout(struct semaphore *sem, long jiffies) +{ +return __down_common (sem,TASK_UNINTERRUPTIBLE , jiffies); +} + +static noinline void __sched __up(struct semaphore *sem) +{ +struct semaphore_waiter *waiter =list_first_entry (&sem->wait_list, + struct semaphore_waiter, list); +list_del (&waiter->list); + waiter->up =1 ; +wake_up_process (waiter->task); +}void down (struct semaphore *sem) {
@@ -129,79 +199,3 @@ void up(struct semaphore *sem)spin_unlock_irqrestore (&sem->lock, flags); }EXPORT_SYMBOL (up); - -/* Functions for the contended case */ - -struct semaphore_waiter { -struct list_head list; -struct task_struct *task; -int up; -}; - -/* -* Because this function is inlined, the 'state' parameter will be -* constant, and thus optimised away by the compiler. Likewise the -* 'timeout' parameter for the cases without timeouts. -*/ -static inline int __sched __down_common(struct semaphore *sem, long state, -long timeout) -{ -struct task_struct *task = current; -struct semaphore_waiter waiter; - -list_add_tail (&waiter.list, &sem->wait_list); - waiter.task = task; - waiter.up =0 ; - -for (;;) { -if (state ==TASK_INTERRUPTIBLE &&signal_pending (task)) - goto interrupted; -if (state ==TASK_KILLABLE &&fatal_signal_pending (task)) - goto interrupted; -if (timeout <=0 ) - goto timed_out; -__set_task_state (task, state); -spin_unlock_irq (&sem->lock); - timeout =schedule_timeout (timeout); -spin_lock_irq (&sem->lock); -if (waiter.up) -return 0 ; - } - - timed_out: -list_del (&waiter.list); -return -ETIME ; - - interrupted: -list_del (&waiter.list); -return -EINTR ; -} - -static noinline void __sched __down(struct semaphore *sem) -{ -__down_common (sem,TASK_UNINTERRUPTIBLE ,MAX_SCHEDULE_TIMEOUT ); -} - -static noinline int __sched __down_interruptible(struct semaphore *sem) -{ -return __down_common (sem,TASK_INTERRUPTIBLE ,MAX_SCHEDULE_TIMEOUT ); -} - -static noinline int __sched __down_killable(struct semaphore *sem) -{ -return __down_common (sem,TASK_KILLABLE ,MAX_SCHEDULE_TIMEOUT ); -} - -static noinline int __sched __down_timeout(struct semaphore *sem, long jiffies) -{ -return __down_common (sem,TASK_UNINTERRUPTIBLE , jiffies); -} - -static noinline void __sched __up(struct semaphore *sem) -{ -struct semaphore_waiter *waiter =list_first_entry (&sem->wait_list, - struct semaphore_waiter, list); -list_del (&waiter->list); - waiter->up =1 ; -wake_up_process (waiter->task); -}
Signature · 1 line
1.5.4.4.684.g0e08
PATCH 1/6 Fix quota.h includes
In reply to Matthew Wilcoxquota.h currently relies on asm/semaphore.h (through some chain; it doesn't actually include semaphore.h itself) to include wait.h. As well as being bad practice to rely on an implicit include, subsequent patches will break this. While I'm in this file, add atomic.h and list.h, and sort the list of includes.
--- include/linux/quota.h | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-)
include/linux/quota.h +6 -2
@@ -160,14 +160,18 @@ enum {#ifdef __KERNEL__ -#include <linux/spinlock.h> -#include <linux/rwsem.h> +#include <linux/list.h> #include <linux/mutex.h> +#include <linux/rwsem.h> +#include <linux/spinlock.h> +#include <linux/wait.h> #include <linux/dqblk_xfs.h> #include <linux/dqblk_v1.h> #include <linux/dqblk_v2.h> +#include <asm/atomic.h> +extern spinlock_t dq_data_lock;/* Maximal numbers of writes for quota operation (insert/delete/update)
Signature · 1 line
1.5.4.3
PATCH 2/6 Add semaphore.h to kernel_lock.c
kernel_lock.c uses DECLARE_MUTEX, up() and down() without explicitly including asm/semaphore.h. This is fragile and leaves it vulnerable to breakage during header reorganisations.
--- lib/kernel_lock.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
lib/kernel_lock.c +1 -0
@@ -8,6 +8,7 @@#include <linux/smp_lock.h> #include <linux/module.h> #include <linux/kallsyms.h> +#include <asm/semaphore.h> /* * The 'big kernel semaphore'
Signature · 1 line
1.5.4.3
PATCH 3/6 Generic semaphore implementation
Semaphores are no longer performance-critical, so a generic C implementation is better for maintainability, debuggability and extensibility. Thanks to Peter Zijlstra for fixing the lockdep warning. Thanks to Harvey Harrison for pointing out that the unlikely() was unnecessary.
--- arch/alpha/kernel/Makefile | 2 +- arch/alpha/kernel/alpha_ksyms.c | 9 - arch/alpha/kernel/semaphore.c | 224 -------------------------- arch/arm/kernel/Makefile | 2 +- arch/arm/kernel/semaphore.c | 221 -------------------------- arch/avr32/kernel/Makefile | 2 +- arch/avr32/kernel/semaphore.c | 148 ----------------- arch/blackfin/Kconfig | 4 - arch/blackfin/kernel/bfin_ksyms.c | 5 - arch/cris/kernel/Makefile | 3 +- arch/cris/kernel/crisksyms.c | 7 - arch/cris/kernel/semaphore.c | 129 --------------- arch/frv/kernel/Makefile | 2 +- arch/frv/kernel/frv_ksyms.c | 1 - arch/frv/kernel/semaphore.c | 155 ------------------ arch/h8300/kernel/Makefile | 2 +- arch/h8300/kernel/h8300_ksyms.c | 1 - arch/h8300/kernel/semaphore.c | 132 ---------------- arch/ia64/kernel/Makefile | 2 +- arch/ia64/kernel/ia64_ksyms.c | 6 - arch/ia64/kernel/semaphore.c | 165 ------------------- arch/m32r/kernel/Makefile | 2 +- arch/m32r/kernel/m32r_ksyms.c | 5 - arch/m32r/kernel/semaphore.c | 185 ---------------------- arch/m68k/kernel/Makefile | 2 +- arch/m68k/kernel/m68k_ksyms.c | 6 - arch/m68k/kernel/semaphore.c | 132 ---------------- arch/m68k/lib/Makefile | 2 +- arch/m68k/lib/semaphore.S | 53 ------ arch/m68knommu/kernel/Makefile | 2 +- arch/m68knommu/kernel/m68k_ksyms.c | 6 - arch/m68knommu/kernel/semaphore.c | 133 ---------------- arch/m68knommu/lib/Makefile | 2 +- arch/m68knommu/lib/semaphore.S | 66 -------- arch/mips/kernel/Makefile | 2 +- arch/mips/kernel/semaphore.c | 168 -------------------- arch/mn10300/kernel/Makefile | 2 +- arch/mn10300/kernel/semaphore.c | 149 ----------------- arch/parisc/kernel/Makefile | 2 +- arch/parisc/kernel/parisc_ksyms.c | 5 - arch/parisc/kernel/semaphore.c | 102 ------------ arch/powerpc/kernel/Makefile | 2 +- arch/powerpc/kernel/ppc_ksyms.c | 1 - arch/powerpc/kernel/semaphore.c | 135 ---------------- arch/ppc/kernel/semaphore.c | 131 --------------- arch/s390/kernel/Makefile | 2 +- arch/s390/kernel/s390_ksyms.c | 7 - arch/s390/kernel/semaphore.c | 108 ------------- arch/sh/kernel/Makefile_32 | 2 +- arch/sh/kernel/Makefile_64 | 2 +- arch/sh/kernel/semaphore.c | 139 ---------------- arch/sh/kernel/sh_ksyms_32.c | 7 - arch/sh/kernel/sh_ksyms_64.c | 4 - arch/sparc/kernel/Makefile | 2 +- arch/sparc/kernel/semaphore.c | 155 ------------------ arch/sparc/kernel/sparc_ksyms.c | 5 - arch/sparc64/kernel/Makefile | 2 +- arch/sparc64/kernel/semaphore.c | 254 ------------------------------ arch/sparc64/kernel/sparc64_ksyms.c | 6 - arch/um/Kconfig.i386 | 4 - arch/um/Kconfig.x86_64 | 4 - arch/um/sys-i386/ksyms.c | 12 -- arch/um/sys-ppc/Makefile | 8 +- arch/um/sys-x86_64/ksyms.c | 13 +-- arch/v850/kernel/Makefile | 2 +- arch/v850/kernel/semaphore.c | 166 ------------------- arch/v850/kernel/v850_ksyms.c | 7 - arch/x86/Kconfig | 3 - arch/x86/kernel/i386_ksyms_32.c | 5 - arch/x86/kernel/x8664_ksyms_64.c | 6 - arch/x86/lib/semaphore_32.S | 83 ---------- arch/x86/lib/thunk_64.S | 5 - arch/xtensa/kernel/Makefile | 2 +- arch/xtensa/kernel/semaphore.c | 226 -------------------------- arch/xtensa/kernel/xtensa_ksyms.c | 9 - include/asm-alpha/semaphore.h | 150 +----------------- include/asm-arm/semaphore-helper.h | 84 ---------- include/asm-arm/semaphore.h | 99 +------------ include/asm-avr32/semaphore.h | 109 +------------- include/asm-blackfin/semaphore-helper.h | 82 ---------- include/asm-blackfin/semaphore.h | 106 +------------ include/asm-cris/semaphore-helper.h | 78 --------- include/asm-cris/semaphore.h | 134 +---------------- include/asm-frv/semaphore.h | 156 +------------------ include/asm-h8300/semaphore-helper.h | 85 ---------- include/asm-h8300/semaphore.h | 191 +---------------------- include/asm-ia64/semaphore.h | 100 +------------ include/asm-m32r/semaphore.h | 145 +----------------- include/asm-m68k/semaphore-helper.h | 142 ----------------- include/asm-m68k/semaphore.h | 164 +------------------- include/asm-m68knommu/semaphore-helper.h | 82 ---------- include/asm-m68knommu/semaphore.h | 154 +------------------ include/asm-mips/semaphore.h | 109 +------------- include/asm-mn10300/semaphore.h | 170 +-------------------- include/asm-parisc/semaphore-helper.h | 89 ----------- include/asm-parisc/semaphore.h | 146 +----------------- include/asm-powerpc/semaphore.h | 95 +----------- include/asm-s390/semaphore.h | 108 +------------- include/asm-sh/semaphore-helper.h | 89 ----------- include/asm-sh/semaphore.h | 116 +-------------- include/asm-sparc/semaphore.h | 193 +---------------------- include/asm-sparc64/semaphore.h | 54 +------ include/asm-um/semaphore.h | 7 +- include/asm-v850/semaphore.h | 85 +---------- include/asm-x86/semaphore.h | 6 +- include/asm-x86/semaphore_32.h | 175 -------------------- include/asm-x86/semaphore_64.h | 180 --------------------- include/asm-xtensa/semaphore.h | 100 +------------ include/linux/semaphore.h | 77 +++++++++ kernel/Makefile | 2 +- kernel/semaphore.c | 187 ++++++++++++++++++++++ lib/Makefile | 1 - lib/semaphore-sleepers.c | 176 --------------------- 113 files changed, 314 insertions(+), 7679 deletions(-) delete mode 100644 arch/alpha/kernel/semaphore.c delete mode 100644 arch/arm/kernel/semaphore.c delete mode 100644 arch/avr32/kernel/semaphore.c delete mode 100644 arch/cris/kernel/semaphore.c delete mode 100644 arch/frv/kernel/semaphore.c delete mode 100644 arch/h8300/kernel/semaphore.c delete mode 100644 arch/ia64/kernel/semaphore.c delete mode 100644 arch/m32r/kernel/semaphore.c delete mode 100644 arch/m68k/kernel/semaphore.c delete mode 100644 arch/m68k/lib/semaphore.S delete mode 100644 arch/m68knommu/kernel/semaphore.c delete mode 100644 arch/m68knommu/lib/semaphore.S delete mode 100644 arch/mips/kernel/semaphore.c delete mode 100644 arch/mn10300/kernel/semaphore.c delete mode 100644 arch/parisc/kernel/semaphore.c delete mode 100644 arch/powerpc/kernel/semaphore.c delete mode 100644 arch/ppc/kernel/semaphore.c delete mode 100644 arch/s390/kernel/semaphore.c delete mode 100644 arch/sh/kernel/semaphore.c delete mode 100644 arch/sparc/kernel/semaphore.c delete mode 100644 arch/sparc64/kernel/semaphore.c delete mode 100644 arch/v850/kernel/semaphore.c delete mode 100644 arch/xtensa/kernel/semaphore.c delete mode 100644 include/asm-arm/semaphore-helper.h delete mode 100644 include/asm-blackfin/semaphore-helper.h delete mode 100644 include/asm-cris/semaphore-helper.h delete mode 100644 include/asm-h8300/semaphore-helper.h delete mode 100644 include/asm-m68k/semaphore-helper.h delete mode 100644 include/asm-m68knommu/semaphore-helper.h delete mode 100644 include/asm-parisc/semaphore-helper.h delete mode 100644 include/asm-sh/semaphore-helper.h delete mode 100644 include/asm-x86/semaphore_32.h delete mode 100644 include/asm-x86/semaphore_64.h create mode 100644 include/linux/semaphore.h create mode 100644 kernel/semaphore.c delete mode 100644 lib/semaphore-sleepers.c
arch/alpha/kernel/Makefile +1 -1
@@ -7,7 +7,7 @@ EXTRA_AFLAGS := $(KBUILD_CFLAGS) EXTRA_CFLAGS := -Werror -Wno-sign-compare obj-y := entry.o traps.o process.o init_task.o osf_sys.o irq.o \ - irq_alpha.o signal.o setup.o ptrace.o time.o semaphore.o \ + irq_alpha.o signal.o setup.o ptrace.o time.o \ alpha_ksyms.o systbls.o err_common.o io.o obj-$(CONFIG_VGA_HOSE) += console.o
arch/alpha/kernel/alpha_ksyms.c +0 -9
@@ -77,15 +77,6 @@ EXPORT_SYMBOL(__do_clear_user);EXPORT_SYMBOL (__strncpy_from_user);EXPORT_SYMBOL (__strnlen_user); -/* Semaphore helper functions. */ -EXPORT_SYMBOL (__down_failed); -EXPORT_SYMBOL (__down_failed_interruptible); -EXPORT_SYMBOL (__up_wakeup); -EXPORT_SYMBOL (down); -EXPORT_SYMBOL (down_interruptible); -EXPORT_SYMBOL (down_trylock); -EXPORT_SYMBOL (up); -/* * SMP-specific symbols. */
arch/alpha/kernel/semaphore.c deleted +0 -224
224 lines not on this page · raw message
arch/arm/kernel/Makefile +1 -1
@@ -7,7 +7,7 @@ AFLAGS_head.o := -DTEXT_OFFSET=$(TEXT_OFFSET) # Object file lists. obj-y := compat.o entry-armv.o entry-common.o irq.o \ - process.o ptrace.o semaphore.o setup.o signal.o \ + process.o ptrace.o setup.o signal.o \ sys_arm.o stacktrace.o time.o traps.o obj-$(CONFIG_ISA_DMA_API) += dma.o
arch/arm/kernel/semaphore.c deleted +0 -221
221 lines not on this page · raw message
arch/avr32/kernel/Makefile +1 -1
@@ -6,7 +6,7 @@ extra-y := head.o vmlinux.lds obj-$(CONFIG_SUBARCH_AVR32B) += entry-avr32b.o obj-y += syscall_table.o syscall-stubs.o irq.o -obj-y += setup.o traps.o semaphore.o ocd.o ptrace.o +obj-y += setup.o traps.o ocd.o ptrace.o obj-y += signal.o sys_avr32.o process.o time.o obj-y += init_task.o switch_to.o cpu.o obj-$(CONFIG_MODULES) += module.o avr32_ksyms.o
arch/avr32/kernel/semaphore.c deleted +0 -148
148 lines not on this page · raw message
arch/blackfin/Kconfig +0 -4
@@ -31,10 +31,6 @@ config ZONE_DMA bool default y -config SEMAPHORE_SLEEPERS - bool - default y - config GENERIC_FIND_NEXT_BIT bool default y
arch/blackfin/kernel/bfin_ksyms.c +0 -5
@@ -42,11 +42,6 @@ EXPORT_SYMBOL(ip_fast_csum);EXPORT_SYMBOL (kernel_thread); -EXPORT_SYMBOL (__up); -EXPORT_SYMBOL (__down); -EXPORT_SYMBOL (__down_trylock); -EXPORT_SYMBOL (__down_interruptible); -EXPORT_SYMBOL (is_in_rom);EXPORT_SYMBOL (bfin_return_from_exception);
arch/cris/kernel/Makefile +1 -2
@@ -5,8 +5,7 @@ extra-y := vmlinux.lds -obj-y := process.o traps.o irq.o ptrace.o setup.o \ - time.o sys_cris.o semaphore.o +obj-y := process.o traps.o irq.o ptrace.o setup.o time.o sys_cris.o obj-$(CONFIG_MODULES) += crisksyms.o obj-$(CONFIG_MODULES) += module.o
arch/cris/kernel/crisksyms.c +0 -7
@@ -9,7 +9,6 @@#include <linux/string.h> #include <linux/tty.h> -#include <asm/semaphore.h> #include <asm/processor.h> #include <asm/uaccess.h> #include <asm/checksum.h>
@@ -49,12 +48,6 @@ EXPORT_SYMBOL(__negdi2);EXPORT_SYMBOL (__ioremap);EXPORT_SYMBOL (iounmap); -/* Semaphore functions */ -EXPORT_SYMBOL (__up); -EXPORT_SYMBOL (__down); -EXPORT_SYMBOL (__down_interruptible); -EXPORT_SYMBOL (__down_trylock); -/* Userspace access functions */ EXPORT_SYMBOL (__copy_user_zeroing);EXPORT_SYMBOL (__copy_user);
arch/cris/kernel/semaphore.c deleted +0 -129
129 lines not on this page · raw message
arch/frv/kernel/Makefile +1 -1
@@ -9,7 +9,7 @@ extra-y:= head.o init_task.o vmlinux.lds obj-y := $(heads-y) entry.o entry-table.o break.o switch_to.o kernel_thread.o \ kernel_execve.o process.o traps.o ptrace.o signal.o dma.o \ - sys_frv.o time.o semaphore.o setup.o frv_ksyms.o \ + sys_frv.o time.o setup.o frv_ksyms.o \ debug-stub.o irq.o sleep.o uaccess.o obj-$(CONFIG_GDBSTUB) += gdb-stub.o gdb-io.o
arch/frv/kernel/frv_ksyms.c +0 -1
@@ -12,7 +12,6 @@#include <asm/pgalloc.h> #include <asm/irq.h> #include <asm/io.h> -#include <asm/semaphore.h> #include <asm/checksum.h> #include <asm/hardirq.h> #include <asm/cacheflush.h>
arch/frv/kernel/semaphore.c deleted +0 -155
155 lines not on this page · raw message
arch/h8300/kernel/Makefile +1 -1
@@ -5,7 +5,7 @@ extra-y := vmlinux.lds obj-y := process.o traps.o ptrace.o irq.o \ - sys_h8300.o time.o semaphore.o signal.o \ + sys_h8300.o time.o signal.o \ setup.o gpio.o init_task.o syscalls.o \ entry.o
arch/h8300/kernel/h8300_ksyms.c +0 -1
@@ -12,7 +12,6 @@#include <asm/pgalloc.h> #include <asm/irq.h> #include <asm/io.h> -#include <asm/semaphore.h> #include <asm/checksum.h> #include <asm/current.h> #include <asm/gpio.h>
arch/h8300/kernel/semaphore.c deleted +0 -132
132 lines not on this page · raw message
arch/ia64/kernel/Makefile +1 -1
@@ -6,7 +6,7 @@ extra-y := head.o init_task.o vmlinux.lds obj-y := acpi.o entry.o efi.o efi_stub.o gate-data.o fsys.o ia64_ksyms.o irq.o irq_ia64.o \ irq_lsapic.o ivt.o machvec.o pal.o patch.o process.o perfmon.o ptrace.o sal.o \ - salinfo.o semaphore.o setup.o signal.o sys_ia64.o time.o traps.o unaligned.o \ + salinfo.o setup.o signal.o sys_ia64.o time.o traps.o unaligned.o \ unwind.o mca.o mca_asm.o topology.o obj-$(CONFIG_IA64_BRL_EMU) += brl_emu.o
arch/ia64/kernel/ia64_ksyms.c +0 -6
@@ -19,12 +19,6 @@ EXPORT_SYMBOL_GPL(empty_zero_page);EXPORT_SYMBOL (ip_fast_csum);/* hand-coded assembly */ EXPORT_SYMBOL (csum_ipv6_magic); -#include <asm/semaphore.h> -EXPORT_SYMBOL (__down); -EXPORT_SYMBOL (__down_interruptible); -EXPORT_SYMBOL (__down_trylock); -EXPORT_SYMBOL (__up); -#include <asm/page.h> EXPORT_SYMBOL (clear_page);
arch/ia64/kernel/semaphore.c deleted +0 -165
165 lines not on this page · raw message
arch/m32r/kernel/Makefile +1 -1
@@ -5,7 +5,7 @@ extra-y := head.o init_task.o vmlinux.lds obj-y := process.o entry.o traps.o align.o irq.o setup.o time.o \ - m32r_ksyms.o sys_m32r.o semaphore.o signal.o ptrace.o + m32r_ksyms.o sys_m32r.o signal.o ptrace.o obj-$(CONFIG_SMP) += smp.o smpboot.o obj-$(CONFIG_MODULES) += module.o
arch/m32r/kernel/m32r_ksyms.c +0 -5
@@ -7,7 +7,6 @@#include <linux/interrupt.h> #include <linux/string.h> -#include <asm/semaphore.h> #include <asm/processor.h> #include <asm/uaccess.h> #include <asm/checksum.h>
@@ -22,10 +21,6 @@ EXPORT_SYMBOL(dump_fpu);EXPORT_SYMBOL (__ioremap);EXPORT_SYMBOL (iounmap);EXPORT_SYMBOL (kernel_thread); -EXPORT_SYMBOL (__down); -EXPORT_SYMBOL (__down_interruptible); -EXPORT_SYMBOL (__up); -EXPORT_SYMBOL (__down_trylock);/* Networking helper routines. */ /* Delay loops */
arch/m32r/kernel/semaphore.c deleted +0 -185
185 lines not on this page · raw message
arch/m68k/kernel/Makefile +1 -1
@@ -10,7 +10,7 @@ endif extra-y += vmlinux.lds obj-y := entry.o process.o traps.o ints.o signal.o ptrace.o module.o \ - sys_m68k.o time.o semaphore.o setup.o m68k_ksyms.o devres.o + sys_m68k.o time.o setup.o m68k_ksyms.o devres.o devres-y = ../../../kernel/irq/devres.o
arch/m68k/kernel/m68k_ksyms.c +0 -6
@@ -1,5 +1,4 @@#include <linux/module.h> -#include <asm/semaphore.h> asmlinkage long long __ashldi3 (long long ,int );asmlinkage long long __ashrdi3 (long long ,int );
@@ -15,8 +14,3 @@ EXPORT_SYMBOL(__ashrdi3);EXPORT_SYMBOL (__lshrdi3);EXPORT_SYMBOL (__muldi3); -EXPORT_SYMBOL (__down_failed); -EXPORT_SYMBOL (__down_failed_interruptible); -EXPORT_SYMBOL (__down_failed_trylock); -EXPORT_SYMBOL (__up_wakeup); -
arch/m68k/kernel/semaphore.c deleted +0 -132
132 lines not on this page · raw message
arch/m68k/lib/Makefile +1 -1
@@ -5,4 +5,4 @@ EXTRA_AFLAGS := -traditional lib-y := ashldi3.o ashrdi3.o lshrdi3.o muldi3.o \ - checksum.o string.o semaphore.o uaccess.o + checksum.o string.o uaccess.o
arch/m68k/lib/semaphore.S deleted +0 -53
53 lines not on this page · raw message
arch/m68knommu/kernel/Makefile +1 -1
@@ -5,7 +5,7 @@ extra-y := vmlinux.lds obj-y += dma.o entry.o init_task.o irq.o m68k_ksyms.o process.o ptrace.o \ - semaphore.o setup.o signal.o syscalltable.o sys_m68k.o time.o traps.o + setup.o signal.o syscalltable.o sys_m68k.o time.o traps.o obj-$(CONFIG_MODULES) += module.o obj-$(CONFIG_COMEMPCI) += comempci.o
arch/m68knommu/kernel/m68k_ksyms.c +0 -6
@@ -13,7 +13,6 @@#include <asm/pgalloc.h> #include <asm/irq.h> #include <asm/io.h> -#include <asm/semaphore.h> #include <asm/checksum.h> #include <asm/current.h>
@@ -39,11 +38,6 @@ EXPORT_SYMBOL(csum_partial_copy_nocheck);EXPORT_SYMBOL (memcpy);EXPORT_SYMBOL (memset); -EXPORT_SYMBOL (__down_failed); -EXPORT_SYMBOL (__down_failed_interruptible); -EXPORT_SYMBOL (__down_failed_trylock); -EXPORT_SYMBOL (__up_wakeup); -/* * libgcc functions - functions that are used internally by the * compiler... (prototypes are not correct though, but that
arch/m68knommu/kernel/semaphore.c deleted +0 -133
133 lines not on this page · raw message
arch/m68knommu/lib/Makefile +1 -1
@@ -4,4 +4,4 @@ lib-y := ashldi3.o ashrdi3.o lshrdi3.o \ muldi3.o mulsi3.o divsi3.o udivsi3.o modsi3.o umodsi3.o \ - checksum.o semaphore.o memcpy.o memset.o delay.o + checksum.o memcpy.o memset.o delay.o
arch/m68knommu/lib/semaphore.S deleted +0 -66
66 lines not on this page · raw message
arch/mips/kernel/Makefile +1 -1
@@ -5,7 +5,7 @@ extra-y := head.o init_task.o vmlinux.lds obj-y += cpu-probe.o branch.o entry.o genex.o irq.o process.o \ - ptrace.o reset.o semaphore.o setup.o signal.o syscall.o \ + ptrace.o reset.o setup.o signal.o syscall.o \ time.o topology.o traps.o unaligned.o obj-$(CONFIG_CEVT_BCM1480) += cevt-bcm1480.o
arch/mips/kernel/semaphore.c deleted +0 -168
168 lines not on this page · raw message
arch/mn10300/kernel/Makefile +1 -1
@@ -3,7 +3,7 @@ # extra-y := head.o init_task.o vmlinux.lds -obj-y := process.o semaphore.o signal.o entry.o fpu.o traps.o irq.o \ +obj-y := process.o signal.o entry.o fpu.o traps.o irq.o \ ptrace.o setup.o time.o sys_mn10300.o io.o kthread.o \ switch_to.o mn10300_ksyms.o kernel_execve.o
arch/mn10300/kernel/semaphore.c deleted +0 -149
149 lines not on this page · raw message
arch/parisc/kernel/Makefile +1 -1
@@ -9,7 +9,7 @@ AFLAGS_pacache.o := -traditional obj-y := cache.o pacache.o setup.o traps.o time.o irq.o \ pa7300lc.o syscall.o entry.o sys_parisc.o firmware.o \ - ptrace.o hardware.o inventory.o drivers.o semaphore.o \ + ptrace.o hardware.o inventory.o drivers.o \ signal.o hpmc.o real2.o parisc_ksyms.o unaligned.o \ process.o processor.o pdc_cons.o pdc_chassis.o unwind.o \ topology.o
arch/parisc/kernel/parisc_ksyms.c +0 -5
@@ -69,11 +69,6 @@ EXPORT_SYMBOL(memcpy_toio);EXPORT_SYMBOL (memcpy_fromio);EXPORT_SYMBOL (memset_io); -#include <asm/semaphore.h> -EXPORT_SYMBOL (__up); -EXPORT_SYMBOL (__down_interruptible); -EXPORT_SYMBOL (__down); -extern void $$divI (void );extern void $$divU (void );extern void $$remI (void );
arch/parisc/kernel/semaphore.c deleted +0 -102
102 lines not on this page · raw message
arch/powerpc/kernel/Makefile +1 -1
@@ -12,7 +12,7 @@ CFLAGS_prom_init.o += -fPIC CFLAGS_btext.o += -fPIC endif -obj-y := semaphore.o cputable.o ptrace.o syscalls.o \ +obj-y := cputable.o ptrace.o syscalls.o \ irq.o align.o signal_32.o pmc.o vdso.o \ init_task.o process.o systbl.o idle.o \ signal.o
arch/powerpc/kernel/ppc_ksyms.c +0 -1
@@ -15,7 +15,6 @@#include <linux/bitops.h> #include <asm/page.h> -#include <asm/semaphore.h> #include <asm/processor.h> #include <asm/cacheflush.h> #include <asm/uaccess.h>
arch/powerpc/kernel/semaphore.c deleted +0 -135
135 lines not on this page · raw message
arch/ppc/kernel/semaphore.c deleted +0 -131
131 lines not on this page · raw message
arch/s390/kernel/Makefile +1 -1
@@ -11,7 +11,7 @@ CFLAGS_smp.o := -Wno-nonnull obj-y := bitmap.o traps.o time.o process.o base.o early.o \ setup.o sys_s390.o ptrace.o signal.o cpcmd.o ebcdic.o \ - semaphore.o s390_ext.o debug.o irq.o ipl.o dis.o diag.o + s390_ext.o debug.o irq.o ipl.o dis.o diag.o obj-y += $(if $(CONFIG_64BIT),entry64.o,entry.o) obj-y += $(if $(CONFIG_64BIT),reipl64.o,reipl.o)
arch/s390/kernel/s390_ksyms.c +0 -7
@@ -27,13 +27,6 @@ EXPORT_SYMBOL(_zb_findmap);EXPORT_SYMBOL (_sb_findmap);/* -* semaphore ops -*/ -EXPORT_SYMBOL (__up); -EXPORT_SYMBOL (__down); -EXPORT_SYMBOL (__down_interruptible); - -/* * binfmt_elf loader */ extern int dump_fpu (struct pt_regs * regs,s390_fp_regs *fpregs);
arch/s390/kernel/semaphore.c deleted +0 -108
108 lines not on this page · raw message
arch/sh/kernel/Makefile_32 +1 -1
@@ -5,7 +5,7 @@ extra-y := head_32.o init_task.o vmlinux.lds obj-y := debugtraps.o io.o io_generic.o irq.o machvec.o process_32.o \ - ptrace_32.o semaphore.o setup.o signal_32.o sys_sh.o sys_sh32.o \ + ptrace_32.o setup.o signal_32.o sys_sh.o sys_sh32.o \ syscalls_32.o time_32.o topology.o traps.o traps_32.o obj-y += cpu/ timers/
arch/sh/kernel/Makefile_64 +1 -1
@@ -1,7 +1,7 @@ extra-y := head_64.o init_task.o vmlinux.lds obj-y := debugtraps.o io.o io_generic.o irq.o machvec.o process_64.o \ - ptrace_64.o semaphore.o setup.o signal_64.o sys_sh.o sys_sh64.o \ + ptrace_64.o setup.o signal_64.o sys_sh.o sys_sh64.o \ syscalls_64.o time_64.o topology.o traps.o traps_64.o obj-y += cpu/ timers/
arch/sh/kernel/semaphore.c deleted +0 -139
139 lines not on this page · raw message
arch/sh/kernel/sh_ksyms_32.c +0 -7
@@ -9,7 +9,6 @@#include <linux/pci.h> #include <linux/irq.h> #include <asm/sections.h> -#include <asm/semaphore.h> #include <asm/processor.h> #include <asm/uaccess.h> #include <asm/checksum.h>
@@ -48,12 +47,6 @@ EXPORT_SYMBOL(__copy_user);EXPORT_SYMBOL (get_vm_area);#endif -/* semaphore exports */ -EXPORT_SYMBOL (__up); -EXPORT_SYMBOL (__down); -EXPORT_SYMBOL (__down_interruptible); -EXPORT_SYMBOL (__down_trylock); -EXPORT_SYMBOL (__udelay);EXPORT_SYMBOL (__ndelay);
Lines of this file are not shown. View the raw message.
arch/sparc/kernel/semaphore.c deleted +0 -155
155 lines not on this page · raw message
arch/sparc64/kernel/semaphore.c deleted +0 -254
254 lines not on this page · raw message
arch/v850/kernel/semaphore.c deleted +0 -166
166 lines not on this page · raw message
arch/x86/lib/semaphore_32.S +0 -83
83 lines not on this page · raw message
arch/xtensa/kernel/semaphore.c deleted +0 -226
226 lines not on this page · raw message
include/asm-alpha/semaphore.h +1 -149
150 lines not on this page · raw message
include/asm-arm/semaphore-helper.h deleted +0 -84
84 lines not on this page · raw message
include/asm-arm/semaphore.h +1 -98
99 lines not on this page · raw message
include/asm-avr32/semaphore.h +1 -108
109 lines not on this page · raw message
include/asm-blackfin/semaphore-helper.h deleted +0 -82
82 lines not on this page · raw message
include/asm-blackfin/semaphore.h +1 -105
106 lines not on this page · raw message
include/asm-cris/semaphore-helper.h deleted +0 -78
78 lines not on this page · raw message
include/asm-cris/semaphore.h +1 -133
134 lines not on this page · raw message
include/asm-frv/semaphore.h +1 -155
156 lines not on this page · raw message
include/asm-h8300/semaphore-helper.h deleted +0 -85
85 lines not on this page · raw message
include/asm-h8300/semaphore.h +1 -190
191 lines not on this page · raw message
include/asm-ia64/semaphore.h +1 -99
100 lines not on this page · raw message
include/asm-m32r/semaphore.h +1 -144
145 lines not on this page · raw message
include/asm-m68k/semaphore-helper.h deleted +0 -142
142 lines not on this page · raw message
include/asm-m68k/semaphore.h +1 -163
164 lines not on this page · raw message
include/asm-m68knommu/semaphore-helper.h deleted +0 -82
82 lines not on this page · raw message
include/asm-m68knommu/semaphore.h +1 -153
154 lines not on this page · raw message
include/asm-mips/semaphore.h +1 -108
109 lines not on this page · raw message
include/asm-mn10300/semaphore.h +1 -169
170 lines not on this page · raw message
include/asm-parisc/semaphore-helper.h deleted +0 -89
89 lines not on this page · raw message
include/asm-parisc/semaphore.h +1 -145
146 lines not on this page · raw message
include/asm-powerpc/semaphore.h +1 -94
95 lines not on this page · raw message
include/asm-s390/semaphore.h +1 -107
108 lines not on this page · raw message
include/asm-sh/semaphore-helper.h deleted +0 -89
89 lines not on this page · raw message
include/asm-sh/semaphore.h +1 -115
116 lines not on this page · raw message
include/asm-sparc/semaphore.h +1 -192
193 lines not on this page · raw message
include/asm-sparc64/semaphore.h +1 -53
54 lines not on this page · raw message
include/asm-v850/semaphore.h +1 -84
85 lines not on this page · raw message
include/asm-x86/semaphore_32.h deleted +0 -175
175 lines not on this page · raw message
include/asm-x86/semaphore_64.h deleted +0 -180
180 lines not on this page · raw message
include/asm-xtensa/semaphore.h +1 -99
100 lines not on this page · raw message
include/linux/semaphore.h new file +77 -0
77 lines not on this page · raw message
kernel/semaphore.c new file +187 -0
187 lines not on this page · raw message
lib/semaphore-sleepers.c deleted +0 -176
176 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.5.4.3
Part of the diff is not shown here. View the raw message.
PATCH 4/6 Introduce down_killable()
down_killable() is the functional counterpart of mutex_lock_killable.
--- include/linux/semaphore.h | 6 ++++++ kernel/semaphore.c | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 0 deletions(-)
include/linux/semaphore.h +6 -0
@@ -62,6 +62,12 @@ extern void down(struct semaphore *sem);extern int __must_check down_interruptible (struct semaphore *sem);/* +* As down_interruptible(), except the sleep may only be interrupted by +* signals which are fatal to this process. +*/ +extern int __must_check down_killable (struct semaphore *sem); + +/* * As down(), except this function will not sleep. It will return 0 if it * acquired the semaphore and 1 if the semaphore was contended. This * function may be called from any context, including interrupt and softirq.
kernel/semaphore.c +22 -0
@@ -34,6 +34,7 @@ static noinline void __down(struct semaphore *sem); static noinline int __down_interruptible(struct semaphore *sem); +static noinline int __down_killable(struct semaphore *sem); static noinline void __up(struct semaphore *sem);void down (struct semaphore *sem)
@@ -61,6 +62,20 @@ int down_interruptible(struct semaphore *sem) }EXPORT_SYMBOL (down_interruptible); +int down_killable (struct semaphore *sem) +{ +unsigned long flags; +int result =0 ; + +spin_lock_irqsave (&sem->lock, flags); +if (unlikely (sem->count-- <=0 )) + result =__down_killable (sem); +spin_unlock_irqrestore (&sem->lock, flags); + +return result; +} +EXPORT_SYMBOL (down_killable); +/** * down_trylock - try to acquire the semaphore, without waiting * @sem: the semaphore to be acquired
@@ -143,6 +158,8 @@ static inline int __sched __down_common(struct semaphore *sem, long state)for (;;) {if (state ==TASK_INTERRUPTIBLE &&signal_pending (task)) goto interrupted; +if (state ==TASK_KILLABLE &&fatal_signal_pending (task)) + goto interrupted;__set_task_state (task, state);spin_unlock_irq (&sem->lock);schedule ();
@@ -178,6 +195,11 @@ static noinline int __sched __down_interruptible(struct semaphore *sem)return __down_common (sem,TASK_INTERRUPTIBLE ); } +static noinline int __sched __down_killable(struct semaphore *sem) +{ +return __down_common (sem,TASK_KILLABLE ); +} + static noinline void __sched __up(struct semaphore *sem) {if (unlikely (list_empty (&sem->wait_list)))
Signature · 1 line
1.5.4.3
PATCH 5/6 Add down_timeout and change ACPI to use it
ACPI currently emulates a timeout for semaphores with calls to down_trylock and sleep. This produces horrible behaviour in terms of fairness and excessive wakeups. Now that we have a unified semaphore implementation, adding a real down_trylock is almost trivial.
--- drivers/acpi/osl.c | 89 +++++++++++---------------------------------- include/linux/semaphore.h | 6 +++ kernel/semaphore.c | 42 ++++++++++++++++++---- 3 files changed, 62 insertions(+), 75 deletions(-)
drivers/acpi/osl.c +21 -68
@@ -4,6 +4,8 @@* Copyright (C) 2000 Andrew Henroid * Copyright (C) 2001, 2002 Andy Grover <[email protected]> * Copyright (C) 2001, 2002 Paul Diefenbaugh <[email protected]> +* Copyright (c) 2008 Intel Corporation +* Author: Matthew Wilcox <[email protected]> * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
@@ -37,15 +39,18 @@#include <linux/workqueue.h> #include <linux/nmi.h> #include <linux/acpi.h> -#include <acpi/acpi.h> -#include <asm/io.h> -#include <acpi/acpi_bus.h> -#include <acpi/processor.h> -#include <asm/uaccess.h> -#include <linux/efi.h> #include <linux/ioport.h> #include <linux/list.h> +#include <linux/jiffies.h> +#include <linux/semaphore.h> + +#include <asm/io.h> +#include <asm/uaccess.h> + +#include <acpi/acpi.h> +#include <acpi/acpi_bus.h> +#include <acpi/processor.h> #define _COMPONENT ACPI_OS_SERVICESACPI_MODULE_NAME ("osl" );
@@ -848,7 +853,6 @@ acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle) {struct semaphore *sem =NULL ; - sem =acpi_os_allocate (sizeof (struct semaphore ));if (!sem)return AE_NO_MEMORY ;
@@ -875,12 +879,12 @@ acpi_status acpi_os_delete_semaphore(acpi_handle handle) {struct semaphore *sem = (struct semaphore *)handle; -if (!sem)return AE_BAD_PARAMETER ;ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX ,"Deleting semaphore[%p].\n" , handle)); +BUG_ON (!list_empty (&sem->wait_list));kfree (sem); sem =NULL ;
@@ -888,21 +892,15 @@ acpi_status acpi_os_delete_semaphore(acpi_handle handle) }/* -* TODO: The kernel doesn't have a 'down_timeout' function -- had to -* improvise. The process is to sleep for one scheduler quantum -* until the semaphore becomes available. Downside is that this -* may result in starvation for timeout-based waits when there's -* lots of semaphore activity. -* * TODO: Support for units > 1? */ acpi_status acpi_os_wait_semaphore (acpi_handle handle,u32 units,u16 timeout) {acpi_status status =AE_OK ;struct semaphore *sem = (struct semaphore *)handle; +long jiffies;int ret =0 ; -if (!sem || (units <1 ))return AE_BAD_PARAMETER ;
@@ -912,58 +910,14 @@ acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX ,"Waiting for semaphore[%p|%d|%d]\n" , handle, units, timeout)); -/* -* This can be called during resume with interrupts off. -* Like boot-time, we should be single threaded and will -* always get the lock if we try -- timeout or not. -* If this doesn't succeed, then we will oops courtesy of -* might_sleep() in down(). -*/ -if (!down_trylock (sem)) -return AE_OK ; - -switch (timeout) { -/* -* No Wait: -* -------- -* A zero timeout value indicates that we shouldn't wait - just -* acquire the semaphore if available otherwise return AE_TIME -* (a.k.a. 'would block'). -*/ -case 0 : -if (down_trylock (sem)) - status =AE_TIME ; -break ; - -/* -* Wait Indefinitely: -* ------------------ -*/ -case ACPI_WAIT_FOREVER : -down (sem); -break ; - -/* -* Wait w/ Timeout: -* ---------------- -*/ -default : -// TODO: A better timeout algorithm? - { -int i =0 ; -static const int quantum_ms =1000 /HZ ; - - ret =down_trylock (sem); -for (i = timeout; (i >0 && ret !=0 ); i -= quantum_ms) { -schedule_timeout_interruptible (1 ); - ret =down_trylock (sem); - } - -if (ret !=0 ) - status =AE_TIME ; - } -break ; - } +if (timeout ==ACPI_WAIT_FOREVER ) + jiffies =MAX_SCHEDULE_TIMEOUT ; +else + jiffies =msecs_to_jiffies (timeout); + + ret =down_timeout (sem, jiffies); +if (ret) + status =AE_TIME ;if (ACPI_FAILURE (status)) { ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
@@ -986,7 +940,6 @@ acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units) {struct semaphore *sem = (struct semaphore *)handle; -if (!sem || (units <1 ))return AE_BAD_PARAMETER ;
include/linux/semaphore.h +6 -0
@@ -75,6 +75,12 @@ extern int __must_check down_killable(struct semaphore *sem);extern int __must_check down_trylock (struct semaphore *sem);/* +* As down(), except this function will return -ETIME if it fails to +* acquire the semaphore within the specified number of jiffies. +*/ +extern int __must_check down_timeout (struct semaphore *sem,long jiffies); + +/* * Release the semaphore. Unlike mutexes, up() may be called from any * context and even by tasks which have never called down(). */
kernel/semaphore.c +35 -7
88 lines not on this page · raw message
Signature · 1 line
1.5.4.3
PATCH 6/6 Simplify semaphore implementation
By removing the negative values of 'count' and relying on the wait_list to indicate whether we have any waiters, we can simplify the implementation by removing the protection against an unlikely race condition. Thanks to David Howells for his suggestions.
--- include/linux/semaphore.h | 9 ++--- kernel/semaphore.c | 78 ++++++++++++++------------------------------- 2 files changed, 27 insertions(+), 60 deletions(-)
include/linux/semaphore.h +3 -6
@@ -15,15 +15,12 @@/* * The spinlock controls access to the other members of the semaphore. -* 'count' is decremented by every task which calls down*() and incremented -* by every call to up(). Thus, if it is positive, it indicates how many -* more tasks may acquire the lock. If it is negative, it indicates how -* many tasks are waiting for the lock. Tasks waiting for the lock are -* kept on the wait_list. +* 'count' represents how many more tasks can acquire this semaphore. +* Tasks waiting for the lock are kept on the wait_list. */ struct semaphore {spinlock_t lock; -int count; +unsigned int count;struct list_head wait_list; };
kernel/semaphore.c +24 -54
142 lines not on this page · raw message
Signature · 1 line
1.5.4.3
From: Harvey Harrison <[email protected]>
Subject: [PATCH] semaphore: add stubs for kerneldoc to semphore functions
The difference between down/down_trylock/down_interruptable/down_killable should be expanded to note the difference/use case, a simple stub is added here.
---
This applies on top of the last patch I sent, feel free to just use it as a base for a fuller version.
kernel/semaphore.c | 37 ++++++++++++++++++++++++++++++++++--- 1 files changed, 34 insertions(+), 3 deletions(-)
kernel/semaphore.c +34 -3
@@ -98,6 +98,12 @@ static noinline void __sched __up(struct semaphore *sem)wake_up_process (waiter->task); } +/** +* down - acquire the semaphore +* @sem: the semaphore to be acquired +* +* This can be called from interrupt context, unlike mutexes. +*/ void down (struct semaphore *sem) {unsigned long flags;
@@ -111,6 +117,12 @@ void down(struct semaphore *sem) }EXPORT_SYMBOL (down); +/** +* down_killable - try to acquire the semaphore +* @sem: the semaphore to be acquired +* +* This can be called from interrupt context, unlike mutexes. +*/ int down_interruptible (struct semaphore *sem) {unsigned long flags;
@@ -127,6 +139,12 @@ int down_interruptible(struct semaphore *sem) }EXPORT_SYMBOL (down_interruptible); +/** +* down_killable - try to acquire the semaphore +* @sem: the semaphore to be acquired +* +* This can be called from interrupt context, unlike mutexes. +*/ int down_killable (struct semaphore *sem) {unsigned long flags;
@@ -147,7 +165,7 @@ EXPORT_SYMBOL(down_killable);* down_trylock - try to acquire the semaphore, without waiting * @sem: the semaphore to be acquired * -* Try to acquire the semaphore atomically. Returns 0 if the mutex has +* Try to acquire the semaphore atomically. Returns 0 if the semaphore has * been acquired successfully and 1 if it is contended. * * NOTE: This return value is inverted from both spin_trylock and
@@ -171,7 +189,14 @@ int down_trylock(struct semaphore *sem) }EXPORT_SYMBOL (down_trylock); -int down_timeout (struct semaphore *sem,long jiffies) +/** +* down_timeout - try to acquire the semaphore within a timeout +* @sem: the semaphore to be acquired +* @timeout: the length to wait before timing out, in jiffies +* +* This can be called from interrupt context, unlike mutexes. +*/ +int down_timeout (struct semaphore *sem,long timeout) {unsigned long flags;int result =0 ;
@@ -180,13 +205,19 @@ int down_timeout(struct semaphore *sem, long jiffies)if (likely (sem->count >0 )) sem->count--;else - result =__down_timeout (sem, jiffies); + result =__down_timeout (sem, timeout);spin_unlock_irqrestore (&sem->lock, flags);return result; }EXPORT_SYMBOL (down_timeout); +/** +* up - release the semaphore +* @sem: the semaphore to be released +* +* This can be called from interrupt context, unlike mutexes. +*/ void up (struct semaphore *sem) {unsigned long flags;
Signature · 1 line
1.5.4.4.684.g0e08
Hi Harvey,
Quoted 7 lines · Harvey Harrison
+/**
+ *down_killable- try to acquire the semaphore
+ * @sem: the semaphore to be acquired
+ *
+ * This can be called from interrupt context, unlike mutexes.
+ */
intdown_interruptible(struct semaphore *sem)
Mismatching function names.
Hannes