Skip to content

Commit d59b93d

Browse files
author
Martin Schwidefsky
committed
s390/rwlock: use directed yield for write-locked rwlocks
Add an owner field to the arch_rwlock_t to be able to pass the timeslice of a virtual CPU with diagnose 0x9c to the lock owner in case the rwlock is write-locked. The undirected yield in case the rwlock is acquired writable but the lock is read-locked is removed. Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent 46b05c7 commit d59b93d

5 files changed

Lines changed: 54 additions & 32 deletions

File tree

‎arch/s390/include/asm/smp.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ extern int smp_find_processor_id(u16 address);
2929
extern int smp_store_status(int cpu);
3030
extern int smp_vcpu_scheduled(int cpu);
3131
extern void smp_yield_cpu(int cpu);
32-
extern void smp_yield(void);
3332
extern void smp_cpu_set_polarization(int cpu, int val);
3433
extern int smp_cpu_get_polarization(int cpu);
3534
extern void smp_fill_possible_mask(void);
@@ -50,7 +49,6 @@ static inline int smp_find_processor_id(u16 address) { return 0; }
5049
static inline int smp_store_status(int cpu) { return 0; }
5150
static inline int smp_vcpu_scheduled(int cpu) { return 1; }
5251
static inline void smp_yield_cpu(int cpu) { }
53-
static inline void smp_yield(void) { }
5452
static inline void smp_fill_possible_mask(void) { }
5553

5654
#endif /* CONFIG_SMP */

‎arch/s390/include/asm/spinlock.h‎

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,17 @@ _raw_compare_and_swap(unsigned int *lock, unsigned int old, unsigned int new)
3737
* (the type definitions are in asm/spinlock_types.h)
3838
*/
3939

40+
void arch_lock_relax(unsigned int cpu);
41+
4042
void arch_spin_lock_wait(arch_spinlock_t *);
4143
int arch_spin_trylock_retry(arch_spinlock_t *);
42-
void arch_spin_relax(arch_spinlock_t *);
4344
void arch_spin_lock_wait_flags(arch_spinlock_t *, unsigned long flags);
4445

46+
static inline void arch_spin_relax(arch_spinlock_t *lock)
47+
{
48+
arch_lock_relax(lock->lock);
49+
}
50+
4551
static inline u32 arch_spin_lockval(int cpu)
4652
{
4753
return ~cpu;
@@ -170,17 +176,21 @@ static inline void arch_write_lock(arch_rwlock_t *rw)
170176
{
171177
if (!arch_write_trylock_once(rw))
172178
_raw_write_lock_wait(rw);
179+
rw->owner = SPINLOCK_LOCKVAL;
173180
}
174181

175182
static inline void arch_write_lock_flags(arch_rwlock_t *rw, unsigned long flags)
176183
{
177184
if (!arch_write_trylock_once(rw))
178185
_raw_write_lock_wait_flags(rw, flags);
186+
rw->owner = SPINLOCK_LOCKVAL;
179187
}
180188

181189
static inline void arch_write_unlock(arch_rwlock_t *rw)
182190
{
183191
typecheck(unsigned int, rw->lock);
192+
193+
rw->owner = 0;
184194
asm volatile(
185195
__ASM_BARRIER
186196
"st %1,%0\n"
@@ -198,12 +208,20 @@ static inline int arch_read_trylock(arch_rwlock_t *rw)
198208

199209
static inline int arch_write_trylock(arch_rwlock_t *rw)
200210
{
201-
if (!arch_write_trylock_once(rw))
202-
return _raw_write_trylock_retry(rw);
211+
if (!arch_write_trylock_once(rw) && !_raw_write_trylock_retry(rw))
212+
return 0;
213+
rw->owner = SPINLOCK_LOCKVAL;
203214
return 1;
204215
}
205216

206-
#define arch_read_relax(lock) cpu_relax()
207-
#define arch_write_relax(lock) cpu_relax()
217+
static inline void arch_read_relax(arch_rwlock_t *rw)
218+
{
219+
arch_lock_relax(rw->owner);
220+
}
221+
222+
static inline void arch_write_relax(arch_rwlock_t *rw)
223+
{
224+
arch_lock_relax(rw->owner);
225+
}
208226

209227
#endif /* __ASM_SPINLOCK_H */

‎arch/s390/include/asm/spinlock_types.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ typedef struct {
1313

1414
typedef struct {
1515
unsigned int lock;
16+
unsigned int owner;
1617
} arch_rwlock_t;
1718

1819
#define __ARCH_RW_LOCK_UNLOCKED { 0 }

‎arch/s390/kernel/smp.c‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,12 +333,6 @@ int smp_vcpu_scheduled(int cpu)
333333
return pcpu_running(pcpu_devices + cpu);
334334
}
335335

336-
void smp_yield(void)
337-
{
338-
if (MACHINE_HAS_DIAG44)
339-
asm volatile("diag 0,0,0x44");
340-
}
341-
342336
void smp_yield_cpu(int cpu)
343337
{
344338
if (MACHINE_HAS_DIAG9C)

‎arch/s390/lib/spinlock.c‎

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,6 @@ void arch_spin_lock_wait_flags(arch_spinlock_t *lp, unsigned long flags)
9898
}
9999
EXPORT_SYMBOL(arch_spin_lock_wait_flags);
100100

101-
void arch_spin_relax(arch_spinlock_t *lp)
102-
{
103-
unsigned int cpu = lp->lock;
104-
if (cpu != 0) {
105-
if (MACHINE_IS_VM || MACHINE_IS_KVM ||
106-
!smp_vcpu_scheduled(~cpu))
107-
smp_yield_cpu(~cpu);
108-
}
109-
}
110-
EXPORT_SYMBOL(arch_spin_relax);
111-
112101
int arch_spin_trylock_retry(arch_spinlock_t *lp)
113102
{
114103
int count;
@@ -122,15 +111,18 @@ EXPORT_SYMBOL(arch_spin_trylock_retry);
122111

123112
void _raw_read_lock_wait(arch_rwlock_t *rw)
124113
{
125-
unsigned int old;
114+
unsigned int owner, old;
126115
int count = spin_retry;
127116

117+
owner = 0;
128118
while (1) {
129119
if (count-- <= 0) {
130-
smp_yield();
120+
if (owner && !smp_vcpu_scheduled(~owner))
121+
smp_yield_cpu(~owner);
131122
count = spin_retry;
132123
}
133124
old = ACCESS_ONCE(rw->lock);
125+
owner = ACCESS_ONCE(rw->owner);
134126
if ((int) old < 0)
135127
continue;
136128
if (_raw_compare_and_swap(&rw->lock, old, old + 1))
@@ -141,16 +133,19 @@ EXPORT_SYMBOL(_raw_read_lock_wait);
141133

142134
void _raw_read_lock_wait_flags(arch_rwlock_t *rw, unsigned long flags)
143135
{
144-
unsigned int old;
136+
unsigned int owner, old;
145137
int count = spin_retry;
146138

147139
local_irq_restore(flags);
140+
owner = 0;
148141
while (1) {
149142
if (count-- <= 0) {
150-
smp_yield();
143+
if (owner && !smp_vcpu_scheduled(~owner))
144+
smp_yield_cpu(~owner);
151145
count = spin_retry;
152146
}
153147
old = ACCESS_ONCE(rw->lock);
148+
owner = ACCESS_ONCE(rw->owner);
154149
if ((int) old < 0)
155150
continue;
156151
local_irq_disable();
@@ -179,15 +174,18 @@ EXPORT_SYMBOL(_raw_read_trylock_retry);
179174

180175
void _raw_write_lock_wait(arch_rwlock_t *rw)
181176
{
182-
unsigned int old;
177+
unsigned int owner, old;
183178
int count = spin_retry;
184179

180+
owner = 0;
185181
while (1) {
186182
if (count-- <= 0) {
187-
smp_yield();
183+
if (owner && !smp_vcpu_scheduled(~owner))
184+
smp_yield_cpu(~owner);
188185
count = spin_retry;
189186
}
190187
old = ACCESS_ONCE(rw->lock);
188+
owner = ACCESS_ONCE(rw->owner);
191189
if (old)
192190
continue;
193191
if (_raw_compare_and_swap(&rw->lock, 0, 0x80000000))
@@ -198,16 +196,19 @@ EXPORT_SYMBOL(_raw_write_lock_wait);
198196

199197
void _raw_write_lock_wait_flags(arch_rwlock_t *rw, unsigned long flags)
200198
{
201-
unsigned int old;
199+
unsigned int owner, old;
202200
int count = spin_retry;
203201

204202
local_irq_restore(flags);
203+
owner = 0;
205204
while (1) {
206205
if (count-- <= 0) {
207-
smp_yield();
206+
if (owner && !smp_vcpu_scheduled(~owner))
207+
smp_yield_cpu(~owner);
208208
count = spin_retry;
209209
}
210210
old = ACCESS_ONCE(rw->lock);
211+
owner = ACCESS_ONCE(rw->owner);
211212
if (old)
212213
continue;
213214
local_irq_disable();
@@ -233,3 +234,13 @@ int _raw_write_trylock_retry(arch_rwlock_t *rw)
233234
return 0;
234235
}
235236
EXPORT_SYMBOL(_raw_write_trylock_retry);
237+
238+
void arch_lock_relax(unsigned int cpu)
239+
{
240+
if (!cpu)
241+
return;
242+
if (MACHINE_IS_LPAR && smp_vcpu_scheduled(~cpu))
243+
return;
244+
smp_yield_cpu(~cpu);
245+
}
246+
EXPORT_SYMBOL(arch_lock_relax);

0 commit comments

Comments
 (0)