1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate * Copyright 1994, 2003 Sun Microsystems, Inc. All rights reserved.
24*0Sstevel@tonic-gate * Use is subject to license terms.
25*0Sstevel@tonic-gate */
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate #include <sys/types.h>
30*0Sstevel@tonic-gate #include <sys/param.h>
31*0Sstevel@tonic-gate #include <sys/systm.h>
32*0Sstevel@tonic-gate #include <sys/ddi.h> /* strchr */
33*0Sstevel@tonic-gate #include <sys/sunddi.h> /* strchr */
34*0Sstevel@tonic-gate #include <sys/tnf_com.h>
35*0Sstevel@tonic-gate #include <sys/tnf_writer.h>
36*0Sstevel@tonic-gate #include <sys/tnf_probe.h>
37*0Sstevel@tonic-gate #include <sys/debug.h>
38*0Sstevel@tonic-gate
39*0Sstevel@tonic-gate #include "tnf_buf.h"
40*0Sstevel@tonic-gate #include "tnf_types.h"
41*0Sstevel@tonic-gate #include "tnf_trace.h"
42*0Sstevel@tonic-gate
43*0Sstevel@tonic-gate /*
44*0Sstevel@tonic-gate * New derived types for probes
45*0Sstevel@tonic-gate */
46*0Sstevel@tonic-gate
47*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_probe_event, tnf_tag,
48*0Sstevel@tonic-gate tnf_derived_properties, TNF_OPAQUE);
49*0Sstevel@tonic-gate
50*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_time_base, tnf_int64,
51*0Sstevel@tonic-gate tnf_derived_properties, TNF_INT64);
52*0Sstevel@tonic-gate
53*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_time_delta, tnf_uint32,
54*0Sstevel@tonic-gate tnf_derived_properties, TNF_UINT32);
55*0Sstevel@tonic-gate
56*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_pid, tnf_int32,
57*0Sstevel@tonic-gate tnf_derived_properties, TNF_INT32);
58*0Sstevel@tonic-gate
59*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_lwpid, tnf_uint32,
60*0Sstevel@tonic-gate tnf_derived_properties, TNF_UINT32);
61*0Sstevel@tonic-gate
62*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_kthread_id, tnf_opaque,
63*0Sstevel@tonic-gate tnf_derived_properties, TNF_OPAQUE);
64*0Sstevel@tonic-gate
65*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_cpuid, tnf_int32,
66*0Sstevel@tonic-gate tnf_derived_properties, TNF_INT32);
67*0Sstevel@tonic-gate
68*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_device, tnf_ulong,
69*0Sstevel@tonic-gate tnf_derived_properties, TNF_ULONG);
70*0Sstevel@tonic-gate
71*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_symbol, tnf_opaque,
72*0Sstevel@tonic-gate tnf_derived_properties, TNF_OPAQUE);
73*0Sstevel@tonic-gate
74*0Sstevel@tonic-gate TNF_STD_ARRAY_TAG(tnf_symbols, tnf_symbol, TNF_ARRAY);
75*0Sstevel@tonic-gate
76*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_sysnum, tnf_int16,
77*0Sstevel@tonic-gate tnf_derived_properties, TNF_INT32);
78*0Sstevel@tonic-gate
79*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_microstate, tnf_int32,
80*0Sstevel@tonic-gate tnf_derived_properties, TNF_INT32);
81*0Sstevel@tonic-gate
82*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_offset, tnf_int64,
83*0Sstevel@tonic-gate tnf_derived_properties, TNF_INT64);
84*0Sstevel@tonic-gate
85*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_fault_type, tnf_int32,
86*0Sstevel@tonic-gate tnf_derived_properties, TNF_INT32);
87*0Sstevel@tonic-gate
88*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_seg_access, tnf_int32,
89*0Sstevel@tonic-gate tnf_derived_properties, TNF_INT32);
90*0Sstevel@tonic-gate
91*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_bioflags, tnf_int32,
92*0Sstevel@tonic-gate tnf_derived_properties, TNF_INT32);
93*0Sstevel@tonic-gate
94*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_diskaddr, tnf_int64,
95*0Sstevel@tonic-gate tnf_derived_properties, TNF_INT64);
96*0Sstevel@tonic-gate
97*0Sstevel@tonic-gate static char *kernel_schedule_slot_names[] = {
98*0Sstevel@tonic-gate TNF_N_TAG,
99*0Sstevel@tonic-gate TNF_N_TID,
100*0Sstevel@tonic-gate TNF_N_LWPID,
101*0Sstevel@tonic-gate TNF_N_PID,
102*0Sstevel@tonic-gate TNF_N_TIME_BASE,
103*0Sstevel@tonic-gate "cpuid", /* XXX */
104*0Sstevel@tonic-gate 0};
105*0Sstevel@tonic-gate
106*0Sstevel@tonic-gate static tnf_tag_data_t **kernel_schedule_slots[] = {
107*0Sstevel@tonic-gate &TAG_DATA(tnf_tag),
108*0Sstevel@tonic-gate &TAG_DATA(tnf_kthread_id),
109*0Sstevel@tonic-gate &TAG_DATA(tnf_lwpid),
110*0Sstevel@tonic-gate &TAG_DATA(tnf_pid),
111*0Sstevel@tonic-gate &TAG_DATA(tnf_time_base),
112*0Sstevel@tonic-gate &TAG_DATA(tnf_cpuid),
113*0Sstevel@tonic-gate 0};
114*0Sstevel@tonic-gate
115*0Sstevel@tonic-gate TNF_STD_STRUCT_TAG(tnf_kernel_schedule,
116*0Sstevel@tonic-gate kernel_schedule_slots,
117*0Sstevel@tonic-gate kernel_schedule_slot_names,
118*0Sstevel@tonic-gate sizeof (tnf_schedule_prototype_t));
119*0Sstevel@tonic-gate
120*0Sstevel@tonic-gate /*
121*0Sstevel@tonic-gate * Probe type record (metatag)
122*0Sstevel@tonic-gate */
123*0Sstevel@tonic-gate
124*0Sstevel@tonic-gate static tnf_tag_data_t **probe_type_slots[] = {
125*0Sstevel@tonic-gate &TAG_DATA(tnf_tag),
126*0Sstevel@tonic-gate &TAG_DATA(tnf_name),
127*0Sstevel@tonic-gate &TAG_DATA(tnf_properties),
128*0Sstevel@tonic-gate &TAG_DATA(tnf_slot_types),
129*0Sstevel@tonic-gate &TAG_DATA(tnf_type_size),
130*0Sstevel@tonic-gate &TAG_DATA(tnf_slot_names),
131*0Sstevel@tonic-gate &TAG_DATA(tnf_string), /* detail */
132*0Sstevel@tonic-gate 0};
133*0Sstevel@tonic-gate
134*0Sstevel@tonic-gate TNF_METATAG(tnf_probe_type, tnf_type_properties,
135*0Sstevel@tonic-gate probe_type_slots, tnf_struct_tag_1);
136*0Sstevel@tonic-gate
137*0Sstevel@tonic-gate /*
138*0Sstevel@tonic-gate * Write a kernel schedule record
139*0Sstevel@tonic-gate * Can only be written in reusable data space.
140*0Sstevel@tonic-gate */
141*0Sstevel@tonic-gate
142*0Sstevel@tonic-gate tnf_record_p
tnf_kernel_schedule(tnf_ops_t * ops,tnf_schedule_t * sched)143*0Sstevel@tonic-gate tnf_kernel_schedule(tnf_ops_t *ops, tnf_schedule_t *sched)
144*0Sstevel@tonic-gate {
145*0Sstevel@tonic-gate tnf_tag_data_t *metatag_data;
146*0Sstevel@tonic-gate tnf_record_p metatag_index;
147*0Sstevel@tonic-gate tnf_schedule_prototype_t *buffer;
148*0Sstevel@tonic-gate kthread_t *t;
149*0Sstevel@tonic-gate
150*0Sstevel@tonic-gate t = curthread;
151*0Sstevel@tonic-gate
152*0Sstevel@tonic-gate /* Cannot be called when writing into tag space */
153*0Sstevel@tonic-gate ASSERT(ops->mode == TNF_ALLOC_REUSABLE);
154*0Sstevel@tonic-gate
155*0Sstevel@tonic-gate ALLOC(ops, sizeof (*buffer), buffer, sched->record_p,
156*0Sstevel@tonic-gate TNF_ALLOC_REUSABLE); /* XXX see comment above */
157*0Sstevel@tonic-gate
158*0Sstevel@tonic-gate metatag_data = TAG_DATA(tnf_kernel_schedule);
159*0Sstevel@tonic-gate metatag_index = metatag_data->tag_index ?
160*0Sstevel@tonic-gate metatag_data->tag_index :
161*0Sstevel@tonic-gate metatag_data->tag_desc(ops, metatag_data);
162*0Sstevel@tonic-gate
163*0Sstevel@tonic-gate ASSIGN(buffer, tag, metatag_index);
164*0Sstevel@tonic-gate ASSIGN2(buffer, tid, t, kthread_id);
165*0Sstevel@tonic-gate ASSIGN(buffer, lwpid, t->t_tid);
166*0Sstevel@tonic-gate ASSIGN(buffer, pid, ttoproc(t)->p_pid);
167*0Sstevel@tonic-gate ASSIGN(buffer, time_base, sched->time_base);
168*0Sstevel@tonic-gate ASSIGN(buffer, cpuid, sched->cpuid);
169*0Sstevel@tonic-gate
170*0Sstevel@tonic-gate /*
171*0Sstevel@tonic-gate * Remember schedule record generation number so the distance
172*0Sstevel@tonic-gate * in virtual space can be calculated from an event record
173*0Sstevel@tonic-gate */
174*0Sstevel@tonic-gate sched->record_gen = ((tnf_block_header_t *)
175*0Sstevel@tonic-gate ((uintptr_t)buffer & TNF_BLOCK_MASK))->generation;
176*0Sstevel@tonic-gate /* Cannot have been written into tag space */
177*0Sstevel@tonic-gate ASSERT(sched->record_gen != TNF_TAG_GENERATION_NUM);
178*0Sstevel@tonic-gate
179*0Sstevel@tonic-gate return ((tnf_record_p)buffer);
180*0Sstevel@tonic-gate }
181*0Sstevel@tonic-gate
182*0Sstevel@tonic-gate /*
183*0Sstevel@tonic-gate * Array of addresses and derivatives
184*0Sstevel@tonic-gate */
185*0Sstevel@tonic-gate
186*0Sstevel@tonic-gate tnf_reference_t
tnf_opaque_array_1(tnf_ops_t * ops,tnf_opaque_t * opaques,tnf_record_p reference,tnf_tag_data_t * tag_data)187*0Sstevel@tonic-gate tnf_opaque_array_1(tnf_ops_t *ops, tnf_opaque_t *opaques,
188*0Sstevel@tonic-gate tnf_record_p reference, tnf_tag_data_t *tag_data)
189*0Sstevel@tonic-gate {
190*0Sstevel@tonic-gate tnf_record_p tag_index;
191*0Sstevel@tonic-gate size_t record_size;
192*0Sstevel@tonic-gate tnf_opaque_t *tmp;
193*0Sstevel@tonic-gate tnf_opaque_t *ref_p;
194*0Sstevel@tonic-gate tnf_array_header_t *bufhdr;
195*0Sstevel@tonic-gate
196*0Sstevel@tonic-gate tag_index = tag_data->tag_index ? tag_data->tag_index :
197*0Sstevel@tonic-gate tag_data->tag_desc(ops, tag_data);
198*0Sstevel@tonic-gate
199*0Sstevel@tonic-gate if (!opaques)
200*0Sstevel@tonic-gate return (TNF_NULL);
201*0Sstevel@tonic-gate
202*0Sstevel@tonic-gate record_size = sizeof (*bufhdr);
203*0Sstevel@tonic-gate tmp = opaques;
204*0Sstevel@tonic-gate while (*tmp++)
205*0Sstevel@tonic-gate record_size += sizeof (*ref_p);
206*0Sstevel@tonic-gate
207*0Sstevel@tonic-gate ALLOC2(ops, record_size, bufhdr, ops->mode);
208*0Sstevel@tonic-gate
209*0Sstevel@tonic-gate ASSIGN(bufhdr, tag, tag_index);
210*0Sstevel@tonic-gate /* LINTED assignment of 64-bit integer to 32-bit integer */
211*0Sstevel@tonic-gate ASSIGN(bufhdr, self_size, record_size);
212*0Sstevel@tonic-gate
213*0Sstevel@tonic-gate tmp = opaques;
214*0Sstevel@tonic-gate /* LINTED pointer cast may result in improper alignment */
215*0Sstevel@tonic-gate ref_p = (tnf_opaque_t *)((char *)bufhdr + sizeof (*bufhdr));
216*0Sstevel@tonic-gate while (*tmp) {
217*0Sstevel@tonic-gate *ref_p = tnf_opaque(ops, *tmp, (tnf_reference_t *)ref_p);
218*0Sstevel@tonic-gate tmp++;
219*0Sstevel@tonic-gate ref_p++;
220*0Sstevel@tonic-gate }
221*0Sstevel@tonic-gate
222*0Sstevel@tonic-gate return (tnf_ref32(ops, (tnf_record_p) bufhdr, reference));
223*0Sstevel@tonic-gate }
224*0Sstevel@tonic-gate
225*0Sstevel@tonic-gate #ifdef __sparc
226*0Sstevel@tonic-gate
227*0Sstevel@tonic-gate tnf_reference_t
tnf_opaque32_array_1(tnf_ops_t * ops,tnf_uint32_t * opaques,tnf_record_p reference,tnf_tag_data_t * tag_data)228*0Sstevel@tonic-gate tnf_opaque32_array_1(tnf_ops_t *ops, tnf_uint32_t *opaques,
229*0Sstevel@tonic-gate tnf_record_p reference, tnf_tag_data_t *tag_data)
230*0Sstevel@tonic-gate {
231*0Sstevel@tonic-gate tnf_record_p tag_index;
232*0Sstevel@tonic-gate size_t record_size;
233*0Sstevel@tonic-gate tnf_uint32_t *tmp;
234*0Sstevel@tonic-gate tnf_uint32_t *ref_p;
235*0Sstevel@tonic-gate tnf_array_header_t *bufhdr;
236*0Sstevel@tonic-gate
237*0Sstevel@tonic-gate tag_index = tag_data->tag_index ? tag_data->tag_index :
238*0Sstevel@tonic-gate tag_data->tag_desc(ops, tag_data);
239*0Sstevel@tonic-gate
240*0Sstevel@tonic-gate if (!opaques)
241*0Sstevel@tonic-gate return (TNF_NULL);
242*0Sstevel@tonic-gate
243*0Sstevel@tonic-gate record_size = sizeof (*bufhdr);
244*0Sstevel@tonic-gate tmp = opaques;
245*0Sstevel@tonic-gate while (*tmp++)
246*0Sstevel@tonic-gate record_size += sizeof (*ref_p);
247*0Sstevel@tonic-gate
248*0Sstevel@tonic-gate ALLOC2(ops, record_size, bufhdr, ops->mode);
249*0Sstevel@tonic-gate
250*0Sstevel@tonic-gate ASSIGN(bufhdr, tag, tag_index);
251*0Sstevel@tonic-gate /* LINTED assignment of 64-bit integer to 32-bit integer */
252*0Sstevel@tonic-gate ASSIGN(bufhdr, self_size, record_size);
253*0Sstevel@tonic-gate
254*0Sstevel@tonic-gate tmp = opaques;
255*0Sstevel@tonic-gate /* LINTED pointer cast may result in improper alignment */
256*0Sstevel@tonic-gate ref_p = (tnf_uint32_t *)((char *)bufhdr + sizeof (*bufhdr));
257*0Sstevel@tonic-gate while (*tmp) {
258*0Sstevel@tonic-gate *ref_p = tnf_uint32(ops, *tmp, (tnf_reference_t *)ref_p);
259*0Sstevel@tonic-gate tmp++;
260*0Sstevel@tonic-gate ref_p++;
261*0Sstevel@tonic-gate }
262*0Sstevel@tonic-gate
263*0Sstevel@tonic-gate return (tnf_ref32(ops, (tnf_record_p) bufhdr, reference));
264*0Sstevel@tonic-gate }
265*0Sstevel@tonic-gate
266*0Sstevel@tonic-gate #endif /* __sparc */
267*0Sstevel@tonic-gate
268*0Sstevel@tonic-gate /*
269*0Sstevel@tonic-gate * Tag initializer
270*0Sstevel@tonic-gate */
271*0Sstevel@tonic-gate
272*0Sstevel@tonic-gate void
tnf_tag_trace_init(void)273*0Sstevel@tonic-gate tnf_tag_trace_init(void)
274*0Sstevel@tonic-gate {
275*0Sstevel@tonic-gate
276*0Sstevel@tonic-gate TAG_SNAP(tnf_probe_event);
277*0Sstevel@tonic-gate TAG_SNAP(tnf_time_base);
278*0Sstevel@tonic-gate TAG_SNAP(tnf_time_delta);
279*0Sstevel@tonic-gate TAG_SNAP(tnf_pid);
280*0Sstevel@tonic-gate TAG_SNAP(tnf_lwpid);
281*0Sstevel@tonic-gate
282*0Sstevel@tonic-gate TAG_SNAP(tnf_kthread_id);
283*0Sstevel@tonic-gate TAG_SNAP(tnf_cpuid);
284*0Sstevel@tonic-gate TAG_SNAP(tnf_device);
285*0Sstevel@tonic-gate TAG_SNAP(tnf_symbol);
286*0Sstevel@tonic-gate TAG_SNAP(tnf_symbols);
287*0Sstevel@tonic-gate TAG_SNAP(tnf_sysnum);
288*0Sstevel@tonic-gate TAG_SNAP(tnf_microstate);
289*0Sstevel@tonic-gate TAG_SNAP(tnf_offset);
290*0Sstevel@tonic-gate TAG_SNAP(tnf_fault_type);
291*0Sstevel@tonic-gate TAG_SNAP(tnf_seg_access);
292*0Sstevel@tonic-gate TAG_SNAP(tnf_bioflags);
293*0Sstevel@tonic-gate TAG_SNAP(tnf_diskaddr);
294*0Sstevel@tonic-gate TAG_SNAP(tnf_kernel_schedule);
295*0Sstevel@tonic-gate
296*0Sstevel@tonic-gate TAG_SNAP(tnf_probe_type);
297*0Sstevel@tonic-gate
298*0Sstevel@tonic-gate }
299