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