Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/dtrace/lockstat.c
+++ new/usr/src/uts/common/dtrace/lockstat.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26
27 27 #include <sys/types.h>
28 28 #include <sys/param.h>
29 29 #include <sys/stat.h>
30 30 #include <sys/open.h>
31 31 #include <sys/file.h>
32 32 #include <sys/conf.h>
33 33 #include <sys/modctl.h>
34 34 #include <sys/cmn_err.h>
35 35 #include <sys/bitmap.h>
36 36 #include <sys/debug.h>
37 37 #include <sys/kmem.h>
38 38 #include <sys/errno.h>
39 39 #include <sys/sysmacros.h>
40 40 #include <sys/lockstat.h>
41 41 #include <sys/atomic.h>
42 42 #include <sys/dtrace.h>
43 43
44 44 #include <sys/ddi.h>
45 45 #include <sys/sunddi.h>
46 46
47 47 typedef struct lockstat_probe {
48 48 const char *lsp_func;
49 49 const char *lsp_name;
50 50 int lsp_probe;
51 51 dtrace_id_t lsp_id;
52 52 } lockstat_probe_t;
53 53
54 54 lockstat_probe_t lockstat_probes[] =
55 55 {
56 56 { LS_MUTEX_ENTER, LSA_ACQUIRE, LS_MUTEX_ENTER_ACQUIRE },
57 57 { LS_MUTEX_ENTER, LSA_BLOCK, LS_MUTEX_ENTER_BLOCK },
58 58 { LS_MUTEX_ENTER, LSA_SPIN, LS_MUTEX_ENTER_SPIN },
59 59 { LS_MUTEX_EXIT, LSA_RELEASE, LS_MUTEX_EXIT_RELEASE },
60 60 { LS_MUTEX_DESTROY, LSA_RELEASE, LS_MUTEX_DESTROY_RELEASE },
61 61 { LS_MUTEX_TRYENTER, LSA_ACQUIRE, LS_MUTEX_TRYENTER_ACQUIRE },
62 62 { LS_LOCK_SET, LSS_ACQUIRE, LS_LOCK_SET_ACQUIRE },
63 63 { LS_LOCK_SET, LSS_SPIN, LS_LOCK_SET_SPIN },
64 64 { LS_LOCK_SET_SPL, LSS_ACQUIRE, LS_LOCK_SET_SPL_ACQUIRE },
65 65 { LS_LOCK_SET_SPL, LSS_SPIN, LS_LOCK_SET_SPL_SPIN },
66 66 { LS_LOCK_TRY, LSS_ACQUIRE, LS_LOCK_TRY_ACQUIRE },
67 67 { LS_LOCK_CLEAR, LSS_RELEASE, LS_LOCK_CLEAR_RELEASE },
68 68 { LS_LOCK_CLEAR_SPLX, LSS_RELEASE, LS_LOCK_CLEAR_SPLX_RELEASE },
69 69 { LS_CLOCK_UNLOCK, LSS_RELEASE, LS_CLOCK_UNLOCK_RELEASE },
70 70 { LS_RW_ENTER, LSR_ACQUIRE, LS_RW_ENTER_ACQUIRE },
71 71 { LS_RW_ENTER, LSR_BLOCK, LS_RW_ENTER_BLOCK },
72 72 { LS_RW_EXIT, LSR_RELEASE, LS_RW_EXIT_RELEASE },
73 73 { LS_RW_TRYENTER, LSR_ACQUIRE, LS_RW_TRYENTER_ACQUIRE },
74 74 { LS_RW_TRYUPGRADE, LSR_UPGRADE, LS_RW_TRYUPGRADE_UPGRADE },
75 75 { LS_RW_DOWNGRADE, LSR_DOWNGRADE, LS_RW_DOWNGRADE_DOWNGRADE },
76 76 { LS_THREAD_LOCK, LST_SPIN, LS_THREAD_LOCK_SPIN },
77 77 { LS_THREAD_LOCK_HIGH, LST_SPIN, LS_THREAD_LOCK_HIGH_SPIN },
78 78 { NULL }
79 79 };
80 80
81 81 static dev_info_t *lockstat_devi; /* saved in xxattach() for xxinfo() */
82 82 static kmutex_t lockstat_test; /* for testing purposes only */
83 83 static dtrace_provider_id_t lockstat_id;
84 84
85 85 /*ARGSUSED*/
86 86 static int
87 87 lockstat_enable(void *arg, dtrace_id_t id, void *parg)
88 88 {
89 89 lockstat_probe_t *probe = parg;
90 90
91 91 ASSERT(!lockstat_probemap[probe->lsp_probe]);
92 92
93 93 lockstat_probemap[probe->lsp_probe] = id;
94 94 membar_producer();
95 95
96 96 lockstat_hot_patch();
97 97 membar_producer();
98 98
99 99 /*
100 100 * Immediately generate a record for the lockstat_test mutex
101 101 * to verify that the mutex hot-patch code worked as expected.
102 102 */
103 103 mutex_enter(&lockstat_test);
104 104 mutex_exit(&lockstat_test);
105 105 return (0);
106 106 }
107 107
108 108 /*ARGSUSED*/
109 109 static void
110 110 lockstat_disable(void *arg, dtrace_id_t id, void *parg)
111 111 {
112 112 lockstat_probe_t *probe = parg;
113 113 int i;
114 114
115 115 ASSERT(lockstat_probemap[probe->lsp_probe]);
116 116
117 117 lockstat_probemap[probe->lsp_probe] = 0;
118 118 lockstat_hot_patch();
119 119 membar_producer();
120 120
121 121 /*
122 122 * See if we have any probes left enabled.
123 123 */
124 124 for (i = 0; i < LS_NPROBES; i++) {
125 125 if (lockstat_probemap[i]) {
126 126 /*
127 127 * This probe is still enabled. We don't need to deal
128 128 * with waiting for all threads to be out of the
129 129 * lockstat critical sections; just return.
130 130 */
131 131 return;
132 132 }
133 133 }
134 134
135 135 /*
136 136 * The delay() here isn't as cheesy as you might think. We don't
137 137 * want to busy-loop in the kernel, so we have to give up the
138 138 * CPU between calls to lockstat_active_threads(); that much is
139 139 * obvious. But the reason it's a do..while loop rather than a
140 140 * while loop is subtle. The memory barrier above guarantees that
141 141 * no threads will enter the lockstat code from this point forward.
142 142 * However, another thread could already be executing lockstat code
143 143 * without our knowledge if the update to its t_lockstat field hasn't
144 144 * cleared its CPU's store buffer. Delaying for one clock tick
145 145 * guarantees that either (1) the thread will have *ample* time to
146 146 * complete its work, or (2) the thread will be preempted, in which
147 147 * case it will have to grab and release a dispatcher lock, which
148 148 * will flush that CPU's store buffer. Either way we're covered.
149 149 */
150 150 do {
151 151 delay(1);
152 152 } while (lockstat_active_threads());
153 153 }
154 154
155 155 /*ARGSUSED*/
156 156 static int
157 157 lockstat_open(dev_t *devp, int flag, int otyp, cred_t *cred_p)
158 158 {
159 159 return (0);
160 160 }
161 161
162 162 /* ARGSUSED */
163 163 static int
164 164 lockstat_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
165 165 {
166 166 int error;
167 167
168 168 switch (infocmd) {
169 169 case DDI_INFO_DEVT2DEVINFO:
170 170 *result = (void *) lockstat_devi;
171 171 error = DDI_SUCCESS;
172 172 break;
173 173 case DDI_INFO_DEVT2INSTANCE:
174 174 *result = (void *)0;
175 175 error = DDI_SUCCESS;
176 176 break;
177 177 default:
178 178 error = DDI_FAILURE;
179 179 }
180 180 return (error);
181 181 }
182 182
183 183 /*ARGSUSED*/
184 184 static void
185 185 lockstat_provide(void *arg, const dtrace_probedesc_t *desc)
186 186 {
187 187 int i = 0;
188 188
189 189 for (i = 0; lockstat_probes[i].lsp_func != NULL; i++) {
190 190 lockstat_probe_t *probe = &lockstat_probes[i];
191 191
192 192 if (dtrace_probe_lookup(lockstat_id, "genunix",
193 193 probe->lsp_func, probe->lsp_name) != 0)
194 194 continue;
195 195
196 196 ASSERT(!probe->lsp_id);
197 197 probe->lsp_id = dtrace_probe_create(lockstat_id,
198 198 "genunix", probe->lsp_func, probe->lsp_name,
199 199 1, probe);
200 200 }
201 201 }
202 202
203 203 /*ARGSUSED*/
204 204 static void
205 205 lockstat_destroy(void *arg, dtrace_id_t id, void *parg)
206 206 {
207 207 lockstat_probe_t *probe = parg;
208 208
209 209 ASSERT(!lockstat_probemap[probe->lsp_probe]);
210 210 probe->lsp_id = 0;
211 211 }
212 212
213 213 static dtrace_pattr_t lockstat_attr = {
214 214 { DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
215 215 { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
216 216 { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
217 217 { DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
218 218 { DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
219 219 };
220 220
221 221 static dtrace_pops_t lockstat_pops = {
222 222 lockstat_provide,
223 223 NULL,
224 224 lockstat_enable,
225 225 lockstat_disable,
226 226 NULL,
227 227 NULL,
228 228 NULL,
229 229 NULL,
230 230 NULL,
231 231 lockstat_destroy
232 232 };
233 233
234 234 static int
235 235 lockstat_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
236 236 {
237 237 switch (cmd) {
238 238 case DDI_ATTACH:
239 239 break;
240 240 case DDI_RESUME:
241 241 return (DDI_SUCCESS);
242 242 default:
243 243 return (DDI_FAILURE);
244 244 }
245 245
246 246 if (ddi_create_minor_node(devi, "lockstat", S_IFCHR, 0,
247 247 DDI_PSEUDO, 0) == DDI_FAILURE ||
248 248 dtrace_register("lockstat", &lockstat_attr, DTRACE_PRIV_KERNEL,
249 249 NULL, &lockstat_pops, NULL, &lockstat_id) != 0) {
250 250 ddi_remove_minor_node(devi, NULL);
251 251 return (DDI_FAILURE);
252 252 }
253 253
254 254 lockstat_probe = dtrace_probe;
255 255 membar_producer();
256 256
257 257 ddi_report_dev(devi);
258 258 lockstat_devi = devi;
259 259 return (DDI_SUCCESS);
260 260 }
261 261
262 262 static int
263 263 lockstat_detach(dev_info_t *devi, ddi_detach_cmd_t cmd)
264 264 {
265 265 switch (cmd) {
266 266 case DDI_DETACH:
267 267 break;
268 268 case DDI_SUSPEND:
269 269 return (DDI_SUCCESS);
270 270 default:
271 271 return (DDI_FAILURE);
272 272 }
273 273
274 274 if (dtrace_unregister(lockstat_id) != 0)
275 275 return (DDI_FAILURE);
276 276
277 277 ddi_remove_minor_node(devi, NULL);
278 278 return (DDI_SUCCESS);
279 279 }
280 280
281 281 /*
282 282 * Configuration data structures
283 283 */
284 284 static struct cb_ops lockstat_cb_ops = {
285 285 lockstat_open, /* open */
286 286 nodev, /* close */
287 287 nulldev, /* strategy */
288 288 nulldev, /* print */
289 289 nodev, /* dump */
290 290 nodev, /* read */
291 291 nodev, /* write */
292 292 nodev, /* ioctl */
293 293 nodev, /* devmap */
294 294 nodev, /* mmap */
295 295 nodev, /* segmap */
296 296 nochpoll, /* poll */
297 297 ddi_prop_op, /* cb_prop_op */
298 298 0, /* streamtab */
299 299 D_MP | D_NEW /* Driver compatibility flag */
300 300 };
301 301
302 302 static struct dev_ops lockstat_ops = {
303 303 DEVO_REV, /* devo_rev, */
304 304 0, /* refcnt */
305 305 lockstat_info, /* getinfo */
306 306 nulldev, /* identify */
307 307 nulldev, /* probe */
308 308 lockstat_attach, /* attach */
309 309 lockstat_detach, /* detach */
310 310 nulldev, /* reset */
311 311 &lockstat_cb_ops, /* cb_ops */
312 312 NULL, /* bus_ops */
313 313 NULL, /* power */
↓ open down ↓ |
313 lines elided |
↑ open up ↑ |
314 314 ddi_quiesce_not_needed, /* quiesce */
315 315 };
316 316
317 317 static struct modldrv modldrv = {
318 318 &mod_driverops, /* Type of module. This one is a driver */
319 319 "Lock Statistics", /* name of module */
320 320 &lockstat_ops, /* driver ops */
321 321 };
322 322
323 323 static struct modlinkage modlinkage = {
324 - MODREV_1, (void *)&modldrv, NULL
324 + MODREV_1, { (void *)&modldrv, NULL }
325 325 };
326 326
327 327 int
328 328 _init(void)
329 329 {
330 330 return (mod_install(&modlinkage));
331 331 }
332 332
333 333 int
334 334 _fini(void)
335 335 {
336 336 return (mod_remove(&modlinkage));
337 337 }
338 338
339 339 int
340 340 _info(struct modinfo *modinfop)
341 341 {
342 342 return (mod_info(&modlinkage, modinfop));
343 343 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX