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 2005 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 #ifndef _SYS_STRFT_H 28*7c478bd9Sstevel@tonic-gate #define _SYS_STRFT_H 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 33*7c478bd9Sstevel@tonic-gate extern "C" { 34*7c478bd9Sstevel@tonic-gate #endif 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate /* 37*7c478bd9Sstevel@tonic-gate * The flow trace subsystem is used to trace the flow of STREAMS messages 38*7c478bd9Sstevel@tonic-gate * through a stream. 39*7c478bd9Sstevel@tonic-gate * 40*7c478bd9Sstevel@tonic-gate * WARNING: this is a private subsystem and subject to change at any time! 41*7c478bd9Sstevel@tonic-gate */ 42*7c478bd9Sstevel@tonic-gate 43*7c478bd9Sstevel@tonic-gate #include <sys/time.h> 44*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 45*7c478bd9Sstevel@tonic-gate #include <sys/stream.h> 46*7c478bd9Sstevel@tonic-gate 47*7c478bd9Sstevel@tonic-gate /* 48*7c478bd9Sstevel@tonic-gate * Some evnt defines, values 0..N are reserved for internal use, 49*7c478bd9Sstevel@tonic-gate * (N+1)..0x1FFF are available for arbitrary module/drvier use, 50*7c478bd9Sstevel@tonic-gate * 0x8000 (RD/WR q marker) and 0x4000 (thread cs marker) are or'ed 51*7c478bd9Sstevel@tonic-gate * flag bits reserved for internal use. 52*7c478bd9Sstevel@tonic-gate */ 53*7c478bd9Sstevel@tonic-gate #define FTEV_MASK 0x1FFF 54*7c478bd9Sstevel@tonic-gate #define FTEV_ISWR 0x8000 55*7c478bd9Sstevel@tonic-gate #define FTEV_CS 0x4000 56*7c478bd9Sstevel@tonic-gate #define FTEV_PS 0x2000 57*7c478bd9Sstevel@tonic-gate 58*7c478bd9Sstevel@tonic-gate #define FTEV_QMASK 0x1F00 59*7c478bd9Sstevel@tonic-gate 60*7c478bd9Sstevel@tonic-gate #define FTEV_ALLOCMASK 0x1FF8 61*7c478bd9Sstevel@tonic-gate #define FTEV_ALLOCB 0x0000 62*7c478bd9Sstevel@tonic-gate #define FTEV_ESBALLOC 0x0001 63*7c478bd9Sstevel@tonic-gate #define FTEV_DESBALLOC 0x0002 64*7c478bd9Sstevel@tonic-gate #define FTEV_ESBALLOCA 0x0003 65*7c478bd9Sstevel@tonic-gate #define FTEV_DESBALLOCA 0x0004 66*7c478bd9Sstevel@tonic-gate #define FTEV_ALLOCBIG 0x0005 67*7c478bd9Sstevel@tonic-gate #define FTEV_ALLOCBW 0x0006 68*7c478bd9Sstevel@tonic-gate #define FTEV_BCALLOCB 0x0007 69*7c478bd9Sstevel@tonic-gate #define FTEV_FREEB 0x0008 70*7c478bd9Sstevel@tonic-gate #define FTEV_DUPB 0x0009 71*7c478bd9Sstevel@tonic-gate #define FTEV_COPYB 0x000A 72*7c478bd9Sstevel@tonic-gate 73*7c478bd9Sstevel@tonic-gate #define FTEV_CALLER 0x000F 74*7c478bd9Sstevel@tonic-gate 75*7c478bd9Sstevel@tonic-gate #define FTEV_PUT 0x0100 76*7c478bd9Sstevel@tonic-gate #define FTEV_PUTQ 0x0105 77*7c478bd9Sstevel@tonic-gate #define FTEV_GETQ 0x0106 78*7c478bd9Sstevel@tonic-gate #define FTEV_RMVQ 0x0107 79*7c478bd9Sstevel@tonic-gate #define FTEV_INSQ 0x0108 80*7c478bd9Sstevel@tonic-gate #define FTEV_PUTBQ 0x0109 81*7c478bd9Sstevel@tonic-gate #define FTEV_FLUSHQ 0x010A 82*7c478bd9Sstevel@tonic-gate #define FTEV_PUTNEXT 0x010D 83*7c478bd9Sstevel@tonic-gate #define FTEV_RWNEXT 0x010E 84*7c478bd9Sstevel@tonic-gate 85*7c478bd9Sstevel@tonic-gate #define FTBLK_EVNTS 0x9 86*7c478bd9Sstevel@tonic-gate 87*7c478bd9Sstevel@tonic-gate /* 88*7c478bd9Sstevel@tonic-gate * Data structure that contains the timestamp, module, event and event data 89*7c478bd9Sstevel@tonic-gate * (not certain as to its use yet: RSF). There is one per event. Every time 90*7c478bd9Sstevel@tonic-gate * str_ftevent() is called, one of the indices is filled in with this data. 91*7c478bd9Sstevel@tonic-gate */ 92*7c478bd9Sstevel@tonic-gate typedef struct ftevnt { 93*7c478bd9Sstevel@tonic-gate hrtime_t ts; /* a time-stamp as returned by gethrtime() */ 94*7c478bd9Sstevel@tonic-gate char *mid; /* the q->q_qinfo->qi_minfo->mi_idname pointer */ 95*7c478bd9Sstevel@tonic-gate ushort_t evnt; /* what event occured (put, srv, freeb, ...) */ 96*7c478bd9Sstevel@tonic-gate ushort_t data; /* event data */ 97*7c478bd9Sstevel@tonic-gate } ftevnt_t; 98*7c478bd9Sstevel@tonic-gate 99*7c478bd9Sstevel@tonic-gate /* 100*7c478bd9Sstevel@tonic-gate * A linked list of ftevnts. 101*7c478bd9Sstevel@tonic-gate */ 102*7c478bd9Sstevel@tonic-gate typedef struct ftblk { 103*7c478bd9Sstevel@tonic-gate struct ftblk *nxt; /* next ftblk (or NULL if none) */ 104*7c478bd9Sstevel@tonic-gate int ix; /* index of next free ev[] */ 105*7c478bd9Sstevel@tonic-gate struct ftevnt ev[FTBLK_EVNTS]; 106*7c478bd9Sstevel@tonic-gate } ftblk_t; 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate /* 109*7c478bd9Sstevel@tonic-gate * The flow trace header (start of event list). It consists of the 110*7c478bd9Sstevel@tonic-gate * current writable block (tail) 111*7c478bd9Sstevel@tonic-gate * a hash value (for recovering trace information) 112*7c478bd9Sstevel@tonic-gate * The last thread to process an event 113*7c478bd9Sstevel@tonic-gate * The last cpu to process an event 114*7c478bd9Sstevel@tonic-gate * The start of the list 115*7c478bd9Sstevel@tonic-gate * This structure is attached to a dblk, and traces a message through 116*7c478bd9Sstevel@tonic-gate * a flow. 117*7c478bd9Sstevel@tonic-gate */ 118*7c478bd9Sstevel@tonic-gate typedef struct fthdr { 119*7c478bd9Sstevel@tonic-gate struct ftblk *tail; 120*7c478bd9Sstevel@tonic-gate uint_t hash; /* accumulated hash value (sum of mid's) */ 121*7c478bd9Sstevel@tonic-gate void *thread; 122*7c478bd9Sstevel@tonic-gate int cpu_seqid; 123*7c478bd9Sstevel@tonic-gate struct ftblk first; 124*7c478bd9Sstevel@tonic-gate } fthdr_t; 125*7c478bd9Sstevel@tonic-gate 126*7c478bd9Sstevel@tonic-gate #ifdef _KERNEL 127*7c478bd9Sstevel@tonic-gate 128*7c478bd9Sstevel@tonic-gate struct datab; 129*7c478bd9Sstevel@tonic-gate 130*7c478bd9Sstevel@tonic-gate extern void str_ftevent(fthdr_t *, void *, ushort_t, ushort_t); 131*7c478bd9Sstevel@tonic-gate extern void str_ftfree(struct datab *); 132*7c478bd9Sstevel@tonic-gate extern int str_ftnever; 133*7c478bd9Sstevel@tonic-gate 134*7c478bd9Sstevel@tonic-gate /* 135*7c478bd9Sstevel@tonic-gate * Allocate flow-trace information and record an allocation event. 136*7c478bd9Sstevel@tonic-gate */ 137*7c478bd9Sstevel@tonic-gate #define STR_FTALLOC(hpp, e, d) { \ 138*7c478bd9Sstevel@tonic-gate if (str_ftnever == 0) { \ 139*7c478bd9Sstevel@tonic-gate fthdr_t *_hp = *(hpp); \ 140*7c478bd9Sstevel@tonic-gate \ 141*7c478bd9Sstevel@tonic-gate ASSERT(_hp == NULL); \ 142*7c478bd9Sstevel@tonic-gate _hp = kmem_cache_alloc(fthdr_cache, KM_NOSLEEP); \ 143*7c478bd9Sstevel@tonic-gate if ((*hpp = _hp) != NULL) { \ 144*7c478bd9Sstevel@tonic-gate _hp->tail = &_hp->first; \ 145*7c478bd9Sstevel@tonic-gate _hp->hash = 0; \ 146*7c478bd9Sstevel@tonic-gate _hp->thread = curthread; \ 147*7c478bd9Sstevel@tonic-gate _hp->cpu_seqid = CPU->cpu_seqid; \ 148*7c478bd9Sstevel@tonic-gate _hp->first.nxt = NULL; \ 149*7c478bd9Sstevel@tonic-gate _hp->first.ix = 0; \ 150*7c478bd9Sstevel@tonic-gate str_ftevent(_hp, caller(), (e), (d)); \ 151*7c478bd9Sstevel@tonic-gate } \ 152*7c478bd9Sstevel@tonic-gate } \ 153*7c478bd9Sstevel@tonic-gate } 154*7c478bd9Sstevel@tonic-gate 155*7c478bd9Sstevel@tonic-gate /* 156*7c478bd9Sstevel@tonic-gate * Add a flow-trace event to the passed-in mblk_t and any other mblk_t's 157*7c478bd9Sstevel@tonic-gate * chained off of b_cont. 158*7c478bd9Sstevel@tonic-gate */ 159*7c478bd9Sstevel@tonic-gate #define STR_FTEVENT_MSG(mp, p, e, d) { \ 160*7c478bd9Sstevel@tonic-gate if (str_ftnever == 0) { \ 161*7c478bd9Sstevel@tonic-gate mblk_t *_mp; \ 162*7c478bd9Sstevel@tonic-gate fthdr_t *_hp; \ 163*7c478bd9Sstevel@tonic-gate \ 164*7c478bd9Sstevel@tonic-gate for (_mp = (mp); _mp != NULL; _mp = _mp->b_cont) { \ 165*7c478bd9Sstevel@tonic-gate if ((_hp = DB_FTHDR(_mp)) != NULL) \ 166*7c478bd9Sstevel@tonic-gate str_ftevent(_hp, (p), (e), (d)); \ 167*7c478bd9Sstevel@tonic-gate } \ 168*7c478bd9Sstevel@tonic-gate } \ 169*7c478bd9Sstevel@tonic-gate } 170*7c478bd9Sstevel@tonic-gate 171*7c478bd9Sstevel@tonic-gate /* 172*7c478bd9Sstevel@tonic-gate * Add a flow-trace event to *just* the passed-in mblk_t. 173*7c478bd9Sstevel@tonic-gate */ 174*7c478bd9Sstevel@tonic-gate #define STR_FTEVENT_MBLK(mp, p, e, d) { \ 175*7c478bd9Sstevel@tonic-gate if (str_ftnever == 0) { \ 176*7c478bd9Sstevel@tonic-gate fthdr_t *_hp; \ 177*7c478bd9Sstevel@tonic-gate \ 178*7c478bd9Sstevel@tonic-gate if ((mp) != NULL && ((_hp = DB_FTHDR(mp)) != NULL)) \ 179*7c478bd9Sstevel@tonic-gate str_ftevent(_hp, (p), (e), (d)); \ 180*7c478bd9Sstevel@tonic-gate } \ 181*7c478bd9Sstevel@tonic-gate } 182*7c478bd9Sstevel@tonic-gate 183*7c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 184*7c478bd9Sstevel@tonic-gate 185*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 186*7c478bd9Sstevel@tonic-gate } 187*7c478bd9Sstevel@tonic-gate #endif 188*7c478bd9Sstevel@tonic-gate 189*7c478bd9Sstevel@tonic-gate #endif /* _SYS_STRFT_H */ 190