xref: /onnv-gate/usr/src/uts/common/sys/ftrace.h (revision 3647:76d3d42bd153)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*3647Sbs21162  * Common Development and Distribution License (the "License").
6*3647Sbs21162  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*3647Sbs21162  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23*3647Sbs21162  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef	_SYS_FTRACE_H
270Sstevel@tonic-gate #define	_SYS_FTRACE_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #ifdef	__cplusplus
320Sstevel@tonic-gate extern "C" {
330Sstevel@tonic-gate #endif
340Sstevel@tonic-gate 
350Sstevel@tonic-gate /*
360Sstevel@tonic-gate  * Constants used by both asm and non-asm code.
370Sstevel@tonic-gate  */
380Sstevel@tonic-gate 
390Sstevel@tonic-gate /*
400Sstevel@tonic-gate  * Flags determining the state of tracing -
410Sstevel@tonic-gate  *   both for the "ftrace_state" variable, and for the per-CPU variable
420Sstevel@tonic-gate  *   "cpu[N]->cpu_ftrace_state".
430Sstevel@tonic-gate  */
440Sstevel@tonic-gate #define	FTRACE_READY	0x00000001
450Sstevel@tonic-gate #define	FTRACE_ENABLED	0x00000002
460Sstevel@tonic-gate 
470Sstevel@tonic-gate #if !defined(_ASM)
480Sstevel@tonic-gate 
490Sstevel@tonic-gate #include <sys/thread.h>
500Sstevel@tonic-gate #include <sys/cpuvar.h>
510Sstevel@tonic-gate #include <sys/types.h>
520Sstevel@tonic-gate 
530Sstevel@tonic-gate /*
540Sstevel@tonic-gate  * The record of a single event.
550Sstevel@tonic-gate  *
560Sstevel@tonic-gate  * Should fit nicely into a standard cache line.
570Sstevel@tonic-gate  * Here, the 32-bit version is 32 bytes, and the 64-bit version is 64 bytes.
580Sstevel@tonic-gate  */
590Sstevel@tonic-gate typedef struct ftrace_record {
600Sstevel@tonic-gate 	char		*ftr_event;
610Sstevel@tonic-gate 	kthread_t	*ftr_thread;
620Sstevel@tonic-gate 	uint64_t	ftr_tick;
630Sstevel@tonic-gate 	caddr_t		ftr_caller;
640Sstevel@tonic-gate 	ulong_t		ftr_data1;
650Sstevel@tonic-gate 	ulong_t		ftr_data2;
660Sstevel@tonic-gate 	ulong_t		ftr_data3;
670Sstevel@tonic-gate #ifdef	_LP64
680Sstevel@tonic-gate 	ulong_t		__pad;
690Sstevel@tonic-gate #endif
700Sstevel@tonic-gate } ftrace_record_t;
710Sstevel@tonic-gate 
720Sstevel@tonic-gate /*
730Sstevel@tonic-gate  * Default per-CPU event ring buffer size.
740Sstevel@tonic-gate  */
750Sstevel@tonic-gate #define	FTRACE_NENT 1024
760Sstevel@tonic-gate 
770Sstevel@tonic-gate #ifdef _KERNEL
780Sstevel@tonic-gate 
790Sstevel@tonic-gate /*
800Sstevel@tonic-gate  * Tunable parameters in /etc/system.
810Sstevel@tonic-gate  */
820Sstevel@tonic-gate extern int ftrace_atboot;	/* Whether to start fast tracing on boot. */
830Sstevel@tonic-gate extern int ftrace_nent;		/* Size of the per-CPU event ring buffer. */
840Sstevel@tonic-gate 
850Sstevel@tonic-gate extern int		ftrace_cpu_setup(cpu_setup_t, int, void *);
860Sstevel@tonic-gate extern void		ftrace_init(void);
870Sstevel@tonic-gate extern int		ftrace_start(void);
880Sstevel@tonic-gate extern int		ftrace_stop(void);
89*3647Sbs21162 extern void		ftrace_0(char *, caddr_t);
90*3647Sbs21162 extern void		ftrace_1(char *, ulong_t, caddr_t);
91*3647Sbs21162 extern void		ftrace_2(char *, ulong_t, ulong_t, caddr_t);
92*3647Sbs21162 extern void		ftrace_3(char *, ulong_t, ulong_t, ulong_t, caddr_t);
93*3647Sbs21162 extern void		ftrace_3_notick(char *, ulong_t, ulong_t, ulong_t,
94*3647Sbs21162     caddr_t);
95*3647Sbs21162 
96*3647Sbs21162 typedef	uintptr_t	ftrace_icookie_t;
97*3647Sbs21162 extern ftrace_icookie_t ftrace_interrupt_disable(void);
98*3647Sbs21162 extern void ftrace_interrupt_enable(ftrace_icookie_t);
99*3647Sbs21162 extern caddr_t caller(void);
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate #define	FTRACE_0(fmt)						\
1020Sstevel@tonic-gate 	{							\
1030Sstevel@tonic-gate 		if (CPU->cpu_ftrace.ftd_state & FTRACE_ENABLED)	\
104*3647Sbs21162 			ftrace_0(fmt, caller());		\
1050Sstevel@tonic-gate 	}
1060Sstevel@tonic-gate #define	FTRACE_1(fmt, d1) 					\
1070Sstevel@tonic-gate 	{							\
1080Sstevel@tonic-gate 		if (CPU->cpu_ftrace.ftd_state & FTRACE_ENABLED)	\
109*3647Sbs21162 			ftrace_1(fmt, d1, caller());		\
1100Sstevel@tonic-gate 	}
1110Sstevel@tonic-gate #define	FTRACE_2(fmt, d1, d2) 					\
1120Sstevel@tonic-gate 	{							\
1130Sstevel@tonic-gate 		if (CPU->cpu_ftrace.ftd_state & FTRACE_ENABLED)	\
114*3647Sbs21162 			ftrace_2(fmt, d1, d2, caller());	\
1150Sstevel@tonic-gate 	}
1160Sstevel@tonic-gate #define	FTRACE_3(fmt, d1, d2, d3) 				\
1170Sstevel@tonic-gate 	{							\
1180Sstevel@tonic-gate 		if (CPU->cpu_ftrace.ftd_state & FTRACE_ENABLED)	\
119*3647Sbs21162 			ftrace_3(fmt, d1, d2, d3, caller());	\
1200Sstevel@tonic-gate 	}
1210Sstevel@tonic-gate #define	FTRACE_START()	ftrace_start()
1220Sstevel@tonic-gate #define	FTRACE_STOP()	ftrace_stop()
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate #endif	/* _KERNEL */
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate #endif	/* !defined(_ASM) */
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate #ifdef	__cplusplus
1290Sstevel@tonic-gate }
1300Sstevel@tonic-gate #endif
1310Sstevel@tonic-gate 
1320Sstevel@tonic-gate #endif	/* _SYS_FTRACE_H */
133