spinlock_api_smp.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. #ifndef __LINUX_SPINLOCK_API_SMP_H
  2. #define __LINUX_SPINLOCK_API_SMP_H
  3. #ifndef __LINUX_SPINLOCK_H
  4. # error "please don't include this file directly"
  5. #endif
  6. /*
  7. * include/linux/spinlock_api_smp.h
  8. *
  9. * spinlock API declarations on SMP (and debug)
  10. * (implemented in kernel/spinlock.c)
  11. *
  12. * portions Copyright 2005, Red Hat, Inc., Ingo Molnar
  13. * Released under the General Public License (GPL).
  14. */
  15. int in_lock_functions(unsigned long addr);
  16. #define assert_raw_spin_locked(x) BUG_ON(!raw_spin_is_locked(x))
  17. void __lockfunc _raw_spin_lock(raw_spinlock_t *lock) __acquires(lock);
  18. void __lockfunc _raw_spin_lock_nested(raw_spinlock_t *lock, int subclass)
  19. __acquires(lock);
  20. void __lockfunc _raw_spin_lock_bh_nested(raw_spinlock_t *lock, int subclass)
  21. __acquires(lock);
  22. void __lockfunc
  23. _raw_spin_lock_nest_lock(raw_spinlock_t *lock, struct lockdep_map *map)
  24. __acquires(lock);
  25. void __lockfunc _raw_spin_lock_bh(raw_spinlock_t *lock) __acquires(lock);
  26. void __lockfunc _raw_spin_lock_irq(raw_spinlock_t *lock)
  27. __acquires(lock);
  28. unsigned long __lockfunc _raw_spin_lock_irqsave(raw_spinlock_t *lock)
  29. __acquires(lock);
  30. unsigned long __lockfunc
  31. _raw_spin_lock_irqsave_nested(raw_spinlock_t *lock, int subclass)
  32. __acquires(lock);
  33. int __lockfunc _raw_spin_trylock(raw_spinlock_t *lock);
  34. int __lockfunc _raw_spin_trylock_bh(raw_spinlock_t *lock);
  35. void __lockfunc _raw_spin_unlock(raw_spinlock_t *lock) __releases(lock);
  36. void __lockfunc _raw_spin_unlock_bh(raw_spinlock_t *lock) __releases(lock);
  37. void __lockfunc _raw_spin_unlock_irq(raw_spinlock_t *lock) __releases(lock);
  38. void __lockfunc
  39. _raw_spin_unlock_irqrestore(raw_spinlock_t *lock, unsigned long flags)
  40. __releases(lock);
  41. #ifdef CONFIG_INLINE_SPIN_LOCK
  42. #define _raw_spin_lock(lock) __raw_spin_lock(lock)
  43. #endif
  44. #ifdef CONFIG_INLINE_SPIN_LOCK_BH
  45. #define _raw_spin_lock_bh(lock) __raw_spin_lock_bh(lock)
  46. #endif
  47. #ifdef CONFIG_INLINE_SPIN_LOCK_IRQ
  48. #define _raw_spin_lock_irq(lock) __raw_spin_lock_irq(lock)
  49. #endif
  50. #ifdef CONFIG_INLINE_SPIN_LOCK_IRQSAVE
  51. #define _raw_spin_lock_irqsave(lock) __raw_spin_lock_irqsave(lock)
  52. #endif
  53. #ifdef CONFIG_INLINE_SPIN_TRYLOCK
  54. #define _raw_spin_trylock(lock) __raw_spin_trylock(lock)
  55. #endif
  56. #ifdef CONFIG_INLINE_SPIN_TRYLOCK_BH
  57. #define _raw_spin_trylock_bh(lock) __raw_spin_trylock_bh(lock)
  58. #endif
  59. #ifndef CONFIG_UNINLINE_SPIN_UNLOCK
  60. #define _raw_spin_unlock(lock) __raw_spin_unlock(lock)
  61. #endif
  62. #ifdef CONFIG_INLINE_SPIN_UNLOCK_BH
  63. #define _raw_spin_unlock_bh(lock) __raw_spin_unlock_bh(lock)
  64. #endif
  65. #ifdef CONFIG_INLINE_SPIN_UNLOCK_IRQ
  66. #define _raw_spin_unlock_irq(lock) __raw_spin_unlock_irq(lock)
  67. #endif
  68. #ifdef CONFIG_INLINE_SPIN_UNLOCK_IRQRESTORE
  69. #define _raw_spin_unlock_irqrestore(lock, flags) __raw_spin_unlock_irqrestore(lock, flags)
  70. #endif
  71. static inline int __raw_spin_trylock(raw_spinlock_t *lock)
  72. {
  73. preempt_disable();
  74. if (do_raw_spin_trylock(lock)) {
  75. spin_acquire(&lock->dep_map, 0, 1, _RET_IP_);
  76. return 1;
  77. }
  78. preempt_enable();
  79. return 0;
  80. }
  81. /*
  82. * If lockdep is enabled then we use the non-preemption spin-ops
  83. * even on CONFIG_PREEMPT, because lockdep assumes that interrupts are
  84. * not re-enabled during lock-acquire (which the preempt-spin-ops do):
  85. */
  86. #if !defined(CONFIG_GENERIC_LOCKBREAK) || defined(CONFIG_DEBUG_LOCK_ALLOC)
  87. static inline unsigned long __raw_spin_lock_irqsave(raw_spinlock_t *lock)
  88. {
  89. unsigned long flags;
  90. local_irq_save(flags);
  91. preempt_disable();
  92. spin_acquire(&lock->dep_map, 0, 0, _RET_IP_);
  93. /*
  94. * On lockdep we dont want the hand-coded irq-enable of
  95. * do_raw_spin_lock_flags() code, because lockdep assumes
  96. * that interrupts are not re-enabled during lock-acquire:
  97. */
  98. #ifdef CONFIG_LOCKDEP
  99. LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock);
  100. #else
  101. do_raw_spin_lock_flags(lock, &flags);
  102. #endif
  103. return flags;
  104. }
  105. static inline void __raw_spin_lock_irq(raw_spinlock_t *lock)
  106. {
  107. local_irq_disable();
  108. preempt_disable();
  109. spin_acquire(&lock->dep_map, 0, 0, _RET_IP_);
  110. LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock);
  111. }
  112. static inline void __raw_spin_lock_bh(raw_spinlock_t *lock)
  113. {
  114. __local_bh_disable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET);
  115. spin_acquire(&lock->dep_map, 0, 0, _RET_IP_);
  116. LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock);
  117. }
  118. static inline void __raw_spin_lock(raw_spinlock_t *lock)
  119. {
  120. preempt_disable();
  121. spin_acquire(&lock->dep_map, 0, 0, _RET_IP_);
  122. LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock);
  123. }
  124. #endif /* !CONFIG_GENERIC_LOCKBREAK || CONFIG_DEBUG_LOCK_ALLOC */
  125. static inline void __raw_spin_unlock(raw_spinlock_t *lock)
  126. {
  127. spin_release(&lock->dep_map, 1, _RET_IP_);
  128. do_raw_spin_unlock(lock);
  129. preempt_enable();
  130. }
  131. static inline void __raw_spin_unlock_irqrestore(raw_spinlock_t *lock,
  132. unsigned long flags)
  133. {
  134. spin_release(&lock->dep_map, 1, _RET_IP_);
  135. do_raw_spin_unlock(lock);
  136. local_irq_restore(flags);
  137. preempt_enable();
  138. }
  139. static inline void __raw_spin_unlock_irq(raw_spinlock_t *lock)
  140. {
  141. spin_release(&lock->dep_map, 1, _RET_IP_);
  142. do_raw_spin_unlock(lock);
  143. local_irq_enable();
  144. preempt_enable();
  145. }
  146. static inline void __raw_spin_unlock_bh(raw_spinlock_t *lock)
  147. {
  148. spin_release(&lock->dep_map, 1, _RET_IP_);
  149. do_raw_spin_unlock(lock);
  150. __local_bh_enable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET);
  151. }
  152. static inline int __raw_spin_trylock_bh(raw_spinlock_t *lock)
  153. {
  154. __local_bh_disable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET);
  155. if (do_raw_spin_trylock(lock)) {
  156. spin_acquire(&lock->dep_map, 0, 1, _RET_IP_);
  157. return 1;
  158. }
  159. __local_bh_enable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET);
  160. return 0;
  161. }
  162. #include <linux/rwlock_api_smp.h>
  163. #endif /* __LINUX_SPINLOCK_API_SMP_H */