1179237Sjb/*
2179237Sjb * CDDL HEADER START
3179237Sjb *
4179237Sjb * The contents of this file are subject to the terms of the
5179237Sjb * Common Development and Distribution License, Version 1.0 only
6179237Sjb * (the "License").  You may not use this file except in compliance
7179237Sjb * with the License.
8179237Sjb *
9179237Sjb * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10179237Sjb * or http://www.opensolaris.org/os/licensing.
11179237Sjb * See the License for the specific language governing permissions
12179237Sjb * and limitations under the License.
13179237Sjb *
14179237Sjb * When distributing Covered Code, include this CDDL HEADER in each
15179237Sjb * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16179237Sjb * If applicable, add the following below this CDDL HEADER, with the
17179237Sjb * fields enclosed by brackets "[]" replaced with your own identifying
18179237Sjb * information: Portions Copyright [yyyy] [name of copyright owner]
19179237Sjb *
20179237Sjb * CDDL HEADER END
21179237Sjb *
22179237Sjb * $FreeBSD$
23179237Sjb */
24179237Sjb
25179237Sjb/*
26179237Sjb * DTrace Anonymous Enabling Functions
27179237Sjb */
28179237Sjbstatic void
29179237Sjbdtrace_anon_init(void *dummy)
30179237Sjb{
31179237Sjb	dtrace_state_t *state = NULL;
32179237Sjb	dtrace_enabling_t *enab;
33179237Sjb
34179237Sjb	mutex_enter(&cpu_lock);
35179237Sjb	mutex_enter(&dtrace_provider_lock);
36179237Sjb	mutex_enter(&dtrace_lock);
37179237Sjb
38179237Sjb	dtrace_anon_property();
39179237Sjb
40179237Sjb	mutex_exit(&cpu_lock);
41179237Sjb
42179237Sjb	/*
43179237Sjb	 * If there are already providers, we must ask them to provide their
44179237Sjb	 * probes, and then match any anonymous enabling against them.  Note
45179237Sjb	 * that there should be no other retained enablings at this time:
46179237Sjb	 * the only retained enablings at this time should be the anonymous
47179237Sjb	 * enabling.
48179237Sjb	 */
49179237Sjb	if (dtrace_anon.dta_enabling != NULL) {
50179237Sjb		ASSERT(dtrace_retained == dtrace_anon.dta_enabling);
51179237Sjb
52179237Sjb		dtrace_enabling_provide(NULL);
53179237Sjb		state = dtrace_anon.dta_state;
54179237Sjb
55179237Sjb		/*
56179237Sjb		 * We couldn't hold cpu_lock across the above call to
57179237Sjb		 * dtrace_enabling_provide(), but we must hold it to actually
58179237Sjb		 * enable the probes.  We have to drop all of our locks, pick
59179237Sjb		 * up cpu_lock, and regain our locks before matching the
60179237Sjb		 * retained anonymous enabling.
61179237Sjb		 */
62179237Sjb		mutex_exit(&dtrace_lock);
63179237Sjb		mutex_exit(&dtrace_provider_lock);
64179237Sjb
65179237Sjb		mutex_enter(&cpu_lock);
66179237Sjb		mutex_enter(&dtrace_provider_lock);
67179237Sjb		mutex_enter(&dtrace_lock);
68179237Sjb
69179237Sjb		if ((enab = dtrace_anon.dta_enabling) != NULL)
70179237Sjb			(void) dtrace_enabling_match(enab, NULL);
71179237Sjb
72179237Sjb		mutex_exit(&cpu_lock);
73179237Sjb	}
74179237Sjb
75179237Sjb	mutex_exit(&dtrace_provider_lock);
76179237Sjb	mutex_exit(&dtrace_lock);
77179237Sjb
78179237Sjb	if (state != NULL) {
79179237Sjb		/*
80179237Sjb		 * If we created any anonymous state, set it going now.
81179237Sjb		 */
82179237Sjb		(void) dtrace_state_go(state, &dtrace_anon.dta_beganon);
83179237Sjb	}
84179237Sjb}
85