xref: /titanic_51/usr/src/uts/common/sys/ftrace.h (revision 4df4bd6096e60a7062ad804cc29ac7cc4b03811a)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*4df4bd60Sbs21162  * Common Development and Distribution License (the "License").
6*4df4bd60Sbs21162  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*4df4bd60Sbs21162  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23*4df4bd60Sbs21162  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_SYS_FTRACE_H
277c478bd9Sstevel@tonic-gate #define	_SYS_FTRACE_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
327c478bd9Sstevel@tonic-gate extern "C" {
337c478bd9Sstevel@tonic-gate #endif
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate /*
367c478bd9Sstevel@tonic-gate  * Constants used by both asm and non-asm code.
377c478bd9Sstevel@tonic-gate  */
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate /*
407c478bd9Sstevel@tonic-gate  * Flags determining the state of tracing -
417c478bd9Sstevel@tonic-gate  *   both for the "ftrace_state" variable, and for the per-CPU variable
427c478bd9Sstevel@tonic-gate  *   "cpu[N]->cpu_ftrace_state".
437c478bd9Sstevel@tonic-gate  */
447c478bd9Sstevel@tonic-gate #define	FTRACE_READY	0x00000001
457c478bd9Sstevel@tonic-gate #define	FTRACE_ENABLED	0x00000002
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate #if !defined(_ASM)
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate #include <sys/thread.h>
507c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
517c478bd9Sstevel@tonic-gate #include <sys/types.h>
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate /*
547c478bd9Sstevel@tonic-gate  * The record of a single event.
557c478bd9Sstevel@tonic-gate  *
567c478bd9Sstevel@tonic-gate  * Should fit nicely into a standard cache line.
577c478bd9Sstevel@tonic-gate  * Here, the 32-bit version is 32 bytes, and the 64-bit version is 64 bytes.
587c478bd9Sstevel@tonic-gate  */
597c478bd9Sstevel@tonic-gate typedef struct ftrace_record {
607c478bd9Sstevel@tonic-gate 	char		*ftr_event;
617c478bd9Sstevel@tonic-gate 	kthread_t	*ftr_thread;
627c478bd9Sstevel@tonic-gate 	uint64_t	ftr_tick;
637c478bd9Sstevel@tonic-gate 	caddr_t		ftr_caller;
647c478bd9Sstevel@tonic-gate 	ulong_t		ftr_data1;
657c478bd9Sstevel@tonic-gate 	ulong_t		ftr_data2;
667c478bd9Sstevel@tonic-gate 	ulong_t		ftr_data3;
677c478bd9Sstevel@tonic-gate #ifdef	_LP64
687c478bd9Sstevel@tonic-gate 	ulong_t		__pad;
697c478bd9Sstevel@tonic-gate #endif
707c478bd9Sstevel@tonic-gate } ftrace_record_t;
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate /*
737c478bd9Sstevel@tonic-gate  * Default per-CPU event ring buffer size.
747c478bd9Sstevel@tonic-gate  */
757c478bd9Sstevel@tonic-gate #define	FTRACE_NENT 1024
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate #ifdef _KERNEL
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate /*
807c478bd9Sstevel@tonic-gate  * Tunable parameters in /etc/system.
817c478bd9Sstevel@tonic-gate  */
827c478bd9Sstevel@tonic-gate extern int ftrace_atboot;	/* Whether to start fast tracing on boot. */
837c478bd9Sstevel@tonic-gate extern int ftrace_nent;		/* Size of the per-CPU event ring buffer. */
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate extern int		ftrace_cpu_setup(cpu_setup_t, int, void *);
867c478bd9Sstevel@tonic-gate extern void		ftrace_init(void);
877c478bd9Sstevel@tonic-gate extern int		ftrace_start(void);
887c478bd9Sstevel@tonic-gate extern int		ftrace_stop(void);
89*4df4bd60Sbs21162 extern void		ftrace_0(char *, caddr_t);
90*4df4bd60Sbs21162 extern void		ftrace_1(char *, ulong_t, caddr_t);
91*4df4bd60Sbs21162 extern void		ftrace_2(char *, ulong_t, ulong_t, caddr_t);
92*4df4bd60Sbs21162 extern void		ftrace_3(char *, ulong_t, ulong_t, ulong_t, caddr_t);
93*4df4bd60Sbs21162 extern void		ftrace_3_notick(char *, ulong_t, ulong_t, ulong_t,
94*4df4bd60Sbs21162     caddr_t);
95*4df4bd60Sbs21162 
96*4df4bd60Sbs21162 typedef	uintptr_t	ftrace_icookie_t;
97*4df4bd60Sbs21162 extern ftrace_icookie_t ftrace_interrupt_disable(void);
98*4df4bd60Sbs21162 extern void ftrace_interrupt_enable(ftrace_icookie_t);
99*4df4bd60Sbs21162 extern caddr_t caller(void);
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate #define	FTRACE_0(fmt)						\
1027c478bd9Sstevel@tonic-gate 	{							\
1037c478bd9Sstevel@tonic-gate 		if (CPU->cpu_ftrace.ftd_state & FTRACE_ENABLED)	\
104*4df4bd60Sbs21162 			ftrace_0(fmt, caller());		\
1057c478bd9Sstevel@tonic-gate 	}
1067c478bd9Sstevel@tonic-gate #define	FTRACE_1(fmt, d1) 					\
1077c478bd9Sstevel@tonic-gate 	{							\
1087c478bd9Sstevel@tonic-gate 		if (CPU->cpu_ftrace.ftd_state & FTRACE_ENABLED)	\
109*4df4bd60Sbs21162 			ftrace_1(fmt, d1, caller());		\
1107c478bd9Sstevel@tonic-gate 	}
1117c478bd9Sstevel@tonic-gate #define	FTRACE_2(fmt, d1, d2) 					\
1127c478bd9Sstevel@tonic-gate 	{							\
1137c478bd9Sstevel@tonic-gate 		if (CPU->cpu_ftrace.ftd_state & FTRACE_ENABLED)	\
114*4df4bd60Sbs21162 			ftrace_2(fmt, d1, d2, caller());	\
1157c478bd9Sstevel@tonic-gate 	}
1167c478bd9Sstevel@tonic-gate #define	FTRACE_3(fmt, d1, d2, d3) 				\
1177c478bd9Sstevel@tonic-gate 	{							\
1187c478bd9Sstevel@tonic-gate 		if (CPU->cpu_ftrace.ftd_state & FTRACE_ENABLED)	\
119*4df4bd60Sbs21162 			ftrace_3(fmt, d1, d2, d3, caller());	\
1207c478bd9Sstevel@tonic-gate 	}
1217c478bd9Sstevel@tonic-gate #define	FTRACE_START()	ftrace_start()
1227c478bd9Sstevel@tonic-gate #define	FTRACE_STOP()	ftrace_stop()
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate #endif	/* !defined(_ASM) */
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1297c478bd9Sstevel@tonic-gate }
1307c478bd9Sstevel@tonic-gate #endif
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate #endif	/* _SYS_FTRACE_H */
133