| 1 | /*- |
| 2 | * SPDX-License-Identifier: BSD-2-Clause |
| 3 | * |
| 4 | * Copyright (c) 2008-2009 Stacey Son <sson@FreeBSD.org> |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions |
| 8 | * are met: |
| 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. |
| 14 | * |
| 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 |
| 25 | * SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | /* |
| 29 | * DTrace lockstat provider definitions |
| 30 | */ |
| 31 | |
| 32 | #ifndef _SYS_LOCKSTAT_H |
| 33 | #define	_SYS_LOCKSTAT_H |
| 34 | |
| 35 | #ifdef _KERNEL |
| 36 | |
| 37 | #include <sys/param.h> |
| 38 | #include <sys/queue.h> |
| 39 | #include <sys/sdt.h> |
| 40 | |
| 41 | SDT_PROVIDER_DECLARE(lockstat); |
| 42 | |
| 43 | SDT_PROBE_DECLARE(lockstat, , , adaptive__acquire); |
| 44 | SDT_PROBE_DECLARE(lockstat, , , adaptive__release); |
| 45 | SDT_PROBE_DECLARE(lockstat, , , adaptive__spin); |
| 46 | SDT_PROBE_DECLARE(lockstat, , , adaptive__block); |
| 47 | |
| 48 | SDT_PROBE_DECLARE(lockstat, , , spin__acquire); |
| 49 | SDT_PROBE_DECLARE(lockstat, , , spin__release); |
| 50 | SDT_PROBE_DECLARE(lockstat, , , spin__spin); |
| 51 | |
| 52 | SDT_PROBE_DECLARE(lockstat, , , rw__acquire); |
| 53 | SDT_PROBE_DECLARE(lockstat, , , rw__release); |
| 54 | SDT_PROBE_DECLARE(lockstat, , , rw__block); |
| 55 | SDT_PROBE_DECLARE(lockstat, , , rw__spin); |
| 56 | SDT_PROBE_DECLARE(lockstat, , , rw__upgrade); |
| 57 | SDT_PROBE_DECLARE(lockstat, , , rw__downgrade); |
| 58 | |
| 59 | SDT_PROBE_DECLARE(lockstat, , , sx__acquire); |
| 60 | SDT_PROBE_DECLARE(lockstat, , , sx__release); |
| 61 | SDT_PROBE_DECLARE(lockstat, , , sx__block); |
| 62 | SDT_PROBE_DECLARE(lockstat, , , sx__spin); |
| 63 | SDT_PROBE_DECLARE(lockstat, , , sx__upgrade); |
| 64 | SDT_PROBE_DECLARE(lockstat, , , sx__downgrade); |
| 65 | |
| 66 | SDT_PROBE_DECLARE(lockstat, , , lockmgr__acquire); |
| 67 | SDT_PROBE_DECLARE(lockstat, , , lockmgr__release); |
| 68 | SDT_PROBE_DECLARE(lockstat, , , lockmgr__disown); |
| 69 | SDT_PROBE_DECLARE(lockstat, , , lockmgr__block); |
| 70 | SDT_PROBE_DECLARE(lockstat, , , lockmgr__upgrade); |
| 71 | SDT_PROBE_DECLARE(lockstat, , , lockmgr__downgrade); |
| 72 | |
| 73 | SDT_PROBE_DECLARE(lockstat, , , thread__spin); |
| 74 | |
| 75 | #define	LOCKSTAT_WRITER		0 |
| 76 | #define	LOCKSTAT_READER		1 |
| 77 | |
| 78 | extern volatile bool lockstat_enabled; |
| 79 | |
| 80 | #ifdef KDTRACE_HOOKS |
| 81 | |
| 82 | #define	LOCKSTAT_RECORD0(probe, lp)					\ |
| 83 | 	SDT_PROBE1(lockstat, , , probe, lp) |
| 84 | |
| 85 | #define	LOCKSTAT_RECORD1(probe, lp, arg1)				\ |
| 86 | 	SDT_PROBE2(lockstat, , , probe, lp, arg1) |
| 87 | |
| 88 | #define	LOCKSTAT_RECORD2(probe, lp, arg1, arg2)				\ |
| 89 | 	SDT_PROBE3(lockstat, , , probe, lp, arg1, arg2) |
| 90 | |
| 91 | #define	LOCKSTAT_RECORD3(probe, lp, arg1, arg2, arg3)			\ |
| 92 | 	SDT_PROBE4(lockstat, , , probe, lp, arg1, arg2, arg3) |
| 93 | |
| 94 | #define	LOCKSTAT_RECORD4(probe, lp, arg1, arg2, arg3, arg4)		\ |
| 95 | 	SDT_PROBE5(lockstat, , , probe, lp, arg1, arg2, arg3, arg4) |
| 96 | |
| 97 | #define	LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(probe, lp, c, wt, f, l) do { \ |
| 98 | 	lock_profile_obtain_lock_success(&(lp)->lock_object, false, c, wt, f, l); \ |
| 99 | 	LOCKSTAT_RECORD0(probe, lp);					\ |
| 100 | } while (0) |
| 101 | |
| 102 | #define	LOCKSTAT_PROFILE_OBTAIN_SPIN_LOCK_SUCCESS(probe, lp, c, wt, f, l) do { \ |
| 103 | 	lock_profile_obtain_lock_success(&(lp)->lock_object, true, c, wt, f, l); \ |
| 104 | 	LOCKSTAT_RECORD0(probe, lp);					\ |
| 105 | } while (0) |
| 106 | |
| 107 | #define	LOCKSTAT_PROFILE_OBTAIN_RWLOCK_SUCCESS(probe, lp, c, wt, f, l, a) do { \ |
| 108 | 	lock_profile_obtain_lock_success(&(lp)->lock_object, false, c, wt, f, l); \ |
| 109 | 	LOCKSTAT_RECORD1(probe, lp, a);					\ |
| 110 | } while (0) |
| 111 | |
| 112 | #define	LOCKSTAT_PROFILE_RELEASE_LOCK(probe, lp) do {			\ |
| 113 | 	lock_profile_release_lock(&(lp)->lock_object, false);		\ |
| 114 | 	LOCKSTAT_RECORD0(probe, lp);					\ |
| 115 | } while (0) |
| 116 | |
| 117 | #define	LOCKSTAT_PROFILE_RELEASE_SPIN_LOCK(probe, lp) do {		\ |
| 118 | 	lock_profile_release_lock(&(lp)->lock_object, true);		\ |
| 119 | 	LOCKSTAT_RECORD0(probe, lp);					\ |
| 120 | } while (0) |
| 121 | |
| 122 | #define	LOCKSTAT_PROFILE_RELEASE_RWLOCK(probe, lp, a) do {		\ |
| 123 | 	lock_profile_release_lock(&(lp)->lock_object, false);		\ |
| 124 | 	LOCKSTAT_RECORD1(probe, lp, a);					\ |
| 125 | } while (0) |
| 126 | |
| 127 | #define	LOCKSTAT_PROFILE_ENABLED(probe)		__predict_false(lockstat_enabled) |
| 128 | |
| 129 | struct lock_object; |
| 130 | uint64_t lockstat_nsecs(struct lock_object *); |
| 131 | |
| 132 | #else /* !KDTRACE_HOOKS */ |
| 133 | |
| 134 | #define	LOCKSTAT_RECORD0(probe, lp) |
| 135 | #define	LOCKSTAT_RECORD1(probe, lp, arg1) |
| 136 | #define	LOCKSTAT_RECORD2(probe, lp, arg1, arg2) |
| 137 | #define	LOCKSTAT_RECORD3(probe, lp, arg1, arg2, arg3) |
| 138 | #define	LOCKSTAT_RECORD4(probe, lp, arg1, arg2, arg3, arg4) |
| 139 | |
| 140 | #define	LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(probe, lp, c, wt, f, l)	\ |
| 141 | 	lock_profile_obtain_lock_success(&(lp)->lock_object, false, c, wt, f, l) |
| 142 | |
| 143 | #define	LOCKSTAT_PROFILE_OBTAIN_SPIN_LOCK_SUCCESS(probe, lp, c, wt, f, l)	\ |
| 144 | 	lock_profile_obtain_lock_success(&(lp)->lock_object, true, c, wt, f, l) |
| 145 | |
| 146 | #define	LOCKSTAT_PROFILE_OBTAIN_RWLOCK_SUCCESS(probe, lp, c, wt, f, l, a) \ |
| 147 | 	LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(probe, lp, c, wt, f, l) |
| 148 | |
| 149 | #define	LOCKSTAT_PROFILE_RELEASE_LOCK(probe, lp) 			\ |
| 150 | 	lock_profile_release_lock(&(lp)->lock_object, false) |
| 151 | |
| 152 | #define	LOCKSTAT_PROFILE_RELEASE_SPIN_LOCK(probe, lp) 			\ |
| 153 | 	lock_profile_release_lock(&(lp)->lock_object, true) |
| 154 | |
| 155 | #define	LOCKSTAT_PROFILE_RELEASE_RWLOCK(probe, lp, a) 			\ |
| 156 | 	LOCKSTAT_PROFILE_RELEASE_LOCK(probe, lp) |
| 157 | |
| 158 | #define	LOCKSTAT_PROFILE_ENABLED(probe)		0 |
| 159 | |
| 160 | #endif /* !KDTRACE_HOOKS */ |
| 161 | |
| 162 | #endif /* _KERNEL */ |
| 163 | #endif /* _SYS_LOCKSTAT_H */ |