Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 1 | #ifndef __LINUX_SPINLOCK_API_SMP_H |
| 2 | #define __LINUX_SPINLOCK_API_SMP_H |
| 3 | |
| 4 | #ifndef __LINUX_SPINLOCK_H |
| 5 | # error "please don't include this file directly" |
| 6 | #endif |
| 7 | |
| 8 | /* |
| 9 | * include/linux/spinlock_api_smp.h |
| 10 | * |
| 11 | * spinlock API declarations on SMP (and debug) |
| 12 | * (implemented in kernel/spinlock.c) |
| 13 | * |
| 14 | * portions Copyright 2005, Red Hat, Inc., Ingo Molnar |
| 15 | * Released under the General Public License (GPL). |
| 16 | */ |
| 17 | |
| 18 | int in_lock_functions(unsigned long addr); |
| 19 | |
Thomas Gleixner | c2f21ce | 2009-12-02 20:02:59 +0100 | [diff] [blame] | 20 | #define assert_raw_spin_locked(x) BUG_ON(!raw_spin_is_locked(x)) |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 21 | |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 22 | void __lockfunc _raw_spin_lock(raw_spinlock_t *lock) __acquires(lock); |
| 23 | void __lockfunc _raw_spin_lock_nested(raw_spinlock_t *lock, int subclass) |
| 24 | __acquires(lock); |
Thomas Graf | 113948d | 2015-01-02 23:00:19 +0100 | [diff] [blame] | 25 | void __lockfunc _raw_spin_lock_bh_nested(raw_spinlock_t *lock, int subclass) |
| 26 | __acquires(lock); |
Thomas Gleixner | c2f21ce | 2009-12-02 20:02:59 +0100 | [diff] [blame] | 27 | void __lockfunc |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 28 | _raw_spin_lock_nest_lock(raw_spinlock_t *lock, struct lockdep_map *map) |
| 29 | __acquires(lock); |
| 30 | void __lockfunc _raw_spin_lock_bh(raw_spinlock_t *lock) __acquires(lock); |
| 31 | void __lockfunc _raw_spin_lock_irq(raw_spinlock_t *lock) |
| 32 | __acquires(lock); |
Thomas Gleixner | 6b6b479 | 2009-11-16 18:48:37 +0100 | [diff] [blame] | 33 | |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 34 | unsigned long __lockfunc _raw_spin_lock_irqsave(raw_spinlock_t *lock) |
| 35 | __acquires(lock); |
Thomas Gleixner | c2f21ce | 2009-12-02 20:02:59 +0100 | [diff] [blame] | 36 | unsigned long __lockfunc |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 37 | _raw_spin_lock_irqsave_nested(raw_spinlock_t *lock, int subclass) |
| 38 | __acquires(lock); |
| 39 | int __lockfunc _raw_spin_trylock(raw_spinlock_t *lock); |
| 40 | int __lockfunc _raw_spin_trylock_bh(raw_spinlock_t *lock); |
| 41 | void __lockfunc _raw_spin_unlock(raw_spinlock_t *lock) __releases(lock); |
| 42 | void __lockfunc _raw_spin_unlock_bh(raw_spinlock_t *lock) __releases(lock); |
| 43 | void __lockfunc _raw_spin_unlock_irq(raw_spinlock_t *lock) __releases(lock); |
Thomas Gleixner | c2f21ce | 2009-12-02 20:02:59 +0100 | [diff] [blame] | 44 | void __lockfunc |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 45 | _raw_spin_unlock_irqrestore(raw_spinlock_t *lock, unsigned long flags) |
| 46 | __releases(lock); |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 47 | |
Thomas Gleixner | 6beb000 | 2009-11-09 15:21:34 +0000 | [diff] [blame] | 48 | #ifdef CONFIG_INLINE_SPIN_LOCK |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 49 | #define _raw_spin_lock(lock) __raw_spin_lock(lock) |
Heiko Carstens | 892a7c6 | 2009-08-31 14:43:37 +0200 | [diff] [blame] | 50 | #endif |
| 51 | |
Thomas Gleixner | 6beb000 | 2009-11-09 15:21:34 +0000 | [diff] [blame] | 52 | #ifdef CONFIG_INLINE_SPIN_LOCK_BH |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 53 | #define _raw_spin_lock_bh(lock) __raw_spin_lock_bh(lock) |
Heiko Carstens | 892a7c6 | 2009-08-31 14:43:37 +0200 | [diff] [blame] | 54 | #endif |
| 55 | |
Thomas Gleixner | 6beb000 | 2009-11-09 15:21:34 +0000 | [diff] [blame] | 56 | #ifdef CONFIG_INLINE_SPIN_LOCK_IRQ |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 57 | #define _raw_spin_lock_irq(lock) __raw_spin_lock_irq(lock) |
Heiko Carstens | 892a7c6 | 2009-08-31 14:43:37 +0200 | [diff] [blame] | 58 | #endif |
| 59 | |
Thomas Gleixner | 6beb000 | 2009-11-09 15:21:34 +0000 | [diff] [blame] | 60 | #ifdef CONFIG_INLINE_SPIN_LOCK_IRQSAVE |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 61 | #define _raw_spin_lock_irqsave(lock) __raw_spin_lock_irqsave(lock) |
Heiko Carstens | 892a7c6 | 2009-08-31 14:43:37 +0200 | [diff] [blame] | 62 | #endif |
| 63 | |
Thomas Gleixner | 6beb000 | 2009-11-09 15:21:34 +0000 | [diff] [blame] | 64 | #ifdef CONFIG_INLINE_SPIN_TRYLOCK |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 65 | #define _raw_spin_trylock(lock) __raw_spin_trylock(lock) |
Heiko Carstens | 892a7c6 | 2009-08-31 14:43:37 +0200 | [diff] [blame] | 66 | #endif |
| 67 | |
Thomas Gleixner | 6beb000 | 2009-11-09 15:21:34 +0000 | [diff] [blame] | 68 | #ifdef CONFIG_INLINE_SPIN_TRYLOCK_BH |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 69 | #define _raw_spin_trylock_bh(lock) __raw_spin_trylock_bh(lock) |
Heiko Carstens | 892a7c6 | 2009-08-31 14:43:37 +0200 | [diff] [blame] | 70 | #endif |
| 71 | |
Raghavendra K T | e335e3e | 2012-03-22 15:25:08 +0530 | [diff] [blame] | 72 | #ifndef CONFIG_UNINLINE_SPIN_UNLOCK |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 73 | #define _raw_spin_unlock(lock) __raw_spin_unlock(lock) |
Heiko Carstens | 892a7c6 | 2009-08-31 14:43:37 +0200 | [diff] [blame] | 74 | #endif |
| 75 | |
Thomas Gleixner | 6beb000 | 2009-11-09 15:21:34 +0000 | [diff] [blame] | 76 | #ifdef CONFIG_INLINE_SPIN_UNLOCK_BH |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 77 | #define _raw_spin_unlock_bh(lock) __raw_spin_unlock_bh(lock) |
Heiko Carstens | 892a7c6 | 2009-08-31 14:43:37 +0200 | [diff] [blame] | 78 | #endif |
| 79 | |
Thomas Gleixner | 6beb000 | 2009-11-09 15:21:34 +0000 | [diff] [blame] | 80 | #ifdef CONFIG_INLINE_SPIN_UNLOCK_IRQ |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 81 | #define _raw_spin_unlock_irq(lock) __raw_spin_unlock_irq(lock) |
Heiko Carstens | 892a7c6 | 2009-08-31 14:43:37 +0200 | [diff] [blame] | 82 | #endif |
| 83 | |
Thomas Gleixner | 6beb000 | 2009-11-09 15:21:34 +0000 | [diff] [blame] | 84 | #ifdef CONFIG_INLINE_SPIN_UNLOCK_IRQRESTORE |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 85 | #define _raw_spin_unlock_irqrestore(lock, flags) __raw_spin_unlock_irqrestore(lock, flags) |
Heiko Carstens | 892a7c6 | 2009-08-31 14:43:37 +0200 | [diff] [blame] | 86 | #endif |
| 87 | |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 88 | static inline int __raw_spin_trylock(raw_spinlock_t *lock) |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 89 | { |
| 90 | preempt_disable(); |
Thomas Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 91 | if (do_raw_spin_trylock(lock)) { |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 92 | spin_acquire(&lock->dep_map, 0, 1, _RET_IP_); |
| 93 | return 1; |
| 94 | } |
| 95 | preempt_enable(); |
| 96 | return 0; |
| 97 | } |
| 98 | |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 99 | /* |
| 100 | * If lockdep is enabled then we use the non-preemption spin-ops |
| 101 | * even on CONFIG_PREEMPT, because lockdep assumes that interrupts are |
| 102 | * not re-enabled during lock-acquire (which the preempt-spin-ops do): |
| 103 | */ |
| 104 | #if !defined(CONFIG_GENERIC_LOCKBREAK) || defined(CONFIG_DEBUG_LOCK_ALLOC) |
| 105 | |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 106 | static inline unsigned long __raw_spin_lock_irqsave(raw_spinlock_t *lock) |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 107 | { |
| 108 | unsigned long flags; |
| 109 | |
| 110 | local_irq_save(flags); |
| 111 | preempt_disable(); |
| 112 | spin_acquire(&lock->dep_map, 0, 0, _RET_IP_); |
| 113 | /* |
| 114 | * On lockdep we dont want the hand-coded irq-enable of |
Thomas Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 115 | * do_raw_spin_lock_flags() code, because lockdep assumes |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 116 | * that interrupts are not re-enabled during lock-acquire: |
| 117 | */ |
| 118 | #ifdef CONFIG_LOCKDEP |
Thomas Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 119 | LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock); |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 120 | #else |
Thomas Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 121 | do_raw_spin_lock_flags(lock, &flags); |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 122 | #endif |
| 123 | return flags; |
| 124 | } |
| 125 | |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 126 | static inline void __raw_spin_lock_irq(raw_spinlock_t *lock) |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 127 | { |
| 128 | local_irq_disable(); |
| 129 | preempt_disable(); |
| 130 | spin_acquire(&lock->dep_map, 0, 0, _RET_IP_); |
Thomas Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 131 | LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock); |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 132 | } |
| 133 | |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 134 | static inline void __raw_spin_lock_bh(raw_spinlock_t *lock) |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 135 | { |
Peter Zijlstra | 9ea4c38 | 2013-11-19 16:13:38 +0100 | [diff] [blame] | 136 | __local_bh_disable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET); |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 137 | spin_acquire(&lock->dep_map, 0, 0, _RET_IP_); |
Thomas Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 138 | LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock); |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 139 | } |
| 140 | |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 141 | static inline void __raw_spin_lock(raw_spinlock_t *lock) |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 142 | { |
| 143 | preempt_disable(); |
| 144 | spin_acquire(&lock->dep_map, 0, 0, _RET_IP_); |
Thomas Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 145 | LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock); |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 146 | } |
| 147 | |
Chen Gang | ae58403 | 2013-06-19 11:15:46 +0800 | [diff] [blame] | 148 | #endif /* !CONFIG_GENERIC_LOCKBREAK || CONFIG_DEBUG_LOCK_ALLOC */ |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 149 | |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 150 | static inline void __raw_spin_unlock(raw_spinlock_t *lock) |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 151 | { |
| 152 | spin_release(&lock->dep_map, 1, _RET_IP_); |
Thomas Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 153 | do_raw_spin_unlock(lock); |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 154 | preempt_enable(); |
| 155 | } |
| 156 | |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 157 | static inline void __raw_spin_unlock_irqrestore(raw_spinlock_t *lock, |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 158 | unsigned long flags) |
| 159 | { |
| 160 | spin_release(&lock->dep_map, 1, _RET_IP_); |
Thomas Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 161 | do_raw_spin_unlock(lock); |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 162 | local_irq_restore(flags); |
| 163 | preempt_enable(); |
| 164 | } |
| 165 | |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 166 | static inline void __raw_spin_unlock_irq(raw_spinlock_t *lock) |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 167 | { |
| 168 | spin_release(&lock->dep_map, 1, _RET_IP_); |
Thomas Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 169 | do_raw_spin_unlock(lock); |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 170 | local_irq_enable(); |
| 171 | preempt_enable(); |
| 172 | } |
| 173 | |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 174 | static inline void __raw_spin_unlock_bh(raw_spinlock_t *lock) |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 175 | { |
| 176 | spin_release(&lock->dep_map, 1, _RET_IP_); |
Thomas Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 177 | do_raw_spin_unlock(lock); |
Peter Zijlstra | 9ea4c38 | 2013-11-19 16:13:38 +0100 | [diff] [blame] | 178 | __local_bh_enable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET); |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 179 | } |
| 180 | |
Thomas Gleixner | 9c1721a | 2009-12-03 21:52:18 +0100 | [diff] [blame] | 181 | static inline int __raw_spin_trylock_bh(raw_spinlock_t *lock) |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 182 | { |
Peter Zijlstra | 9ea4c38 | 2013-11-19 16:13:38 +0100 | [diff] [blame] | 183 | __local_bh_disable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET); |
Thomas Gleixner | 9828ea9 | 2009-12-03 20:55:53 +0100 | [diff] [blame] | 184 | if (do_raw_spin_trylock(lock)) { |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 185 | spin_acquire(&lock->dep_map, 0, 1, _RET_IP_); |
| 186 | return 1; |
| 187 | } |
Peter Zijlstra | 9ea4c38 | 2013-11-19 16:13:38 +0100 | [diff] [blame] | 188 | __local_bh_enable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET); |
Heiko Carstens | 69d0ee7 | 2009-08-31 14:43:36 +0200 | [diff] [blame] | 189 | return 0; |
| 190 | } |
| 191 | |
Thomas Gleixner | 6b6b479 | 2009-11-16 18:48:37 +0100 | [diff] [blame] | 192 | #include <linux/rwlock_api_smp.h> |
| 193 | |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 194 | #endif /* __LINUX_SPINLOCK_API_SMP_H */ |