1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Runtime locking correctness validator
5 * Copyright (C) 2006,2007 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
6 * Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra
8 * see Documentation/locking/lockdep-design.rst for more details.
10 #ifndef __LINUX_LOCKDEP_TYPES_H
11 #define __LINUX_LOCKDEP_TYPES_H
13 #include <linux/types.h>
15 #define MAX_LOCKDEP_SUBCLASSES 8UL
17 enum lockdep_wait_type
{
18 LD_WAIT_INV
= 0, /* not checked, catch all */
20 LD_WAIT_FREE
, /* wait free, rcu etc.. */
21 LD_WAIT_SPIN
, /* spin loops, raw_spinlock_t etc.. */
23 #ifdef CONFIG_PROVE_RAW_LOCK_NESTING
24 LD_WAIT_CONFIG
, /* CONFIG_PREEMPT_LOCK, spinlock_t etc.. */
26 LD_WAIT_CONFIG
= LD_WAIT_SPIN
,
28 LD_WAIT_SLEEP
, /* sleeping locks, mutex_t etc.. */
30 LD_WAIT_MAX
, /* must be last */
33 enum lockdep_lock_type
{
34 LD_LOCK_NORMAL
= 0, /* normal, catch all */
35 LD_LOCK_PERCPU
, /* percpu */
42 * We'd rather not expose kernel/lockdep_states.h this wide, but we do need
43 * the total number of states... :-(
45 * XXX_LOCK_USAGE_STATES is the number of lines in lockdep_states.h, for each
46 * of those we generates 4 states, Additionally we report on USED and USED_READ.
48 #define XXX_LOCK_USAGE_STATES 2
49 #define LOCK_TRACE_STATES (XXX_LOCK_USAGE_STATES*4 + 2)
52 * NR_LOCKDEP_CACHING_CLASSES ... Number of classes
53 * cached in the instance of lockdep_map
55 * Currently main class (subclass == 0) and single depth subclass
56 * are cached in lockdep_map. This optimization is mainly targeting
57 * on rq->lock. double_rq_lock() acquires this highly competitive with
60 #define NR_LOCKDEP_CACHING_CLASSES 2
63 * A lockdep key is associated with each lock object. For static locks we use
64 * the lock address itself as the key. Dynamically allocated lock objects can
65 * have a statically or dynamically allocated key. Dynamically allocated lock
66 * keys must be registered before being used and must be unregistered before
67 * the key memory is freed.
69 struct lockdep_subclass_key
{
71 } __attribute__ ((__packed__
));
73 /* hash_entry is used to keep track of dynamically allocated keys. */
74 struct lock_class_key
{
76 struct hlist_node hash_entry
;
77 struct lockdep_subclass_key subkeys
[MAX_LOCKDEP_SUBCLASSES
];
81 extern struct lock_class_key __lockdep_no_validate__
;
85 #define LOCKSTAT_POINTS 4
88 * The lock-class itself. The order of the structure members matters.
89 * reinit_class() zeroes the key member and all subsequent members.
95 struct hlist_node hash_entry
;
98 * Entry in all_lock_classes when in use. Entry in free_lock_classes
99 * when not in use. Instances that are being freed are on one of the
100 * zapped_classes lists.
102 struct list_head lock_entry
;
105 * These fields represent a directed graph of lock dependencies,
106 * to every node we attach a list of "forward" and a list of
107 * "backward" graph nodes.
109 struct list_head locks_after
, locks_before
;
111 const struct lockdep_subclass_key
*key
;
112 unsigned int subclass
;
113 unsigned int dep_gen_id
;
116 * IRQ/softirq usage tracking bits:
118 unsigned long usage_mask
;
119 const struct lock_trace
*usage_traces
[LOCK_TRACE_STATES
];
122 * Generation counter, when doing certain classes of graph walking,
123 * to ensure that we check one node only once:
133 #ifdef CONFIG_LOCK_STAT
134 unsigned long contention_point
[LOCKSTAT_POINTS
];
135 unsigned long contending_point
[LOCKSTAT_POINTS
];
137 } __no_randomize_layout
;
139 #ifdef CONFIG_LOCK_STAT
148 bounce_acquired_write
,
149 bounce_acquired_read
,
150 bounce_contended_write
,
151 bounce_contended_read
,
154 bounce_acquired
= bounce_acquired_write
,
155 bounce_contended
= bounce_contended_write
,
158 struct lock_class_stats
{
159 unsigned long contention_point
[LOCKSTAT_POINTS
];
160 unsigned long contending_point
[LOCKSTAT_POINTS
];
161 struct lock_time read_waittime
;
162 struct lock_time write_waittime
;
163 struct lock_time read_holdtime
;
164 struct lock_time write_holdtime
;
165 unsigned long bounces
[nr_bounce_types
];
168 struct lock_class_stats
lock_stats(struct lock_class
*class);
169 void clear_lock_stats(struct lock_class
*class);
173 * Map the lock object (the lock instance) to the lock-class object.
174 * This is embedded into specific lock instances:
177 struct lock_class_key
*key
;
178 struct lock_class
*class_cache
[NR_LOCKDEP_CACHING_CLASSES
];
180 u8 wait_type_outer
; /* can be taken in this context */
181 u8 wait_type_inner
; /* presents this context */
184 #ifdef CONFIG_LOCK_STAT
190 struct pin_cookie
{ unsigned int val
; };
192 #else /* !CONFIG_LOCKDEP */
195 * The class key takes no space if lockdep is disabled:
197 struct lock_class_key
{ };
200 * The lockdep_map takes no space if lockdep is disabled:
202 struct lockdep_map
{ };
204 struct pin_cookie
{ };
206 #endif /* !LOCKDEP */
208 #endif /* __LINUX_LOCKDEP_TYPES_H */