xref: /freebsd-src/sys/cddl/dev/dtrace/dtrace_anon.c (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1*91eaf3e1SJohn Birrell /*
2*91eaf3e1SJohn Birrell  * CDDL HEADER START
3*91eaf3e1SJohn Birrell  *
4*91eaf3e1SJohn Birrell  * The contents of this file are subject to the terms of the
5*91eaf3e1SJohn Birrell  * Common Development and Distribution License, Version 1.0 only
6*91eaf3e1SJohn Birrell  * (the "License").  You may not use this file except in compliance
7*91eaf3e1SJohn Birrell  * with the License.
8*91eaf3e1SJohn Birrell  *
9*91eaf3e1SJohn Birrell  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*91eaf3e1SJohn Birrell  * or http://www.opensolaris.org/os/licensing.
11*91eaf3e1SJohn Birrell  * See the License for the specific language governing permissions
12*91eaf3e1SJohn Birrell  * and limitations under the License.
13*91eaf3e1SJohn Birrell  *
14*91eaf3e1SJohn Birrell  * When distributing Covered Code, include this CDDL HEADER in each
15*91eaf3e1SJohn Birrell  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*91eaf3e1SJohn Birrell  * If applicable, add the following below this CDDL HEADER, with the
17*91eaf3e1SJohn Birrell  * fields enclosed by brackets "[]" replaced with your own identifying
18*91eaf3e1SJohn Birrell  * information: Portions Copyright [yyyy] [name of copyright owner]
19*91eaf3e1SJohn Birrell  *
20*91eaf3e1SJohn Birrell  * CDDL HEADER END
21*91eaf3e1SJohn Birrell  */
22*91eaf3e1SJohn Birrell 
23*91eaf3e1SJohn Birrell /*
24*91eaf3e1SJohn Birrell  * DTrace Anonymous Enabling Functions
25*91eaf3e1SJohn Birrell  */
26*91eaf3e1SJohn Birrell static void
dtrace_anon_init(void * dummy)27*91eaf3e1SJohn Birrell dtrace_anon_init(void *dummy)
28*91eaf3e1SJohn Birrell {
29*91eaf3e1SJohn Birrell 	dtrace_state_t *state = NULL;
30*91eaf3e1SJohn Birrell 	dtrace_enabling_t *enab;
31*91eaf3e1SJohn Birrell 
32*91eaf3e1SJohn Birrell 	mutex_enter(&cpu_lock);
33*91eaf3e1SJohn Birrell 	mutex_enter(&dtrace_provider_lock);
34*91eaf3e1SJohn Birrell 	mutex_enter(&dtrace_lock);
35*91eaf3e1SJohn Birrell 
36*91eaf3e1SJohn Birrell 	dtrace_anon_property();
37*91eaf3e1SJohn Birrell 
38*91eaf3e1SJohn Birrell 	mutex_exit(&cpu_lock);
39*91eaf3e1SJohn Birrell 
40*91eaf3e1SJohn Birrell 	/*
41*91eaf3e1SJohn Birrell 	 * If there are already providers, we must ask them to provide their
42*91eaf3e1SJohn Birrell 	 * probes, and then match any anonymous enabling against them.  Note
43*91eaf3e1SJohn Birrell 	 * that there should be no other retained enablings at this time:
44*91eaf3e1SJohn Birrell 	 * the only retained enablings at this time should be the anonymous
45*91eaf3e1SJohn Birrell 	 * enabling.
46*91eaf3e1SJohn Birrell 	 */
47*91eaf3e1SJohn Birrell 	if (dtrace_anon.dta_enabling != NULL) {
48*91eaf3e1SJohn Birrell 		ASSERT(dtrace_retained == dtrace_anon.dta_enabling);
49*91eaf3e1SJohn Birrell 
50*91eaf3e1SJohn Birrell 		dtrace_enabling_provide(NULL);
51*91eaf3e1SJohn Birrell 		state = dtrace_anon.dta_state;
52*91eaf3e1SJohn Birrell 
53*91eaf3e1SJohn Birrell 		/*
54*91eaf3e1SJohn Birrell 		 * We couldn't hold cpu_lock across the above call to
55*91eaf3e1SJohn Birrell 		 * dtrace_enabling_provide(), but we must hold it to actually
56*91eaf3e1SJohn Birrell 		 * enable the probes.  We have to drop all of our locks, pick
57*91eaf3e1SJohn Birrell 		 * up cpu_lock, and regain our locks before matching the
58*91eaf3e1SJohn Birrell 		 * retained anonymous enabling.
59*91eaf3e1SJohn Birrell 		 */
60*91eaf3e1SJohn Birrell 		mutex_exit(&dtrace_lock);
61*91eaf3e1SJohn Birrell 		mutex_exit(&dtrace_provider_lock);
62*91eaf3e1SJohn Birrell 
63*91eaf3e1SJohn Birrell 		mutex_enter(&cpu_lock);
64*91eaf3e1SJohn Birrell 		mutex_enter(&dtrace_provider_lock);
65*91eaf3e1SJohn Birrell 		mutex_enter(&dtrace_lock);
66*91eaf3e1SJohn Birrell 
67*91eaf3e1SJohn Birrell 		if ((enab = dtrace_anon.dta_enabling) != NULL)
68*91eaf3e1SJohn Birrell 			(void) dtrace_enabling_match(enab, NULL);
69*91eaf3e1SJohn Birrell 
70*91eaf3e1SJohn Birrell 		mutex_exit(&cpu_lock);
71*91eaf3e1SJohn Birrell 	}
72*91eaf3e1SJohn Birrell 
73*91eaf3e1SJohn Birrell 	mutex_exit(&dtrace_provider_lock);
74*91eaf3e1SJohn Birrell 	mutex_exit(&dtrace_lock);
75*91eaf3e1SJohn Birrell 
76*91eaf3e1SJohn Birrell 	if (state != NULL) {
77*91eaf3e1SJohn Birrell 		/*
78*91eaf3e1SJohn Birrell 		 * If we created any anonymous state, set it going now.
79*91eaf3e1SJohn Birrell 		 */
80*91eaf3e1SJohn Birrell 		(void) dtrace_state_go(state, &dtrace_anon.dta_beganon);
81*91eaf3e1SJohn Birrell 	}
82*91eaf3e1SJohn Birrell }
83