xref: /illumos-gate/usr/src/uts/common/sys/lockstat.h (revision 7c478bd9)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1997-2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_LOCKSTAT_H
28 #define	_SYS_LOCKSTAT_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/dtrace.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 #define	LS_MUTEX_ENTER_ACQUIRE		0
39 #define	LS_MUTEX_ENTER_BLOCK		1
40 #define	LS_MUTEX_ENTER_SPIN		2
41 #define	LS_MUTEX_EXIT_RELEASE		3
42 #define	LS_MUTEX_DESTROY_RELEASE	4
43 #define	LS_MUTEX_TRYENTER_ACQUIRE	5
44 #define	LS_LOCK_SET_ACQUIRE		6
45 #define	LS_LOCK_SET_SPIN		7
46 #define	LS_LOCK_SET_SPL_ACQUIRE		8
47 #define	LS_LOCK_SET_SPL_SPIN		9
48 #define	LS_LOCK_TRY_ACQUIRE		10
49 #define	LS_LOCK_CLEAR_RELEASE		11
50 #define	LS_LOCK_CLEAR_SPLX_RELEASE	12
51 #define	LS_CLOCK_UNLOCK_RELEASE		13
52 #define	LS_RW_ENTER_ACQUIRE		14
53 #define	LS_RW_ENTER_BLOCK		15
54 #define	LS_RW_EXIT_RELEASE		16
55 #define	LS_RW_TRYENTER_ACQUIRE		17
56 #define	LS_RW_TRYUPGRADE_UPGRADE	18
57 #define	LS_RW_DOWNGRADE_DOWNGRADE	19
58 #define	LS_THREAD_LOCK_ACQUIRE		20
59 #define	LS_THREAD_LOCK_SPIN		21
60 #define	LS_THREAD_LOCK_HIGH_ACQUIRE	22
61 #define	LS_THREAD_LOCK_HIGH_SPIN	23
62 #define	LS_TURNSTILE_INTERLOCK_SPIN	24
63 #define	LS_NPROBES			25
64 
65 #define	LS_MUTEX_ENTER			"mutex_enter"
66 #define	LS_MUTEX_EXIT			"mutex_exit"
67 #define	LS_MUTEX_DESTROY		"mutex_destroy"
68 #define	LS_MUTEX_TRYENTER		"mutex_tryenter"
69 #define	LS_LOCK_SET			"lock_set"
70 #define	LS_LOCK_SET_SPL			"lock_set_spl"
71 #define	LS_LOCK_TRY			"lock_try"
72 #define	LS_LOCK_CLEAR			"lock_clear"
73 #define	LS_LOCK_CLEAR_SPLX		"lock_clear_splx"
74 #define	LS_CLOCK_UNLOCK			"CLOCK_UNLOCK"
75 #define	LS_RW_ENTER			"rw_enter"
76 #define	LS_RW_EXIT			"rw_exit"
77 #define	LS_RW_TRYENTER			"rw_tryenter"
78 #define	LS_RW_TRYUPGRADE		"rw_tryupgrade"
79 #define	LS_RW_DOWNGRADE			"rw_downgrade"
80 #define	LS_THREAD_LOCK			"thread_lock"
81 #define	LS_THREAD_LOCK_HIGH		"thread_lock_high"
82 
83 #define	LS_ACQUIRE			"acquire"
84 #define	LS_RELEASE			"release"
85 #define	LS_SPIN				"spin"
86 #define	LS_BLOCK			"block"
87 #define	LS_UPGRADE			"upgrade"
88 #define	LS_DOWNGRADE			"downgrade"
89 
90 #define	LS_TYPE_ADAPTIVE		"adaptive"
91 #define	LS_TYPE_SPIN			"spin"
92 #define	LS_TYPE_THREAD			"thread"
93 #define	LS_TYPE_RW			"rw"
94 
95 #define	LSA_ACQUIRE			(LS_TYPE_ADAPTIVE "-" LS_ACQUIRE)
96 #define	LSA_RELEASE			(LS_TYPE_ADAPTIVE "-" LS_RELEASE)
97 #define	LSA_SPIN			(LS_TYPE_ADAPTIVE "-" LS_SPIN)
98 #define	LSA_BLOCK			(LS_TYPE_ADAPTIVE "-" LS_BLOCK)
99 #define	LSS_ACQUIRE			(LS_TYPE_SPIN "-" LS_ACQUIRE)
100 #define	LSS_RELEASE			(LS_TYPE_SPIN "-" LS_RELEASE)
101 #define	LSS_SPIN			(LS_TYPE_SPIN "-" LS_SPIN)
102 #define	LSR_ACQUIRE			(LS_TYPE_RW "-" LS_ACQUIRE)
103 #define	LSR_RELEASE			(LS_TYPE_RW "-" LS_RELEASE)
104 #define	LSR_BLOCK			(LS_TYPE_RW "-" LS_BLOCK)
105 #define	LSR_UPGRADE			(LS_TYPE_RW "-" LS_UPGRADE)
106 #define	LSR_DOWNGRADE			(LS_TYPE_RW "-" LS_DOWNGRADE)
107 #define	LST_SPIN			(LS_TYPE_THREAD "-" LS_SPIN)
108 
109 #ifndef _ASM
110 
111 #include <sys/types.h>
112 #include <sys/inttypes.h>
113 #include <sys/systm.h>
114 #include <sys/atomic.h>
115 
116 #ifdef _KERNEL
117 
118 /*
119  * Platform-independent kernel support for the lockstat driver.
120  */
121 extern dtrace_id_t lockstat_probemap[LS_NPROBES];
122 extern void (*lockstat_probe)(dtrace_id_t, uintptr_t, uintptr_t,
123     uintptr_t, uintptr_t, uintptr_t);
124 
125 extern int lockstat_active_threads(void);
126 extern int lockstat_depth(void);
127 extern void lockstat_hot_patch(void);
128 
129 /*
130  * Macros to record lockstat probes.
131  */
132 #define	LOCKSTAT_RECORD4(probe, lp, arg0, arg1, arg2, arg3)		\
133 	if (lockstat_probemap[(probe)]) {				\
134 		dtrace_id_t id;						\
135 		curthread->t_lockstat++;				\
136 		membar_enter();						\
137 		if ((id = lockstat_probemap[(probe)]) != 0)		\
138 			(*lockstat_probe)(id, (uintptr_t)(lp), (arg0),	\
139 			    (arg1), (arg2), (arg3));			\
140 		curthread->t_lockstat--;				\
141 	}
142 
143 #define	LOCKSTAT_RECORD(probe, lp, arg)	\
144 	LOCKSTAT_RECORD4(probe, lp, arg, 0, 0, 0)
145 
146 #define	LOCKSTAT_RECORD0(probe, lp)	\
147 	LOCKSTAT_RECORD4(probe, lp, 0, 0, 0, 0)
148 
149 #endif /* _KERNEL */
150 
151 #endif /* _ASM */
152 
153 #ifdef	__cplusplus
154 }
155 #endif
156 
157 #endif	/* _SYS_LOCKSTAT_H */
158