diff options
Diffstat (limited to 'arch/x86/include/asm/spinlock.h')
| -rw-r--r-- | arch/x86/include/asm/spinlock.h | 69 |
1 files changed, 3 insertions, 66 deletions
diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h index 8247e94ac6b1..3a5696656680 100644 --- a/arch/x86/include/asm/spinlock.h +++ b/arch/x86/include/asm/spinlock.h | |||
| @@ -172,70 +172,8 @@ static inline int __ticket_spin_is_contended(raw_spinlock_t *lock) | |||
| 172 | return (((tmp >> TICKET_SHIFT) - tmp) & ((1 << TICKET_SHIFT) - 1)) > 1; | 172 | return (((tmp >> TICKET_SHIFT) - tmp) & ((1 << TICKET_SHIFT) - 1)) > 1; |
| 173 | } | 173 | } |
| 174 | 174 | ||
| 175 | #ifdef CONFIG_PARAVIRT | 175 | #ifndef CONFIG_PARAVIRT |
| 176 | /* | ||
| 177 | * Define virtualization-friendly old-style lock byte lock, for use in | ||
| 178 | * pv_lock_ops if desired. | ||
| 179 | * | ||
| 180 | * This differs from the pre-2.6.24 spinlock by always using xchgb | ||
| 181 | * rather than decb to take the lock; this allows it to use a | ||
| 182 | * zero-initialized lock structure. It also maintains a 1-byte | ||
| 183 | * contention counter, so that we can implement | ||
| 184 | * __byte_spin_is_contended. | ||
| 185 | */ | ||
| 186 | struct __byte_spinlock { | ||
| 187 | s8 lock; | ||
| 188 | s8 spinners; | ||
| 189 | }; | ||
| 190 | |||
| 191 | static inline int __byte_spin_is_locked(raw_spinlock_t *lock) | ||
| 192 | { | ||
| 193 | struct __byte_spinlock *bl = (struct __byte_spinlock *)lock; | ||
| 194 | return bl->lock != 0; | ||
| 195 | } | ||
| 196 | |||
| 197 | static inline int __byte_spin_is_contended(raw_spinlock_t *lock) | ||
| 198 | { | ||
| 199 | struct __byte_spinlock *bl = (struct __byte_spinlock *)lock; | ||
| 200 | return bl->spinners != 0; | ||
| 201 | } | ||
| 202 | |||
| 203 | static inline void __byte_spin_lock(raw_spinlock_t *lock) | ||
| 204 | { | ||
| 205 | struct __byte_spinlock *bl = (struct __byte_spinlock *)lock; | ||
| 206 | s8 val = 1; | ||
| 207 | |||
| 208 | asm("1: xchgb %1, %0\n" | ||
| 209 | " test %1,%1\n" | ||
| 210 | " jz 3f\n" | ||
| 211 | " " LOCK_PREFIX "incb %2\n" | ||
| 212 | "2: rep;nop\n" | ||
| 213 | " cmpb $1, %0\n" | ||
| 214 | " je 2b\n" | ||
| 215 | " " LOCK_PREFIX "decb %2\n" | ||
| 216 | " jmp 1b\n" | ||
| 217 | "3:" | ||
| 218 | : "+m" (bl->lock), "+q" (val), "+m" (bl->spinners): : "memory"); | ||
| 219 | } | ||
| 220 | |||
| 221 | static inline int __byte_spin_trylock(raw_spinlock_t *lock) | ||
| 222 | { | ||
| 223 | struct __byte_spinlock *bl = (struct __byte_spinlock *)lock; | ||
| 224 | u8 old = 1; | ||
| 225 | |||
| 226 | asm("xchgb %1,%0" | ||
| 227 | : "+m" (bl->lock), "+q" (old) : : "memory"); | ||
| 228 | 176 | ||
| 229 | return old == 0; | ||
| 230 | } | ||
| 231 | |||
| 232 | static inline void __byte_spin_unlock(raw_spinlock_t *lock) | ||
| 233 | { | ||
| 234 | struct __byte_spinlock *bl = (struct __byte_spinlock *)lock; | ||
| 235 | smp_wmb(); | ||
| 236 | bl->lock = 0; | ||
| 237 | } | ||
| 238 | #else /* !CONFIG_PARAVIRT */ | ||
| 239 | static inline int __raw_spin_is_locked(raw_spinlock_t *lock) | 177 | static inline int __raw_spin_is_locked(raw_spinlock_t *lock) |
| 240 | { | 178 | { |
| 241 | return __ticket_spin_is_locked(lock); | 179 | return __ticket_spin_is_locked(lock); |
| @@ -268,7 +206,7 @@ static __always_inline void __raw_spin_lock_flags(raw_spinlock_t *lock, | |||
| 268 | __raw_spin_lock(lock); | 206 | __raw_spin_lock(lock); |
| 269 | } | 207 | } |
| 270 | 208 | ||
| 271 | #endif /* CONFIG_PARAVIRT */ | 209 | #endif |
| 272 | 210 | ||
| 273 | static inline void __raw_spin_unlock_wait(raw_spinlock_t *lock) | 211 | static inline void __raw_spin_unlock_wait(raw_spinlock_t *lock) |
| 274 | { | 212 | { |
| @@ -330,8 +268,7 @@ static inline int __raw_read_trylock(raw_rwlock_t *lock) | |||
| 330 | { | 268 | { |
| 331 | atomic_t *count = (atomic_t *)lock; | 269 | atomic_t *count = (atomic_t *)lock; |
| 332 | 270 | ||
| 333 | atomic_dec(count); | 271 | if (atomic_dec_return(count) >= 0) |
| 334 | if (atomic_read(count) >= 0) | ||
| 335 | return 1; | 272 | return 1; |
| 336 | atomic_inc(count); | 273 | atomic_inc(count); |
| 337 | return 0; | 274 | return 0; |
