forked from apple/darwin-xnu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lockstat.h
218 lines (180 loc) · 6.41 KB
/
lockstat.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1997-2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _SYS_LOCKSTAT_H
#define _SYS_LOCKSTAT_H
#endif
/* #pragma ident "@(#)lockstat.h 1.6 05/06/08 SMI" */
#ifdef __cplusplus
extern "C" {
#endif
/*
* Spin locks - we have less variants
*/
#define LS_LCK_SPIN_LOCK_ACQUIRE 0
#define LS_LCK_SPIN_LOCK_SPIN 1
#define LS_LCK_SPIN_UNLOCK_RELEASE 2
/*
* Mutexes can also have interlock-spin events, which are
* unique to our lock implementation.
*/
#define LS_LCK_MTX_LOCK_ACQUIRE 3
#define LS_LCK_MTX_LOCK_BLOCK 5
#define LS_LCK_MTX_LOCK_SPIN 6
#define LS_LCK_MTX_LOCK_ILK_SPIN 7
#define LS_LCK_MTX_TRY_LOCK_ACQUIRE 8
#define LS_LCK_MTX_TRY_SPIN_LOCK_ACQUIRE 9
#define LS_LCK_MTX_UNLOCK_RELEASE 10
#define LS_LCK_MTX_LOCK_SPIN_ACQUIRE 39
/*
* Provide a parallel set for indirect mutexes
*/
#define LS_LCK_MTX_EXT_LOCK_ACQUIRE 17
#define LS_LCK_MTX_EXT_LOCK_BLOCK 18
#define LS_LCK_MTX_EXT_LOCK_SPIN 19
#define LS_LCK_MTX_EXT_LOCK_ILK_SPIN 20
#define LS_LCK_MTX_TRY_EXT_LOCK_ACQUIRE 21
#define LS_LCK_MTX_EXT_UNLOCK_RELEASE 22
/*
* Our reader-writer locks support a blocking upgrade primitive, as
* well as the possibility of spinning on the interlock.
*/
#define LS_LCK_RW_LOCK_SHARED_ACQUIRE 23
#define LS_LCK_RW_LOCK_SHARED_BLOCK 24
#define LS_LCK_RW_LOCK_SHARED_SPIN 25
#define LS_LCK_RW_LOCK_EXCL_ACQUIRE 26
#define LS_LCK_RW_LOCK_EXCL_BLOCK 27
#define LS_LCK_RW_LOCK_EXCL_SPIN 28
#define LS_LCK_RW_DONE_RELEASE 29
#define LS_LCK_RW_TRY_LOCK_SHARED_ACQUIRE 30
#define LS_LCK_RW_TRY_LOCK_SHARED_SPIN 31
#define LS_LCK_RW_TRY_LOCK_EXCL_ACQUIRE 32
#define LS_LCK_RW_TRY_LOCK_EXCL_ILK_SPIN 33
#define LS_LCK_RW_LOCK_SHARED_TO_EXCL_UPGRADE 34
#define LS_LCK_RW_LOCK_SHARED_TO_EXCL_SPIN 35
#define LS_LCK_RW_LOCK_SHARED_TO_EXCL_BLOCK 36
#define LS_LCK_RW_LOCK_EXCL_TO_SHARED_DOWNGRADE 37
#define LS_LCK_RW_LOCK_EXCL_TO_SHARED_ILK_SPIN 38
#define LS_NPROBES 40
#define LS_LCK_INVALID LS_NPROBES
/*
* Name the various locking functions...
*/
#define LS_LCK_MTX_LOCK "lck_mtx_lock"
#define LS_LCK_MTX_SPIN_LOCK "lck_mtx_spin_lock"
#define LS_LCK_MTX_UNLOCK "lck_mtx_unlock"
#define LS_LCK_MTX_TRY_LOCK "lck_mtx_try_lock"
#define LS_LCK_MTX_TRY_SPIN_LOCK "lck_mtx_try_spin_lock"
#define LS_LCK_MTX_EXT_LOCK "lck_mtx_ext_lock"
#define LS_LCK_MTX_EXT_UNLOCK "lck_mtx_ext_unlock"
#define LS_LCK_MTX_EXT_TRY_LOCK "lck_mtx_ext_try_lock"
#define LS_LCK_MTX_LOCK_SPIN_LOCK "lck_mtx_lock_spin"
#define LS_LCK_SPIN_LOCK "lck_spin_lock"
#define LS_LCK_SPIN_TRY_LOCK "lck_spin_try_lock"
#define LS_LCK_SPIN_UNLOCK "lck_spin_unlock"
#define LS_LCK_RW_LOCK_SHARED "lck_rw_lock_shared"
#define LS_LCK_RW_LOCK_EXCL "lck_rw_lock_exclusive"
#define LS_LCK_RW_DONE "lck_rw_done"
#define LS_LCK_RW_TRY_LOCK_EXCL "lck_rw_try_lock_exclusive"
#define LS_LCK_RW_TRY_LOCK_SHARED "lck_rw_try_lock_shared"
#define LS_LCK_RW_LOCK_SHARED_TO_EXCL "lck_rw_shared_to_exclusive"
#define LS_LCK_RW_LOCK_EXCL_TO_SHARED "lck_rw_exclusive_to_shared"
#define LS_ACQUIRE "acquire"
#define LS_RELEASE "release"
#define LS_SPIN "spin"
#define LS_BLOCK "block"
#define LS_UPGRADE "upgrade"
#define LS_DOWNGRADE "downgrade"
#define LS_TYPE_ADAPTIVE "adaptive"
#define LS_TYPE_SPIN "spin"
#define LS_TYPE_ILK "interlock" /* OS X only */
#define LS_TYPE_THREAD "thread" /* Solaris only */
#define LS_TYPE_RW "rw"
#define LS_TYPE_RWUPGRADE "rwupgrade" /* OS X only */
#define LSA_ACQUIRE (LS_TYPE_ADAPTIVE "-" LS_ACQUIRE)
#define LSA_RELEASE (LS_TYPE_ADAPTIVE "-" LS_RELEASE)
#define LSA_SPIN (LS_TYPE_ADAPTIVE "-" LS_SPIN)
#define LSA_BLOCK (LS_TYPE_ADAPTIVE "-" LS_BLOCK)
#define LSA_ILK_SPIN (LS_TYPE_ILK "-" LS_SPIN)
#define LSS_ACQUIRE (LS_TYPE_SPIN "-" LS_ACQUIRE)
#define LSS_RELEASE (LS_TYPE_SPIN "-" LS_RELEASE)
#define LSS_SPIN (LS_TYPE_SPIN "-" LS_SPIN)
#define LSR_ACQUIRE (LS_TYPE_RW "-" LS_ACQUIRE)
#define LSR_RELEASE (LS_TYPE_RW "-" LS_RELEASE)
#define LSR_BLOCK (LS_TYPE_RW "-" LS_BLOCK)
#define LSR_SPIN (LS_TYPE_RW "-" LS_SPIN)
#define LSR_UPGRADE (LS_TYPE_RW "-" LS_UPGRADE)
#define LSR_UPGRADE_BLOCK (LS_TYPE_RWUPGRADE "-" LS_BLOCK)
#define LSR_DOWNGRADE (LS_TYPE_RW "-" LS_DOWNGRADE)
#define LST_SPIN (LS_TYPE_THREAD "-" LS_SPIN)
#ifndef _ASM
#include <stdint.h>
#ifdef KERNEL
#ifndef _KERNEL
#define _KERNEL /* Solaris vs. Darwin */
#endif
/*
* Platform-independent kernel support for the lockstat driver.
*/
#if defined(NEED_DTRACE_DEFS)
typedef uint32_t dtrace_id_t; /* probe identifier - also in dtrace.h! */
typedef uint64_t u_longlong_t; /* also in dtrace.h! */
#endif
extern dtrace_id_t lockstat_probemap[LS_NPROBES];
extern void (*lockstat_probe)(dtrace_id_t, uint64_t, uint64_t,
uint64_t, uint64_t, uint64_t);
#ifdef _KERNEL
#if CONFIG_DTRACE
extern void (lockstat_probe_wrapper)(int, uintptr_t, int);
/*
* Macros to record lockstat probes.
*/
#define LOCKSTAT_RECORD4(probe, lp, arg0, arg1, arg2, arg3) \
{ \
dtrace_id_t id; \
if ((id = lockstat_probemap[(probe)])) { \
(*lockstat_probe)(id, (uintptr_t)(lp), (arg0), \
(arg1), (arg2), (arg3)); \
} \
}
#define LOCKSTAT_RECORD2(probe, lp, arg1, arg2) \
LOCKSTAT_RECORD4(probe, lp, arg1, arg2, 0, 0)
#define LOCKSTAT_RECORD(probe, lp, arg) \
LOCKSTAT_RECORD4(probe, lp, arg, 0, 0, 0)
#define LOCKSTAT_RECORD0(probe, lp) \
LOCKSTAT_RECORD4(probe, lp, 0, 0, 0, 0)
#else
/* No Lockstat provider */
#define LOCKSTAT_RECORD()
#define LOCKSTAT_RECORD0()
#define LOCKSTAT_RECORD2()
#define LOCKSTAT_RECORD4()
#endif /* !CONFIG_DTRACE */
#endif /* _KERNEL */
#endif /* _ASM */
#ifdef __cplusplus
}
#endif
#endif /* _SYS_LOCKSTAT_H */