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