xref: /titanic_41/usr/src/uts/common/sys/ftrace.h (revision 4df4bd6096e60a7062ad804cc29ac7cc4b03811a)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_FTRACE_H
27 #define	_SYS_FTRACE_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 /*
36  * Constants used by both asm and non-asm code.
37  */
38 
39 /*
40  * Flags determining the state of tracing -
41  *   both for the "ftrace_state" variable, and for the per-CPU variable
42  *   "cpu[N]->cpu_ftrace_state".
43  */
44 #define	FTRACE_READY	0x00000001
45 #define	FTRACE_ENABLED	0x00000002
46 
47 #if !defined(_ASM)
48 
49 #include <sys/thread.h>
50 #include <sys/cpuvar.h>
51 #include <sys/types.h>
52 
53 /*
54  * The record of a single event.
55  *
56  * Should fit nicely into a standard cache line.
57  * Here, the 32-bit version is 32 bytes, and the 64-bit version is 64 bytes.
58  */
59 typedef struct ftrace_record {
60 	char		*ftr_event;
61 	kthread_t	*ftr_thread;
62 	uint64_t	ftr_tick;
63 	caddr_t		ftr_caller;
64 	ulong_t		ftr_data1;
65 	ulong_t		ftr_data2;
66 	ulong_t		ftr_data3;
67 #ifdef	_LP64
68 	ulong_t		__pad;
69 #endif
70 } ftrace_record_t;
71 
72 /*
73  * Default per-CPU event ring buffer size.
74  */
75 #define	FTRACE_NENT 1024
76 
77 #ifdef _KERNEL
78 
79 /*
80  * Tunable parameters in /etc/system.
81  */
82 extern int ftrace_atboot;	/* Whether to start fast tracing on boot. */
83 extern int ftrace_nent;		/* Size of the per-CPU event ring buffer. */
84 
85 extern int		ftrace_cpu_setup(cpu_setup_t, int, void *);
86 extern void		ftrace_init(void);
87 extern int		ftrace_start(void);
88 extern int		ftrace_stop(void);
89 extern void		ftrace_0(char *, caddr_t);
90 extern void		ftrace_1(char *, ulong_t, caddr_t);
91 extern void		ftrace_2(char *, ulong_t, ulong_t, caddr_t);
92 extern void		ftrace_3(char *, ulong_t, ulong_t, ulong_t, caddr_t);
93 extern void		ftrace_3_notick(char *, ulong_t, ulong_t, ulong_t,
94     caddr_t);
95 
96 typedef	uintptr_t	ftrace_icookie_t;
97 extern ftrace_icookie_t ftrace_interrupt_disable(void);
98 extern void ftrace_interrupt_enable(ftrace_icookie_t);
99 extern caddr_t caller(void);
100 
101 #define	FTRACE_0(fmt)						\
102 	{							\
103 		if (CPU->cpu_ftrace.ftd_state & FTRACE_ENABLED)	\
104 			ftrace_0(fmt, caller());		\
105 	}
106 #define	FTRACE_1(fmt, d1) 					\
107 	{							\
108 		if (CPU->cpu_ftrace.ftd_state & FTRACE_ENABLED)	\
109 			ftrace_1(fmt, d1, caller());		\
110 	}
111 #define	FTRACE_2(fmt, d1, d2) 					\
112 	{							\
113 		if (CPU->cpu_ftrace.ftd_state & FTRACE_ENABLED)	\
114 			ftrace_2(fmt, d1, d2, caller());	\
115 	}
116 #define	FTRACE_3(fmt, d1, d2, d3) 				\
117 	{							\
118 		if (CPU->cpu_ftrace.ftd_state & FTRACE_ENABLED)	\
119 			ftrace_3(fmt, d1, d2, d3, caller());	\
120 	}
121 #define	FTRACE_START()	ftrace_start()
122 #define	FTRACE_STOP()	ftrace_stop()
123 
124 #endif	/* _KERNEL */
125 
126 #endif	/* !defined(_ASM) */
127 
128 #ifdef	__cplusplus
129 }
130 #endif
131 
132 #endif	/* _SYS_FTRACE_H */
133