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