blk-mq: Record nr_active_requests per queue for when using shared sbitmap
[linux-2.6-microblaze.git] / include / linux / lockdep_types.h
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
13 #include <linux/types.h>
14
15 #define MAX_LOCKDEP_SUBCLASSES          8UL
16
17 enum lockdep_wait_type {
18         LD_WAIT_INV = 0,        /* not checked, catch all */
19
20         LD_WAIT_FREE,           /* wait free, rcu etc.. */
21         LD_WAIT_SPIN,           /* spin loops, raw_spinlock_t etc.. */
22
23 #ifdef CONFIG_PROVE_RAW_LOCK_NESTING
24         LD_WAIT_CONFIG,         /* CONFIG_PREEMPT_LOCK, spinlock_t etc.. */
25 #else
26         LD_WAIT_CONFIG = LD_WAIT_SPIN,
27 #endif
28         LD_WAIT_SLEEP,          /* sleeping locks, mutex_t etc.. */
29
30         LD_WAIT_MAX,            /* must be last */
31 };
32
33 #ifdef CONFIG_LOCKDEP
34
35 /*
36  * We'd rather not expose kernel/lockdep_states.h this wide, but we do need
37  * the total number of states... :-(
38  */
39 #define XXX_LOCK_USAGE_STATES           (1+2*4)
40
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 /*
53  * A lockdep key is associated with each lock object. For static locks we use
54  * the lock address itself as the key. Dynamically allocated lock objects can
55  * have a statically or dynamically allocated key. Dynamically allocated lock
56  * keys must be registered before being used and must be unregistered before
57  * the key memory is freed.
58  */
59 struct lockdep_subclass_key {
60         char __one_byte;
61 } __attribute__ ((__packed__));
62
63 /* hash_entry is used to keep track of dynamically allocated keys. */
64 struct lock_class_key {
65         union {
66                 struct hlist_node               hash_entry;
67                 struct lockdep_subclass_key     subkeys[MAX_LOCKDEP_SUBCLASSES];
68         };
69 };
70
71 extern struct lock_class_key __lockdep_no_validate__;
72
73 struct lock_trace;
74
75 #define LOCKSTAT_POINTS         4
76
77 /*
78  * The lock-class itself. The order of the structure members matters.
79  * reinit_class() zeroes the key member and all subsequent members.
80  */
81 struct lock_class {
82         /*
83          * class-hash:
84          */
85         struct hlist_node               hash_entry;
86
87         /*
88          * Entry in all_lock_classes when in use. Entry in free_lock_classes
89          * when not in use. Instances that are being freed are on one of the
90          * zapped_classes lists.
91          */
92         struct list_head                lock_entry;
93
94         /*
95          * These fields represent a directed graph of lock dependencies,
96          * to every node we attach a list of "forward" and a list of
97          * "backward" graph nodes.
98          */
99         struct list_head                locks_after, locks_before;
100
101         const struct lockdep_subclass_key *key;
102         unsigned int                    subclass;
103         unsigned int                    dep_gen_id;
104
105         /*
106          * IRQ/softirq usage tracking bits:
107          */
108         unsigned long                   usage_mask;
109         const struct lock_trace         *usage_traces[XXX_LOCK_USAGE_STATES];
110
111         /*
112          * Generation counter, when doing certain classes of graph walking,
113          * to ensure that we check one node only once:
114          */
115         int                             name_version;
116         const char                      *name;
117
118         short                           wait_type_inner;
119         short                           wait_type_outer;
120
121 #ifdef CONFIG_LOCK_STAT
122         unsigned long                   contention_point[LOCKSTAT_POINTS];
123         unsigned long                   contending_point[LOCKSTAT_POINTS];
124 #endif
125 } __no_randomize_layout;
126
127 #ifdef CONFIG_LOCK_STAT
128 struct lock_time {
129         s64                             min;
130         s64                             max;
131         s64                             total;
132         unsigned long                   nr;
133 };
134
135 enum bounce_type {
136         bounce_acquired_write,
137         bounce_acquired_read,
138         bounce_contended_write,
139         bounce_contended_read,
140         nr_bounce_types,
141
142         bounce_acquired = bounce_acquired_write,
143         bounce_contended = bounce_contended_write,
144 };
145
146 struct lock_class_stats {
147         unsigned long                   contention_point[LOCKSTAT_POINTS];
148         unsigned long                   contending_point[LOCKSTAT_POINTS];
149         struct lock_time                read_waittime;
150         struct lock_time                write_waittime;
151         struct lock_time                read_holdtime;
152         struct lock_time                write_holdtime;
153         unsigned long                   bounces[nr_bounce_types];
154 };
155
156 struct lock_class_stats lock_stats(struct lock_class *class);
157 void clear_lock_stats(struct lock_class *class);
158 #endif
159
160 /*
161  * Map the lock object (the lock instance) to the lock-class object.
162  * This is embedded into specific lock instances:
163  */
164 struct lockdep_map {
165         struct lock_class_key           *key;
166         struct lock_class               *class_cache[NR_LOCKDEP_CACHING_CLASSES];
167         const char                      *name;
168         short                           wait_type_outer; /* can be taken in this context */
169         short                           wait_type_inner; /* presents this context */
170 #ifdef CONFIG_LOCK_STAT
171         int                             cpu;
172         unsigned long                   ip;
173 #endif
174 };
175
176 struct pin_cookie { unsigned int val; };
177
178 #else /* !CONFIG_LOCKDEP */
179
180 /*
181  * The class key takes no space if lockdep is disabled:
182  */
183 struct lock_class_key { };
184
185 /*
186  * The lockdep_map takes no space if lockdep is disabled:
187  */
188 struct lockdep_map { };
189
190 struct pin_cookie { };
191
192 #endif /* !LOCKDEP */
193
194 #endif /* __LINUX_LOCKDEP_TYPES_H */