Martin Schwidefsky | 951f22d | 2005-07-27 11:44:57 -0700 | [diff] [blame] | 1 | /* |
Martin Schwidefsky | 951f22d | 2005-07-27 11:44:57 -0700 | [diff] [blame] | 2 | * Out of line spinlock code. |
| 3 | * |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 4 | * Copyright IBM Corp. 2004, 2006 |
Martin Schwidefsky | 951f22d | 2005-07-27 11:44:57 -0700 | [diff] [blame] | 5 | * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com) |
| 6 | */ |
| 7 | |
| 8 | #include <linux/types.h> |
| 9 | #include <linux/module.h> |
| 10 | #include <linux/spinlock.h> |
| 11 | #include <linux/init.h> |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 12 | #include <linux/smp.h> |
Martin Schwidefsky | 951f22d | 2005-07-27 11:44:57 -0700 | [diff] [blame] | 13 | #include <asm/io.h> |
| 14 | |
Martin Schwidefsky | 2c72a44 | 2015-01-14 17:52:33 +0100 | [diff] [blame] | 15 | int spin_retry = -1; |
| 16 | |
| 17 | static int __init spin_retry_init(void) |
| 18 | { |
| 19 | if (spin_retry < 0) |
| 20 | spin_retry = MACHINE_HAS_CAD ? 10 : 1000; |
| 21 | return 0; |
| 22 | } |
| 23 | early_initcall(spin_retry_init); |
Martin Schwidefsky | 951f22d | 2005-07-27 11:44:57 -0700 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * spin_retry= parameter |
| 27 | */ |
| 28 | static int __init spin_retry_setup(char *str) |
| 29 | { |
| 30 | spin_retry = simple_strtoul(str, &str, 0); |
| 31 | return 1; |
| 32 | } |
| 33 | __setup("spin_retry=", spin_retry_setup); |
| 34 | |
Martin Schwidefsky | 2c72a44 | 2015-01-14 17:52:33 +0100 | [diff] [blame] | 35 | static inline void _raw_compare_and_delay(unsigned int *lock, unsigned int old) |
| 36 | { |
| 37 | asm(".insn rsy,0xeb0000000022,%0,0,%1" : : "d" (old), "Q" (*lock)); |
| 38 | } |
| 39 | |
Martin Schwidefsky | 419123f | 2015-11-19 11:09:45 +0100 | [diff] [blame] | 40 | static inline int cpu_is_preempted(int cpu) |
| 41 | { |
| 42 | if (test_cpu_flag_of(CIF_ENABLED_WAIT, cpu)) |
| 43 | return 0; |
| 44 | if (smp_vcpu_scheduled(cpu)) |
| 45 | return 0; |
| 46 | return 1; |
| 47 | } |
| 48 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 49 | void arch_spin_lock_wait(arch_spinlock_t *lp) |
Martin Schwidefsky | 951f22d | 2005-07-27 11:44:57 -0700 | [diff] [blame] | 50 | { |
Philipp Hachtmann | 6c8cd5b | 2014-04-07 18:25:23 +0200 | [diff] [blame] | 51 | unsigned int cpu = SPINLOCK_LOCKVAL; |
Gerald Schaefer | 59b6978 | 2010-02-26 22:37:40 +0100 | [diff] [blame] | 52 | unsigned int owner; |
Martin Schwidefsky | db1c451 | 2015-11-12 12:51:17 +0100 | [diff] [blame] | 53 | int count, first_diag; |
Martin Schwidefsky | 951f22d | 2005-07-27 11:44:57 -0700 | [diff] [blame] | 54 | |
Martin Schwidefsky | db1c451 | 2015-11-12 12:51:17 +0100 | [diff] [blame] | 55 | first_diag = 1; |
Martin Schwidefsky | 951f22d | 2005-07-27 11:44:57 -0700 | [diff] [blame] | 56 | while (1) { |
Martin Schwidefsky | 470ada6 | 2014-05-16 15:11:12 +0200 | [diff] [blame] | 57 | owner = ACCESS_ONCE(lp->lock); |
| 58 | /* Try to get the lock if it is free. */ |
| 59 | if (!owner) { |
| 60 | if (_raw_compare_and_swap(&lp->lock, 0, cpu)) |
| 61 | return; |
| 62 | continue; |
Martin Schwidefsky | 951f22d | 2005-07-27 11:44:57 -0700 | [diff] [blame] | 63 | } |
Martin Schwidefsky | db1c451 | 2015-11-12 12:51:17 +0100 | [diff] [blame] | 64 | /* First iteration: check if the lock owner is running. */ |
Martin Schwidefsky | 419123f | 2015-11-19 11:09:45 +0100 | [diff] [blame] | 65 | if (first_diag && cpu_is_preempted(~owner)) { |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 66 | smp_yield_cpu(~owner); |
Martin Schwidefsky | db1c451 | 2015-11-12 12:51:17 +0100 | [diff] [blame] | 67 | first_diag = 0; |
Martin Schwidefsky | 470ada6 | 2014-05-16 15:11:12 +0200 | [diff] [blame] | 68 | continue; |
| 69 | } |
| 70 | /* Loop for a while on the lock value. */ |
| 71 | count = spin_retry; |
| 72 | do { |
Martin Schwidefsky | 2c72a44 | 2015-01-14 17:52:33 +0100 | [diff] [blame] | 73 | if (MACHINE_HAS_CAD) |
| 74 | _raw_compare_and_delay(&lp->lock, owner); |
Martin Schwidefsky | 470ada6 | 2014-05-16 15:11:12 +0200 | [diff] [blame] | 75 | owner = ACCESS_ONCE(lp->lock); |
| 76 | } while (owner && count-- > 0); |
| 77 | if (!owner) |
| 78 | continue; |
| 79 | /* |
| 80 | * For multiple layers of hypervisors, e.g. z/VM + LPAR |
Martin Schwidefsky | db1c451 | 2015-11-12 12:51:17 +0100 | [diff] [blame] | 81 | * yield the CPU unconditionally. For LPAR rely on the |
| 82 | * sense running status. |
Martin Schwidefsky | 470ada6 | 2014-05-16 15:11:12 +0200 | [diff] [blame] | 83 | */ |
Martin Schwidefsky | 419123f | 2015-11-19 11:09:45 +0100 | [diff] [blame] | 84 | if (!MACHINE_IS_LPAR || cpu_is_preempted(~owner)) { |
Martin Schwidefsky | 470ada6 | 2014-05-16 15:11:12 +0200 | [diff] [blame] | 85 | smp_yield_cpu(~owner); |
Martin Schwidefsky | db1c451 | 2015-11-12 12:51:17 +0100 | [diff] [blame] | 86 | first_diag = 0; |
| 87 | } |
Martin Schwidefsky | 951f22d | 2005-07-27 11:44:57 -0700 | [diff] [blame] | 88 | } |
| 89 | } |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 90 | EXPORT_SYMBOL(arch_spin_lock_wait); |
Martin Schwidefsky | 951f22d | 2005-07-27 11:44:57 -0700 | [diff] [blame] | 91 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 92 | void arch_spin_lock_wait_flags(arch_spinlock_t *lp, unsigned long flags) |
Hisashi Hifumi | 894cdde | 2008-01-26 14:11:28 +0100 | [diff] [blame] | 93 | { |
Philipp Hachtmann | 6c8cd5b | 2014-04-07 18:25:23 +0200 | [diff] [blame] | 94 | unsigned int cpu = SPINLOCK_LOCKVAL; |
Gerald Schaefer | 59b6978 | 2010-02-26 22:37:40 +0100 | [diff] [blame] | 95 | unsigned int owner; |
Martin Schwidefsky | db1c451 | 2015-11-12 12:51:17 +0100 | [diff] [blame] | 96 | int count, first_diag; |
Hisashi Hifumi | 894cdde | 2008-01-26 14:11:28 +0100 | [diff] [blame] | 97 | |
| 98 | local_irq_restore(flags); |
Martin Schwidefsky | db1c451 | 2015-11-12 12:51:17 +0100 | [diff] [blame] | 99 | first_diag = 1; |
Hisashi Hifumi | 894cdde | 2008-01-26 14:11:28 +0100 | [diff] [blame] | 100 | while (1) { |
Martin Schwidefsky | 470ada6 | 2014-05-16 15:11:12 +0200 | [diff] [blame] | 101 | owner = ACCESS_ONCE(lp->lock); |
| 102 | /* Try to get the lock if it is free. */ |
| 103 | if (!owner) { |
| 104 | local_irq_disable(); |
| 105 | if (_raw_compare_and_swap(&lp->lock, 0, cpu)) |
| 106 | return; |
| 107 | local_irq_restore(flags); |
Hisashi Hifumi | 894cdde | 2008-01-26 14:11:28 +0100 | [diff] [blame] | 108 | } |
Martin Schwidefsky | 470ada6 | 2014-05-16 15:11:12 +0200 | [diff] [blame] | 109 | /* Check if the lock owner is running. */ |
Martin Schwidefsky | 419123f | 2015-11-19 11:09:45 +0100 | [diff] [blame] | 110 | if (first_diag && cpu_is_preempted(~owner)) { |
Martin Schwidefsky | 8b646bd | 2012-03-11 11:59:26 -0400 | [diff] [blame] | 111 | smp_yield_cpu(~owner); |
Martin Schwidefsky | db1c451 | 2015-11-12 12:51:17 +0100 | [diff] [blame] | 112 | first_diag = 0; |
Martin Schwidefsky | 470ada6 | 2014-05-16 15:11:12 +0200 | [diff] [blame] | 113 | continue; |
| 114 | } |
| 115 | /* Loop for a while on the lock value. */ |
| 116 | count = spin_retry; |
| 117 | do { |
Martin Schwidefsky | 2c72a44 | 2015-01-14 17:52:33 +0100 | [diff] [blame] | 118 | if (MACHINE_HAS_CAD) |
| 119 | _raw_compare_and_delay(&lp->lock, owner); |
Martin Schwidefsky | 470ada6 | 2014-05-16 15:11:12 +0200 | [diff] [blame] | 120 | owner = ACCESS_ONCE(lp->lock); |
| 121 | } while (owner && count-- > 0); |
| 122 | if (!owner) |
| 123 | continue; |
| 124 | /* |
| 125 | * For multiple layers of hypervisors, e.g. z/VM + LPAR |
Martin Schwidefsky | db1c451 | 2015-11-12 12:51:17 +0100 | [diff] [blame] | 126 | * yield the CPU unconditionally. For LPAR rely on the |
| 127 | * sense running status. |
Martin Schwidefsky | 470ada6 | 2014-05-16 15:11:12 +0200 | [diff] [blame] | 128 | */ |
Martin Schwidefsky | 419123f | 2015-11-19 11:09:45 +0100 | [diff] [blame] | 129 | if (!MACHINE_IS_LPAR || cpu_is_preempted(~owner)) { |
Martin Schwidefsky | 470ada6 | 2014-05-16 15:11:12 +0200 | [diff] [blame] | 130 | smp_yield_cpu(~owner); |
Martin Schwidefsky | db1c451 | 2015-11-12 12:51:17 +0100 | [diff] [blame] | 131 | first_diag = 0; |
| 132 | } |
Hisashi Hifumi | 894cdde | 2008-01-26 14:11:28 +0100 | [diff] [blame] | 133 | } |
| 134 | } |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 135 | EXPORT_SYMBOL(arch_spin_lock_wait_flags); |
Hisashi Hifumi | 894cdde | 2008-01-26 14:11:28 +0100 | [diff] [blame] | 136 | |
Philipp Hachtmann | 5b3f683 | 2014-04-07 18:25:23 +0200 | [diff] [blame] | 137 | int arch_spin_trylock_retry(arch_spinlock_t *lp) |
| 138 | { |
Martin Schwidefsky | 2c72a44 | 2015-01-14 17:52:33 +0100 | [diff] [blame] | 139 | unsigned int cpu = SPINLOCK_LOCKVAL; |
| 140 | unsigned int owner; |
Philipp Hachtmann | 5b3f683 | 2014-04-07 18:25:23 +0200 | [diff] [blame] | 141 | int count; |
| 142 | |
Martin Schwidefsky | 2c72a44 | 2015-01-14 17:52:33 +0100 | [diff] [blame] | 143 | for (count = spin_retry; count > 0; count--) { |
| 144 | owner = ACCESS_ONCE(lp->lock); |
| 145 | /* Try to get the lock if it is free. */ |
| 146 | if (!owner) { |
| 147 | if (_raw_compare_and_swap(&lp->lock, 0, cpu)) |
| 148 | return 1; |
| 149 | } else if (MACHINE_HAS_CAD) |
| 150 | _raw_compare_and_delay(&lp->lock, owner); |
| 151 | } |
Philipp Hachtmann | 5b3f683 | 2014-04-07 18:25:23 +0200 | [diff] [blame] | 152 | return 0; |
| 153 | } |
| 154 | EXPORT_SYMBOL(arch_spin_trylock_retry); |
| 155 | |
Thomas Gleixner | fb3a6bb | 2009-12-03 20:01:19 +0100 | [diff] [blame] | 156 | void _raw_read_lock_wait(arch_rwlock_t *rw) |
Martin Schwidefsky | 951f22d | 2005-07-27 11:44:57 -0700 | [diff] [blame] | 157 | { |
Martin Schwidefsky | d59b93d | 2014-09-19 14:29:31 +0200 | [diff] [blame] | 158 | unsigned int owner, old; |
Martin Schwidefsky | 951f22d | 2005-07-27 11:44:57 -0700 | [diff] [blame] | 159 | int count = spin_retry; |
| 160 | |
Martin Schwidefsky | bbae71b | 2014-09-22 16:34:38 +0200 | [diff] [blame] | 161 | #ifdef CONFIG_HAVE_MARCH_Z196_FEATURES |
| 162 | __RAW_LOCK(&rw->lock, -1, __RAW_OP_ADD); |
| 163 | #endif |
Martin Schwidefsky | d59b93d | 2014-09-19 14:29:31 +0200 | [diff] [blame] | 164 | owner = 0; |
Martin Schwidefsky | 951f22d | 2005-07-27 11:44:57 -0700 | [diff] [blame] | 165 | while (1) { |
| 166 | if (count-- <= 0) { |
Martin Schwidefsky | 419123f | 2015-11-19 11:09:45 +0100 | [diff] [blame] | 167 | if (owner && cpu_is_preempted(~owner)) |
Martin Schwidefsky | d59b93d | 2014-09-19 14:29:31 +0200 | [diff] [blame] | 168 | smp_yield_cpu(~owner); |
Martin Schwidefsky | 951f22d | 2005-07-27 11:44:57 -0700 | [diff] [blame] | 169 | count = spin_retry; |
| 170 | } |
Martin Schwidefsky | bae8f56 | 2014-05-15 11:00:44 +0200 | [diff] [blame] | 171 | old = ACCESS_ONCE(rw->lock); |
Martin Schwidefsky | d59b93d | 2014-09-19 14:29:31 +0200 | [diff] [blame] | 172 | owner = ACCESS_ONCE(rw->owner); |
Martin Schwidefsky | 2c72a44 | 2015-01-14 17:52:33 +0100 | [diff] [blame] | 173 | if ((int) old < 0) { |
| 174 | if (MACHINE_HAS_CAD) |
| 175 | _raw_compare_and_delay(&rw->lock, old); |
Christian Ehrhardt | 9656716 | 2006-03-09 17:33:49 -0800 | [diff] [blame] | 176 | continue; |
Martin Schwidefsky | 2c72a44 | 2015-01-14 17:52:33 +0100 | [diff] [blame] | 177 | } |
Philipp Hachtmann | 5b3f683 | 2014-04-07 18:25:23 +0200 | [diff] [blame] | 178 | if (_raw_compare_and_swap(&rw->lock, old, old + 1)) |
Martin Schwidefsky | 951f22d | 2005-07-27 11:44:57 -0700 | [diff] [blame] | 179 | return; |
| 180 | } |
| 181 | } |
| 182 | EXPORT_SYMBOL(_raw_read_lock_wait); |
| 183 | |
Thomas Gleixner | fb3a6bb | 2009-12-03 20:01:19 +0100 | [diff] [blame] | 184 | int _raw_read_trylock_retry(arch_rwlock_t *rw) |
Martin Schwidefsky | 951f22d | 2005-07-27 11:44:57 -0700 | [diff] [blame] | 185 | { |
| 186 | unsigned int old; |
| 187 | int count = spin_retry; |
| 188 | |
| 189 | while (count-- > 0) { |
Martin Schwidefsky | bae8f56 | 2014-05-15 11:00:44 +0200 | [diff] [blame] | 190 | old = ACCESS_ONCE(rw->lock); |
Martin Schwidefsky | 2c72a44 | 2015-01-14 17:52:33 +0100 | [diff] [blame] | 191 | if ((int) old < 0) { |
| 192 | if (MACHINE_HAS_CAD) |
| 193 | _raw_compare_and_delay(&rw->lock, old); |
Christian Ehrhardt | 9656716 | 2006-03-09 17:33:49 -0800 | [diff] [blame] | 194 | continue; |
Martin Schwidefsky | 2c72a44 | 2015-01-14 17:52:33 +0100 | [diff] [blame] | 195 | } |
Philipp Hachtmann | 5b3f683 | 2014-04-07 18:25:23 +0200 | [diff] [blame] | 196 | if (_raw_compare_and_swap(&rw->lock, old, old + 1)) |
Martin Schwidefsky | 951f22d | 2005-07-27 11:44:57 -0700 | [diff] [blame] | 197 | return 1; |
| 198 | } |
| 199 | return 0; |
| 200 | } |
| 201 | EXPORT_SYMBOL(_raw_read_trylock_retry); |
| 202 | |
Martin Schwidefsky | bbae71b | 2014-09-22 16:34:38 +0200 | [diff] [blame] | 203 | #ifdef CONFIG_HAVE_MARCH_Z196_FEATURES |
| 204 | |
| 205 | void _raw_write_lock_wait(arch_rwlock_t *rw, unsigned int prev) |
| 206 | { |
| 207 | unsigned int owner, old; |
| 208 | int count = spin_retry; |
| 209 | |
| 210 | owner = 0; |
| 211 | while (1) { |
| 212 | if (count-- <= 0) { |
Martin Schwidefsky | 419123f | 2015-11-19 11:09:45 +0100 | [diff] [blame] | 213 | if (owner && cpu_is_preempted(~owner)) |
Martin Schwidefsky | bbae71b | 2014-09-22 16:34:38 +0200 | [diff] [blame] | 214 | smp_yield_cpu(~owner); |
| 215 | count = spin_retry; |
| 216 | } |
| 217 | old = ACCESS_ONCE(rw->lock); |
| 218 | owner = ACCESS_ONCE(rw->owner); |
Christian Borntraeger | e0af21c | 2015-09-11 16:09:56 +0200 | [diff] [blame] | 219 | smp_mb(); |
Martin Schwidefsky | bbae71b | 2014-09-22 16:34:38 +0200 | [diff] [blame] | 220 | if ((int) old >= 0) { |
| 221 | prev = __RAW_LOCK(&rw->lock, 0x80000000, __RAW_OP_OR); |
| 222 | old = prev; |
| 223 | } |
| 224 | if ((old & 0x7fffffff) == 0 && (int) prev >= 0) |
| 225 | break; |
Martin Schwidefsky | 2c72a44 | 2015-01-14 17:52:33 +0100 | [diff] [blame] | 226 | if (MACHINE_HAS_CAD) |
| 227 | _raw_compare_and_delay(&rw->lock, old); |
Martin Schwidefsky | bbae71b | 2014-09-22 16:34:38 +0200 | [diff] [blame] | 228 | } |
| 229 | } |
| 230 | EXPORT_SYMBOL(_raw_write_lock_wait); |
| 231 | |
| 232 | #else /* CONFIG_HAVE_MARCH_Z196_FEATURES */ |
| 233 | |
Thomas Gleixner | fb3a6bb | 2009-12-03 20:01:19 +0100 | [diff] [blame] | 234 | void _raw_write_lock_wait(arch_rwlock_t *rw) |
Martin Schwidefsky | 951f22d | 2005-07-27 11:44:57 -0700 | [diff] [blame] | 235 | { |
Martin Schwidefsky | 94232a4 | 2014-09-22 16:25:25 +0200 | [diff] [blame] | 236 | unsigned int owner, old, prev; |
Martin Schwidefsky | 951f22d | 2005-07-27 11:44:57 -0700 | [diff] [blame] | 237 | int count = spin_retry; |
| 238 | |
Martin Schwidefsky | 94232a4 | 2014-09-22 16:25:25 +0200 | [diff] [blame] | 239 | prev = 0x80000000; |
Martin Schwidefsky | d59b93d | 2014-09-19 14:29:31 +0200 | [diff] [blame] | 240 | owner = 0; |
Martin Schwidefsky | 951f22d | 2005-07-27 11:44:57 -0700 | [diff] [blame] | 241 | while (1) { |
| 242 | if (count-- <= 0) { |
Martin Schwidefsky | 419123f | 2015-11-19 11:09:45 +0100 | [diff] [blame] | 243 | if (owner && cpu_is_preempted(~owner)) |
Martin Schwidefsky | d59b93d | 2014-09-19 14:29:31 +0200 | [diff] [blame] | 244 | smp_yield_cpu(~owner); |
Martin Schwidefsky | 951f22d | 2005-07-27 11:44:57 -0700 | [diff] [blame] | 245 | count = spin_retry; |
| 246 | } |
Martin Schwidefsky | bae8f56 | 2014-05-15 11:00:44 +0200 | [diff] [blame] | 247 | old = ACCESS_ONCE(rw->lock); |
Martin Schwidefsky | d59b93d | 2014-09-19 14:29:31 +0200 | [diff] [blame] | 248 | owner = ACCESS_ONCE(rw->owner); |
Martin Schwidefsky | 94232a4 | 2014-09-22 16:25:25 +0200 | [diff] [blame] | 249 | if ((int) old >= 0 && |
| 250 | _raw_compare_and_swap(&rw->lock, old, old | 0x80000000)) |
| 251 | prev = old; |
| 252 | else |
Christian Borntraeger | e0af21c | 2015-09-11 16:09:56 +0200 | [diff] [blame] | 253 | smp_mb(); |
Martin Schwidefsky | 94232a4 | 2014-09-22 16:25:25 +0200 | [diff] [blame] | 254 | if ((old & 0x7fffffff) == 0 && (int) prev >= 0) |
| 255 | break; |
Martin Schwidefsky | 2c72a44 | 2015-01-14 17:52:33 +0100 | [diff] [blame] | 256 | if (MACHINE_HAS_CAD) |
| 257 | _raw_compare_and_delay(&rw->lock, old); |
Martin Schwidefsky | 951f22d | 2005-07-27 11:44:57 -0700 | [diff] [blame] | 258 | } |
| 259 | } |
| 260 | EXPORT_SYMBOL(_raw_write_lock_wait); |
| 261 | |
Martin Schwidefsky | bbae71b | 2014-09-22 16:34:38 +0200 | [diff] [blame] | 262 | #endif /* CONFIG_HAVE_MARCH_Z196_FEATURES */ |
| 263 | |
Thomas Gleixner | fb3a6bb | 2009-12-03 20:01:19 +0100 | [diff] [blame] | 264 | int _raw_write_trylock_retry(arch_rwlock_t *rw) |
Martin Schwidefsky | 951f22d | 2005-07-27 11:44:57 -0700 | [diff] [blame] | 265 | { |
Martin Schwidefsky | bae8f56 | 2014-05-15 11:00:44 +0200 | [diff] [blame] | 266 | unsigned int old; |
Martin Schwidefsky | 951f22d | 2005-07-27 11:44:57 -0700 | [diff] [blame] | 267 | int count = spin_retry; |
| 268 | |
| 269 | while (count-- > 0) { |
Martin Schwidefsky | bae8f56 | 2014-05-15 11:00:44 +0200 | [diff] [blame] | 270 | old = ACCESS_ONCE(rw->lock); |
Martin Schwidefsky | 2c72a44 | 2015-01-14 17:52:33 +0100 | [diff] [blame] | 271 | if (old) { |
| 272 | if (MACHINE_HAS_CAD) |
| 273 | _raw_compare_and_delay(&rw->lock, old); |
Christian Ehrhardt | 9656716 | 2006-03-09 17:33:49 -0800 | [diff] [blame] | 274 | continue; |
Martin Schwidefsky | 2c72a44 | 2015-01-14 17:52:33 +0100 | [diff] [blame] | 275 | } |
Philipp Hachtmann | 5b3f683 | 2014-04-07 18:25:23 +0200 | [diff] [blame] | 276 | if (_raw_compare_and_swap(&rw->lock, 0, 0x80000000)) |
Martin Schwidefsky | 951f22d | 2005-07-27 11:44:57 -0700 | [diff] [blame] | 277 | return 1; |
| 278 | } |
| 279 | return 0; |
| 280 | } |
| 281 | EXPORT_SYMBOL(_raw_write_trylock_retry); |
Martin Schwidefsky | d59b93d | 2014-09-19 14:29:31 +0200 | [diff] [blame] | 282 | |
| 283 | void arch_lock_relax(unsigned int cpu) |
| 284 | { |
| 285 | if (!cpu) |
| 286 | return; |
Martin Schwidefsky | 419123f | 2015-11-19 11:09:45 +0100 | [diff] [blame] | 287 | if (MACHINE_IS_LPAR && !cpu_is_preempted(~cpu)) |
Martin Schwidefsky | d59b93d | 2014-09-19 14:29:31 +0200 | [diff] [blame] | 288 | return; |
| 289 | smp_yield_cpu(~cpu); |
| 290 | } |
| 291 | EXPORT_SYMBOL(arch_lock_relax); |