xref: /titanic_52/usr/src/uts/common/sys/ftrace.h (revision 99ebb4ca412cb0a19d77a3899a87c055b9c30fa8)
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 (c) 1998 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ifndef	_SYS_FTRACE_H
28 #define	_SYS_FTRACE_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 /*
37  * Constants used by both asm and non-asm code.
38  */
39 
40 /*
41  * Flags determining the state of tracing -
42  *   both for the "ftrace_state" variable, and for the per-CPU variable
43  *   "cpu[N]->cpu_ftrace_state".
44  */
45 #define	FTRACE_READY	0x00000001
46 #define	FTRACE_ENABLED	0x00000002
47 
48 #if !defined(_ASM)
49 
50 #include <sys/thread.h>
51 #include <sys/cpuvar.h>
52 #include <sys/types.h>
53 
54 /*
55  * The record of a single event.
56  *
57  * Should fit nicely into a standard cache line.
58  * Here, the 32-bit version is 32 bytes, and the 64-bit version is 64 bytes.
59  */
60 typedef struct ftrace_record {
61 	char		*ftr_event;
62 	kthread_t	*ftr_thread;
63 	uint64_t	ftr_tick;
64 	caddr_t		ftr_caller;
65 	ulong_t		ftr_data1;
66 	ulong_t		ftr_data2;
67 	ulong_t		ftr_data3;
68 #ifdef	_LP64
69 	ulong_t		__pad;
70 #endif
71 } ftrace_record_t;
72 
73 /*
74  * Default per-CPU event ring buffer size.
75  */
76 #define	FTRACE_NENT 1024
77 
78 #ifdef _KERNEL
79 
80 /*
81  * Tunable parameters in /etc/system.
82  */
83 extern int ftrace_atboot;	/* Whether to start fast tracing on boot. */
84 extern int ftrace_nent;		/* Size of the per-CPU event ring buffer. */
85 
86 extern int		ftrace_cpu_setup(cpu_setup_t, int, void *);
87 extern void		ftrace_init(void);
88 extern int		ftrace_start(void);
89 extern int		ftrace_stop(void);
90 extern void		ftrace_0(char *);
91 extern void		ftrace_1(char *, ulong_t);
92 extern void		ftrace_2(char *, ulong_t, ulong_t);
93 extern void		ftrace_3(char *, ulong_t, ulong_t, ulong_t);
94 
95 #define	FTRACE_0(fmt)						\
96 	{							\
97 		if (CPU->cpu_ftrace.ftd_state & FTRACE_ENABLED)	\
98 			ftrace_0(fmt);				\
99 	}
100 #define	FTRACE_1(fmt, d1) 					\
101 	{							\
102 		if (CPU->cpu_ftrace.ftd_state & FTRACE_ENABLED)	\
103 			ftrace_1(fmt, d1);			\
104 	}
105 #define	FTRACE_2(fmt, d1, d2) 					\
106 	{							\
107 		if (CPU->cpu_ftrace.ftd_state & FTRACE_ENABLED)	\
108 			ftrace_2(fmt, d1, d2);			\
109 	}
110 #define	FTRACE_3(fmt, d1, d2, d3) 				\
111 	{							\
112 		if (CPU->cpu_ftrace.ftd_state & FTRACE_ENABLED)	\
113 			ftrace_3(fmt, d1, d2, d3);		\
114 	}
115 #define	FTRACE_START()	ftrace_start()
116 #define	FTRACE_STOP()	ftrace_stop()
117 
118 #endif	/* _KERNEL */
119 
120 #endif	/* !defined(_ASM) */
121 
122 #ifdef	__cplusplus
123 }
124 #endif
125 
126 #endif	/* _SYS_FTRACE_H */
127