spinlock.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * arch/s390/lib/spinlock.c
  3. * Out of line spinlock code.
  4. *
  5. * S390 version
  6. * Copyright (C) 2004 IBM Deutschland Entwicklung GmbH, IBM Corporation
  7. * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
  8. */
  9. #include <linux/types.h>
  10. #include <linux/module.h>
  11. #include <linux/spinlock.h>
  12. #include <linux/init.h>
  13. #include <asm/io.h>
  14. int spin_retry = 1000;
  15. /**
  16. * spin_retry= parameter
  17. */
  18. static int __init spin_retry_setup(char *str)
  19. {
  20. spin_retry = simple_strtoul(str, &str, 0);
  21. return 1;
  22. }
  23. __setup("spin_retry=", spin_retry_setup);
  24. static inline void
  25. _diag44(void)
  26. {
  27. #ifdef CONFIG_64BIT
  28. if (MACHINE_HAS_DIAG44)
  29. #endif
  30. asm volatile("diag 0,0,0x44");
  31. }
  32. void
  33. _raw_spin_lock_wait(raw_spinlock_t *lp, unsigned int pc)
  34. {
  35. int count = spin_retry;
  36. while (1) {
  37. if (count-- <= 0) {
  38. _diag44();
  39. count = spin_retry;
  40. }
  41. if (_raw_compare_and_swap(&lp->lock, 0, pc) == 0)
  42. return;
  43. }
  44. }
  45. EXPORT_SYMBOL(_raw_spin_lock_wait);
  46. int
  47. _raw_spin_trylock_retry(raw_spinlock_t *lp, unsigned int pc)
  48. {
  49. int count = spin_retry;
  50. while (count-- > 0) {
  51. if (_raw_compare_and_swap(&lp->lock, 0, pc) == 0)
  52. return 1;
  53. }
  54. return 0;
  55. }
  56. EXPORT_SYMBOL(_raw_spin_trylock_retry);
  57. void
  58. _raw_read_lock_wait(raw_rwlock_t *rw)
  59. {
  60. unsigned int old;
  61. int count = spin_retry;
  62. while (1) {
  63. if (count-- <= 0) {
  64. _diag44();
  65. count = spin_retry;
  66. }
  67. old = rw->lock & 0x7fffffffU;
  68. if (_raw_compare_and_swap(&rw->lock, old, old + 1) == old)
  69. return;
  70. }
  71. }
  72. EXPORT_SYMBOL(_raw_read_lock_wait);
  73. int
  74. _raw_read_trylock_retry(raw_rwlock_t *rw)
  75. {
  76. unsigned int old;
  77. int count = spin_retry;
  78. while (count-- > 0) {
  79. old = rw->lock & 0x7fffffffU;
  80. if (_raw_compare_and_swap(&rw->lock, old, old + 1) == old)
  81. return 1;
  82. }
  83. return 0;
  84. }
  85. EXPORT_SYMBOL(_raw_read_trylock_retry);
  86. void
  87. _raw_write_lock_wait(raw_rwlock_t *rw)
  88. {
  89. int count = spin_retry;
  90. while (1) {
  91. if (count-- <= 0) {
  92. _diag44();
  93. count = spin_retry;
  94. }
  95. if (_raw_compare_and_swap(&rw->lock, 0, 0x80000000) == 0)
  96. return;
  97. }
  98. }
  99. EXPORT_SYMBOL(_raw_write_lock_wait);
  100. int
  101. _raw_write_trylock_retry(raw_rwlock_t *rw)
  102. {
  103. int count = spin_retry;
  104. while (count-- > 0) {
  105. if (_raw_compare_and_swap(&rw->lock, 0, 0x80000000) == 0)
  106. return 1;
  107. }
  108. return 0;
  109. }
  110. EXPORT_SYMBOL(_raw_write_trylock_retry);