diff options
Diffstat (limited to 'arch/s390/lib/spinlock.c')
-rw-r--r-- | arch/s390/lib/spinlock.c | 62 |
1 files changed, 39 insertions, 23 deletions
diff --git a/arch/s390/lib/spinlock.c b/arch/s390/lib/spinlock.c index b9b7958a226a..8d76403fcf89 100644 --- a/arch/s390/lib/spinlock.c +++ b/arch/s390/lib/spinlock.c | |||
@@ -24,57 +24,76 @@ static int __init spin_retry_setup(char *str) | |||
24 | } | 24 | } |
25 | __setup("spin_retry=", spin_retry_setup); | 25 | __setup("spin_retry=", spin_retry_setup); |
26 | 26 | ||
27 | static inline void | 27 | static inline void _raw_yield(void) |
28 | _diag44(void) | ||
29 | { | 28 | { |
30 | #ifdef CONFIG_64BIT | ||
31 | if (MACHINE_HAS_DIAG44) | 29 | if (MACHINE_HAS_DIAG44) |
32 | #endif | ||
33 | asm volatile("diag 0,0,0x44"); | 30 | asm volatile("diag 0,0,0x44"); |
34 | } | 31 | } |
35 | 32 | ||
36 | void | 33 | static inline void _raw_yield_cpu(int cpu) |
37 | _raw_spin_lock_wait(raw_spinlock_t *lp, unsigned int pc) | 34 | { |
35 | if (MACHINE_HAS_DIAG9C) | ||
36 | asm volatile("diag %0,0,0x9c" | ||
37 | : : "d" (__cpu_logical_map[cpu])); | ||
38 | else | ||
39 | _raw_yield(); | ||
40 | } | ||
41 | |||
42 | void _raw_spin_lock_wait(raw_spinlock_t *lp, unsigned int pc) | ||
38 | { | 43 | { |
39 | int count = spin_retry; | 44 | int count = spin_retry; |
45 | unsigned int cpu = ~smp_processor_id(); | ||
40 | 46 | ||
41 | while (1) { | 47 | while (1) { |
42 | if (count-- <= 0) { | 48 | if (count-- <= 0) { |
43 | _diag44(); | 49 | unsigned int owner = lp->owner_cpu; |
50 | if (owner != 0) | ||
51 | _raw_yield_cpu(~owner); | ||
44 | count = spin_retry; | 52 | count = spin_retry; |
45 | } | 53 | } |
46 | if (__raw_spin_is_locked(lp)) | 54 | if (__raw_spin_is_locked(lp)) |
47 | continue; | 55 | continue; |
48 | if (_raw_compare_and_swap(&lp->lock, 0, pc) == 0) | 56 | if (_raw_compare_and_swap(&lp->owner_cpu, 0, cpu) == 0) { |
57 | lp->owner_pc = pc; | ||
49 | return; | 58 | return; |
59 | } | ||
50 | } | 60 | } |
51 | } | 61 | } |
52 | EXPORT_SYMBOL(_raw_spin_lock_wait); | 62 | EXPORT_SYMBOL(_raw_spin_lock_wait); |
53 | 63 | ||
54 | int | 64 | int _raw_spin_trylock_retry(raw_spinlock_t *lp, unsigned int pc) |
55 | _raw_spin_trylock_retry(raw_spinlock_t *lp, unsigned int pc) | ||
56 | { | 65 | { |
57 | int count = spin_retry; | 66 | unsigned int cpu = ~smp_processor_id(); |
67 | int count; | ||
58 | 68 | ||
59 | while (count-- > 0) { | 69 | for (count = spin_retry; count > 0; count--) { |
60 | if (__raw_spin_is_locked(lp)) | 70 | if (__raw_spin_is_locked(lp)) |
61 | continue; | 71 | continue; |
62 | if (_raw_compare_and_swap(&lp->lock, 0, pc) == 0) | 72 | if (_raw_compare_and_swap(&lp->owner_cpu, 0, cpu) == 0) { |
73 | lp->owner_pc = pc; | ||
63 | return 1; | 74 | return 1; |
75 | } | ||
64 | } | 76 | } |
65 | return 0; | 77 | return 0; |
66 | } | 78 | } |
67 | EXPORT_SYMBOL(_raw_spin_trylock_retry); | 79 | EXPORT_SYMBOL(_raw_spin_trylock_retry); |
68 | 80 | ||
69 | void | 81 | void _raw_spin_relax(raw_spinlock_t *lock) |
70 | _raw_read_lock_wait(raw_rwlock_t *rw) | 82 | { |
83 | unsigned int cpu = lock->owner_cpu; | ||
84 | if (cpu != 0) | ||
85 | _raw_yield_cpu(~cpu); | ||
86 | } | ||
87 | EXPORT_SYMBOL(_raw_spin_relax); | ||
88 | |||
89 | void _raw_read_lock_wait(raw_rwlock_t *rw) | ||
71 | { | 90 | { |
72 | unsigned int old; | 91 | unsigned int old; |
73 | int count = spin_retry; | 92 | int count = spin_retry; |
74 | 93 | ||
75 | while (1) { | 94 | while (1) { |
76 | if (count-- <= 0) { | 95 | if (count-- <= 0) { |
77 | _diag44(); | 96 | _raw_yield(); |
78 | count = spin_retry; | 97 | count = spin_retry; |
79 | } | 98 | } |
80 | if (!__raw_read_can_lock(rw)) | 99 | if (!__raw_read_can_lock(rw)) |
@@ -86,8 +105,7 @@ _raw_read_lock_wait(raw_rwlock_t *rw) | |||
86 | } | 105 | } |
87 | EXPORT_SYMBOL(_raw_read_lock_wait); | 106 | EXPORT_SYMBOL(_raw_read_lock_wait); |
88 | 107 | ||
89 | int | 108 | int _raw_read_trylock_retry(raw_rwlock_t *rw) |
90 | _raw_read_trylock_retry(raw_rwlock_t *rw) | ||
91 | { | 109 | { |
92 | unsigned int old; | 110 | unsigned int old; |
93 | int count = spin_retry; | 111 | int count = spin_retry; |
@@ -103,14 +121,13 @@ _raw_read_trylock_retry(raw_rwlock_t *rw) | |||
103 | } | 121 | } |
104 | EXPORT_SYMBOL(_raw_read_trylock_retry); | 122 | EXPORT_SYMBOL(_raw_read_trylock_retry); |
105 | 123 | ||
106 | void | 124 | void _raw_write_lock_wait(raw_rwlock_t *rw) |
107 | _raw_write_lock_wait(raw_rwlock_t *rw) | ||
108 | { | 125 | { |
109 | int count = spin_retry; | 126 | int count = spin_retry; |
110 | 127 | ||
111 | while (1) { | 128 | while (1) { |
112 | if (count-- <= 0) { | 129 | if (count-- <= 0) { |
113 | _diag44(); | 130 | _raw_yield(); |
114 | count = spin_retry; | 131 | count = spin_retry; |
115 | } | 132 | } |
116 | if (!__raw_write_can_lock(rw)) | 133 | if (!__raw_write_can_lock(rw)) |
@@ -121,8 +138,7 @@ _raw_write_lock_wait(raw_rwlock_t *rw) | |||
121 | } | 138 | } |
122 | EXPORT_SYMBOL(_raw_write_lock_wait); | 139 | EXPORT_SYMBOL(_raw_write_lock_wait); |
123 | 140 | ||
124 | int | 141 | int _raw_write_trylock_retry(raw_rwlock_t *rw) |
125 | _raw_write_trylock_retry(raw_rwlock_t *rw) | ||
126 | { | 142 | { |
127 | int count = spin_retry; | 143 | int count = spin_retry; |
128 | 144 | ||