2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2008-2009 Stacey Son <sson@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * DTrace lockstat provider definitions
34 #ifndef _SYS_LOCKSTAT_H
35 #define _SYS_LOCKSTAT_H
39 #include <sys/param.h>
40 #include <sys/queue.h>
43 SDT_PROVIDER_DECLARE(lockstat);
45 SDT_PROBE_DECLARE(lockstat, , , adaptive__acquire);
46 SDT_PROBE_DECLARE(lockstat, , , adaptive__release);
47 SDT_PROBE_DECLARE(lockstat, , , adaptive__spin);
48 SDT_PROBE_DECLARE(lockstat, , , adaptive__block);
50 SDT_PROBE_DECLARE(lockstat, , , spin__acquire);
51 SDT_PROBE_DECLARE(lockstat, , , spin__release);
52 SDT_PROBE_DECLARE(lockstat, , , spin__spin);
54 SDT_PROBE_DECLARE(lockstat, , , rw__acquire);
55 SDT_PROBE_DECLARE(lockstat, , , rw__release);
56 SDT_PROBE_DECLARE(lockstat, , , rw__block);
57 SDT_PROBE_DECLARE(lockstat, , , rw__spin);
58 SDT_PROBE_DECLARE(lockstat, , , rw__upgrade);
59 SDT_PROBE_DECLARE(lockstat, , , rw__downgrade);
61 SDT_PROBE_DECLARE(lockstat, , , sx__acquire);
62 SDT_PROBE_DECLARE(lockstat, , , sx__release);
63 SDT_PROBE_DECLARE(lockstat, , , sx__block);
64 SDT_PROBE_DECLARE(lockstat, , , sx__spin);
65 SDT_PROBE_DECLARE(lockstat, , , sx__upgrade);
66 SDT_PROBE_DECLARE(lockstat, , , sx__downgrade);
68 SDT_PROBE_DECLARE(lockstat, , , lockmgr__acquire);
69 SDT_PROBE_DECLARE(lockstat, , , lockmgr__release);
70 SDT_PROBE_DECLARE(lockstat, , , lockmgr__disown);
71 SDT_PROBE_DECLARE(lockstat, , , lockmgr__block);
72 SDT_PROBE_DECLARE(lockstat, , , lockmgr__upgrade);
73 SDT_PROBE_DECLARE(lockstat, , , lockmgr__downgrade);
75 SDT_PROBE_DECLARE(lockstat, , , thread__spin);
77 #define LOCKSTAT_WRITER 0
78 #define LOCKSTAT_READER 1
80 extern volatile bool lockstat_enabled;
84 #define LOCKSTAT_RECORD0(probe, lp) \
85 SDT_PROBE1(lockstat, , , probe, lp)
87 #define LOCKSTAT_RECORD1(probe, lp, arg1) \
88 SDT_PROBE2(lockstat, , , probe, lp, arg1)
90 #define LOCKSTAT_RECORD2(probe, lp, arg1, arg2) \
91 SDT_PROBE3(lockstat, , , probe, lp, arg1, arg2)
93 #define LOCKSTAT_RECORD3(probe, lp, arg1, arg2, arg3) \
94 SDT_PROBE4(lockstat, , , probe, lp, arg1, arg2, arg3)
96 #define LOCKSTAT_RECORD4(probe, lp, arg1, arg2, arg3, arg4) \
97 SDT_PROBE5(lockstat, , , probe, lp, arg1, arg2, arg3, arg4)
99 #define LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(probe, lp, c, wt, f, l) do { \
100 lock_profile_obtain_lock_success(&(lp)->lock_object, c, wt, f, l); \
101 LOCKSTAT_RECORD0(probe, lp); \
104 #define LOCKSTAT_PROFILE_OBTAIN_RWLOCK_SUCCESS(probe, lp, c, wt, f, l, a) do { \
105 lock_profile_obtain_lock_success(&(lp)->lock_object, c, wt, f, l); \
106 LOCKSTAT_RECORD1(probe, lp, a); \
109 #define LOCKSTAT_PROFILE_RELEASE_LOCK(probe, lp) do { \
110 lock_profile_release_lock(&(lp)->lock_object); \
111 LOCKSTAT_RECORD0(probe, lp); \
114 #define LOCKSTAT_PROFILE_RELEASE_RWLOCK(probe, lp, a) do { \
115 lock_profile_release_lock(&(lp)->lock_object); \
116 LOCKSTAT_RECORD1(probe, lp, a); \
119 #define LOCKSTAT_PROFILE_ENABLED(probe) __predict_false(lockstat_enabled)
122 uint64_t lockstat_nsecs(struct lock_object *);
124 #else /* !KDTRACE_HOOKS */
126 #define LOCKSTAT_RECORD0(probe, lp)
127 #define LOCKSTAT_RECORD1(probe, lp, arg1)
128 #define LOCKSTAT_RECORD2(probe, lp, arg1, arg2)
129 #define LOCKSTAT_RECORD3(probe, lp, arg1, arg2, arg3)
130 #define LOCKSTAT_RECORD4(probe, lp, arg1, arg2, arg3, arg4)
132 #define LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(probe, lp, c, wt, f, l) \
133 lock_profile_obtain_lock_success(&(lp)->lock_object, c, wt, f, l)
135 #define LOCKSTAT_PROFILE_OBTAIN_RWLOCK_SUCCESS(probe, lp, c, wt, f, l, a) \
136 LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(probe, lp, c, wt, f, l)
138 #define LOCKSTAT_PROFILE_RELEASE_LOCK(probe, lp) \
139 lock_profile_release_lock(&(lp)->lock_object)
141 #define LOCKSTAT_PROFILE_RELEASE_RWLOCK(probe, lp, a) \
142 LOCKSTAT_PROFILE_RELEASE_LOCK(probe, lp)
144 #define LOCKSTAT_PROFILE_ENABLED(probe) 0
146 #endif /* !KDTRACE_HOOKS */
149 #endif /* _SYS_LOCKSTAT_H */