1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
/*-
* Copyright (c) 2008-2009 Stacey Son <sson@FreeBSD.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
/*
* DTrace lockstat provider definitions
*
*/
#ifndef _SYS_LOCKSTAT_H
#define _SYS_LOCKSTAT_H
#ifdef _KERNEL
/*
* Spin Locks
*/
#define LS_MTX_SPIN_LOCK_ACQUIRE 0
#define LS_MTX_SPIN_UNLOCK_RELEASE 1
#define LS_MTX_SPIN_LOCK_SPIN 2
/*
* Adaptive Locks
*/
#define LS_MTX_LOCK_ACQUIRE 3
#define LS_MTX_UNLOCK_RELEASE 4
#define LS_MTX_LOCK_SPIN 5
#define LS_MTX_LOCK_BLOCK 6
#define LS_MTX_TRYLOCK_ACQUIRE 7
/*
* Reader/Writer Locks
*/
#define LS_RW_RLOCK_ACQUIRE 8
#define LS_RW_RUNLOCK_RELEASE 9
#define LS_RW_WLOCK_ACQUIRE 10
#define LS_RW_WUNLOCK_RELEASE 11
#define LS_RW_RLOCK_SPIN 12
#define LS_RW_RLOCK_BLOCK 13
#define LS_RW_WLOCK_SPIN 14
#define LS_RW_WLOCK_BLOCK 15
#define LS_RW_TRYUPGRADE_UPGRADE 16
#define LS_RW_DOWNGRADE_DOWNGRADE 17
/*
* Shared/Exclusive Locks
*/
#define LS_SX_SLOCK_ACQUIRE 18
#define LS_SX_SUNLOCK_RELEASE 19
#define LS_SX_XLOCK_ACQUIRE 20
#define LS_SX_XUNLOCK_RELEASE 21
#define LS_SX_SLOCK_SPIN 22
#define LS_SX_SLOCK_BLOCK 23
#define LS_SX_XLOCK_SPIN 24
#define LS_SX_XLOCK_BLOCK 25
#define LS_SX_TRYUPGRADE_UPGRADE 26
#define LS_SX_DOWNGRADE_DOWNGRADE 27
/*
* Thread Locks
*/
#define LS_THREAD_LOCK_SPIN 28
/*
* Lockmanager Locks
* According to locking(9) Lockmgr locks are "Largely deprecated"
* so no support for these have been added in the lockstat provider.
*/
#define LS_NPROBES 29
#define LS_MTX_LOCK "mtx_lock"
#define LS_MTX_UNLOCK "mtx_unlock"
#define LS_MTX_SPIN_LOCK "mtx_lock_spin"
#define LS_MTX_SPIN_UNLOCK "mtx_unlock_spin"
#define LS_MTX_TRYLOCK "mtx_trylock"
#define LS_RW_RLOCK "rw_rlock"
#define LS_RW_WLOCK "rw_wlock"
#define LS_RW_RUNLOCK "rw_runlock"
#define LS_RW_WUNLOCK "rw_wunlock"
#define LS_RW_TRYUPGRADE "rw_try_upgrade"
#define LS_RW_DOWNGRADE "rw_downgrade"
#define LS_SX_SLOCK "sx_slock"
#define LS_SX_XLOCK "sx_xlock"
#define LS_SX_SUNLOCK "sx_sunlock"
#define LS_SX_XUNLOCK "sx_xunlock"
#define LS_SX_TRYUPGRADE "sx_try_upgrade"
#define LS_SX_DOWNGRADE "sx_downgrade"
#define LS_THREAD_LOCK "thread_lock"
#define LS_ACQUIRE "acquire"
#define LS_RELEASE "release"
#define LS_SPIN "spin"
#define LS_BLOCK "block"
#define LS_UPGRADE "upgrade"
#define LS_DOWNGRADE "downgrade"
#define LS_TYPE_ADAPTIVE "adaptive"
#define LS_TYPE_SPIN "spin"
#define LS_TYPE_THREAD "thread"
#define LS_TYPE_RW "rw"
#define LS_TYPE_SX "sx"
#define LSA_ACQUIRE (LS_TYPE_ADAPTIVE "-" LS_ACQUIRE)
#define LSA_RELEASE (LS_TYPE_ADAPTIVE "-" LS_RELEASE)
#define LSA_SPIN (LS_TYPE_ADAPTIVE "-" LS_SPIN)
#define LSA_BLOCK (LS_TYPE_ADAPTIVE "-" LS_BLOCK)
#define LSS_ACQUIRE (LS_TYPE_SPIN "-" LS_ACQUIRE)
#define LSS_RELEASE (LS_TYPE_SPIN "-" LS_RELEASE)
#define LSS_SPIN (LS_TYPE_SPIN "-" LS_SPIN)
#define LSR_ACQUIRE (LS_TYPE_RW "-" LS_ACQUIRE)
#define LSR_RELEASE (LS_TYPE_RW "-" LS_RELEASE)
#define LSR_BLOCK (LS_TYPE_RW "-" LS_BLOCK)
#define LSR_SPIN (LS_TYPE_RW "-" LS_SPIN)
#define LSR_UPGRADE (LS_TYPE_RW "-" LS_UPGRADE)
#define LSR_DOWNGRADE (LS_TYPE_RW "-" LS_DOWNGRADE)
#define LSX_ACQUIRE (LS_TYPE_SX "-" LS_ACQUIRE)
#define LSX_RELEASE (LS_TYPE_SX "-" LS_RELEASE)
#define LSX_BLOCK (LS_TYPE_SX "-" LS_BLOCK)
#define LSX_SPIN (LS_TYPE_SX "-" LS_SPIN)
#define LSX_UPGRADE (LS_TYPE_SX "-" LS_UPGRADE)
#define LSX_DOWNGRADE (LS_TYPE_SX "-" LS_DOWNGRADE)
#define LST_SPIN (LS_TYPE_THREAD "-" LS_SPIN)
/*
* The following must match the type definition of dtrace_probe. It is
* defined this way to avoid having to rely on CDDL code.
*/
extern uint32_t lockstat_probemap[LS_NPROBES];
typedef void (*lockstat_probe_func_t)(uint32_t, uintptr_t arg0, uintptr_t arg1,
uintptr_t arg2, uintptr_t arg3, uintptr_t arg4);
extern lockstat_probe_func_t lockstat_probe_func;
extern uint64_t lockstat_nsecs(void);
#ifdef KDTRACE_HOOKS
/*
* Macros to record lockstat probes.
*/
#define LOCKSTAT_RECORD4(probe, lp, arg1, arg2, arg3, arg4) do { \
uint32_t id; \
\
if ((id = lockstat_probemap[(probe)])) \
(*lockstat_probe_func)(id, (uintptr_t)(lp), (arg1), (arg2), \
(arg3), (arg4)); \
} while (0)
#define LOCKSTAT_RECORD(probe, lp, arg1) \
LOCKSTAT_RECORD4(probe, lp, arg1, 0, 0, 0)
#define LOCKSTAT_RECORD0(probe, lp) \
LOCKSTAT_RECORD4(probe, lp, 0, 0, 0, 0)
#define LOCKSTAT_RECORD1(probe, lp, arg1) \
LOCKSTAT_RECORD4(probe, lp, arg1, 0, 0, 0)
#define LOCKSTAT_RECORD2(probe, lp, arg1, arg2) \
LOCKSTAT_RECORD4(probe, lp, arg1, arg2, 0, 0)
#define LOCKSTAT_RECORD3(probe, lp, arg1, arg2, arg3) \
LOCKSTAT_RECORD4(probe, lp, arg1, arg2, arg3, 0)
#define LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(probe, lp, c, wt, f, l) do { \
uint32_t id; \
\
lock_profile_obtain_lock_success(&(lp)->lock_object, c, wt, f, l); \
if ((id = lockstat_probemap[(probe)])) \
(*lockstat_probe_func)(id, (uintptr_t)(lp), 0, 0, 0, 0); \
} while (0)
#define LOCKSTAT_PROFILE_RELEASE_LOCK(probe, lp) do { \
uint32_t id; \
\
lock_profile_release_lock(&(lp)->lock_object); \
if ((id = lockstat_probemap[(probe)])) \
(*lockstat_probe_func)(id, (uintptr_t)(lp), 0, 0, 0, 0); \
} while (0)
#else /* !KDTRACE_HOOKS */
#define LOCKSTAT_RECORD(probe, lp, arg1)
#define LOCKSTAT_RECORD0(probe, lp)
#define LOCKSTAT_RECORD1(probe, lp, arg1)
#define LOCKSTAT_RECORD2(probe, lp, arg1, arg2)
#define LOCKSTAT_RECORD3(probe, lp, arg1, arg2, arg3)
#define LOCKSTAT_RECORD4(probe, lp, arg1, arg2, arg3, arg4)
#define LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(probe, lp, c, wt, f, l) \
lock_profile_obtain_lock_success(&(lp)->lock_object, c, wt, f, l)
#define LOCKSTAT_PROFILE_RELEASE_LOCK(probe, lp) \
lock_profile_release_lock(&(lp)->lock_object)
#endif /* !KDTRACE_HOOKS */
#endif /* _KERNEL */
#endif /* _SYS_LOCKSTAT_H */
|