smp_lock.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #ifndef __LINUX_SMPLOCK_H
  2. #define __LINUX_SMPLOCK_H
  3. #ifdef CONFIG_LOCK_KERNEL
  4. #include <linux/sched.h>
  5. #include <trace/events/bkl.h>
  6. #define kernel_locked() (current->lock_depth >= 0)
  7. extern int __lockfunc __reacquire_kernel_lock(void);
  8. extern void __lockfunc __release_kernel_lock(void);
  9. /*
  10. * Release/re-acquire global kernel lock for the scheduler
  11. */
  12. #define release_kernel_lock(tsk) do { \
  13. if (unlikely((tsk)->lock_depth >= 0)) \
  14. __release_kernel_lock(); \
  15. } while (0)
  16. static inline int reacquire_kernel_lock(struct task_struct *task)
  17. {
  18. if (unlikely(task->lock_depth >= 0))
  19. return __reacquire_kernel_lock();
  20. return 0;
  21. }
  22. extern void __lockfunc _lock_kernel(void) __acquires(kernel_lock);
  23. extern void __lockfunc _unlock_kernel(void) __releases(kernel_lock);
  24. #define lock_kernel() { \
  25. trace_lock_kernel(__func__, __FILE__, __LINE__); \
  26. _lock_kernel(); \
  27. }
  28. #define unlock_kernel() { \
  29. trace_unlock_kernel(__func__, __FILE__, __LINE__); \
  30. _unlock_kernel(); \
  31. }
  32. /*
  33. * Various legacy drivers don't really need the BKL in a specific
  34. * function, but they *do* need to know that the BKL became available.
  35. * This function just avoids wrapping a bunch of lock/unlock pairs
  36. * around code which doesn't really need it.
  37. */
  38. static inline void cycle_kernel_lock(void)
  39. {
  40. lock_kernel();
  41. unlock_kernel();
  42. }
  43. #else
  44. #define lock_kernel() trace_lock_kernel(__func__, __FILE__, __LINE__);
  45. #define unlock_kernel() trace_unlock_kernel(__func__, __FILE__, __LINE__);
  46. #define release_kernel_lock(task) do { } while(0)
  47. #define cycle_kernel_lock() do { } while(0)
  48. #define reacquire_kernel_lock(task) 0
  49. #define kernel_locked() 1
  50. #endif /* CONFIG_LOCK_KERNEL */
  51. #endif /* __LINUX_SMPLOCK_H */