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