xref: /onnv-gate/usr/src/uts/common/sys/strft.h (revision 8752:379ec9d30f5c)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*8752SPeter.Memishian@Sun.COM  * Common Development and Distribution License (the "License").
6*8752SPeter.Memishian@Sun.COM  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*8752SPeter.Memishian@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef _SYS_STRFT_H
270Sstevel@tonic-gate #define	_SYS_STRFT_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #ifdef	__cplusplus
300Sstevel@tonic-gate extern "C" {
310Sstevel@tonic-gate #endif
320Sstevel@tonic-gate 
330Sstevel@tonic-gate /*
340Sstevel@tonic-gate  * The flow trace subsystem is used to trace the flow of STREAMS messages
350Sstevel@tonic-gate  * through a stream.
360Sstevel@tonic-gate  *
370Sstevel@tonic-gate  * WARNING: this is a private subsystem and subject to change at any time!
380Sstevel@tonic-gate  */
390Sstevel@tonic-gate 
400Sstevel@tonic-gate #include <sys/time.h>
410Sstevel@tonic-gate #include <sys/types.h>
420Sstevel@tonic-gate #include <sys/stream.h>
430Sstevel@tonic-gate 
440Sstevel@tonic-gate /*
450Sstevel@tonic-gate  * Some evnt defines, values 0..N are reserved for internal use,
460Sstevel@tonic-gate  * (N+1)..0x1FFF are available for arbitrary module/drvier use,
470Sstevel@tonic-gate  * 0x8000 (RD/WR q marker) and 0x4000 (thread cs marker) are or'ed
480Sstevel@tonic-gate  * flag bits reserved for internal use.
490Sstevel@tonic-gate  */
500Sstevel@tonic-gate #define	FTEV_MASK	0x1FFF
510Sstevel@tonic-gate #define	FTEV_ISWR	0x8000
520Sstevel@tonic-gate #define	FTEV_CS		0x4000
530Sstevel@tonic-gate #define	FTEV_PS		0x2000
540Sstevel@tonic-gate 
550Sstevel@tonic-gate #define	FTEV_QMASK	0x1F00
560Sstevel@tonic-gate 
570Sstevel@tonic-gate #define	FTEV_ALLOCMASK	0x1FF8
580Sstevel@tonic-gate #define	FTEV_ALLOCB	0x0000
590Sstevel@tonic-gate #define	FTEV_ESBALLOC	0x0001
600Sstevel@tonic-gate #define	FTEV_DESBALLOC	0x0002
610Sstevel@tonic-gate #define	FTEV_ESBALLOCA	0x0003
620Sstevel@tonic-gate #define	FTEV_DESBALLOCA	0x0004
630Sstevel@tonic-gate #define	FTEV_ALLOCBIG	0x0005
640Sstevel@tonic-gate #define	FTEV_ALLOCBW	0x0006
650Sstevel@tonic-gate #define	FTEV_BCALLOCB	0x0007
660Sstevel@tonic-gate #define	FTEV_FREEB	0x0008
670Sstevel@tonic-gate #define	FTEV_DUPB	0x0009
680Sstevel@tonic-gate #define	FTEV_COPYB	0x000A
690Sstevel@tonic-gate 
700Sstevel@tonic-gate #define	FTEV_CALLER	0x000F
710Sstevel@tonic-gate 
720Sstevel@tonic-gate #define	FTEV_PUT	0x0100
730Sstevel@tonic-gate #define	FTEV_PUTQ	0x0105
740Sstevel@tonic-gate #define	FTEV_GETQ	0x0106
750Sstevel@tonic-gate #define	FTEV_RMVQ	0x0107
760Sstevel@tonic-gate #define	FTEV_INSQ	0x0108
770Sstevel@tonic-gate #define	FTEV_PUTBQ	0x0109
780Sstevel@tonic-gate #define	FTEV_FLUSHQ	0x010A
790Sstevel@tonic-gate #define	FTEV_PUTNEXT	0x010D
800Sstevel@tonic-gate #define	FTEV_RWNEXT	0x010E
810Sstevel@tonic-gate 
82*8752SPeter.Memishian@Sun.COM #define	FTBLK_EVNTS	9
83*8752SPeter.Memishian@Sun.COM #define	FTSTK_DEPTH	15
84*8752SPeter.Memishian@Sun.COM 
85*8752SPeter.Memishian@Sun.COM /*
86*8752SPeter.Memishian@Sun.COM  * Stack information for each flow trace event; recorded when str_ftstack
87*8752SPeter.Memishian@Sun.COM  * is non-zero.
88*8752SPeter.Memishian@Sun.COM  */
89*8752SPeter.Memishian@Sun.COM typedef struct ftstk {
90*8752SPeter.Memishian@Sun.COM 	uint_t		fs_depth;
91*8752SPeter.Memishian@Sun.COM 	pc_t		fs_stk[FTSTK_DEPTH];
92*8752SPeter.Memishian@Sun.COM } ftstk_t;
930Sstevel@tonic-gate 
940Sstevel@tonic-gate /*
95*8752SPeter.Memishian@Sun.COM  * Data structure that contains the timestamp, module/driver name, next
96*8752SPeter.Memishian@Sun.COM  * module/driver name, optional callstack, event and event data (not certain
97*8752SPeter.Memishian@Sun.COM  * as to its use yet: RSF).  There is one per event.  Every time str_ftevent()
98*8752SPeter.Memishian@Sun.COM  * is called, one of the indices is filled in with this data.
990Sstevel@tonic-gate  */
1000Sstevel@tonic-gate typedef struct ftevnt {
101*8752SPeter.Memishian@Sun.COM 	hrtime_t	ts;		/* event timestamp, per gethrtime() */
102*8752SPeter.Memishian@Sun.COM 	char 		*mid;		/* module/driver name */
103*8752SPeter.Memishian@Sun.COM 	char		*midnext; 	/* next module/driver name */
104*8752SPeter.Memishian@Sun.COM 	ushort_t 	evnt;		/* FTEV_* value above */
105*8752SPeter.Memishian@Sun.COM 	ushort_t 	data;		/* event data */
106*8752SPeter.Memishian@Sun.COM 	ftstk_t		*stk;		/* optional event callstack */
1070Sstevel@tonic-gate } ftevnt_t;
1080Sstevel@tonic-gate 
1090Sstevel@tonic-gate /*
110*8752SPeter.Memishian@Sun.COM  * A linked list of ftevnt arrays.
1110Sstevel@tonic-gate  */
1120Sstevel@tonic-gate typedef struct ftblk {
1130Sstevel@tonic-gate 	struct ftblk *nxt;	/* next ftblk (or NULL if none) */
1140Sstevel@tonic-gate 	int ix;			/* index of next free ev[] */
1150Sstevel@tonic-gate 	struct ftevnt ev[FTBLK_EVNTS];
1160Sstevel@tonic-gate } ftblk_t;
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate /*
1190Sstevel@tonic-gate  * The flow trace header (start of event list).  It consists of the
1200Sstevel@tonic-gate  *      current writable block (tail)
1210Sstevel@tonic-gate  *      a hash value (for recovering trace information)
1220Sstevel@tonic-gate  *      The last thread to process an event
1230Sstevel@tonic-gate  *      The last cpu to process an event
1240Sstevel@tonic-gate  *      The start of the list
1250Sstevel@tonic-gate  * This structure is attached to a dblk, and traces a message through
1260Sstevel@tonic-gate  * a flow.
1270Sstevel@tonic-gate  */
1280Sstevel@tonic-gate typedef struct fthdr {
1290Sstevel@tonic-gate 	struct ftblk *tail;
1300Sstevel@tonic-gate 	uint_t hash;		/* accumulated hash value (sum of mid's) */
1310Sstevel@tonic-gate 	void *thread;
1320Sstevel@tonic-gate 	int cpu_seqid;
1330Sstevel@tonic-gate 	struct ftblk first;
1340Sstevel@tonic-gate } fthdr_t;
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate #ifdef _KERNEL
1370Sstevel@tonic-gate 
1380Sstevel@tonic-gate struct datab;
1390Sstevel@tonic-gate 
1400Sstevel@tonic-gate extern void str_ftevent(fthdr_t *, void *, ushort_t, ushort_t);
1410Sstevel@tonic-gate extern void str_ftfree(struct datab *);
142*8752SPeter.Memishian@Sun.COM extern int str_ftnever, str_ftstack;
1430Sstevel@tonic-gate 
1440Sstevel@tonic-gate /*
1450Sstevel@tonic-gate  * Allocate flow-trace information and record an allocation event.
1460Sstevel@tonic-gate  */
1470Sstevel@tonic-gate #define	STR_FTALLOC(hpp, e, d) {					\
1480Sstevel@tonic-gate 	if (str_ftnever == 0) {						\
1490Sstevel@tonic-gate 		fthdr_t *_hp = *(hpp);					\
1500Sstevel@tonic-gate 									\
1510Sstevel@tonic-gate 		ASSERT(_hp == NULL);					\
1520Sstevel@tonic-gate 		_hp = kmem_cache_alloc(fthdr_cache, KM_NOSLEEP);	\
1530Sstevel@tonic-gate 		if ((*hpp = _hp) != NULL) {				\
1540Sstevel@tonic-gate 			_hp->tail = &_hp->first;			\
1550Sstevel@tonic-gate 			_hp->hash = 0;					\
1560Sstevel@tonic-gate 			_hp->thread = curthread;			\
1570Sstevel@tonic-gate 			_hp->cpu_seqid = CPU->cpu_seqid;		\
1580Sstevel@tonic-gate 			_hp->first.nxt = NULL;				\
1590Sstevel@tonic-gate 			_hp->first.ix = 0;				\
1600Sstevel@tonic-gate 			str_ftevent(_hp, caller(), (e), (d));		\
1610Sstevel@tonic-gate 		}							\
1620Sstevel@tonic-gate 	}								\
1630Sstevel@tonic-gate }
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate /*
1660Sstevel@tonic-gate  * Add a flow-trace event to the passed-in mblk_t and any other mblk_t's
1670Sstevel@tonic-gate  * chained off of b_cont.
1680Sstevel@tonic-gate  */
1690Sstevel@tonic-gate #define	STR_FTEVENT_MSG(mp, p, e, d) {					\
1700Sstevel@tonic-gate 	if (str_ftnever == 0) {						\
1710Sstevel@tonic-gate 		mblk_t *_mp;						\
1720Sstevel@tonic-gate 		fthdr_t *_hp;						\
1730Sstevel@tonic-gate 									\
1740Sstevel@tonic-gate 		for (_mp = (mp); _mp != NULL; _mp = _mp->b_cont) {	\
1750Sstevel@tonic-gate 			if ((_hp = DB_FTHDR(_mp)) != NULL)		\
1760Sstevel@tonic-gate 				str_ftevent(_hp, (p), (e), (d));	\
1770Sstevel@tonic-gate 		}							\
1780Sstevel@tonic-gate 	}								\
1790Sstevel@tonic-gate }
1800Sstevel@tonic-gate 
1810Sstevel@tonic-gate /*
1820Sstevel@tonic-gate  * Add a flow-trace event to *just* the passed-in mblk_t.
1830Sstevel@tonic-gate  */
1840Sstevel@tonic-gate #define	STR_FTEVENT_MBLK(mp, p, e, d) {					\
1850Sstevel@tonic-gate 	if (str_ftnever == 0) {						\
1860Sstevel@tonic-gate 		fthdr_t *_hp;						\
1870Sstevel@tonic-gate 									\
1880Sstevel@tonic-gate 		if ((mp) != NULL && ((_hp = DB_FTHDR(mp)) != NULL)) 	\
1890Sstevel@tonic-gate 			str_ftevent(_hp, (p), (e), (d));		\
1900Sstevel@tonic-gate 	}								\
1910Sstevel@tonic-gate }
1920Sstevel@tonic-gate 
1930Sstevel@tonic-gate #endif /* _KERNEL */
1940Sstevel@tonic-gate 
1950Sstevel@tonic-gate #ifdef	__cplusplus
1960Sstevel@tonic-gate }
1970Sstevel@tonic-gate #endif
1980Sstevel@tonic-gate 
1990Sstevel@tonic-gate #endif	/* _SYS_STRFT_H */
200