4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1994, 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <sys/types.h>
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/ddi.h> /* strchr */
33 #include <sys/sunddi.h> /* strchr */
34 #include <sys/tnf_com.h>
35 #include <sys/tnf_writer.h>
36 #include <sys/tnf_probe.h>
37 #include <sys/debug.h>
40 #include "tnf_types.h"
41 #include "tnf_trace.h"
44 * New derived types for probes
47 TNF_STD_DERIVED_TAG(tnf_probe_event
, tnf_tag
,
48 tnf_derived_properties
, TNF_OPAQUE
);
50 TNF_STD_DERIVED_TAG(tnf_time_base
, tnf_int64
,
51 tnf_derived_properties
, TNF_INT64
);
53 TNF_STD_DERIVED_TAG(tnf_time_delta
, tnf_uint32
,
54 tnf_derived_properties
, TNF_UINT32
);
56 TNF_STD_DERIVED_TAG(tnf_pid
, tnf_int32
,
57 tnf_derived_properties
, TNF_INT32
);
59 TNF_STD_DERIVED_TAG(tnf_lwpid
, tnf_uint32
,
60 tnf_derived_properties
, TNF_UINT32
);
62 TNF_STD_DERIVED_TAG(tnf_kthread_id
, tnf_opaque
,
63 tnf_derived_properties
, TNF_OPAQUE
);
65 TNF_STD_DERIVED_TAG(tnf_cpuid
, tnf_int32
,
66 tnf_derived_properties
, TNF_INT32
);
68 TNF_STD_DERIVED_TAG(tnf_device
, tnf_ulong
,
69 tnf_derived_properties
, TNF_ULONG
);
71 TNF_STD_DERIVED_TAG(tnf_symbol
, tnf_opaque
,
72 tnf_derived_properties
, TNF_OPAQUE
);
74 TNF_STD_ARRAY_TAG(tnf_symbols
, tnf_symbol
, TNF_ARRAY
);
76 TNF_STD_DERIVED_TAG(tnf_sysnum
, tnf_int16
,
77 tnf_derived_properties
, TNF_INT32
);
79 TNF_STD_DERIVED_TAG(tnf_microstate
, tnf_int32
,
80 tnf_derived_properties
, TNF_INT32
);
82 TNF_STD_DERIVED_TAG(tnf_offset
, tnf_int64
,
83 tnf_derived_properties
, TNF_INT64
);
85 TNF_STD_DERIVED_TAG(tnf_fault_type
, tnf_int32
,
86 tnf_derived_properties
, TNF_INT32
);
88 TNF_STD_DERIVED_TAG(tnf_seg_access
, tnf_int32
,
89 tnf_derived_properties
, TNF_INT32
);
91 TNF_STD_DERIVED_TAG(tnf_bioflags
, tnf_int32
,
92 tnf_derived_properties
, TNF_INT32
);
94 TNF_STD_DERIVED_TAG(tnf_diskaddr
, tnf_int64
,
95 tnf_derived_properties
, TNF_INT64
);
97 static char *kernel_schedule_slot_names
[] = {
106 static tnf_tag_data_t
**kernel_schedule_slots
[] = {
108 &TAG_DATA(tnf_kthread_id
),
109 &TAG_DATA(tnf_lwpid
),
111 &TAG_DATA(tnf_time_base
),
112 &TAG_DATA(tnf_cpuid
),
115 TNF_STD_STRUCT_TAG(tnf_kernel_schedule
,
116 kernel_schedule_slots
,
117 kernel_schedule_slot_names
,
118 sizeof (tnf_schedule_prototype_t
));
121 * Probe type record (metatag)
124 static tnf_tag_data_t
**probe_type_slots
[] = {
127 &TAG_DATA(tnf_properties
),
128 &TAG_DATA(tnf_slot_types
),
129 &TAG_DATA(tnf_type_size
),
130 &TAG_DATA(tnf_slot_names
),
131 &TAG_DATA(tnf_string
), /* detail */
134 TNF_METATAG(tnf_probe_type
, tnf_type_properties
,
135 probe_type_slots
, tnf_struct_tag_1
);
138 * Write a kernel schedule record
139 * Can only be written in reusable data space.
143 tnf_kernel_schedule(tnf_ops_t
*ops
, tnf_schedule_t
*sched
)
145 tnf_tag_data_t
*metatag_data
;
146 tnf_record_p metatag_index
;
147 tnf_schedule_prototype_t
*buffer
;
152 /* Cannot be called when writing into tag space */
153 ASSERT(ops
->mode
== TNF_ALLOC_REUSABLE
);
155 ALLOC(ops
, sizeof (*buffer
), buffer
, sched
->record_p
,
156 TNF_ALLOC_REUSABLE
); /* XXX see comment above */
158 metatag_data
= TAG_DATA(tnf_kernel_schedule
);
159 metatag_index
= metatag_data
->tag_index
?
160 metatag_data
->tag_index
:
161 metatag_data
->tag_desc(ops
, metatag_data
);
163 ASSIGN(buffer
, tag
, metatag_index
);
164 ASSIGN2(buffer
, tid
, t
, kthread_id
);
165 ASSIGN(buffer
, lwpid
, t
->t_tid
);
166 ASSIGN(buffer
, pid
, ttoproc(t
)->p_pid
);
167 ASSIGN(buffer
, time_base
, sched
->time_base
);
168 ASSIGN(buffer
, cpuid
, sched
->cpuid
);
171 * Remember schedule record generation number so the distance
172 * in virtual space can be calculated from an event record
174 sched
->record_gen
= ((tnf_block_header_t
*)
175 ((uintptr_t)buffer
& TNF_BLOCK_MASK
))->generation
;
176 /* Cannot have been written into tag space */
177 ASSERT(sched
->record_gen
!= TNF_TAG_GENERATION_NUM
);
179 return ((tnf_record_p
)buffer
);
183 * Array of addresses and derivatives
187 tnf_opaque_array_1(tnf_ops_t
*ops
, tnf_opaque_t
*opaques
,
188 tnf_record_p reference
, tnf_tag_data_t
*tag_data
)
190 tnf_record_p tag_index
;
194 tnf_array_header_t
*bufhdr
;
196 tag_index
= tag_data
->tag_index
? tag_data
->tag_index
:
197 tag_data
->tag_desc(ops
, tag_data
);
202 record_size
= sizeof (*bufhdr
);
205 record_size
+= sizeof (*ref_p
);
207 ALLOC2(ops
, record_size
, bufhdr
, ops
->mode
);
209 ASSIGN(bufhdr
, tag
, tag_index
);
210 /* LINTED assignment of 64-bit integer to 32-bit integer */
211 ASSIGN(bufhdr
, self_size
, record_size
);
214 /* LINTED pointer cast may result in improper alignment */
215 ref_p
= (tnf_opaque_t
*)((char *)bufhdr
+ sizeof (*bufhdr
));
217 *ref_p
= tnf_opaque(ops
, *tmp
, (tnf_reference_t
*)ref_p
);
222 return (tnf_ref32(ops
, (tnf_record_p
) bufhdr
, reference
));
228 tnf_opaque32_array_1(tnf_ops_t
*ops
, tnf_uint32_t
*opaques
,
229 tnf_record_p reference
, tnf_tag_data_t
*tag_data
)
231 tnf_record_p tag_index
;
235 tnf_array_header_t
*bufhdr
;
237 tag_index
= tag_data
->tag_index
? tag_data
->tag_index
:
238 tag_data
->tag_desc(ops
, tag_data
);
243 record_size
= sizeof (*bufhdr
);
246 record_size
+= sizeof (*ref_p
);
248 ALLOC2(ops
, record_size
, bufhdr
, ops
->mode
);
250 ASSIGN(bufhdr
, tag
, tag_index
);
251 /* LINTED assignment of 64-bit integer to 32-bit integer */
252 ASSIGN(bufhdr
, self_size
, record_size
);
255 /* LINTED pointer cast may result in improper alignment */
256 ref_p
= (tnf_uint32_t
*)((char *)bufhdr
+ sizeof (*bufhdr
));
258 *ref_p
= tnf_uint32(ops
, *tmp
, (tnf_reference_t
*)ref_p
);
263 return (tnf_ref32(ops
, (tnf_record_p
) bufhdr
, reference
));
273 tnf_tag_trace_init(void)
276 TAG_SNAP(tnf_probe_event
);
277 TAG_SNAP(tnf_time_base
);
278 TAG_SNAP(tnf_time_delta
);
282 TAG_SNAP(tnf_kthread_id
);
284 TAG_SNAP(tnf_device
);
285 TAG_SNAP(tnf_symbol
);
286 TAG_SNAP(tnf_symbols
);
287 TAG_SNAP(tnf_sysnum
);
288 TAG_SNAP(tnf_microstate
);
289 TAG_SNAP(tnf_offset
);
290 TAG_SNAP(tnf_fault_type
);
291 TAG_SNAP(tnf_seg_access
);
292 TAG_SNAP(tnf_bioflags
);
293 TAG_SNAP(tnf_diskaddr
);
294 TAG_SNAP(tnf_kernel_schedule
);
296 TAG_SNAP(tnf_probe_type
);