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