xref: /freebsd/sys/cddl/dev/profile/profile.c (revision 74d9553e43cfafc29448d0bb836916aa21dea0de)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  *
21  * Portions Copyright 2006-2008 John Birrell jb@freebsd.org
22  *
23  * $FreeBSD$
24  *
25  */
26 
27 /*
28  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
29  * Use is subject to license terms.
30  */
31 
32 #include <sys/cdefs.h>
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/conf.h>
36 #include <sys/cpuvar.h>
37 #include <sys/fcntl.h>
38 #include <sys/filio.h>
39 #include <sys/kdb.h>
40 #include <sys/kernel.h>
41 #include <sys/kmem.h>
42 #include <sys/kthread.h>
43 #include <sys/limits.h>
44 #include <sys/linker.h>
45 #include <sys/lock.h>
46 #include <sys/malloc.h>
47 #include <sys/module.h>
48 #include <sys/mutex.h>
49 #include <sys/poll.h>
50 #include <sys/proc.h>
51 #include <sys/selinfo.h>
52 #include <sys/smp.h>
53 #include <sys/sysctl.h>
54 #include <sys/uio.h>
55 #include <sys/unistd.h>
56 #include <machine/cpu.h>
57 #include <machine/stdarg.h>
58 
59 #include <sys/dtrace.h>
60 #include <sys/dtrace_bsd.h>
61 
62 #define	PROF_NAMELEN		15
63 
64 #define	PROF_PROFILE		0
65 #define	PROF_TICK		1
66 #define	PROF_PREFIX_PROFILE	"profile-"
67 #define	PROF_PREFIX_TICK	"tick-"
68 
69 /*
70  * Regardless of platform, there are five artificial frames in the case of the
71  * profile provider:
72  *
73  *	profile_fire
74  *	cyclic_expire
75  *	cyclic_fire
76  *	[ cbe ]
77  *	[ locore ]
78  *
79  * On amd64, there are two frames associated with locore:  one in locore, and
80  * another in common interrupt dispatch code.  (i386 has not been modified to
81  * use this common layer.)  Further, on i386, the interrupted instruction
82  * appears as its own stack frame.  All of this means that we need to add one
83  * frame for amd64, and then take one away for both amd64 and i386.
84  *
85  * On SPARC, the picture is further complicated because the compiler
86  * optimizes away tail-calls -- so the following frames are optimized away:
87  *
88  * 	profile_fire
89  *	cyclic_expire
90  *
91  * This gives three frames.  However, on DEBUG kernels, the cyclic_expire
92  * frame cannot be tail-call eliminated, yielding four frames in this case.
93  *
94  * All of the above constraints lead to the mess below.  Yes, the profile
95  * provider should ideally figure this out on-the-fly by hiting one of its own
96  * probes and then walking its own stack trace.  This is complicated, however,
97  * and the static definition doesn't seem to be overly brittle.  Still, we
98  * allow for a manual override in case we get it completely wrong.
99  */
100 #ifdef __amd64
101 #define	PROF_ARTIFICIAL_FRAMES	10
102 #else
103 #ifdef __i386
104 #define	PROF_ARTIFICIAL_FRAMES	6
105 #else
106 #ifdef __sparc
107 #ifdef DEBUG
108 #define	PROF_ARTIFICIAL_FRAMES	4
109 #else
110 #define	PROF_ARTIFICIAL_FRAMES	3
111 #endif
112 #endif
113 #endif
114 #endif
115 
116 #ifdef __mips
117 /*
118  * This value is bogus just to make module compilable on mips
119  */
120 #define	PROF_ARTIFICIAL_FRAMES	3
121 #endif
122 
123 #ifdef __powerpc__
124 /*
125  * This value is bogus just to make module compilable on powerpc
126  */
127 #define	PROF_ARTIFICIAL_FRAMES	3
128 #endif
129 
130 struct profile_probe_percpu;
131 
132 #ifdef __mips
133 /* bogus */
134 #define	PROF_ARTIFICIAL_FRAMES	3
135 #endif
136 
137 #ifdef __arm__
138 #define	PROF_ARTIFICIAL_FRAMES	3
139 #endif
140 
141 #ifdef __aarch64__
142 /* TODO: verify */
143 #define	PROF_ARTIFICIAL_FRAMES	10
144 #endif
145 
146 #ifdef __riscv__
147 /* TODO: verify */
148 #define	PROF_ARTIFICIAL_FRAMES	10
149 #endif
150 
151 typedef struct profile_probe {
152 	char		prof_name[PROF_NAMELEN];
153 	dtrace_id_t	prof_id;
154 	int		prof_kind;
155 #ifdef illumos
156 	hrtime_t	prof_interval;
157 	cyclic_id_t	prof_cyclic;
158 #else
159 	sbintime_t	prof_interval;
160 	struct callout	prof_cyclic;
161 	sbintime_t	prof_expected;
162 	struct profile_probe_percpu **prof_pcpus;
163 #endif
164 } profile_probe_t;
165 
166 typedef struct profile_probe_percpu {
167 	hrtime_t	profc_expected;
168 	hrtime_t	profc_interval;
169 	profile_probe_t	*profc_probe;
170 #ifdef __FreeBSD__
171 	struct callout	profc_cyclic;
172 #endif
173 } profile_probe_percpu_t;
174 
175 static d_open_t	profile_open;
176 static int	profile_unload(void);
177 static void	profile_create(hrtime_t, char *, int);
178 static void	profile_destroy(void *, dtrace_id_t, void *);
179 static void	profile_enable(void *, dtrace_id_t, void *);
180 static void	profile_disable(void *, dtrace_id_t, void *);
181 static void	profile_load(void *);
182 static void	profile_provide(void *, dtrace_probedesc_t *);
183 
184 static int profile_rates[] = {
185     97, 199, 499, 997, 1999,
186     4001, 4999, 0, 0, 0,
187     0, 0, 0, 0, 0,
188     0, 0, 0, 0, 0
189 };
190 
191 static int profile_ticks[] = {
192     1, 10, 100, 500, 1000,
193     5000, 0, 0, 0, 0,
194     0, 0, 0, 0, 0
195 };
196 
197 /*
198  * profile_max defines the upper bound on the number of profile probes that
199  * can exist (this is to prevent malicious or clumsy users from exhausing
200  * system resources by creating a slew of profile probes). At mod load time,
201  * this gets its value from PROFILE_MAX_DEFAULT or profile-max-probes if it's
202  * present in the profile.conf file.
203  */
204 #define	PROFILE_MAX_DEFAULT	1000	/* default max. number of probes */
205 static uint32_t profile_max = PROFILE_MAX_DEFAULT;
206 					/* maximum number of profile probes */
207 static uint32_t profile_total;		/* current number of profile probes */
208 
209 static struct cdevsw profile_cdevsw = {
210 	.d_version	= D_VERSION,
211 	.d_open		= profile_open,
212 	.d_name		= "profile",
213 };
214 
215 static dtrace_pattr_t profile_attr = {
216 { DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
217 { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
218 { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA },
219 { DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
220 { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA },
221 };
222 
223 static dtrace_pops_t profile_pops = {
224 	profile_provide,
225 	NULL,
226 	profile_enable,
227 	profile_disable,
228 	NULL,
229 	NULL,
230 	NULL,
231 	NULL,
232 	NULL,
233 	profile_destroy
234 };
235 
236 static struct cdev		*profile_cdev;
237 static dtrace_provider_id_t	profile_id;
238 static hrtime_t			profile_interval_min = NANOSEC / 5000;	/* 5000 hz */
239 static int			profile_aframes = PROF_ARTIFICIAL_FRAMES;
240 
241 SYSCTL_DECL(_kern_dtrace);
242 SYSCTL_NODE(_kern_dtrace, OID_AUTO, profile, CTLFLAG_RD, 0, "DTrace profile parameters");
243 SYSCTL_INT(_kern_dtrace_profile, OID_AUTO, aframes, CTLFLAG_RW, &profile_aframes,
244     0, "Skipped frames for profile provider");
245 
246 static sbintime_t
247 nsec_to_sbt(hrtime_t nsec)
248 {
249 	time_t sec;
250 
251 	/*
252 	 * We need to calculate nsec * 2^32 / 10^9
253 	 * Seconds and nanoseconds are split to avoid overflow.
254 	 */
255 	sec = nsec / NANOSEC;
256 	nsec = nsec % NANOSEC;
257 	return (((sbintime_t)sec << 32) | ((sbintime_t)nsec << 32) / NANOSEC);
258 }
259 
260 static hrtime_t
261 sbt_to_nsec(sbintime_t sbt)
262 {
263 
264 	return ((sbt >> 32) * NANOSEC +
265 	    (((uint32_t)sbt * (hrtime_t)NANOSEC) >> 32));
266 }
267 
268 static void
269 profile_fire(void *arg)
270 {
271 	profile_probe_percpu_t *pcpu = arg;
272 	profile_probe_t *prof = pcpu->profc_probe;
273 	hrtime_t late;
274 	struct trapframe *frame;
275 	uintfptr_t pc, upc;
276 
277 #ifdef illumos
278 	late = gethrtime() - pcpu->profc_expected;
279 #else
280 	late = sbt_to_nsec(sbinuptime() - pcpu->profc_expected);
281 #endif
282 
283 	pc = 0;
284 	upc = 0;
285 
286 	/*
287 	 * td_intr_frame can be unset if this is a catch up event
288 	 * after waking up from idle sleep.
289 	 * This can only happen on a CPU idle thread.
290 	 */
291 	frame = curthread->td_intr_frame;
292 	if (frame != NULL) {
293 		if (TRAPF_USERMODE(frame))
294 			upc = TRAPF_PC(frame);
295 		else
296 			pc = TRAPF_PC(frame);
297 	}
298 	dtrace_probe(prof->prof_id, pc, upc, late, 0, 0);
299 
300 	pcpu->profc_expected += pcpu->profc_interval;
301 	callout_schedule_sbt_curcpu(&pcpu->profc_cyclic,
302 	    pcpu->profc_expected, 0, C_DIRECT_EXEC | C_ABSOLUTE);
303 }
304 
305 static void
306 profile_tick(void *arg)
307 {
308 	profile_probe_t *prof = arg;
309 	struct trapframe *frame;
310 	uintfptr_t pc, upc;
311 
312 	pc = 0;
313 	upc = 0;
314 
315 	/*
316 	 * td_intr_frame can be unset if this is a catch up event
317 	 * after waking up from idle sleep.
318 	 * This can only happen on a CPU idle thread.
319 	 */
320 	frame = curthread->td_intr_frame;
321 	if (frame != NULL) {
322 		if (TRAPF_USERMODE(frame))
323 			upc = TRAPF_PC(frame);
324 		else
325 			pc = TRAPF_PC(frame);
326 	}
327 	dtrace_probe(prof->prof_id, pc, upc, 0, 0, 0);
328 
329 	prof->prof_expected += prof->prof_interval;
330 	callout_schedule_sbt(&prof->prof_cyclic,
331 	    prof->prof_expected, 0, C_DIRECT_EXEC | C_ABSOLUTE);
332 }
333 
334 static void
335 profile_create(hrtime_t interval, char *name, int kind)
336 {
337 	profile_probe_t *prof;
338 
339 	if (interval < profile_interval_min)
340 		return;
341 
342 	if (dtrace_probe_lookup(profile_id, NULL, NULL, name) != 0)
343 		return;
344 
345 	atomic_add_32(&profile_total, 1);
346 	if (profile_total > profile_max) {
347 		atomic_add_32(&profile_total, -1);
348 		return;
349 	}
350 
351 	prof = kmem_zalloc(sizeof (profile_probe_t), KM_SLEEP);
352 	(void) strcpy(prof->prof_name, name);
353 #ifdef illumos
354 	prof->prof_interval = interval;
355 	prof->prof_cyclic = CYCLIC_NONE;
356 #else
357 	prof->prof_interval = nsec_to_sbt(interval);
358 	callout_init(&prof->prof_cyclic, 1);
359 #endif
360 	prof->prof_kind = kind;
361 	prof->prof_id = dtrace_probe_create(profile_id,
362 	    NULL, NULL, name,
363 	    profile_aframes, prof);
364 }
365 
366 /*ARGSUSED*/
367 static void
368 profile_provide(void *arg, dtrace_probedesc_t *desc)
369 {
370 	int i, j, rate, kind;
371 	hrtime_t val = 0, mult = 1, len = 0;
372 	char *name, *suffix = NULL;
373 
374 	const struct {
375 		char *prefix;
376 		int kind;
377 	} types[] = {
378 		{ PROF_PREFIX_PROFILE, PROF_PROFILE },
379 		{ PROF_PREFIX_TICK, PROF_TICK },
380 		{ 0, 0 }
381 	};
382 
383 	const struct {
384 		char *name;
385 		hrtime_t mult;
386 	} suffixes[] = {
387 		{ "ns", 	NANOSEC / NANOSEC },
388 		{ "nsec",	NANOSEC / NANOSEC },
389 		{ "us",		NANOSEC / MICROSEC },
390 		{ "usec",	NANOSEC / MICROSEC },
391 		{ "ms",		NANOSEC / MILLISEC },
392 		{ "msec",	NANOSEC / MILLISEC },
393 		{ "s",		NANOSEC / SEC },
394 		{ "sec",	NANOSEC / SEC },
395 		{ "m",		NANOSEC * (hrtime_t)60 },
396 		{ "min",	NANOSEC * (hrtime_t)60 },
397 		{ "h",		NANOSEC * (hrtime_t)(60 * 60) },
398 		{ "hour",	NANOSEC * (hrtime_t)(60 * 60) },
399 		{ "d",		NANOSEC * (hrtime_t)(24 * 60 * 60) },
400 		{ "day",	NANOSEC * (hrtime_t)(24 * 60 * 60) },
401 		{ "hz",		0 },
402 		{ NULL }
403 	};
404 
405 	if (desc == NULL) {
406 		char n[PROF_NAMELEN];
407 
408 		/*
409 		 * If no description was provided, provide all of our probes.
410 		 */
411 		for (i = 0; i < sizeof (profile_rates) / sizeof (int); i++) {
412 			if ((rate = profile_rates[i]) == 0)
413 				continue;
414 
415 			(void) snprintf(n, PROF_NAMELEN, "%s%d",
416 			    PROF_PREFIX_PROFILE, rate);
417 			profile_create(NANOSEC / rate, n, PROF_PROFILE);
418 		}
419 
420 		for (i = 0; i < sizeof (profile_ticks) / sizeof (int); i++) {
421 			if ((rate = profile_ticks[i]) == 0)
422 				continue;
423 
424 			(void) snprintf(n, PROF_NAMELEN, "%s%d",
425 			    PROF_PREFIX_TICK, rate);
426 			profile_create(NANOSEC / rate, n, PROF_TICK);
427 		}
428 
429 		return;
430 	}
431 
432 	name = desc->dtpd_name;
433 
434 	for (i = 0; types[i].prefix != NULL; i++) {
435 		len = strlen(types[i].prefix);
436 
437 		if (strncmp(name, types[i].prefix, len) != 0)
438 			continue;
439 		break;
440 	}
441 
442 	if (types[i].prefix == NULL)
443 		return;
444 
445 	kind = types[i].kind;
446 	j = strlen(name) - len;
447 
448 	/*
449 	 * We need to start before any time suffix.
450 	 */
451 	for (j = strlen(name); j >= len; j--) {
452 		if (name[j] >= '0' && name[j] <= '9')
453 			break;
454 		suffix = &name[j];
455 	}
456 
457 	ASSERT(suffix != NULL);
458 
459 	/*
460 	 * Now determine the numerical value present in the probe name.
461 	 */
462 	for (; j >= len; j--) {
463 		if (name[j] < '0' || name[j] > '9')
464 			return;
465 
466 		val += (name[j] - '0') * mult;
467 		mult *= (hrtime_t)10;
468 	}
469 
470 	if (val == 0)
471 		return;
472 
473 	/*
474 	 * Look-up the suffix to determine the multiplier.
475 	 */
476 	for (i = 0, mult = 0; suffixes[i].name != NULL; i++) {
477 		if (strcasecmp(suffixes[i].name, suffix) == 0) {
478 			mult = suffixes[i].mult;
479 			break;
480 		}
481 	}
482 
483 	if (suffixes[i].name == NULL && *suffix != '\0')
484 		return;
485 
486 	if (mult == 0) {
487 		/*
488 		 * The default is frequency-per-second.
489 		 */
490 		val = NANOSEC / val;
491 	} else {
492 		val *= mult;
493 	}
494 
495 	profile_create(val, name, kind);
496 }
497 
498 /* ARGSUSED */
499 static void
500 profile_destroy(void *arg, dtrace_id_t id, void *parg)
501 {
502 	profile_probe_t *prof = parg;
503 
504 #ifdef illumos
505 	ASSERT(prof->prof_cyclic == CYCLIC_NONE);
506 #else
507 	ASSERT(!callout_active(&prof->prof_cyclic) && prof->prof_pcpus == NULL);
508 #endif
509 	kmem_free(prof, sizeof (profile_probe_t));
510 
511 	ASSERT(profile_total >= 1);
512 	atomic_add_32(&profile_total, -1);
513 }
514 
515 #ifdef illumos
516 /*ARGSUSED*/
517 static void
518 profile_online(void *arg, cpu_t *cpu, cyc_handler_t *hdlr, cyc_time_t *when)
519 {
520 	profile_probe_t *prof = arg;
521 	profile_probe_percpu_t *pcpu;
522 
523 	pcpu = kmem_zalloc(sizeof (profile_probe_percpu_t), KM_SLEEP);
524 	pcpu->profc_probe = prof;
525 
526 	hdlr->cyh_func = profile_fire;
527 	hdlr->cyh_arg = pcpu;
528 
529 	when->cyt_interval = prof->prof_interval;
530 	when->cyt_when = gethrtime() + when->cyt_interval;
531 
532 	pcpu->profc_expected = when->cyt_when;
533 	pcpu->profc_interval = when->cyt_interval;
534 }
535 
536 /*ARGSUSED*/
537 static void
538 profile_offline(void *arg, cpu_t *cpu, void *oarg)
539 {
540 	profile_probe_percpu_t *pcpu = oarg;
541 
542 	ASSERT(pcpu->profc_probe == arg);
543 	kmem_free(pcpu, sizeof (profile_probe_percpu_t));
544 }
545 
546 /* ARGSUSED */
547 static void
548 profile_enable(void *arg, dtrace_id_t id, void *parg)
549 {
550 	profile_probe_t *prof = parg;
551 	cyc_omni_handler_t omni;
552 	cyc_handler_t hdlr;
553 	cyc_time_t when;
554 
555 	ASSERT(prof->prof_interval != 0);
556 	ASSERT(MUTEX_HELD(&cpu_lock));
557 
558 	if (prof->prof_kind == PROF_TICK) {
559 		hdlr.cyh_func = profile_tick;
560 		hdlr.cyh_arg = prof;
561 
562 		when.cyt_interval = prof->prof_interval;
563 		when.cyt_when = gethrtime() + when.cyt_interval;
564 	} else {
565 		ASSERT(prof->prof_kind == PROF_PROFILE);
566 		omni.cyo_online = profile_online;
567 		omni.cyo_offline = profile_offline;
568 		omni.cyo_arg = prof;
569 	}
570 
571 	if (prof->prof_kind == PROF_TICK) {
572 		prof->prof_cyclic = cyclic_add(&hdlr, &when);
573 	} else {
574 		prof->prof_cyclic = cyclic_add_omni(&omni);
575 	}
576 }
577 
578 /* ARGSUSED */
579 static void
580 profile_disable(void *arg, dtrace_id_t id, void *parg)
581 {
582 	profile_probe_t *prof = parg;
583 
584 	ASSERT(prof->prof_cyclic != CYCLIC_NONE);
585 	ASSERT(MUTEX_HELD(&cpu_lock));
586 
587 	cyclic_remove(prof->prof_cyclic);
588 	prof->prof_cyclic = CYCLIC_NONE;
589 }
590 
591 #else
592 
593 static void
594 profile_enable_omni(profile_probe_t *prof)
595 {
596 	profile_probe_percpu_t *pcpu;
597 	int cpu;
598 
599 	prof->prof_pcpus = kmem_zalloc((mp_maxid + 1) * sizeof(pcpu), KM_SLEEP);
600 	CPU_FOREACH(cpu) {
601 		pcpu = kmem_zalloc(sizeof(profile_probe_percpu_t), KM_SLEEP);
602 		prof->prof_pcpus[cpu] = pcpu;
603 		pcpu->profc_probe = prof;
604 		pcpu->profc_expected = sbinuptime() + prof->prof_interval;
605 		pcpu->profc_interval = prof->prof_interval;
606 		callout_init(&pcpu->profc_cyclic, 1);
607 		callout_reset_sbt_on(&pcpu->profc_cyclic,
608 		    pcpu->profc_expected, 0, profile_fire, pcpu,
609 		    cpu, C_DIRECT_EXEC | C_ABSOLUTE);
610 	}
611 }
612 
613 static void
614 profile_disable_omni(profile_probe_t *prof)
615 {
616 	profile_probe_percpu_t *pcpu;
617 	int cpu;
618 
619 	ASSERT(prof->prof_pcpus != NULL);
620 	CPU_FOREACH(cpu) {
621 		pcpu = prof->prof_pcpus[cpu];
622 		ASSERT(pcpu->profc_probe == prof);
623 		ASSERT(callout_active(&pcpu->profc_cyclic));
624 		callout_stop(&pcpu->profc_cyclic);
625 		callout_drain(&pcpu->profc_cyclic);
626 		kmem_free(pcpu, sizeof(profile_probe_percpu_t));
627 	}
628 	kmem_free(prof->prof_pcpus, (mp_maxid + 1) * sizeof(pcpu));
629 	prof->prof_pcpus = NULL;
630 }
631 
632 /* ARGSUSED */
633 static void
634 profile_enable(void *arg, dtrace_id_t id, void *parg)
635 {
636 	profile_probe_t *prof = parg;
637 
638 	if (prof->prof_kind == PROF_TICK) {
639 		prof->prof_expected = sbinuptime() + prof->prof_interval;
640 		callout_reset_sbt(&prof->prof_cyclic,
641 		    prof->prof_expected, 0, profile_tick, prof,
642 		    C_DIRECT_EXEC | C_ABSOLUTE);
643 	} else {
644 		ASSERT(prof->prof_kind == PROF_PROFILE);
645 		profile_enable_omni(prof);
646 	}
647 }
648 
649 /* ARGSUSED */
650 static void
651 profile_disable(void *arg, dtrace_id_t id, void *parg)
652 {
653 	profile_probe_t *prof = parg;
654 
655 	if (prof->prof_kind == PROF_TICK) {
656 		ASSERT(callout_active(&prof->prof_cyclic));
657 		callout_stop(&prof->prof_cyclic);
658 		callout_drain(&prof->prof_cyclic);
659 	} else {
660 		ASSERT(prof->prof_kind == PROF_PROFILE);
661 		profile_disable_omni(prof);
662 	}
663 }
664 #endif
665 
666 static void
667 profile_load(void *dummy)
668 {
669 	/* Create the /dev/dtrace/profile entry. */
670 	profile_cdev = make_dev(&profile_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600,
671 	    "dtrace/profile");
672 
673 	if (dtrace_register("profile", &profile_attr, DTRACE_PRIV_USER,
674 	    NULL, &profile_pops, NULL, &profile_id) != 0)
675 		return;
676 }
677 
678 
679 static int
680 profile_unload()
681 {
682 	int error = 0;
683 
684 	if ((error = dtrace_unregister(profile_id)) != 0)
685 		return (error);
686 
687 	destroy_dev(profile_cdev);
688 
689 	return (error);
690 }
691 
692 /* ARGSUSED */
693 static int
694 profile_modevent(module_t mod __unused, int type, void *data __unused)
695 {
696 	int error = 0;
697 
698 	switch (type) {
699 	case MOD_LOAD:
700 		break;
701 
702 	case MOD_UNLOAD:
703 		break;
704 
705 	case MOD_SHUTDOWN:
706 		break;
707 
708 	default:
709 		error = EOPNOTSUPP;
710 		break;
711 
712 	}
713 	return (error);
714 }
715 
716 /* ARGSUSED */
717 static int
718 profile_open(struct cdev *dev __unused, int oflags __unused, int devtype __unused, struct thread *td __unused)
719 {
720 	return (0);
721 }
722 
723 SYSINIT(profile_load, SI_SUB_DTRACE_PROVIDER, SI_ORDER_ANY, profile_load, NULL);
724 SYSUNINIT(profile_unload, SI_SUB_DTRACE_PROVIDER, SI_ORDER_ANY, profile_unload, NULL);
725 
726 DEV_MODULE(profile, profile_modevent, NULL);
727 MODULE_VERSION(profile, 1);
728 MODULE_DEPEND(profile, dtrace, 1, 1, 1);
729 MODULE_DEPEND(profile, opensolaris, 1, 1, 1);
730