lockdep_types.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Runtime locking correctness validator
  4. *
  5. * Copyright (C) 2006,2007 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
  6. * Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra
  7. *
  8. * see Documentation/locking/lockdep-design.rst for more details.
  9. */
  10. #ifndef __LINUX_LOCKDEP_TYPES_H
  11. #define __LINUX_LOCKDEP_TYPES_H
  12. #include <linux/types.h>
  13. #define MAX_LOCKDEP_SUBCLASSES 8UL
  14. enum lockdep_wait_type {
  15. LD_WAIT_INV = 0, /* not checked, catch all */
  16. LD_WAIT_FREE, /* wait free, rcu etc.. */
  17. LD_WAIT_SPIN, /* spin loops, raw_spinlock_t etc.. */
  18. #ifdef CONFIG_PROVE_RAW_LOCK_NESTING
  19. LD_WAIT_CONFIG, /* CONFIG_PREEMPT_LOCK, spinlock_t etc.. */
  20. #else
  21. LD_WAIT_CONFIG = LD_WAIT_SPIN,
  22. #endif
  23. LD_WAIT_SLEEP, /* sleeping locks, mutex_t etc.. */
  24. LD_WAIT_MAX, /* must be last */
  25. };
  26. enum lockdep_lock_type {
  27. LD_LOCK_NORMAL = 0, /* normal, catch all */
  28. LD_LOCK_PERCPU, /* percpu */
  29. LD_LOCK_MAX,
  30. };
  31. #ifdef CONFIG_LOCKDEP
  32. /*
  33. * We'd rather not expose kernel/lockdep_states.h this wide, but we do need
  34. * the total number of states... :-(
  35. *
  36. * XXX_LOCK_USAGE_STATES is the number of lines in lockdep_states.h, for each
  37. * of those we generates 4 states, Additionally we report on USED and USED_READ.
  38. */
  39. #define XXX_LOCK_USAGE_STATES 2
  40. #define LOCK_TRACE_STATES (XXX_LOCK_USAGE_STATES*4 + 2)
  41. /*
  42. * NR_LOCKDEP_CACHING_CLASSES ... Number of classes
  43. * cached in the instance of lockdep_map
  44. *
  45. * Currently main class (subclass == 0) and signle depth subclass
  46. * are cached in lockdep_map. This optimization is mainly targeting
  47. * on rq->lock. double_rq_lock() acquires this highly competitive with
  48. * single depth.
  49. */
  50. #define NR_LOCKDEP_CACHING_CLASSES 2
  51. /*
  52. * A lockdep key is associated with each lock object. For static locks we use
  53. * the lock address itself as the key. Dynamically allocated lock objects can
  54. * have a statically or dynamically allocated key. Dynamically allocated lock
  55. * keys must be registered before being used and must be unregistered before
  56. * the key memory is freed.
  57. */
  58. struct lockdep_subclass_key {
  59. char __one_byte;
  60. } __attribute__ ((__packed__));
  61. /* hash_entry is used to keep track of dynamically allocated keys. */
  62. struct lock_class_key {
  63. union {
  64. struct hlist_node hash_entry;
  65. struct lockdep_subclass_key subkeys[MAX_LOCKDEP_SUBCLASSES];
  66. };
  67. };
  68. extern struct lock_class_key __lockdep_no_validate__;
  69. struct lock_trace;
  70. #define LOCKSTAT_POINTS 4
  71. /*
  72. * The lock-class itself. The order of the structure members matters.
  73. * reinit_class() zeroes the key member and all subsequent members.
  74. */
  75. struct lock_class {
  76. /*
  77. * class-hash:
  78. */
  79. struct hlist_node hash_entry;
  80. /*
  81. * Entry in all_lock_classes when in use. Entry in free_lock_classes
  82. * when not in use. Instances that are being freed are on one of the
  83. * zapped_classes lists.
  84. */
  85. struct list_head lock_entry;
  86. /*
  87. * These fields represent a directed graph of lock dependencies,
  88. * to every node we attach a list of "forward" and a list of
  89. * "backward" graph nodes.
  90. */
  91. struct list_head locks_after, locks_before;
  92. const struct lockdep_subclass_key *key;
  93. unsigned int subclass;
  94. unsigned int dep_gen_id;
  95. /*
  96. * IRQ/softirq usage tracking bits:
  97. */
  98. unsigned long usage_mask;
  99. const struct lock_trace *usage_traces[LOCK_TRACE_STATES];
  100. /*
  101. * Generation counter, when doing certain classes of graph walking,
  102. * to ensure that we check one node only once:
  103. */
  104. int name_version;
  105. const char *name;
  106. u8 wait_type_inner;
  107. u8 wait_type_outer;
  108. u8 lock_type;
  109. /* u8 hole; */
  110. #ifdef CONFIG_LOCK_STAT
  111. unsigned long contention_point[LOCKSTAT_POINTS];
  112. unsigned long contending_point[LOCKSTAT_POINTS];
  113. #endif
  114. } __no_randomize_layout;
  115. #ifdef CONFIG_LOCK_STAT
  116. struct lock_time {
  117. s64 min;
  118. s64 max;
  119. s64 total;
  120. unsigned long nr;
  121. };
  122. enum bounce_type {
  123. bounce_acquired_write,
  124. bounce_acquired_read,
  125. bounce_contended_write,
  126. bounce_contended_read,
  127. nr_bounce_types,
  128. bounce_acquired = bounce_acquired_write,
  129. bounce_contended = bounce_contended_write,
  130. };
  131. struct lock_class_stats {
  132. unsigned long contention_point[LOCKSTAT_POINTS];
  133. unsigned long contending_point[LOCKSTAT_POINTS];
  134. struct lock_time read_waittime;
  135. struct lock_time write_waittime;
  136. struct lock_time read_holdtime;
  137. struct lock_time write_holdtime;
  138. unsigned long bounces[nr_bounce_types];
  139. };
  140. struct lock_class_stats lock_stats(struct lock_class *class);
  141. void clear_lock_stats(struct lock_class *class);
  142. #endif
  143. /*
  144. * Map the lock object (the lock instance) to the lock-class object.
  145. * This is embedded into specific lock instances:
  146. */
  147. struct lockdep_map {
  148. struct lock_class_key *key;
  149. struct lock_class *class_cache[NR_LOCKDEP_CACHING_CLASSES];
  150. const char *name;
  151. u8 wait_type_outer; /* can be taken in this context */
  152. u8 wait_type_inner; /* presents this context */
  153. u8 lock_type;
  154. /* u8 hole; */
  155. #ifdef CONFIG_LOCK_STAT
  156. int cpu;
  157. unsigned long ip;
  158. #endif
  159. };
  160. struct pin_cookie { unsigned int val; };
  161. #else /* !CONFIG_LOCKDEP */
  162. /*
  163. * The class key takes no space if lockdep is disabled:
  164. */
  165. struct lock_class_key { };
  166. /*
  167. * The lockdep_map takes no space if lockdep is disabled:
  168. */
  169. struct lockdep_map { };
  170. struct pin_cookie { };
  171. #endif /* !LOCKDEP */
  172. #endif /* __LINUX_LOCKDEP_TYPES_H */