diff options
author | Ingo Molnar <mingo@elte.hu> | 2009-03-11 05:49:34 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-03-11 05:49:34 -0400 |
commit | d95c3578120e5bc4784069439f00ccb1b5f87717 (patch) | |
tree | c819de31de3983f3d69f223ede07667ff23bf7da /arch/x86/include/asm/spinlock.h | |
parent | ba1d755a36f66101aa88ac9ebb54694def6ec38d (diff) | |
parent | 78b020d035074fc3aa4d017353bb2c32e2aff56f (diff) |
Merge branch 'x86/core' into cpus4096
Diffstat (limited to 'arch/x86/include/asm/spinlock.h')
-rw-r--r-- | arch/x86/include/asm/spinlock.h | 70 |
1 files changed, 4 insertions, 66 deletions
diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h index d17c91981da2..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); |
@@ -245,6 +183,7 @@ static inline int __raw_spin_is_contended(raw_spinlock_t *lock) | |||
245 | { | 183 | { |
246 | return __ticket_spin_is_contended(lock); | 184 | return __ticket_spin_is_contended(lock); |
247 | } | 185 | } |
186 | #define __raw_spin_is_contended __raw_spin_is_contended | ||
248 | 187 | ||
249 | static __always_inline void __raw_spin_lock(raw_spinlock_t *lock) | 188 | static __always_inline void __raw_spin_lock(raw_spinlock_t *lock) |
250 | { | 189 | { |
@@ -267,7 +206,7 @@ static __always_inline void __raw_spin_lock_flags(raw_spinlock_t *lock, | |||
267 | __raw_spin_lock(lock); | 206 | __raw_spin_lock(lock); |
268 | } | 207 | } |
269 | 208 | ||
270 | #endif /* CONFIG_PARAVIRT */ | 209 | #endif |
271 | 210 | ||
272 | static inline void __raw_spin_unlock_wait(raw_spinlock_t *lock) | 211 | static inline void __raw_spin_unlock_wait(raw_spinlock_t *lock) |
273 | { | 212 | { |
@@ -329,8 +268,7 @@ static inline int __raw_read_trylock(raw_rwlock_t *lock) | |||
329 | { | 268 | { |
330 | atomic_t *count = (atomic_t *)lock; | 269 | atomic_t *count = (atomic_t *)lock; |
331 | 270 | ||
332 | atomic_dec(count); | 271 | if (atomic_dec_return(count) >= 0) |
333 | if (atomic_read(count) >= 0) | ||
334 | return 1; | 272 | return 1; |
335 | atomic_inc(count); | 273 | atomic_inc(count); |
336 | return 0; | 274 | return 0; |