aboutsummaryrefslogtreecommitdiffstats
path: root/arch/s390
diff options
context:
space:
mode:
Diffstat (limited to 'arch/s390')
-rw-r--r--arch/s390/include/asm/spinlock.h19
-rw-r--r--arch/s390/lib/spinlock.c40
2 files changed, 56 insertions, 3 deletions
diff --git a/arch/s390/include/asm/spinlock.h b/arch/s390/include/asm/spinlock.h
index f3861b09ebb0..c9af0d19c7ab 100644
--- a/arch/s390/include/asm/spinlock.h
+++ b/arch/s390/include/asm/spinlock.h
@@ -122,8 +122,10 @@ static inline void __raw_spin_unlock(raw_spinlock_t *lp)
122#define __raw_write_can_lock(x) ((x)->lock == 0) 122#define __raw_write_can_lock(x) ((x)->lock == 0)
123 123
124extern void _raw_read_lock_wait(raw_rwlock_t *lp); 124extern void _raw_read_lock_wait(raw_rwlock_t *lp);
125extern void _raw_read_lock_wait_flags(raw_rwlock_t *lp, unsigned long flags);
125extern int _raw_read_trylock_retry(raw_rwlock_t *lp); 126extern int _raw_read_trylock_retry(raw_rwlock_t *lp);
126extern void _raw_write_lock_wait(raw_rwlock_t *lp); 127extern void _raw_write_lock_wait(raw_rwlock_t *lp);
128extern void _raw_write_lock_wait_flags(raw_rwlock_t *lp, unsigned long flags);
127extern int _raw_write_trylock_retry(raw_rwlock_t *lp); 129extern int _raw_write_trylock_retry(raw_rwlock_t *lp);
128 130
129static inline void __raw_read_lock(raw_rwlock_t *rw) 131static inline void __raw_read_lock(raw_rwlock_t *rw)
@@ -134,6 +136,14 @@ static inline void __raw_read_lock(raw_rwlock_t *rw)
134 _raw_read_lock_wait(rw); 136 _raw_read_lock_wait(rw);
135} 137}
136 138
139static inline void __raw_read_lock_flags(raw_rwlock_t *rw, unsigned long flags)
140{
141 unsigned int old;
142 old = rw->lock & 0x7fffffffU;
143 if (_raw_compare_and_swap(&rw->lock, old, old + 1) != old)
144 _raw_read_lock_wait_flags(rw, flags);
145}
146
137static inline void __raw_read_unlock(raw_rwlock_t *rw) 147static inline void __raw_read_unlock(raw_rwlock_t *rw)
138{ 148{
139 unsigned int old, cmp; 149 unsigned int old, cmp;
@@ -151,6 +161,12 @@ static inline void __raw_write_lock(raw_rwlock_t *rw)
151 _raw_write_lock_wait(rw); 161 _raw_write_lock_wait(rw);
152} 162}
153 163
164static inline void __raw_write_lock_flags(raw_rwlock_t *rw, unsigned long flags)
165{
166 if (unlikely(_raw_compare_and_swap(&rw->lock, 0, 0x80000000) != 0))
167 _raw_write_lock_wait_flags(rw, flags);
168}
169
154static inline void __raw_write_unlock(raw_rwlock_t *rw) 170static inline void __raw_write_unlock(raw_rwlock_t *rw)
155{ 171{
156 _raw_compare_and_swap(&rw->lock, 0x80000000, 0); 172 _raw_compare_and_swap(&rw->lock, 0x80000000, 0);
@@ -172,9 +188,6 @@ static inline int __raw_write_trylock(raw_rwlock_t *rw)
172 return _raw_write_trylock_retry(rw); 188 return _raw_write_trylock_retry(rw);
173} 189}
174 190
175#define __raw_read_lock_flags(lock, flags) __raw_read_lock(lock)
176#define __raw_write_lock_flags(lock, flags) __raw_write_lock(lock)
177
178#define _raw_read_relax(lock) cpu_relax() 191#define _raw_read_relax(lock) cpu_relax()
179#define _raw_write_relax(lock) cpu_relax() 192#define _raw_write_relax(lock) cpu_relax()
180 193
diff --git a/arch/s390/lib/spinlock.c b/arch/s390/lib/spinlock.c
index e41f4008afc5..f7e0d30250b7 100644
--- a/arch/s390/lib/spinlock.c
+++ b/arch/s390/lib/spinlock.c
@@ -124,6 +124,27 @@ void _raw_read_lock_wait(raw_rwlock_t *rw)
124} 124}
125EXPORT_SYMBOL(_raw_read_lock_wait); 125EXPORT_SYMBOL(_raw_read_lock_wait);
126 126
127void _raw_read_lock_wait_flags(raw_rwlock_t *rw, unsigned long flags)
128{
129 unsigned int old;
130 int count = spin_retry;
131
132 local_irq_restore(flags);
133 while (1) {
134 if (count-- <= 0) {
135 _raw_yield();
136 count = spin_retry;
137 }
138 if (!__raw_read_can_lock(rw))
139 continue;
140 old = rw->lock & 0x7fffffffU;
141 local_irq_disable();
142 if (_raw_compare_and_swap(&rw->lock, old, old + 1) == old)
143 return;
144 }
145}
146EXPORT_SYMBOL(_raw_read_lock_wait_flags);
147
127int _raw_read_trylock_retry(raw_rwlock_t *rw) 148int _raw_read_trylock_retry(raw_rwlock_t *rw)
128{ 149{
129 unsigned int old; 150 unsigned int old;
@@ -157,6 +178,25 @@ void _raw_write_lock_wait(raw_rwlock_t *rw)
157} 178}
158EXPORT_SYMBOL(_raw_write_lock_wait); 179EXPORT_SYMBOL(_raw_write_lock_wait);
159 180
181void _raw_write_lock_wait_flags(raw_rwlock_t *rw, unsigned long flags)
182{
183 int count = spin_retry;
184
185 local_irq_restore(flags);
186 while (1) {
187 if (count-- <= 0) {
188 _raw_yield();
189 count = spin_retry;
190 }
191 if (!__raw_write_can_lock(rw))
192 continue;
193 local_irq_disable();
194 if (_raw_compare_and_swap(&rw->lock, 0, 0x80000000) == 0)
195 return;
196 }
197}
198EXPORT_SYMBOL(_raw_write_lock_wait_flags);
199
160int _raw_write_trylock_retry(raw_rwlock_t *rw) 200int _raw_write_trylock_retry(raw_rwlock_t *rw)
161{ 201{
162 int count = spin_retry; 202 int count = spin_retry;