xref: /freebsd/sys/cddl/dev/dtrace/dtrace_anon.c (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
191eaf3e1SJohn Birrell /*
291eaf3e1SJohn Birrell  * CDDL HEADER START
391eaf3e1SJohn Birrell  *
491eaf3e1SJohn Birrell  * The contents of this file are subject to the terms of the
591eaf3e1SJohn Birrell  * Common Development and Distribution License, Version 1.0 only
691eaf3e1SJohn Birrell  * (the "License").  You may not use this file except in compliance
791eaf3e1SJohn Birrell  * with the License.
891eaf3e1SJohn Birrell  *
991eaf3e1SJohn Birrell  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1091eaf3e1SJohn Birrell  * or http://www.opensolaris.org/os/licensing.
1191eaf3e1SJohn Birrell  * See the License for the specific language governing permissions
1291eaf3e1SJohn Birrell  * and limitations under the License.
1391eaf3e1SJohn Birrell  *
1491eaf3e1SJohn Birrell  * When distributing Covered Code, include this CDDL HEADER in each
1591eaf3e1SJohn Birrell  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1691eaf3e1SJohn Birrell  * If applicable, add the following below this CDDL HEADER, with the
1791eaf3e1SJohn Birrell  * fields enclosed by brackets "[]" replaced with your own identifying
1891eaf3e1SJohn Birrell  * information: Portions Copyright [yyyy] [name of copyright owner]
1991eaf3e1SJohn Birrell  *
2091eaf3e1SJohn Birrell  * CDDL HEADER END
2191eaf3e1SJohn Birrell  */
2291eaf3e1SJohn Birrell 
2391eaf3e1SJohn Birrell /*
2491eaf3e1SJohn Birrell  * DTrace Anonymous Enabling Functions
2591eaf3e1SJohn Birrell  */
2691eaf3e1SJohn Birrell static void
dtrace_anon_init(void * dummy)2791eaf3e1SJohn Birrell dtrace_anon_init(void *dummy)
2891eaf3e1SJohn Birrell {
2991eaf3e1SJohn Birrell 	dtrace_state_t *state = NULL;
3091eaf3e1SJohn Birrell 	dtrace_enabling_t *enab;
3191eaf3e1SJohn Birrell 
3291eaf3e1SJohn Birrell 	mutex_enter(&cpu_lock);
3391eaf3e1SJohn Birrell 	mutex_enter(&dtrace_provider_lock);
3491eaf3e1SJohn Birrell 	mutex_enter(&dtrace_lock);
3591eaf3e1SJohn Birrell 
3691eaf3e1SJohn Birrell 	dtrace_anon_property();
3791eaf3e1SJohn Birrell 
3891eaf3e1SJohn Birrell 	mutex_exit(&cpu_lock);
3991eaf3e1SJohn Birrell 
4091eaf3e1SJohn Birrell 	/*
4191eaf3e1SJohn Birrell 	 * If there are already providers, we must ask them to provide their
4291eaf3e1SJohn Birrell 	 * probes, and then match any anonymous enabling against them.  Note
4391eaf3e1SJohn Birrell 	 * that there should be no other retained enablings at this time:
4491eaf3e1SJohn Birrell 	 * the only retained enablings at this time should be the anonymous
4591eaf3e1SJohn Birrell 	 * enabling.
4691eaf3e1SJohn Birrell 	 */
4791eaf3e1SJohn Birrell 	if (dtrace_anon.dta_enabling != NULL) {
4891eaf3e1SJohn Birrell 		ASSERT(dtrace_retained == dtrace_anon.dta_enabling);
4991eaf3e1SJohn Birrell 
5091eaf3e1SJohn Birrell 		dtrace_enabling_provide(NULL);
5191eaf3e1SJohn Birrell 		state = dtrace_anon.dta_state;
5291eaf3e1SJohn Birrell 
5391eaf3e1SJohn Birrell 		/*
5491eaf3e1SJohn Birrell 		 * We couldn't hold cpu_lock across the above call to
5591eaf3e1SJohn Birrell 		 * dtrace_enabling_provide(), but we must hold it to actually
5691eaf3e1SJohn Birrell 		 * enable the probes.  We have to drop all of our locks, pick
5791eaf3e1SJohn Birrell 		 * up cpu_lock, and regain our locks before matching the
5891eaf3e1SJohn Birrell 		 * retained anonymous enabling.
5991eaf3e1SJohn Birrell 		 */
6091eaf3e1SJohn Birrell 		mutex_exit(&dtrace_lock);
6191eaf3e1SJohn Birrell 		mutex_exit(&dtrace_provider_lock);
6291eaf3e1SJohn Birrell 
6391eaf3e1SJohn Birrell 		mutex_enter(&cpu_lock);
6491eaf3e1SJohn Birrell 		mutex_enter(&dtrace_provider_lock);
6591eaf3e1SJohn Birrell 		mutex_enter(&dtrace_lock);
6691eaf3e1SJohn Birrell 
6791eaf3e1SJohn Birrell 		if ((enab = dtrace_anon.dta_enabling) != NULL)
6891eaf3e1SJohn Birrell 			(void) dtrace_enabling_match(enab, NULL);
6991eaf3e1SJohn Birrell 
7091eaf3e1SJohn Birrell 		mutex_exit(&cpu_lock);
7191eaf3e1SJohn Birrell 	}
7291eaf3e1SJohn Birrell 
7391eaf3e1SJohn Birrell 	mutex_exit(&dtrace_provider_lock);
7491eaf3e1SJohn Birrell 	mutex_exit(&dtrace_lock);
7591eaf3e1SJohn Birrell 
7691eaf3e1SJohn Birrell 	if (state != NULL) {
7791eaf3e1SJohn Birrell 		/*
7891eaf3e1SJohn Birrell 		 * If we created any anonymous state, set it going now.
7991eaf3e1SJohn Birrell 		 */
8091eaf3e1SJohn Birrell 		(void) dtrace_state_go(state, &dtrace_anon.dta_beganon);
8191eaf3e1SJohn Birrell 	}
8291eaf3e1SJohn Birrell }
83