1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright (c) 1994, by Sun Microsytems, Inc. 24*7c478bd9Sstevel@tonic-gate */ 25*7c478bd9Sstevel@tonic-gate 26*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 27*7c478bd9Sstevel@tonic-gate 28*7c478bd9Sstevel@tonic-gate #ifndef DEBUG 29*7c478bd9Sstevel@tonic-gate #define NDEBUG 1 30*7c478bd9Sstevel@tonic-gate #endif 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 33*7c478bd9Sstevel@tonic-gate #include <string.h> 34*7c478bd9Sstevel@tonic-gate #include <tnf/com.h> 35*7c478bd9Sstevel@tonic-gate #include <tnf/writer.h> 36*7c478bd9Sstevel@tonic-gate #include <tnf/probe.h> 37*7c478bd9Sstevel@tonic-gate #include <assert.h> 38*7c478bd9Sstevel@tonic-gate 39*7c478bd9Sstevel@tonic-gate #include "tnf_types.h" 40*7c478bd9Sstevel@tonic-gate #include "tnf_trace.h" 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate #ifdef TNFWB_DEBUG 43*7c478bd9Sstevel@tonic-gate #ifdef _KERNEL 44*7c478bd9Sstevel@tonic-gate #error TNFWB_DEBUG 45*7c478bd9Sstevel@tonic-gate #else /* _KERNEL */ 46*7c478bd9Sstevel@tonic-gate #include <stdio.h> 47*7c478bd9Sstevel@tonic-gate #include <thread.h> 48*7c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 49*7c478bd9Sstevel@tonic-gate #endif /* TNFW_DEBUG */ 50*7c478bd9Sstevel@tonic-gate 51*7c478bd9Sstevel@tonic-gate 52*7c478bd9Sstevel@tonic-gate /* 53*7c478bd9Sstevel@tonic-gate * Defines 54*7c478bd9Sstevel@tonic-gate */ 55*7c478bd9Sstevel@tonic-gate 56*7c478bd9Sstevel@tonic-gate #ifdef _KERNEL 57*7c478bd9Sstevel@tonic-gate #define TNF_ASSERT(expr) ASSERT(expr) 58*7c478bd9Sstevel@tonic-gate #else 59*7c478bd9Sstevel@tonic-gate #define TNF_ASSERT(expr) assert(expr) 60*7c478bd9Sstevel@tonic-gate #endif 61*7c478bd9Sstevel@tonic-gate 62*7c478bd9Sstevel@tonic-gate /* 63*7c478bd9Sstevel@tonic-gate * New properties need for tracing 64*7c478bd9Sstevel@tonic-gate */ 65*7c478bd9Sstevel@tonic-gate 66*7c478bd9Sstevel@tonic-gate static tnf_tag_data_t **derived_tagarg_properties[] = { 67*7c478bd9Sstevel@tonic-gate &TAG_DATA(tnf_derived), 68*7c478bd9Sstevel@tonic-gate &TAG_DATA(tnf_tag_arg), 69*7c478bd9Sstevel@tonic-gate 0 70*7c478bd9Sstevel@tonic-gate }; 71*7c478bd9Sstevel@tonic-gate 72*7c478bd9Sstevel@tonic-gate static tnf_tag_data_t ***derived_tagarg_properties_ptr = 73*7c478bd9Sstevel@tonic-gate derived_tagarg_properties; 74*7c478bd9Sstevel@tonic-gate 75*7c478bd9Sstevel@tonic-gate /* 76*7c478bd9Sstevel@tonic-gate * New derived types for probes 77*7c478bd9Sstevel@tonic-gate */ 78*7c478bd9Sstevel@tonic-gate 79*7c478bd9Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_probe_event, tnf_tag, 80*7c478bd9Sstevel@tonic-gate derived_tagarg_properties_ptr, TNF_OPAQUE); 81*7c478bd9Sstevel@tonic-gate 82*7c478bd9Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_time_base, tnf_int64, 83*7c478bd9Sstevel@tonic-gate tnf_derived_properties, TNF_INT64); 84*7c478bd9Sstevel@tonic-gate 85*7c478bd9Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_time_delta, tnf_uint32, 86*7c478bd9Sstevel@tonic-gate tnf_derived_properties, TNF_UINT32); 87*7c478bd9Sstevel@tonic-gate 88*7c478bd9Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_pid, tnf_int32, 89*7c478bd9Sstevel@tonic-gate tnf_derived_properties, TNF_INT32); 90*7c478bd9Sstevel@tonic-gate 91*7c478bd9Sstevel@tonic-gate TNF_STD_DERIVED_TAG(tnf_lwpid, tnf_uint32, 92*7c478bd9Sstevel@tonic-gate tnf_derived_properties, TNF_UINT32); 93*7c478bd9Sstevel@tonic-gate 94*7c478bd9Sstevel@tonic-gate /* 95*7c478bd9Sstevel@tonic-gate * Schedule records -CAUTION- keep in sync with tnf_internal.h 96*7c478bd9Sstevel@tonic-gate * Note that tnf_schedule_prototype_t has different sizes for 97*7c478bd9Sstevel@tonic-gate * kernel and user. 98*7c478bd9Sstevel@tonic-gate */ 99*7c478bd9Sstevel@tonic-gate 100*7c478bd9Sstevel@tonic-gate static char *user_schedule_slot_names[] = { 101*7c478bd9Sstevel@tonic-gate TNF_N_TAG, 102*7c478bd9Sstevel@tonic-gate TNF_N_TID, 103*7c478bd9Sstevel@tonic-gate TNF_N_LWPID, 104*7c478bd9Sstevel@tonic-gate TNF_N_PID, 105*7c478bd9Sstevel@tonic-gate TNF_N_TIME_BASE, 106*7c478bd9Sstevel@tonic-gate 0}; 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate static tnf_tag_data_t **user_schedule_slots[] = { 109*7c478bd9Sstevel@tonic-gate &TAG_DATA(tnf_tag), /* tag */ 110*7c478bd9Sstevel@tonic-gate &TAG_DATA(tnf_uint32), /* tid XXX */ 111*7c478bd9Sstevel@tonic-gate &TAG_DATA(tnf_lwpid), /* lwpid */ 112*7c478bd9Sstevel@tonic-gate &TAG_DATA(tnf_pid), /* pid */ 113*7c478bd9Sstevel@tonic-gate &TAG_DATA(tnf_time_base), /* time_base */ 114*7c478bd9Sstevel@tonic-gate 0}; 115*7c478bd9Sstevel@tonic-gate 116*7c478bd9Sstevel@tonic-gate TNF_STD_STRUCT_TAG(tnf_sched_rec, 117*7c478bd9Sstevel@tonic-gate user_schedule_slots, 118*7c478bd9Sstevel@tonic-gate user_schedule_slot_names, 119*7c478bd9Sstevel@tonic-gate sizeof (tnf_schedule_prototype_t)); 120*7c478bd9Sstevel@tonic-gate 121*7c478bd9Sstevel@tonic-gate /* 122*7c478bd9Sstevel@tonic-gate * Probe type record (metatag) 123*7c478bd9Sstevel@tonic-gate */ 124*7c478bd9Sstevel@tonic-gate 125*7c478bd9Sstevel@tonic-gate static tnf_tag_data_t **probe_type_slots[] = { 126*7c478bd9Sstevel@tonic-gate &TAG_DATA(tnf_tag), 127*7c478bd9Sstevel@tonic-gate &TAG_DATA(tnf_name), 128*7c478bd9Sstevel@tonic-gate &TAG_DATA(tnf_properties), 129*7c478bd9Sstevel@tonic-gate &TAG_DATA(tnf_slot_types), 130*7c478bd9Sstevel@tonic-gate &TAG_DATA(tnf_type_size), 131*7c478bd9Sstevel@tonic-gate &TAG_DATA(tnf_slot_names), 132*7c478bd9Sstevel@tonic-gate &TAG_DATA(tnf_string), /* detail */ 133*7c478bd9Sstevel@tonic-gate 0}; 134*7c478bd9Sstevel@tonic-gate 135*7c478bd9Sstevel@tonic-gate TNF_STRUCT_TAG(tnf_probe_type, 136*7c478bd9Sstevel@tonic-gate tnf_type_properties, 137*7c478bd9Sstevel@tonic-gate probe_type_slots, 138*7c478bd9Sstevel@tonic-gate 0, 139*7c478bd9Sstevel@tonic-gate sizeof (tnf_probe_prototype_t)); 140*7c478bd9Sstevel@tonic-gate 141*7c478bd9Sstevel@tonic-gate /* 142*7c478bd9Sstevel@tonic-gate * export all tags 143*7c478bd9Sstevel@tonic-gate */ 144*7c478bd9Sstevel@tonic-gate 145*7c478bd9Sstevel@tonic-gate TAG_EXPORT(tnf_probe_event); 146*7c478bd9Sstevel@tonic-gate TAG_EXPORT(tnf_time_base); 147*7c478bd9Sstevel@tonic-gate TAG_EXPORT(tnf_time_delta); 148*7c478bd9Sstevel@tonic-gate TAG_EXPORT(tnf_pid); 149*7c478bd9Sstevel@tonic-gate TAG_EXPORT(tnf_lwpid); 150*7c478bd9Sstevel@tonic-gate 151*7c478bd9Sstevel@tonic-gate TAG_EXPORT(tnf_sched_rec); 152*7c478bd9Sstevel@tonic-gate TAG_EXPORT(tnf_probe_type); 153*7c478bd9Sstevel@tonic-gate 154*7c478bd9Sstevel@tonic-gate /* 155*7c478bd9Sstevel@tonic-gate * Write a schedule record 156*7c478bd9Sstevel@tonic-gate * Can only be written in reusable data space. 157*7c478bd9Sstevel@tonic-gate */ 158*7c478bd9Sstevel@tonic-gate 159*7c478bd9Sstevel@tonic-gate tnf_record_p 160*7c478bd9Sstevel@tonic-gate tnf_schedule_write(tnf_ops_t *ops, tnf_schedule_t *sched) 161*7c478bd9Sstevel@tonic-gate { 162*7c478bd9Sstevel@tonic-gate tnf_tag_data_t *metatag_data; 163*7c478bd9Sstevel@tonic-gate tnf_record_p metatag_index; 164*7c478bd9Sstevel@tonic-gate tnf_schedule_prototype_t *buffer; 165*7c478bd9Sstevel@tonic-gate 166*7c478bd9Sstevel@tonic-gate #ifdef _TNF_VERBOSE 167*7c478bd9Sstevel@tonic-gate fprintf(stderr, "tnf_schedule_write: \n"); 168*7c478bd9Sstevel@tonic-gate #endif 169*7c478bd9Sstevel@tonic-gate /* Cannot be called when writing into tag space */ 170*7c478bd9Sstevel@tonic-gate TNF_ASSERT(ops->mode == TNF_ALLOC_REUSABLE); 171*7c478bd9Sstevel@tonic-gate ALLOC(ops, sizeof (*buffer), buffer, sched->record_p, ops->mode); 172*7c478bd9Sstevel@tonic-gate 173*7c478bd9Sstevel@tonic-gate metatag_data = TAG_DATA(tnf_sched_rec); 174*7c478bd9Sstevel@tonic-gate 175*7c478bd9Sstevel@tonic-gate metatag_index = metatag_data->tag_index ? 176*7c478bd9Sstevel@tonic-gate metatag_data->tag_index : 177*7c478bd9Sstevel@tonic-gate metatag_data->tag_desc(ops, metatag_data); 178*7c478bd9Sstevel@tonic-gate 179*7c478bd9Sstevel@tonic-gate ASSIGN(buffer, tag, metatag_index); 180*7c478bd9Sstevel@tonic-gate /* LINTED - tid is 32 bits */ 181*7c478bd9Sstevel@tonic-gate ASSIGN2(buffer, tid, sched->tid, uint32); 182*7c478bd9Sstevel@tonic-gate /* LINTED - lwpid is 32 bits */ 183*7c478bd9Sstevel@tonic-gate ASSIGN(buffer, lwpid, sched->lwpid); 184*7c478bd9Sstevel@tonic-gate /* LINTED - pid is 32 bits */ 185*7c478bd9Sstevel@tonic-gate ASSIGN(buffer, pid, sched->pid); 186*7c478bd9Sstevel@tonic-gate ASSIGN(buffer, time_base, sched->time_base); 187*7c478bd9Sstevel@tonic-gate 188*7c478bd9Sstevel@tonic-gate /* 189*7c478bd9Sstevel@tonic-gate * Remember schedule record generation number so the distance 190*7c478bd9Sstevel@tonic-gate * in virtual space can be calculated from an event record 191*7c478bd9Sstevel@tonic-gate */ 192*7c478bd9Sstevel@tonic-gate sched->record_gen = ((tnf_block_header_t *) 193*7c478bd9Sstevel@tonic-gate ((uintptr_t)buffer & TNF_BLOCK_MASK))->generation; 194*7c478bd9Sstevel@tonic-gate /* Cannot have been written into tag space */ 195*7c478bd9Sstevel@tonic-gate TNF_ASSERT(sched->record_gen != TNF_TAG_GENERATION_NUM); 196*7c478bd9Sstevel@tonic-gate 197*7c478bd9Sstevel@tonic-gate return ((tnf_record_p) buffer); 198*7c478bd9Sstevel@tonic-gate } 199