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