diff options
author | Jan Beulich <jbeulich@novell.com> | 2008-09-05 08:26:39 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-09-05 11:05:56 -0400 |
commit | 08f5fcbe6e0ea029c7e9b1b1c338700ab7809daf (patch) | |
tree | 46de345d9e5d8960ad0668ba8815475d37c4c78e /include | |
parent | ef1f3413284b9270266cb04a944647e59735f0f1 (diff) |
x86: ticket spin locks: factor out more common code
Signed-off-by: Jan Beulich <jbeulich@novell.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'include')
-rw-r--r-- | include/asm-x86/spinlock.h | 42 |
1 files changed, 16 insertions, 26 deletions
diff --git a/include/asm-x86/spinlock.h b/include/asm-x86/spinlock.h index acd9bdda55cf..63d3b610a5ef 100644 --- a/include/asm-x86/spinlock.h +++ b/include/asm-x86/spinlock.h | |||
@@ -54,19 +54,7 @@ | |||
54 | * much between them in performance though, especially as locks are out of line. | 54 | * much between them in performance though, especially as locks are out of line. |
55 | */ | 55 | */ |
56 | #if (NR_CPUS < 256) | 56 | #if (NR_CPUS < 256) |
57 | static inline int __ticket_spin_is_locked(raw_spinlock_t *lock) | 57 | #define TICKET_SHIFT 8 |
58 | { | ||
59 | int tmp = ACCESS_ONCE(lock->slock); | ||
60 | |||
61 | return (((tmp >> 8) & 0xff) != (tmp & 0xff)); | ||
62 | } | ||
63 | |||
64 | static inline int __ticket_spin_is_contended(raw_spinlock_t *lock) | ||
65 | { | ||
66 | int tmp = ACCESS_ONCE(lock->slock); | ||
67 | |||
68 | return (((tmp >> 8) - tmp) & 0xff) > 1; | ||
69 | } | ||
70 | 58 | ||
71 | static __always_inline void __ticket_spin_lock(raw_spinlock_t *lock) | 59 | static __always_inline void __ticket_spin_lock(raw_spinlock_t *lock) |
72 | { | 60 | { |
@@ -116,19 +104,7 @@ static __always_inline void __ticket_spin_unlock(raw_spinlock_t *lock) | |||
116 | : "memory", "cc"); | 104 | : "memory", "cc"); |
117 | } | 105 | } |
118 | #else | 106 | #else |
119 | static inline int __ticket_spin_is_locked(raw_spinlock_t *lock) | 107 | #define TICKET_SHIFT 16 |
120 | { | ||
121 | int tmp = ACCESS_ONCE(lock->slock); | ||
122 | |||
123 | return (((tmp >> 16) & 0xffff) != (tmp & 0xffff)); | ||
124 | } | ||
125 | |||
126 | static inline int __ticket_spin_is_contended(raw_spinlock_t *lock) | ||
127 | { | ||
128 | int tmp = ACCESS_ONCE(lock->slock); | ||
129 | |||
130 | return (((tmp >> 16) - tmp) & 0xffff) > 1; | ||
131 | } | ||
132 | 108 | ||
133 | static __always_inline void __ticket_spin_lock(raw_spinlock_t *lock) | 109 | static __always_inline void __ticket_spin_lock(raw_spinlock_t *lock) |
134 | { | 110 | { |
@@ -182,6 +158,20 @@ static __always_inline void __ticket_spin_unlock(raw_spinlock_t *lock) | |||
182 | } | 158 | } |
183 | #endif | 159 | #endif |
184 | 160 | ||
161 | static inline int __ticket_spin_is_locked(raw_spinlock_t *lock) | ||
162 | { | ||
163 | int tmp = ACCESS_ONCE(lock->slock); | ||
164 | |||
165 | return !!(((tmp >> TICKET_SHIFT) ^ tmp) & ((1 << TICKET_SHIFT) - 1)); | ||
166 | } | ||
167 | |||
168 | static inline int __ticket_spin_is_contended(raw_spinlock_t *lock) | ||
169 | { | ||
170 | int tmp = ACCESS_ONCE(lock->slock); | ||
171 | |||
172 | return (((tmp >> TICKET_SHIFT) - tmp) & ((1 << TICKET_SHIFT) - 1)) > 1; | ||
173 | } | ||
174 | |||
185 | #define __raw_spin_lock_flags(lock, flags) __raw_spin_lock(lock) | 175 | #define __raw_spin_lock_flags(lock, flags) __raw_spin_lock(lock) |
186 | 176 | ||
187 | #ifdef CONFIG_PARAVIRT | 177 | #ifdef CONFIG_PARAVIRT |