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 (c) 1994, by Sun Microsytems, Inc.
24*0Sstevel@tonic-gate */
25*0Sstevel@tonic-gate
26*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
27*0Sstevel@tonic-gate
28*0Sstevel@tonic-gate #ifndef DEBUG
29*0Sstevel@tonic-gate #define NDEBUG 1
30*0Sstevel@tonic-gate #endif
31*0Sstevel@tonic-gate
32*0Sstevel@tonic-gate #include <stdlib.h>
33*0Sstevel@tonic-gate #include <string.h>
34*0Sstevel@tonic-gate #include <tnf/com.h>
35*0Sstevel@tonic-gate #include <tnf/writer.h>
36*0Sstevel@tonic-gate #include <tnf/probe.h>
37*0Sstevel@tonic-gate #include <assert.h>
38*0Sstevel@tonic-gate
39*0Sstevel@tonic-gate #include "tnf_types.h"
40*0Sstevel@tonic-gate #include "tnf_trace.h"
41*0Sstevel@tonic-gate
42*0Sstevel@tonic-gate #ifdef TNFWB_DEBUG
43*0Sstevel@tonic-gate #ifdef _KERNEL
44*0Sstevel@tonic-gate #error TNFWB_DEBUG
45*0Sstevel@tonic-gate #else /* _KERNEL */
46*0Sstevel@tonic-gate #include <stdio.h>
47*0Sstevel@tonic-gate #include <thread.h>
48*0Sstevel@tonic-gate #endif /* _KERNEL */
49*0Sstevel@tonic-gate #endif /* TNFW_DEBUG */
50*0Sstevel@tonic-gate
51*0Sstevel@tonic-gate
52*0Sstevel@tonic-gate /*
53*0Sstevel@tonic-gate * Defines
54*0Sstevel@tonic-gate */
55*0Sstevel@tonic-gate
56*0Sstevel@tonic-gate #ifdef _KERNEL
57*0Sstevel@tonic-gate #define TNF_ASSERT(expr) ASSERT(expr)
58*0Sstevel@tonic-gate #else
59*0Sstevel@tonic-gate #define TNF_ASSERT(expr) assert(expr)
60*0Sstevel@tonic-gate #endif
61*0Sstevel@tonic-gate
62*0Sstevel@tonic-gate /*
63*0Sstevel@tonic-gate * New properties need for tracing
64*0Sstevel@tonic-gate */
65*0Sstevel@tonic-gate
66*0Sstevel@tonic-gate static tnf_tag_data_t **derived_tagarg_properties[] = {
67*0Sstevel@tonic-gate &TAG_DATA(tnf_derived),
68*0Sstevel@tonic-gate &TAG_DATA(tnf_tag_arg),
69*0Sstevel@tonic-gate 0
70*0Sstevel@tonic-gate };
71*0Sstevel@tonic-gate
72*0Sstevel@tonic-gate static tnf_tag_data_t ***derived_tagarg_properties_ptr =
73*0Sstevel@tonic-gate derived_tagarg_properties;
74*0Sstevel@tonic-gate
75*0Sstevel@tonic-gate /*
76*0Sstevel@tonic-gate * New derived types for probes
77*0Sstevel@tonic-gate */
78*0Sstevel@tonic-gate
79*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_probe_event, tnf_tag,
80*0Sstevel@tonic-gate derived_tagarg_properties_ptr, TNF_OPAQUE);
81*0Sstevel@tonic-gate
82*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_time_base, tnf_int64,
83*0Sstevel@tonic-gate tnf_derived_properties, TNF_INT64);
84*0Sstevel@tonic-gate
85*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_time_delta, tnf_uint32,
86*0Sstevel@tonic-gate tnf_derived_properties, TNF_UINT32);
87*0Sstevel@tonic-gate
88*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_pid, tnf_int32,
89*0Sstevel@tonic-gate tnf_derived_properties, TNF_INT32);
90*0Sstevel@tonic-gate
91*0Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_lwpid, tnf_uint32,
92*0Sstevel@tonic-gate tnf_derived_properties, TNF_UINT32);
93*0Sstevel@tonic-gate
94*0Sstevel@tonic-gate /*
95*0Sstevel@tonic-gate * Schedule records -CAUTION- keep in sync with tnf_internal.h
96*0Sstevel@tonic-gate * Note that tnf_schedule_prototype_t has different sizes for
97*0Sstevel@tonic-gate * kernel and user.
98*0Sstevel@tonic-gate */
99*0Sstevel@tonic-gate
100*0Sstevel@tonic-gate static char *user_schedule_slot_names[] = {
101*0Sstevel@tonic-gate TNF_N_TAG,
102*0Sstevel@tonic-gate TNF_N_TID,
103*0Sstevel@tonic-gate TNF_N_LWPID,
104*0Sstevel@tonic-gate TNF_N_PID,
105*0Sstevel@tonic-gate TNF_N_TIME_BASE,
106*0Sstevel@tonic-gate 0};
107*0Sstevel@tonic-gate
108*0Sstevel@tonic-gate static tnf_tag_data_t **user_schedule_slots[] = {
109*0Sstevel@tonic-gate &TAG_DATA(tnf_tag), /* tag */
110*0Sstevel@tonic-gate &TAG_DATA(tnf_uint32), /* tid XXX */
111*0Sstevel@tonic-gate &TAG_DATA(tnf_lwpid), /* lwpid */
112*0Sstevel@tonic-gate &TAG_DATA(tnf_pid), /* pid */
113*0Sstevel@tonic-gate &TAG_DATA(tnf_time_base), /* time_base */
114*0Sstevel@tonic-gate 0};
115*0Sstevel@tonic-gate
116*0Sstevel@tonic-gate TNF_STD_STRUCT_TAG(tnf_sched_rec,
117*0Sstevel@tonic-gate user_schedule_slots,
118*0Sstevel@tonic-gate user_schedule_slot_names,
119*0Sstevel@tonic-gate sizeof (tnf_schedule_prototype_t));
120*0Sstevel@tonic-gate
121*0Sstevel@tonic-gate /*
122*0Sstevel@tonic-gate * Probe type record (metatag)
123*0Sstevel@tonic-gate */
124*0Sstevel@tonic-gate
125*0Sstevel@tonic-gate static tnf_tag_data_t **probe_type_slots[] = {
126*0Sstevel@tonic-gate &TAG_DATA(tnf_tag),
127*0Sstevel@tonic-gate &TAG_DATA(tnf_name),
128*0Sstevel@tonic-gate &TAG_DATA(tnf_properties),
129*0Sstevel@tonic-gate &TAG_DATA(tnf_slot_types),
130*0Sstevel@tonic-gate &TAG_DATA(tnf_type_size),
131*0Sstevel@tonic-gate &TAG_DATA(tnf_slot_names),
132*0Sstevel@tonic-gate &TAG_DATA(tnf_string), /* detail */
133*0Sstevel@tonic-gate 0};
134*0Sstevel@tonic-gate
135*0Sstevel@tonic-gate TNF_STRUCT_TAG(tnf_probe_type,
136*0Sstevel@tonic-gate tnf_type_properties,
137*0Sstevel@tonic-gate probe_type_slots,
138*0Sstevel@tonic-gate 0,
139*0Sstevel@tonic-gate sizeof (tnf_probe_prototype_t));
140*0Sstevel@tonic-gate
141*0Sstevel@tonic-gate /*
142*0Sstevel@tonic-gate * export all tags
143*0Sstevel@tonic-gate */
144*0Sstevel@tonic-gate
145*0Sstevel@tonic-gate TAG_EXPORT(tnf_probe_event);
146*0Sstevel@tonic-gate TAG_EXPORT(tnf_time_base);
147*0Sstevel@tonic-gate TAG_EXPORT(tnf_time_delta);
148*0Sstevel@tonic-gate TAG_EXPORT(tnf_pid);
149*0Sstevel@tonic-gate TAG_EXPORT(tnf_lwpid);
150*0Sstevel@tonic-gate
151*0Sstevel@tonic-gate TAG_EXPORT(tnf_sched_rec);
152*0Sstevel@tonic-gate TAG_EXPORT(tnf_probe_type);
153*0Sstevel@tonic-gate
154*0Sstevel@tonic-gate /*
155*0Sstevel@tonic-gate * Write a schedule record
156*0Sstevel@tonic-gate * Can only be written in reusable data space.
157*0Sstevel@tonic-gate */
158*0Sstevel@tonic-gate
159*0Sstevel@tonic-gate tnf_record_p
tnf_schedule_write(tnf_ops_t * ops,tnf_schedule_t * sched)160*0Sstevel@tonic-gate tnf_schedule_write(tnf_ops_t *ops, tnf_schedule_t *sched)
161*0Sstevel@tonic-gate {
162*0Sstevel@tonic-gate tnf_tag_data_t *metatag_data;
163*0Sstevel@tonic-gate tnf_record_p metatag_index;
164*0Sstevel@tonic-gate tnf_schedule_prototype_t *buffer;
165*0Sstevel@tonic-gate
166*0Sstevel@tonic-gate #ifdef _TNF_VERBOSE
167*0Sstevel@tonic-gate fprintf(stderr, "tnf_schedule_write: \n");
168*0Sstevel@tonic-gate #endif
169*0Sstevel@tonic-gate /* Cannot be called when writing into tag space */
170*0Sstevel@tonic-gate TNF_ASSERT(ops->mode == TNF_ALLOC_REUSABLE);
171*0Sstevel@tonic-gate ALLOC(ops, sizeof (*buffer), buffer, sched->record_p, ops->mode);
172*0Sstevel@tonic-gate
173*0Sstevel@tonic-gate metatag_data = TAG_DATA(tnf_sched_rec);
174*0Sstevel@tonic-gate
175*0Sstevel@tonic-gate metatag_index = metatag_data->tag_index ?
176*0Sstevel@tonic-gate metatag_data->tag_index :
177*0Sstevel@tonic-gate metatag_data->tag_desc(ops, metatag_data);
178*0Sstevel@tonic-gate
179*0Sstevel@tonic-gate ASSIGN(buffer, tag, metatag_index);
180*0Sstevel@tonic-gate /* LINTED - tid is 32 bits */
181*0Sstevel@tonic-gate ASSIGN2(buffer, tid, sched->tid, uint32);
182*0Sstevel@tonic-gate /* LINTED - lwpid is 32 bits */
183*0Sstevel@tonic-gate ASSIGN(buffer, lwpid, sched->lwpid);
184*0Sstevel@tonic-gate /* LINTED - pid is 32 bits */
185*0Sstevel@tonic-gate ASSIGN(buffer, pid, sched->pid);
186*0Sstevel@tonic-gate ASSIGN(buffer, time_base, sched->time_base);
187*0Sstevel@tonic-gate
188*0Sstevel@tonic-gate /*
189*0Sstevel@tonic-gate * Remember schedule record generation number so the distance
190*0Sstevel@tonic-gate * in virtual space can be calculated from an event record
191*0Sstevel@tonic-gate */
192*0Sstevel@tonic-gate sched->record_gen = ((tnf_block_header_t *)
193*0Sstevel@tonic-gate ((uintptr_t)buffer & TNF_BLOCK_MASK))->generation;
194*0Sstevel@tonic-gate /* Cannot have been written into tag space */
195*0Sstevel@tonic-gate TNF_ASSERT(sched->record_gen != TNF_TAG_GENERATION_NUM);
196*0Sstevel@tonic-gate
197*0Sstevel@tonic-gate return ((tnf_record_p) buffer);
198*0Sstevel@tonic-gate }
199