xref: /freebsd/sys/net/altq/altq_rmclass_debug.h (revision 069ac184)
1 /*-
2  * Copyright (c) Sun Microsystems, Inc. 1998 All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *      This product includes software developed by the SMCC Technology
18  *      Development Group at Sun Microsystems, Inc.
19  *
20  * 4. The name of the Sun Microsystems, Inc nor may not be used to endorse or
21  *      promote products derived from this software without specific prior
22  *      written permission.
23  *
24  * SUN MICROSYSTEMS DOES NOT CLAIM MERCHANTABILITY OF THIS SOFTWARE OR THE
25  * SUITABILITY OF THIS SOFTWARE FOR ANY PARTICULAR PURPOSE.  The software is
26  * provided "as is" without express or implied warranty of any kind.
27  *
28  * These notices must be retained in any copies of any part of this software.
29  *
30  * $KAME: altq_rmclass_debug.h,v 1.3 2002/11/29 04:36:24 kjc Exp $
31  */
32 
33 #ifndef _ALTQ_ALTQ_RMCLASS_DEBUG_H_
34 #define	_ALTQ_ALTQ_RMCLASS_DEBUG_H_
35 
36 /*
37  * Cbq debugging macros
38  */
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 #ifdef	CBQ_TRACE
45 #ifndef NCBQTRACE
46 #define	NCBQTRACE (16 * 1024)
47 #endif
48 
49 /*
50  * To view the trace output, using adb, type:
51  *	adb -k /dev/ksyms /dev/mem <cr>, then type
52  *	cbqtrace_count/D to get the count, then type
53  *	cbqtrace_buffer,0tcount/Dp4C" "Xn
54  *	This will dump the trace buffer from 0 to count.
55  */
56 /*
57  * in ALTQ, "call cbqtrace_dump(N)" from DDB to display 20 events
58  * from Nth event in the circular buffer.
59  */
60 
61 struct cbqtrace {
62 	int count;
63 	int function;		/* address of function */
64 	int trace_action;	/* descriptive 4 characters */
65 	int object;		/* object operated on */
66 };
67 
68 extern struct cbqtrace cbqtrace_buffer[];
69 extern struct cbqtrace *cbqtrace_ptr;
70 extern int cbqtrace_count;
71 
72 #define	CBQTRACEINIT() {				\
73 	if (cbqtrace_ptr == NULL)		\
74 		cbqtrace_ptr = cbqtrace_buffer; \
75 	else { \
76 		cbqtrace_ptr = cbqtrace_buffer; \
77 		bzero((void *)cbqtrace_ptr, sizeof(cbqtrace_buffer)); \
78 		cbqtrace_count = 0; \
79 	} \
80 }
81 
82 #define	LOCK_TRACE()	splimp()
83 #define	UNLOCK_TRACE(x)	splx(x)
84 
85 #define	CBQTRACE(func, act, obj) {		\
86 	int __s = LOCK_TRACE();			\
87 	int *_p = &cbqtrace_ptr->count;	\
88 	*_p++ = ++cbqtrace_count;		\
89 	*_p++ = (int)(func);			\
90 	*_p++ = (int)(act);			\
91 	*_p++ = (int)(obj);			\
92 	if ((struct cbqtrace *)(void *)_p >= &cbqtrace_buffer[NCBQTRACE])\
93 		cbqtrace_ptr = cbqtrace_buffer; \
94 	else					\
95 		cbqtrace_ptr = (struct cbqtrace *)(void *)_p; \
96 	UNLOCK_TRACE(__s);			\
97 	}
98 #else
99 
100 /* If no tracing, define no-ops */
101 #define	CBQTRACEINIT()
102 #define	CBQTRACE(a, b, c)
103 
104 #endif	/* !CBQ_TRACE */
105 
106 #ifdef __cplusplus
107 }
108 #endif
109 
110 #endif	/* _ALTQ_ALTQ_RMCLASS_DEBUG_H_ */
111