Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'core-locking-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull core locking updates from Ingo Molnar:
"The biggest change is the MCS spinlock generalization changes from Tim
Chen, Peter Zijlstra, Jason Low et al. There's also lockdep
fixes/enhancements from Oleg Nesterov, in particular a false negative
fix related to lockdep_set_novalidate_class() usage"

* 'core-locking-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (22 commits)
locking/mutex: Fix debug checks
locking/mutexes: Add extra reschedule point
locking/mutexes: Introduce cancelable MCS lock for adaptive spinning
locking/mutexes: Unlock the mutex without the wait_lock
locking/mutexes: Modify the way optimistic spinners are queued
locking/mutexes: Return false if task need_resched() in mutex_can_spin_on_owner()
locking: Move mcs_spinlock.h into kernel/locking/
m68k: Skip futex_atomic_cmpxchg_inatomic() test
futex: Allow architectures to skip futex_atomic_cmpxchg_inatomic() test
Revert "sched/wait: Suppress Sparse 'variable shadowing' warning"
lockdep: Change lockdep_set_novalidate_class() to use _and_name
lockdep: Change mark_held_locks() to check hlock->check instead of lockdep_no_validate
lockdep: Don't create the wrong dependency on hlock->check == 0
lockdep: Make held_lock->check and "int check" argument bool
locking/mcs: Allow architecture specific asm files to be used for contended case
locking/mcs: Order the header files in Kbuild of each architecture in alphabetical order
sched/wait: Suppress Sparse 'variable shadowing' warning
hung_task/Documentation: Fix hung_task_warnings description
locking/mcs: Allow architectures to hook in to contended paths
locking/mcs: Micro-optimize the MCS code, add extra comments
...

+587 -215
+3 -2
Documentation/sysctl/kernel.txt
··· 320 320 321 321 ============================================================== 322 322 323 - hung_task_warning: 323 + hung_task_warnings: 324 324 325 325 The maximum number of warnings to report. During a check interval 326 - When this value is reached, no more the warnings will be reported. 326 + if a hung task is detected, this value is decreased by 1. 327 + When this value reaches 0, no more warnings will be reported. 327 328 This file shows up if CONFIG_DETECT_HUNG_TASK is enabled. 328 329 329 330 -1: report an infinite number of warnings.
+4 -3
arch/alpha/include/asm/Kbuild
··· 1 1 2 - generic-y += clkdev.h 3 2 3 + generic-y += clkdev.h 4 4 generic-y += exec.h 5 - generic-y += trace_clock.h 6 - generic-y += preempt.h 7 5 generic-y += hash.h 6 + generic-y += mcs_spinlock.h 7 + generic-y += preempt.h 8 + generic-y += trace_clock.h
+4 -3
arch/arc/include/asm/Kbuild
··· 1 1 generic-y += auxvec.h 2 2 generic-y += barrier.h 3 - generic-y += bugs.h 4 3 generic-y += bitsperlong.h 4 + generic-y += bugs.h 5 5 generic-y += clkdev.h 6 6 generic-y += cputime.h 7 7 generic-y += device.h 8 8 generic-y += div64.h 9 9 generic-y += emergency-restart.h 10 10 generic-y += errno.h 11 - generic-y += fcntl.h 12 11 generic-y += fb.h 12 + generic-y += fcntl.h 13 13 generic-y += ftrace.h 14 14 generic-y += hardirq.h 15 15 generic-y += hash.h ··· 22 22 generic-y += kvm_para.h 23 23 generic-y += local.h 24 24 generic-y += local64.h 25 + generic-y += mcs_spinlock.h 25 26 generic-y += mman.h 26 27 generic-y += msgbuf.h 27 28 generic-y += param.h ··· 31 30 generic-y += percpu.h 32 31 generic-y += poll.h 33 32 generic-y += posix_types.h 33 + generic-y += preempt.h 34 34 generic-y += resource.h 35 35 generic-y += scatterlist.h 36 36 generic-y += sembuf.h ··· 50 48 generic-y += user.h 51 49 generic-y += vga.h 52 50 generic-y += xor.h 53 - generic-y += preempt.h
+3 -2
arch/arm/include/asm/Kbuild
··· 7 7 generic-y += emergency-restart.h 8 8 generic-y += errno.h 9 9 generic-y += exec.h 10 + generic-y += hash.h 10 11 generic-y += ioctl.h 11 12 generic-y += ipcbuf.h 12 13 generic-y += irq_regs.h 13 14 generic-y += kdebug.h 14 15 generic-y += local.h 15 16 generic-y += local64.h 17 + generic-y += mcs_spinlock.h 16 18 generic-y += msgbuf.h 17 19 generic-y += param.h 18 20 generic-y += parport.h 19 21 generic-y += poll.h 22 + generic-y += preempt.h 20 23 generic-y += resource.h 21 24 generic-y += sections.h 22 25 generic-y += segment.h ··· 36 33 generic-y += timex.h 37 34 generic-y += trace_clock.h 38 35 generic-y += unaligned.h 39 - generic-y += preempt.h 40 - generic-y += hash.h
+4 -3
arch/arm64/include/asm/Kbuild
··· 12 12 generic-y += emergency-restart.h 13 13 generic-y += errno.h 14 14 generic-y += ftrace.h 15 + generic-y += hash.h 15 16 generic-y += hw_irq.h 16 17 generic-y += ioctl.h 17 18 generic-y += ioctls.h ··· 23 22 generic-y += kvm_para.h 24 23 generic-y += local.h 25 24 generic-y += local64.h 25 + generic-y += mcs_spinlock.h 26 26 generic-y += mman.h 27 27 generic-y += msgbuf.h 28 28 generic-y += mutex.h 29 29 generic-y += pci.h 30 30 generic-y += poll.h 31 31 generic-y += posix_types.h 32 + generic-y += preempt.h 32 33 generic-y += resource.h 33 34 generic-y += scatterlist.h 34 35 generic-y += sections.h ··· 41 38 generic-y += sizes.h 42 39 generic-y += socket.h 43 40 generic-y += sockios.h 44 - generic-y += switch_to.h 45 41 generic-y += swab.h 42 + generic-y += switch_to.h 46 43 generic-y += termbits.h 47 44 generic-y += termios.h 48 45 generic-y += topology.h ··· 52 49 generic-y += user.h 53 50 generic-y += vga.h 54 51 generic-y += xor.h 55 - generic-y += preempt.h 56 - generic-y += hash.h
+21 -20
arch/avr32/include/asm/Kbuild
··· 1 1 2 - generic-y += clkdev.h 3 - generic-y += cputime.h 4 - generic-y += delay.h 5 - generic-y += device.h 6 - generic-y += div64.h 7 - generic-y += emergency-restart.h 8 - generic-y += exec.h 9 - generic-y += futex.h 10 - generic-y += preempt.h 11 - generic-y += irq_regs.h 12 - generic-y += param.h 13 - generic-y += local.h 14 - generic-y += local64.h 15 - generic-y += percpu.h 16 - generic-y += scatterlist.h 17 - generic-y += sections.h 18 - generic-y += topology.h 19 - generic-y += trace_clock.h 2 + generic-y += clkdev.h 3 + generic-y += cputime.h 4 + generic-y += delay.h 5 + generic-y += device.h 6 + generic-y += div64.h 7 + generic-y += emergency-restart.h 8 + generic-y += exec.h 9 + generic-y += futex.h 10 + generic-y += hash.h 11 + generic-y += irq_regs.h 12 + generic-y += local.h 13 + generic-y += local64.h 14 + generic-y += mcs_spinlock.h 15 + generic-y += param.h 16 + generic-y += percpu.h 17 + generic-y += preempt.h 18 + generic-y += scatterlist.h 19 + generic-y += sections.h 20 + generic-y += topology.h 21 + generic-y += trace_clock.h 20 22 generic-y += vga.h 21 - generic-y += xor.h 22 - generic-y += hash.h 23 + generic-y += xor.h
+4 -3
arch/blackfin/include/asm/Kbuild
··· 10 10 generic-y += errno.h 11 11 generic-y += fb.h 12 12 generic-y += futex.h 13 + generic-y += hash.h 13 14 generic-y += hw_irq.h 14 15 generic-y += ioctl.h 15 16 generic-y += ipcbuf.h ··· 18 17 generic-y += kdebug.h 19 18 generic-y += kmap_types.h 20 19 generic-y += kvm_para.h 21 - generic-y += local64.h 22 20 generic-y += local.h 21 + generic-y += local64.h 22 + generic-y += mcs_spinlock.h 23 23 generic-y += mman.h 24 24 generic-y += msgbuf.h 25 25 generic-y += mutex.h 26 26 generic-y += param.h 27 27 generic-y += percpu.h 28 28 generic-y += pgalloc.h 29 + generic-y += preempt.h 29 30 generic-y += resource.h 30 31 generic-y += scatterlist.h 31 32 generic-y += sembuf.h ··· 47 44 generic-y += unaligned.h 48 45 generic-y += user.h 49 46 generic-y += xor.h 50 - generic-y += preempt.h 51 - generic-y += hash.h
+3 -2
arch/c6x/include/asm/Kbuild
··· 15 15 generic-y += fb.h 16 16 generic-y += fcntl.h 17 17 generic-y += futex.h 18 + generic-y += hash.h 18 19 generic-y += hw_irq.h 19 20 generic-y += io.h 20 21 generic-y += ioctl.h ··· 25 24 generic-y += kdebug.h 26 25 generic-y += kmap_types.h 27 26 generic-y += local.h 27 + generic-y += mcs_spinlock.h 28 28 generic-y += mman.h 29 29 generic-y += mmu.h 30 30 generic-y += mmu_context.h ··· 36 34 generic-y += pgalloc.h 37 35 generic-y += poll.h 38 36 generic-y += posix_types.h 37 + generic-y += preempt.h 39 38 generic-y += resource.h 40 39 generic-y += scatterlist.h 41 40 generic-y += segment.h ··· 59 56 generic-y += user.h 60 57 generic-y += vga.h 61 58 generic-y += xor.h 62 - generic-y += preempt.h 63 - generic-y += hash.h
+2 -1
arch/cris/include/asm/Kbuild
··· 9 9 generic-y += hash.h 10 10 generic-y += kvm_para.h 11 11 generic-y += linkage.h 12 + generic-y += mcs_spinlock.h 12 13 generic-y += module.h 14 + generic-y += preempt.h 13 15 generic-y += trace_clock.h 14 16 generic-y += vga.h 15 17 generic-y += xor.h 16 - generic-y += preempt.h
+3 -2
arch/frv/include/asm/Kbuild
··· 1 1 2 2 generic-y += clkdev.h 3 3 generic-y += exec.h 4 - generic-y += trace_clock.h 5 - generic-y += preempt.h 6 4 generic-y += hash.h 5 + generic-y += mcs_spinlock.h 6 + generic-y += preempt.h 7 + generic-y += trace_clock.h
+4 -3
arch/hexagon/include/asm/Kbuild
··· 25 25 generic-y += irq_regs.h 26 26 generic-y += kdebug.h 27 27 generic-y += kmap_types.h 28 - generic-y += local64.h 29 28 generic-y += local.h 29 + generic-y += local64.h 30 + generic-y += mcs_spinlock.h 30 31 generic-y += mman.h 31 32 generic-y += msgbuf.h 32 33 generic-y += pci.h 33 34 generic-y += percpu.h 34 35 generic-y += poll.h 35 36 generic-y += posix_types.h 37 + generic-y += preempt.h 36 38 generic-y += resource.h 37 39 generic-y += rwsem.h 38 40 generic-y += scatterlist.h ··· 47 45 generic-y += sizes.h 48 46 generic-y += socket.h 49 47 generic-y += sockios.h 50 - generic-y += statfs.h 51 48 generic-y += stat.h 49 + generic-y += statfs.h 52 50 generic-y += termbits.h 53 51 generic-y += termios.h 54 52 generic-y += topology.h ··· 57 55 generic-y += ucontext.h 58 56 generic-y += unaligned.h 59 57 generic-y += xor.h 60 - generic-y += preempt.h
+5 -4
arch/ia64/include/asm/Kbuild
··· 1 1 2 2 generic-y += clkdev.h 3 3 generic-y += exec.h 4 - generic-y += kvm_para.h 5 - generic-y += trace_clock.h 6 - generic-y += preempt.h 7 - generic-y += vtime.h 8 4 generic-y += hash.h 5 + generic-y += kvm_para.h 6 + generic-y += mcs_spinlock.h 7 + generic-y += preempt.h 8 + generic-y += trace_clock.h 9 + generic-y += vtime.h
+4 -3
arch/m32r/include/asm/Kbuild
··· 1 1 2 2 generic-y += clkdev.h 3 3 generic-y += exec.h 4 - generic-y += module.h 5 - generic-y += trace_clock.h 6 - generic-y += preempt.h 7 4 generic-y += hash.h 5 + generic-y += mcs_spinlock.h 6 + generic-y += module.h 7 + generic-y += preempt.h 8 + generic-y += trace_clock.h
+1
arch/m68k/Kconfig
··· 17 17 select FPU if MMU 18 18 select ARCH_WANT_IPC_PARSE_VERSION 19 19 select ARCH_USES_GETTIMEOFFSET if MMU && !COLDFIRE 20 + select HAVE_FUTEX_CMPXCHG if MMU && FUTEX 20 21 select HAVE_MOD_ARCH_SPECIFIC 21 22 select MODULES_USE_ELF_REL 22 23 select MODULES_USE_ELF_RELA
+2 -1
arch/m68k/include/asm/Kbuild
··· 14 14 generic-y += kdebug.h 15 15 generic-y += kmap_types.h 16 16 generic-y += kvm_para.h 17 - generic-y += local64.h 18 17 generic-y += local.h 18 + generic-y += local64.h 19 + generic-y += mcs_spinlock.h 19 20 generic-y += mman.h 20 21 generic-y += mutex.h 21 22 generic-y += percpu.h
+3 -2
arch/metag/include/asm/Kbuild
··· 13 13 generic-y += fcntl.h 14 14 generic-y += futex.h 15 15 generic-y += hardirq.h 16 + generic-y += hash.h 16 17 generic-y += hw_irq.h 17 18 generic-y += ioctl.h 18 19 generic-y += ioctls.h ··· 24 23 generic-y += kvm_para.h 25 24 generic-y += local.h 26 25 generic-y += local64.h 26 + generic-y += mcs_spinlock.h 27 27 generic-y += msgbuf.h 28 28 generic-y += mutex.h 29 29 generic-y += param.h ··· 32 30 generic-y += percpu.h 33 31 generic-y += poll.h 34 32 generic-y += posix_types.h 33 + generic-y += preempt.h 35 34 generic-y += scatterlist.h 36 35 generic-y += sections.h 37 36 generic-y += sembuf.h ··· 55 52 generic-y += user.h 56 53 generic-y += vga.h 57 54 generic-y += xor.h 58 - generic-y += preempt.h 59 - generic-y += hash.h
+3 -2
arch/microblaze/include/asm/Kbuild
··· 3 3 generic-y += clkdev.h 4 4 generic-y += exec.h 5 5 generic-y += hash.h 6 - generic-y += trace_clock.h 7 - generic-y += syscalls.h 6 + generic-y += mcs_spinlock.h 8 7 generic-y += preempt.h 8 + generic-y += syscalls.h 9 + generic-y += trace_clock.h
+3 -2
arch/mips/include/asm/Kbuild
··· 2 2 generic-y += cputime.h 3 3 generic-y += current.h 4 4 generic-y += emergency-restart.h 5 + generic-y += hash.h 5 6 generic-y += local64.h 7 + generic-y += mcs_spinlock.h 6 8 generic-y += mutex.h 7 9 generic-y += parport.h 8 10 generic-y += percpu.h 11 + generic-y += preempt.h 9 12 generic-y += scatterlist.h 10 13 generic-y += sections.h 11 14 generic-y += segment.h 12 15 generic-y += serial.h 13 16 generic-y += trace_clock.h 14 - generic-y += preempt.h 15 17 generic-y += ucontext.h 16 18 generic-y += xor.h 17 - generic-y += hash.h
+2 -1
arch/mn10300/include/asm/Kbuild
··· 3 3 generic-y += clkdev.h 4 4 generic-y += exec.h 5 5 generic-y += hash.h 6 - generic-y += trace_clock.h 6 + generic-y += mcs_spinlock.h 7 7 generic-y += preempt.h 8 + generic-y += trace_clock.h
+6 -5
arch/openrisc/include/asm/Kbuild
··· 10 10 generic-y += cacheflush.h 11 11 generic-y += checksum.h 12 12 generic-y += clkdev.h 13 - generic-y += cmpxchg.h 14 13 generic-y += cmpxchg-local.h 14 + generic-y += cmpxchg.h 15 15 generic-y += cputime.h 16 16 generic-y += current.h 17 17 generic-y += device.h ··· 25 25 generic-y += ftrace.h 26 26 generic-y += futex.h 27 27 generic-y += hardirq.h 28 + generic-y += hash.h 28 29 generic-y += hw_irq.h 29 30 generic-y += ioctl.h 30 31 generic-y += ioctls.h ··· 35 34 generic-y += kmap_types.h 36 35 generic-y += kvm_para.h 37 36 generic-y += local.h 37 + generic-y += mcs_spinlock.h 38 38 generic-y += mman.h 39 39 generic-y += module.h 40 40 generic-y += msgbuf.h ··· 43 41 generic-y += percpu.h 44 42 generic-y += poll.h 45 43 generic-y += posix_types.h 44 + generic-y += preempt.h 46 45 generic-y += resource.h 47 46 generic-y += scatterlist.h 48 47 generic-y += sections.h ··· 56 53 generic-y += signal.h 57 54 generic-y += socket.h 58 55 generic-y += sockios.h 59 - generic-y += statfs.h 60 56 generic-y += stat.h 57 + generic-y += statfs.h 61 58 generic-y += string.h 62 - generic-y += switch_to.h 63 59 generic-y += swab.h 60 + generic-y += switch_to.h 64 61 generic-y += termbits.h 65 62 generic-y += termios.h 66 63 generic-y += topology.h ··· 71 68 generic-y += vga.h 72 69 generic-y += word-at-a-time.h 73 70 generic-y += xor.h 74 - generic-y += preempt.h 75 - generic-y += hash.h
+26 -6
arch/parisc/include/asm/Kbuild
··· 1 1 2 + generic-y += auxvec.h 2 3 generic-y += barrier.h 3 - generic-y += word-at-a-time.h auxvec.h user.h cputime.h emergency-restart.h \ 4 - segment.h topology.h vga.h device.h percpu.h hw_irq.h mutex.h \ 5 - div64.h irq_regs.h kdebug.h kvm_para.h local64.h local.h param.h \ 6 - poll.h xor.h clkdev.h exec.h 7 - generic-y += trace_clock.h 8 - generic-y += preempt.h 4 + generic-y += clkdev.h 5 + generic-y += cputime.h 6 + generic-y += device.h 7 + generic-y += div64.h 8 + generic-y += emergency-restart.h 9 + generic-y += exec.h 9 10 generic-y += hash.h 11 + generic-y += hw_irq.h 12 + generic-y += irq_regs.h 13 + generic-y += kdebug.h 14 + generic-y += kvm_para.h 15 + generic-y += local.h 16 + generic-y += local64.h 17 + generic-y += mcs_spinlock.h 18 + generic-y += mutex.h 19 + generic-y += param.h 20 + generic-y += percpu.h 21 + generic-y += poll.h 22 + generic-y += preempt.h 23 + generic-y += segment.h 24 + generic-y += topology.h 25 + generic-y += trace_clock.h 26 + generic-y += user.h 27 + generic-y += vga.h 28 + generic-y += word-at-a-time.h 29 + generic-y += xor.h
+3 -2
arch/powerpc/include/asm/Kbuild
··· 1 1 2 2 generic-y += clkdev.h 3 + generic-y += hash.h 4 + generic-y += mcs_spinlock.h 5 + generic-y += preempt.h 3 6 generic-y += rwsem.h 4 7 generic-y += trace_clock.h 5 - generic-y += preempt.h 6 8 generic-y += vtime.h 7 - generic-y += hash.h
+1
arch/s390/Kconfig
··· 117 117 select HAVE_FUNCTION_GRAPH_TRACER 118 118 select HAVE_FUNCTION_TRACER 119 119 select HAVE_FUNCTION_TRACE_MCOUNT_TEST 120 + select HAVE_FUTEX_CMPXCHG if FUTEX 120 121 select HAVE_KERNEL_BZIP2 121 122 select HAVE_KERNEL_GZIP 122 123 select HAVE_KERNEL_LZ4
+3 -2
arch/s390/include/asm/Kbuild
··· 1 1 2 2 3 3 generic-y += clkdev.h 4 - generic-y += trace_clock.h 5 - generic-y += preempt.h 6 4 generic-y += hash.h 5 + generic-y += mcs_spinlock.h 6 + generic-y += preempt.h 7 + generic-y += trace_clock.h
+3 -2
arch/score/include/asm/Kbuild
··· 1 1 2 2 header-y += 3 3 4 + 4 5 generic-y += barrier.h 5 6 generic-y += clkdev.h 6 7 generic-y += hash.h 8 + generic-y += mcs_spinlock.h 9 + generic-y += preempt.h 7 10 generic-y += trace_clock.h 8 11 generic-y += xor.h 9 - generic-y += preempt.h 10 -
+5 -4
arch/sh/include/asm/Kbuild
··· 8 8 generic-y += errno.h 9 9 generic-y += exec.h 10 10 generic-y += fcntl.h 11 + generic-y += hash.h 11 12 generic-y += ioctl.h 12 13 generic-y += ipcbuf.h 13 14 generic-y += irq_regs.h 14 15 generic-y += kvm_para.h 15 16 generic-y += local.h 16 17 generic-y += local64.h 18 + generic-y += mcs_spinlock.h 19 + generic-y += mman.h 20 + generic-y += msgbuf.h 17 21 generic-y += param.h 18 22 generic-y += parport.h 19 23 generic-y += percpu.h 20 24 generic-y += poll.h 21 - generic-y += mman.h 22 - generic-y += msgbuf.h 25 + generic-y += preempt.h 23 26 generic-y += resource.h 24 27 generic-y += scatterlist.h 25 28 generic-y += sembuf.h ··· 37 34 generic-y += trace_clock.h 38 35 generic-y += ucontext.h 39 36 generic-y += xor.h 40 - generic-y += preempt.h 41 - generic-y += hash.h
+6 -5
arch/sparc/include/asm/Kbuild
··· 6 6 generic-y += div64.h 7 7 generic-y += emergency-restart.h 8 8 generic-y += exec.h 9 - generic-y += linkage.h 10 - generic-y += local64.h 11 - generic-y += mutex.h 9 + generic-y += hash.h 12 10 generic-y += irq_regs.h 11 + generic-y += linkage.h 13 12 generic-y += local.h 13 + generic-y += local64.h 14 + generic-y += mcs_spinlock.h 14 15 generic-y += module.h 16 + generic-y += mutex.h 17 + generic-y += preempt.h 15 18 generic-y += serial.h 16 19 generic-y += trace_clock.h 17 20 generic-y += types.h 18 21 generic-y += word-at-a-time.h 19 - generic-y += preempt.h 20 - generic-y += hash.h
+3 -2
arch/tile/include/asm/Kbuild
··· 11 11 generic-y += exec.h 12 12 generic-y += fb.h 13 13 generic-y += fcntl.h 14 + generic-y += hash.h 14 15 generic-y += hw_irq.h 15 16 generic-y += ioctl.h 16 17 generic-y += ioctls.h ··· 19 18 generic-y += irq_regs.h 20 19 generic-y += local.h 21 20 generic-y += local64.h 21 + generic-y += mcs_spinlock.h 22 22 generic-y += msgbuf.h 23 23 generic-y += mutex.h 24 24 generic-y += param.h 25 25 generic-y += parport.h 26 26 generic-y += poll.h 27 27 generic-y += posix_types.h 28 + generic-y += preempt.h 28 29 generic-y += resource.h 29 30 generic-y += scatterlist.h 30 31 generic-y += sembuf.h ··· 41 38 generic-y += trace_clock.h 42 39 generic-y += types.h 43 40 generic-y += xor.h 44 - generic-y += preempt.h 45 - generic-y += hash.h
+27 -7
arch/um/include/asm/Kbuild
··· 1 - generic-y += bug.h cputime.h device.h emergency-restart.h futex.h hardirq.h 2 - generic-y += hw_irq.h irq_regs.h kdebug.h percpu.h sections.h topology.h xor.h 3 - generic-y += ftrace.h pci.h io.h param.h delay.h mutex.h current.h exec.h 4 - generic-y += switch_to.h clkdev.h 5 - generic-y += trace_clock.h 6 - generic-y += preempt.h 7 - generic-y += hash.h 8 1 generic-y += barrier.h 2 + generic-y += bug.h 3 + generic-y += clkdev.h 4 + generic-y += cputime.h 5 + generic-y += current.h 6 + generic-y += delay.h 7 + generic-y += device.h 8 + generic-y += emergency-restart.h 9 + generic-y += exec.h 10 + generic-y += ftrace.h 11 + generic-y += futex.h 12 + generic-y += hardirq.h 13 + generic-y += hash.h 14 + generic-y += hw_irq.h 15 + generic-y += io.h 16 + generic-y += irq_regs.h 17 + generic-y += kdebug.h 18 + generic-y += mcs_spinlock.h 19 + generic-y += mutex.h 20 + generic-y += param.h 21 + generic-y += pci.h 22 + generic-y += percpu.h 23 + generic-y += preempt.h 24 + generic-y += sections.h 25 + generic-y += switch_to.h 26 + generic-y += topology.h 27 + generic-y += trace_clock.h 28 + generic-y += xor.h
+3 -2
arch/unicore32/include/asm/Kbuild
··· 16 16 generic-y += ftrace.h 17 17 generic-y += futex.h 18 18 generic-y += hardirq.h 19 + generic-y += hash.h 19 20 generic-y += hw_irq.h 20 21 generic-y += ioctl.h 21 22 generic-y += ioctls.h ··· 25 24 generic-y += kdebug.h 26 25 generic-y += kmap_types.h 27 26 generic-y += local.h 27 + generic-y += mcs_spinlock.h 28 28 generic-y += mman.h 29 29 generic-y += module.h 30 30 generic-y += msgbuf.h ··· 34 32 generic-y += percpu.h 35 33 generic-y += poll.h 36 34 generic-y += posix_types.h 35 + generic-y += preempt.h 37 36 generic-y += resource.h 38 37 generic-y += scatterlist.h 39 38 generic-y += sections.h ··· 63 60 generic-y += user.h 64 61 generic-y += vga.h 65 62 generic-y += xor.h 66 - generic-y += preempt.h 67 - generic-y += hash.h
+1
arch/x86/include/asm/Kbuild
··· 5 5 genhdr-y += unistd_x32.h 6 6 7 7 generic-y += clkdev.h 8 + generic-y += mcs_spinlock.h
+3 -2
arch/xtensa/include/asm/Kbuild
··· 9 9 generic-y += exec.h 10 10 generic-y += fcntl.h 11 11 generic-y += hardirq.h 12 + generic-y += hash.h 12 13 generic-y += ioctl.h 13 14 generic-y += irq_regs.h 14 15 generic-y += kdebug.h ··· 18 17 generic-y += linkage.h 19 18 generic-y += local.h 20 19 generic-y += local64.h 20 + generic-y += mcs_spinlock.h 21 21 generic-y += percpu.h 22 + generic-y += preempt.h 22 23 generic-y += resource.h 23 24 generic-y += scatterlist.h 24 25 generic-y += sections.h ··· 30 27 generic-y += topology.h 31 28 generic-y += trace_clock.h 32 29 generic-y += xor.h 33 - generic-y += preempt.h 34 - generic-y += hash.h
+4 -11
drivers/tty/tty_ldsem.c
··· 39 39 lock_acquire(&(l)->dep_map, s, t, r, c, n, i) 40 40 # define __rel(l, n, i) \ 41 41 lock_release(&(l)->dep_map, n, i) 42 - # ifdef CONFIG_PROVE_LOCKING 43 - # define lockdep_acquire(l, s, t, i) __acq(l, s, t, 0, 2, NULL, i) 44 - # define lockdep_acquire_nest(l, s, t, n, i) __acq(l, s, t, 0, 2, n, i) 45 - # define lockdep_acquire_read(l, s, t, i) __acq(l, s, t, 1, 2, NULL, i) 46 - # define lockdep_release(l, n, i) __rel(l, n, i) 47 - # else 48 - # define lockdep_acquire(l, s, t, i) __acq(l, s, t, 0, 1, NULL, i) 49 - # define lockdep_acquire_nest(l, s, t, n, i) __acq(l, s, t, 0, 1, n, i) 50 - # define lockdep_acquire_read(l, s, t, i) __acq(l, s, t, 1, 1, NULL, i) 51 - # define lockdep_release(l, n, i) __rel(l, n, i) 52 - # endif 42 + #define lockdep_acquire(l, s, t, i) __acq(l, s, t, 0, 1, NULL, i) 43 + #define lockdep_acquire_nest(l, s, t, n, i) __acq(l, s, t, 0, 1, n, i) 44 + #define lockdep_acquire_read(l, s, t, i) __acq(l, s, t, 1, 1, NULL, i) 45 + #define lockdep_release(l, n, i) __rel(l, n, i) 53 46 #else 54 47 # define lockdep_acquire(l, s, t, i) do { } while (0) 55 48 # define lockdep_acquire_nest(l, s, t, n, i) do { } while (0)
+13
include/asm-generic/mcs_spinlock.h
··· 1 + #ifndef __ASM_MCS_SPINLOCK_H 2 + #define __ASM_MCS_SPINLOCK_H 3 + 4 + /* 5 + * Architectures can define their own: 6 + * 7 + * arch_mcs_spin_lock_contended(l) 8 + * arch_mcs_spin_unlock_contended(l) 9 + * 10 + * See kernel/locking/mcs_spinlock.c. 11 + */ 12 + 13 + #endif /* __ASM_MCS_SPINLOCK_H */
+4
include/linux/futex.h
··· 55 55 #ifdef CONFIG_FUTEX 56 56 extern void exit_robust_list(struct task_struct *curr); 57 57 extern void exit_pi_state_list(struct task_struct *curr); 58 + #ifdef CONFIG_HAVE_FUTEX_CMPXCHG 59 + #define futex_cmpxchg_enabled 1 60 + #else 58 61 extern int futex_cmpxchg_enabled; 62 + #endif 59 63 #else 60 64 static inline void exit_robust_list(struct task_struct *curr) 61 65 {
+10 -17
include/linux/lockdep.h
··· 252 252 unsigned int trylock:1; /* 16 bits */ 253 253 254 254 unsigned int read:2; /* see lock_acquire() comment */ 255 - unsigned int check:2; /* see lock_acquire() comment */ 255 + unsigned int check:1; /* see lock_acquire() comment */ 256 256 unsigned int hardirqs_off:1; 257 - unsigned int references:11; /* 32 bits */ 257 + unsigned int references:12; /* 32 bits */ 258 258 }; 259 259 260 260 /* ··· 303 303 (lock)->dep_map.key, sub) 304 304 305 305 #define lockdep_set_novalidate_class(lock) \ 306 - lockdep_set_class(lock, &__lockdep_no_validate__) 306 + lockdep_set_class_and_name(lock, &__lockdep_no_validate__, #lock) 307 307 /* 308 308 * Compare locking classes 309 309 */ ··· 326 326 * 327 327 * Values for check: 328 328 * 329 - * 0: disabled 330 - * 1: simple checks (freeing, held-at-exit-time, etc.) 331 - * 2: full validation 329 + * 0: simple checks (freeing, held-at-exit-time, etc.) 330 + * 1: full validation 332 331 */ 333 332 extern void lock_acquire(struct lockdep_map *lock, unsigned int subclass, 334 333 int trylock, int read, int check, ··· 478 479 * on the per lock-class debug mode: 479 480 */ 480 481 481 - #ifdef CONFIG_PROVE_LOCKING 482 - #define lock_acquire_exclusive(l, s, t, n, i) lock_acquire(l, s, t, 0, 2, n, i) 483 - #define lock_acquire_shared(l, s, t, n, i) lock_acquire(l, s, t, 1, 2, n, i) 484 - #define lock_acquire_shared_recursive(l, s, t, n, i) lock_acquire(l, s, t, 2, 2, n, i) 485 - #else 486 - #define lock_acquire_exclusive(l, s, t, n, i) lock_acquire(l, s, t, 0, 1, n, i) 487 - #define lock_acquire_shared(l, s, t, n, i) lock_acquire(l, s, t, 1, 1, n, i) 488 - #define lock_acquire_shared_recursive(l, s, t, n, i) lock_acquire(l, s, t, 2, 1, n, i) 489 - #endif 482 + #define lock_acquire_exclusive(l, s, t, n, i) lock_acquire(l, s, t, 0, 1, n, i) 483 + #define lock_acquire_shared(l, s, t, n, i) lock_acquire(l, s, t, 1, 1, n, i) 484 + #define lock_acquire_shared_recursive(l, s, t, n, i) lock_acquire(l, s, t, 2, 1, n, i) 490 485 491 486 #define spin_acquire(l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i) 492 487 #define spin_acquire_nest(l, s, t, n, i) lock_acquire_exclusive(l, s, t, n, i) ··· 511 518 # define might_lock(lock) \ 512 519 do { \ 513 520 typecheck(struct lockdep_map *, &(lock)->dep_map); \ 514 - lock_acquire(&(lock)->dep_map, 0, 0, 0, 2, NULL, _THIS_IP_); \ 521 + lock_acquire(&(lock)->dep_map, 0, 0, 0, 1, NULL, _THIS_IP_); \ 515 522 lock_release(&(lock)->dep_map, 0, _THIS_IP_); \ 516 523 } while (0) 517 524 # define might_lock_read(lock) \ 518 525 do { \ 519 526 typecheck(struct lockdep_map *, &(lock)->dep_map); \ 520 - lock_acquire(&(lock)->dep_map, 0, 0, 1, 2, NULL, _THIS_IP_); \ 527 + lock_acquire(&(lock)->dep_map, 0, 0, 1, 1, NULL, _THIS_IP_); \ 521 528 lock_release(&(lock)->dep_map, 0, _THIS_IP_); \ 522 529 } while (0) 523 530 #else
+3 -2
include/linux/mutex.h
··· 46 46 * - detects multi-task circular deadlocks and prints out all affected 47 47 * locks and tasks (and only those tasks) 48 48 */ 49 + struct optimistic_spin_queue; 49 50 struct mutex { 50 51 /* 1: unlocked, 0: locked, negative: locked, possible waiters */ 51 52 atomic_t count; ··· 56 55 struct task_struct *owner; 57 56 #endif 58 57 #ifdef CONFIG_MUTEX_SPIN_ON_OWNER 59 - void *spin_mlock; /* Spinner MCS lock */ 58 + struct optimistic_spin_queue *osq; /* Spinner MCS lock */ 60 59 #endif 61 60 #ifdef CONFIG_DEBUG_MUTEXES 62 61 const char *name; ··· 180 179 # define arch_mutex_cpu_relax() cpu_relax() 181 180 #endif 182 181 183 - #endif 182 + #endif /* __LINUX_MUTEX_H */
+1 -1
include/linux/rcupdate.h
··· 314 314 315 315 static inline void rcu_lock_acquire(struct lockdep_map *map) 316 316 { 317 - lock_acquire(map, 0, 0, 2, 1, NULL, _THIS_IP_); 317 + lock_acquire(map, 0, 0, 2, 0, NULL, _THIS_IP_); 318 318 } 319 319 320 320 static inline void rcu_lock_release(struct lockdep_map *map)
+7
init/Kconfig
··· 1387 1387 support for "fast userspace mutexes". The resulting kernel may not 1388 1388 run glibc-based applications correctly. 1389 1389 1390 + config HAVE_FUTEX_CMPXCHG 1391 + bool 1392 + help 1393 + Architectures should select this if futex_atomic_cmpxchg_inatomic() 1394 + is implemented and always working. This removes a couple of runtime 1395 + checks. 1396 + 1390 1397 config EPOLL 1391 1398 bool "Enable eventpoll support" if EXPERT 1392 1399 default y
+24 -13
kernel/futex.c
··· 157 157 * enqueue. 158 158 */ 159 159 160 + #ifndef CONFIG_HAVE_FUTEX_CMPXCHG 160 161 int __read_mostly futex_cmpxchg_enabled; 162 + #endif 161 163 162 164 /* 163 165 * Futex flags used to encode options to functions and preserve them across ··· 2877 2875 return do_futex(uaddr, op, val, tp, uaddr2, val2, val3); 2878 2876 } 2879 2877 2878 + static void __init futex_detect_cmpxchg(void) 2879 + { 2880 + #ifndef CONFIG_HAVE_FUTEX_CMPXCHG 2881 + u32 curval; 2882 + 2883 + /* 2884 + * This will fail and we want it. Some arch implementations do 2885 + * runtime detection of the futex_atomic_cmpxchg_inatomic() 2886 + * functionality. We want to know that before we call in any 2887 + * of the complex code paths. Also we want to prevent 2888 + * registration of robust lists in that case. NULL is 2889 + * guaranteed to fault and we get -EFAULT on functional 2890 + * implementation, the non-functional ones will return 2891 + * -ENOSYS. 2892 + */ 2893 + if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT) 2894 + futex_cmpxchg_enabled = 1; 2895 + #endif 2896 + } 2897 + 2880 2898 static int __init futex_init(void) 2881 2899 { 2882 - u32 curval; 2883 2900 unsigned int futex_shift; 2884 2901 unsigned long i; 2885 2902 ··· 2914 2893 &futex_shift, NULL, 2915 2894 futex_hashsize, futex_hashsize); 2916 2895 futex_hashsize = 1UL << futex_shift; 2917 - /* 2918 - * This will fail and we want it. Some arch implementations do 2919 - * runtime detection of the futex_atomic_cmpxchg_inatomic() 2920 - * functionality. We want to know that before we call in any 2921 - * of the complex code paths. Also we want to prevent 2922 - * registration of robust lists in that case. NULL is 2923 - * guaranteed to fault and we get -EFAULT on functional 2924 - * implementation, the non-functional ones will return 2925 - * -ENOSYS. 2926 - */ 2927 - if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT) 2928 - futex_cmpxchg_enabled = 1; 2896 + 2897 + futex_detect_cmpxchg(); 2929 2898 2930 2899 for (i = 0; i < futex_hashsize; i++) { 2931 2900 atomic_set(&futex_queues[i].waiters, 0);
+1 -1
kernel/locking/Makefile
··· 1 1 2 - obj-y += mutex.o semaphore.o rwsem.o lglock.o 2 + obj-y += mutex.o semaphore.o rwsem.o lglock.o mcs_spinlock.o 3 3 4 4 ifdef CONFIG_FUNCTION_TRACER 5 5 CFLAGS_REMOVE_lockdep.o = -pg
+7 -10
kernel/locking/lockdep.c
··· 1936 1936 1937 1937 for (;;) { 1938 1938 int distance = curr->lockdep_depth - depth + 1; 1939 - hlock = curr->held_locks + depth-1; 1939 + hlock = curr->held_locks + depth - 1; 1940 1940 /* 1941 1941 * Only non-recursive-read entries get new dependencies 1942 1942 * added: 1943 1943 */ 1944 - if (hlock->read != 2) { 1944 + if (hlock->read != 2 && hlock->check) { 1945 1945 if (!check_prev_add(curr, hlock, next, 1946 1946 distance, trylock_loop)) 1947 1947 return 0; ··· 2098 2098 * (If lookup_chain_cache() returns with 1 it acquires 2099 2099 * graph_lock for us) 2100 2100 */ 2101 - if (!hlock->trylock && (hlock->check == 2) && 2101 + if (!hlock->trylock && hlock->check && 2102 2102 lookup_chain_cache(curr, hlock, chain_key)) { 2103 2103 /* 2104 2104 * Check whether last held lock: ··· 2517 2517 2518 2518 BUG_ON(usage_bit >= LOCK_USAGE_STATES); 2519 2519 2520 - if (hlock_class(hlock)->key == __lockdep_no_validate__.subkeys) 2520 + if (!hlock->check) 2521 2521 continue; 2522 2522 2523 2523 if (!mark_lock(curr, hlock, usage_bit)) ··· 3055 3055 int class_idx; 3056 3056 u64 chain_key; 3057 3057 3058 - if (!prove_locking) 3059 - check = 1; 3060 - 3061 3058 if (unlikely(!debug_locks)) 3062 3059 return 0; 3063 3060 ··· 3066 3069 if (DEBUG_LOCKS_WARN_ON(!irqs_disabled())) 3067 3070 return 0; 3068 3071 3069 - if (lock->key == &__lockdep_no_validate__) 3070 - check = 1; 3072 + if (!prove_locking || lock->key == &__lockdep_no_validate__) 3073 + check = 0; 3071 3074 3072 3075 if (subclass < NR_LOCKDEP_CACHING_CLASSES) 3073 3076 class = lock->class_cache[subclass]; ··· 3135 3138 hlock->holdtime_stamp = lockstat_clock(); 3136 3139 #endif 3137 3140 3138 - if (check == 2 && !mark_irqflags(curr, hlock)) 3141 + if (check && !mark_irqflags(curr, hlock)) 3139 3142 return 0; 3140 3143 3141 3144 /* mark it as used: */
+178
kernel/locking/mcs_spinlock.c
··· 1 + 2 + #include <linux/percpu.h> 3 + #include <linux/mutex.h> 4 + #include <linux/sched.h> 5 + #include "mcs_spinlock.h" 6 + 7 + #ifdef CONFIG_SMP 8 + 9 + /* 10 + * An MCS like lock especially tailored for optimistic spinning for sleeping 11 + * lock implementations (mutex, rwsem, etc). 12 + * 13 + * Using a single mcs node per CPU is safe because sleeping locks should not be 14 + * called from interrupt context and we have preemption disabled while 15 + * spinning. 16 + */ 17 + static DEFINE_PER_CPU_SHARED_ALIGNED(struct optimistic_spin_queue, osq_node); 18 + 19 + /* 20 + * Get a stable @node->next pointer, either for unlock() or unqueue() purposes. 21 + * Can return NULL in case we were the last queued and we updated @lock instead. 22 + */ 23 + static inline struct optimistic_spin_queue * 24 + osq_wait_next(struct optimistic_spin_queue **lock, 25 + struct optimistic_spin_queue *node, 26 + struct optimistic_spin_queue *prev) 27 + { 28 + struct optimistic_spin_queue *next = NULL; 29 + 30 + for (;;) { 31 + if (*lock == node && cmpxchg(lock, node, prev) == node) { 32 + /* 33 + * We were the last queued, we moved @lock back. @prev 34 + * will now observe @lock and will complete its 35 + * unlock()/unqueue(). 36 + */ 37 + break; 38 + } 39 + 40 + /* 41 + * We must xchg() the @node->next value, because if we were to 42 + * leave it in, a concurrent unlock()/unqueue() from 43 + * @node->next might complete Step-A and think its @prev is 44 + * still valid. 45 + * 46 + * If the concurrent unlock()/unqueue() wins the race, we'll 47 + * wait for either @lock to point to us, through its Step-B, or 48 + * wait for a new @node->next from its Step-C. 49 + */ 50 + if (node->next) { 51 + next = xchg(&node->next, NULL); 52 + if (next) 53 + break; 54 + } 55 + 56 + arch_mutex_cpu_relax(); 57 + } 58 + 59 + return next; 60 + } 61 + 62 + bool osq_lock(struct optimistic_spin_queue **lock) 63 + { 64 + struct optimistic_spin_queue *node = this_cpu_ptr(&osq_node); 65 + struct optimistic_spin_queue *prev, *next; 66 + 67 + node->locked = 0; 68 + node->next = NULL; 69 + 70 + node->prev = prev = xchg(lock, node); 71 + if (likely(prev == NULL)) 72 + return true; 73 + 74 + ACCESS_ONCE(prev->next) = node; 75 + 76 + /* 77 + * Normally @prev is untouchable after the above store; because at that 78 + * moment unlock can proceed and wipe the node element from stack. 79 + * 80 + * However, since our nodes are static per-cpu storage, we're 81 + * guaranteed their existence -- this allows us to apply 82 + * cmpxchg in an attempt to undo our queueing. 83 + */ 84 + 85 + while (!smp_load_acquire(&node->locked)) { 86 + /* 87 + * If we need to reschedule bail... so we can block. 88 + */ 89 + if (need_resched()) 90 + goto unqueue; 91 + 92 + arch_mutex_cpu_relax(); 93 + } 94 + return true; 95 + 96 + unqueue: 97 + /* 98 + * Step - A -- stabilize @prev 99 + * 100 + * Undo our @prev->next assignment; this will make @prev's 101 + * unlock()/unqueue() wait for a next pointer since @lock points to us 102 + * (or later). 103 + */ 104 + 105 + for (;;) { 106 + if (prev->next == node && 107 + cmpxchg(&prev->next, node, NULL) == node) 108 + break; 109 + 110 + /* 111 + * We can only fail the cmpxchg() racing against an unlock(), 112 + * in which case we should observe @node->locked becomming 113 + * true. 114 + */ 115 + if (smp_load_acquire(&node->locked)) 116 + return true; 117 + 118 + arch_mutex_cpu_relax(); 119 + 120 + /* 121 + * Or we race against a concurrent unqueue()'s step-B, in which 122 + * case its step-C will write us a new @node->prev pointer. 123 + */ 124 + prev = ACCESS_ONCE(node->prev); 125 + } 126 + 127 + /* 128 + * Step - B -- stabilize @next 129 + * 130 + * Similar to unlock(), wait for @node->next or move @lock from @node 131 + * back to @prev. 132 + */ 133 + 134 + next = osq_wait_next(lock, node, prev); 135 + if (!next) 136 + return false; 137 + 138 + /* 139 + * Step - C -- unlink 140 + * 141 + * @prev is stable because its still waiting for a new @prev->next 142 + * pointer, @next is stable because our @node->next pointer is NULL and 143 + * it will wait in Step-A. 144 + */ 145 + 146 + ACCESS_ONCE(next->prev) = prev; 147 + ACCESS_ONCE(prev->next) = next; 148 + 149 + return false; 150 + } 151 + 152 + void osq_unlock(struct optimistic_spin_queue **lock) 153 + { 154 + struct optimistic_spin_queue *node = this_cpu_ptr(&osq_node); 155 + struct optimistic_spin_queue *next; 156 + 157 + /* 158 + * Fast path for the uncontended case. 159 + */ 160 + if (likely(cmpxchg(lock, node, NULL) == node)) 161 + return; 162 + 163 + /* 164 + * Second most likely case. 165 + */ 166 + next = xchg(&node->next, NULL); 167 + if (next) { 168 + ACCESS_ONCE(next->locked) = 1; 169 + return; 170 + } 171 + 172 + next = osq_wait_next(lock, node, NULL); 173 + if (next) 174 + ACCESS_ONCE(next->locked) = 1; 175 + } 176 + 177 + #endif 178 +
+129
kernel/locking/mcs_spinlock.h
··· 1 + /* 2 + * MCS lock defines 3 + * 4 + * This file contains the main data structure and API definitions of MCS lock. 5 + * 6 + * The MCS lock (proposed by Mellor-Crummey and Scott) is a simple spin-lock 7 + * with the desirable properties of being fair, and with each cpu trying 8 + * to acquire the lock spinning on a local variable. 9 + * It avoids expensive cache bouncings that common test-and-set spin-lock 10 + * implementations incur. 11 + */ 12 + #ifndef __LINUX_MCS_SPINLOCK_H 13 + #define __LINUX_MCS_SPINLOCK_H 14 + 15 + #include <asm/mcs_spinlock.h> 16 + 17 + struct mcs_spinlock { 18 + struct mcs_spinlock *next; 19 + int locked; /* 1 if lock acquired */ 20 + }; 21 + 22 + #ifndef arch_mcs_spin_lock_contended 23 + /* 24 + * Using smp_load_acquire() provides a memory barrier that ensures 25 + * subsequent operations happen after the lock is acquired. 26 + */ 27 + #define arch_mcs_spin_lock_contended(l) \ 28 + do { \ 29 + while (!(smp_load_acquire(l))) \ 30 + arch_mutex_cpu_relax(); \ 31 + } while (0) 32 + #endif 33 + 34 + #ifndef arch_mcs_spin_unlock_contended 35 + /* 36 + * smp_store_release() provides a memory barrier to ensure all 37 + * operations in the critical section has been completed before 38 + * unlocking. 39 + */ 40 + #define arch_mcs_spin_unlock_contended(l) \ 41 + smp_store_release((l), 1) 42 + #endif 43 + 44 + /* 45 + * Note: the smp_load_acquire/smp_store_release pair is not 46 + * sufficient to form a full memory barrier across 47 + * cpus for many architectures (except x86) for mcs_unlock and mcs_lock. 48 + * For applications that need a full barrier across multiple cpus 49 + * with mcs_unlock and mcs_lock pair, smp_mb__after_unlock_lock() should be 50 + * used after mcs_lock. 51 + */ 52 + 53 + /* 54 + * In order to acquire the lock, the caller should declare a local node and 55 + * pass a reference of the node to this function in addition to the lock. 56 + * If the lock has already been acquired, then this will proceed to spin 57 + * on this node->locked until the previous lock holder sets the node->locked 58 + * in mcs_spin_unlock(). 59 + * 60 + * We don't inline mcs_spin_lock() so that perf can correctly account for the 61 + * time spent in this lock function. 62 + */ 63 + static inline 64 + void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node) 65 + { 66 + struct mcs_spinlock *prev; 67 + 68 + /* Init node */ 69 + node->locked = 0; 70 + node->next = NULL; 71 + 72 + prev = xchg(lock, node); 73 + if (likely(prev == NULL)) { 74 + /* 75 + * Lock acquired, don't need to set node->locked to 1. Threads 76 + * only spin on its own node->locked value for lock acquisition. 77 + * However, since this thread can immediately acquire the lock 78 + * and does not proceed to spin on its own node->locked, this 79 + * value won't be used. If a debug mode is needed to 80 + * audit lock status, then set node->locked value here. 81 + */ 82 + return; 83 + } 84 + ACCESS_ONCE(prev->next) = node; 85 + 86 + /* Wait until the lock holder passes the lock down. */ 87 + arch_mcs_spin_lock_contended(&node->locked); 88 + } 89 + 90 + /* 91 + * Releases the lock. The caller should pass in the corresponding node that 92 + * was used to acquire the lock. 93 + */ 94 + static inline 95 + void mcs_spin_unlock(struct mcs_spinlock **lock, struct mcs_spinlock *node) 96 + { 97 + struct mcs_spinlock *next = ACCESS_ONCE(node->next); 98 + 99 + if (likely(!next)) { 100 + /* 101 + * Release the lock by setting it to NULL 102 + */ 103 + if (likely(cmpxchg(lock, node, NULL) == node)) 104 + return; 105 + /* Wait until the next pointer is set */ 106 + while (!(next = ACCESS_ONCE(node->next))) 107 + arch_mutex_cpu_relax(); 108 + } 109 + 110 + /* Pass lock to next waiter. */ 111 + arch_mcs_spin_unlock_contended(&next->locked); 112 + } 113 + 114 + /* 115 + * Cancellable version of the MCS lock above. 116 + * 117 + * Intended for adaptive spinning of sleeping locks: 118 + * mutex_lock()/rwsem_down_{read,write}() etc. 119 + */ 120 + 121 + struct optimistic_spin_queue { 122 + struct optimistic_spin_queue *next, *prev; 123 + int locked; /* 1 if lock acquired */ 124 + }; 125 + 126 + extern bool osq_lock(struct optimistic_spin_queue **lock); 127 + extern void osq_unlock(struct optimistic_spin_queue **lock); 128 + 129 + #endif /* __LINUX_MCS_SPINLOCK_H */
+6
kernel/locking/mutex-debug.c
··· 83 83 84 84 DEBUG_LOCKS_WARN_ON(!lock->wait_list.prev && !lock->wait_list.next); 85 85 mutex_clear_owner(lock); 86 + 87 + /* 88 + * __mutex_slowpath_needs_to_unlock() is explicitly 0 for debug 89 + * mutexes so that we can do it here after we've verified state. 90 + */ 91 + atomic_set(&lock->count, 1); 86 92 } 87 93 88 94 void debug_mutex_init(struct mutex *lock, const char *name,
+32 -62
kernel/locking/mutex.c
··· 25 25 #include <linux/spinlock.h> 26 26 #include <linux/interrupt.h> 27 27 #include <linux/debug_locks.h> 28 + #include "mcs_spinlock.h" 28 29 29 30 /* 30 31 * In the DEBUG case we are using the "NULL fastpath" for mutexes, ··· 34 33 #ifdef CONFIG_DEBUG_MUTEXES 35 34 # include "mutex-debug.h" 36 35 # include <asm-generic/mutex-null.h> 36 + /* 37 + * Must be 0 for the debug case so we do not do the unlock outside of the 38 + * wait_lock region. debug_mutex_unlock() will do the actual unlock in this 39 + * case. 40 + */ 41 + # undef __mutex_slowpath_needs_to_unlock 42 + # define __mutex_slowpath_needs_to_unlock() 0 37 43 #else 38 44 # include "mutex.h" 39 45 # include <asm/mutex.h> ··· 60 52 INIT_LIST_HEAD(&lock->wait_list); 61 53 mutex_clear_owner(lock); 62 54 #ifdef CONFIG_MUTEX_SPIN_ON_OWNER 63 - lock->spin_mlock = NULL; 55 + lock->osq = NULL; 64 56 #endif 65 57 66 58 debug_mutex_init(lock, name, key); ··· 119 111 * more or less simultaneously, the spinners need to acquire a MCS lock 120 112 * first before spinning on the owner field. 121 113 * 122 - * We don't inline mspin_lock() so that perf can correctly account for the 123 - * time spent in this lock function. 124 114 */ 125 - struct mspin_node { 126 - struct mspin_node *next ; 127 - int locked; /* 1 if lock acquired */ 128 - }; 129 - #define MLOCK(mutex) ((struct mspin_node **)&((mutex)->spin_mlock)) 130 - 131 - static noinline 132 - void mspin_lock(struct mspin_node **lock, struct mspin_node *node) 133 - { 134 - struct mspin_node *prev; 135 - 136 - /* Init node */ 137 - node->locked = 0; 138 - node->next = NULL; 139 - 140 - prev = xchg(lock, node); 141 - if (likely(prev == NULL)) { 142 - /* Lock acquired */ 143 - node->locked = 1; 144 - return; 145 - } 146 - ACCESS_ONCE(prev->next) = node; 147 - smp_wmb(); 148 - /* Wait until the lock holder passes the lock down */ 149 - while (!ACCESS_ONCE(node->locked)) 150 - arch_mutex_cpu_relax(); 151 - } 152 - 153 - static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node) 154 - { 155 - struct mspin_node *next = ACCESS_ONCE(node->next); 156 - 157 - if (likely(!next)) { 158 - /* 159 - * Release the lock by setting it to NULL 160 - */ 161 - if (cmpxchg(lock, node, NULL) == node) 162 - return; 163 - /* Wait until the next pointer is set */ 164 - while (!(next = ACCESS_ONCE(node->next))) 165 - arch_mutex_cpu_relax(); 166 - } 167 - ACCESS_ONCE(next->locked) = 1; 168 - smp_wmb(); 169 - } 170 115 171 116 /* 172 117 * Mutex spinning code migrated from kernel/sched/core.c ··· 172 211 { 173 212 struct task_struct *owner; 174 213 int retval = 1; 214 + 215 + if (need_resched()) 216 + return 0; 175 217 176 218 rcu_read_lock(); 177 219 owner = ACCESS_ONCE(lock->owner); ··· 410 446 if (!mutex_can_spin_on_owner(lock)) 411 447 goto slowpath; 412 448 449 + if (!osq_lock(&lock->osq)) 450 + goto slowpath; 451 + 413 452 for (;;) { 414 453 struct task_struct *owner; 415 - struct mspin_node node; 416 454 417 455 if (use_ww_ctx && ww_ctx->acquired > 0) { 418 456 struct ww_mutex *ww; ··· 429 463 * performed the optimistic spinning cannot be done. 430 464 */ 431 465 if (ACCESS_ONCE(ww->ctx)) 432 - goto slowpath; 466 + break; 433 467 } 434 468 435 469 /* 436 470 * If there's an owner, wait for it to either 437 471 * release the lock or go to sleep. 438 472 */ 439 - mspin_lock(MLOCK(lock), &node); 440 473 owner = ACCESS_ONCE(lock->owner); 441 - if (owner && !mutex_spin_on_owner(lock, owner)) { 442 - mspin_unlock(MLOCK(lock), &node); 443 - goto slowpath; 444 - } 474 + if (owner && !mutex_spin_on_owner(lock, owner)) 475 + break; 445 476 446 477 if ((atomic_read(&lock->count) == 1) && 447 478 (atomic_cmpxchg(&lock->count, 1, 0) == 1)) { ··· 451 488 } 452 489 453 490 mutex_set_owner(lock); 454 - mspin_unlock(MLOCK(lock), &node); 491 + osq_unlock(&lock->osq); 455 492 preempt_enable(); 456 493 return 0; 457 494 } 458 - mspin_unlock(MLOCK(lock), &node); 459 495 460 496 /* 461 497 * When there's no owner, we might have preempted between the ··· 463 501 * the owner complete. 464 502 */ 465 503 if (!owner && (need_resched() || rt_task(task))) 466 - goto slowpath; 504 + break; 467 505 468 506 /* 469 507 * The cpu_relax() call is a compiler barrier which forces ··· 473 511 */ 474 512 arch_mutex_cpu_relax(); 475 513 } 514 + osq_unlock(&lock->osq); 476 515 slowpath: 516 + /* 517 + * If we fell out of the spin path because of need_resched(), 518 + * reschedule now, before we try-lock the mutex. This avoids getting 519 + * scheduled out right after we obtained the mutex. 520 + */ 521 + if (need_resched()) 522 + schedule_preempt_disabled(); 477 523 #endif 478 524 spin_lock_mutex(&lock->wait_lock, flags); 479 525 ··· 687 717 struct mutex *lock = container_of(lock_count, struct mutex, count); 688 718 unsigned long flags; 689 719 690 - spin_lock_mutex(&lock->wait_lock, flags); 691 - mutex_release(&lock->dep_map, nested, _RET_IP_); 692 - debug_mutex_unlock(lock); 693 - 694 720 /* 695 721 * some architectures leave the lock unlocked in the fastpath failure 696 722 * case, others need to leave it locked. In the later case we have to ··· 694 728 */ 695 729 if (__mutex_slowpath_needs_to_unlock()) 696 730 atomic_set(&lock->count, 1); 731 + 732 + spin_lock_mutex(&lock->wait_lock, flags); 733 + mutex_release(&lock->dep_map, nested, _RET_IP_); 734 + debug_mutex_unlock(lock); 697 735 698 736 if (!list_empty(&lock->wait_list)) { 699 737 /* get the first entry from the wait-list: */