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