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.
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.
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]
26 dtrace_ap_start(void *dummy)
30 mutex_enter(&cpu_lock);
32 /* Setup the rest of the CPUs. */
33 for (i = 1; i <= mp_maxid; i++) {
34 if (pcpu_find(i) == NULL)
37 (void) dtrace_cpu_setup(CPU_CONFIG, i);
40 mutex_exit(&cpu_lock);
43 SYSINIT(dtrace_ap_start, SI_SUB_SMP, SI_ORDER_ANY, dtrace_ap_start, NULL);
46 dtrace_load(void *dummy)
48 dtrace_provider_id_t id;
50 /* Hook into the trap handler. */
51 dtrace_trap_func = dtrace_trap;
53 /* Hang our hook for thread switches. */
54 dtrace_vtime_switch_func = dtrace_vtime_switch;
56 /* Hang our hook for exceptions. */
60 * XXX This is a short term hack to avoid having to comment
61 * out lots and lots of lock/unlock calls.
63 mutex_init(&mod_lock,"XXX mod_lock hack", MUTEX_DEFAULT, NULL);
66 * Initialise the mutexes without 'witness' because the dtrace
67 * code is mostly written to wait for memory. To have the
68 * witness code change a malloc() from M_WAITOK to M_NOWAIT
69 * because a lock is held would surely create a panic in a
70 * low memory situation. And that low memory situation might be
71 * the very problem we are trying to trace.
73 mutex_init(&dtrace_lock,"dtrace probe state", MUTEX_DEFAULT, NULL);
74 mutex_init(&dtrace_provider_lock,"dtrace provider state", MUTEX_DEFAULT, NULL);
75 mutex_init(&dtrace_meta_lock,"dtrace meta-provider state", MUTEX_DEFAULT, NULL);
76 mutex_init(&dtrace_errlock,"dtrace error lock", MUTEX_DEFAULT, NULL);
78 mutex_enter(&dtrace_provider_lock);
79 mutex_enter(&dtrace_lock);
80 mutex_enter(&cpu_lock);
82 ASSERT(MUTEX_HELD(&cpu_lock));
84 dtrace_arena = new_unrhdr(1, INT_MAX, &dtrace_unr_mtx);
86 dtrace_state_cache = kmem_cache_create("dtrace_state_cache",
87 sizeof (dtrace_dstate_percpu_t) * NCPU, DTRACE_STATE_ALIGN,
88 NULL, NULL, NULL, NULL, NULL, 0);
90 ASSERT(MUTEX_HELD(&cpu_lock));
91 dtrace_bymod = dtrace_hash_create(offsetof(dtrace_probe_t, dtpr_mod),
92 offsetof(dtrace_probe_t, dtpr_nextmod),
93 offsetof(dtrace_probe_t, dtpr_prevmod));
95 dtrace_byfunc = dtrace_hash_create(offsetof(dtrace_probe_t, dtpr_func),
96 offsetof(dtrace_probe_t, dtpr_nextfunc),
97 offsetof(dtrace_probe_t, dtpr_prevfunc));
99 dtrace_byname = dtrace_hash_create(offsetof(dtrace_probe_t, dtpr_name),
100 offsetof(dtrace_probe_t, dtpr_nextname),
101 offsetof(dtrace_probe_t, dtpr_prevname));
103 if (dtrace_retain_max < 1) {
104 cmn_err(CE_WARN, "illegal value (%lu) for dtrace_retain_max; "
105 "setting to 1", dtrace_retain_max);
106 dtrace_retain_max = 1;
110 * Now discover our toxic ranges.
112 dtrace_toxic_ranges(dtrace_toxrange_add);
115 * Before we register ourselves as a provider to our own framework,
116 * we would like to assert that dtrace_provider is NULL -- but that's
117 * not true if we were loaded as a dependency of a DTrace provider.
118 * Once we've registered, we can assert that dtrace_provider is our
121 (void) dtrace_register("dtrace", &dtrace_provider_attr,
122 DTRACE_PRIV_NONE, 0, &dtrace_provider_ops, NULL, &id);
124 ASSERT(dtrace_provider != NULL);
125 ASSERT((dtrace_provider_id_t)dtrace_provider == id);
127 dtrace_probeid_begin = dtrace_probe_create((dtrace_provider_id_t)
128 dtrace_provider, NULL, NULL, "BEGIN", 0, NULL);
129 dtrace_probeid_end = dtrace_probe_create((dtrace_provider_id_t)
130 dtrace_provider, NULL, NULL, "END", 0, NULL);
131 dtrace_probeid_error = dtrace_probe_create((dtrace_provider_id_t)
132 dtrace_provider, NULL, NULL, "ERROR", 1, NULL);
134 mutex_exit(&cpu_lock);
137 * If DTrace helper tracing is enabled, we need to allocate the
138 * trace buffer and initialize the values.
140 if (dtrace_helptrace_enabled) {
141 ASSERT(dtrace_helptrace_buffer == NULL);
142 dtrace_helptrace_buffer =
143 kmem_zalloc(dtrace_helptrace_bufsize, KM_SLEEP);
144 dtrace_helptrace_next = 0;
147 mutex_exit(&dtrace_lock);
148 mutex_exit(&dtrace_provider_lock);
150 mutex_enter(&cpu_lock);
152 /* Setup the boot CPU */
153 (void) dtrace_cpu_setup(CPU_CONFIG, 0);
155 mutex_exit(&cpu_lock);
157 #if __FreeBSD_version < 800039
158 /* Enable device cloning. */
159 clone_setup(&dtrace_clones);
161 /* Setup device cloning events. */
162 eh_tag = EVENTHANDLER_REGISTER(dev_clone, dtrace_clone, 0, 1000);
164 dtrace_dev = make_dev(&dtrace_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "dtrace/dtrace");