xref: /illumos-gate/usr/src/uts/common/sys/ftrace.h (revision 2d6eb4a5)
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 #ifdef	__cplusplus
307c478bd9Sstevel@tonic-gate extern "C" {
317c478bd9Sstevel@tonic-gate #endif
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate /*
347c478bd9Sstevel@tonic-gate  * Constants used by both asm and non-asm code.
357c478bd9Sstevel@tonic-gate  */
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate /*
387c478bd9Sstevel@tonic-gate  * Flags determining the state of tracing -
397c478bd9Sstevel@tonic-gate  *   both for the "ftrace_state" variable, and for the per-CPU variable
407c478bd9Sstevel@tonic-gate  *   "cpu[N]->cpu_ftrace_state".
417c478bd9Sstevel@tonic-gate  */
427c478bd9Sstevel@tonic-gate #define	FTRACE_READY	0x00000001
437c478bd9Sstevel@tonic-gate #define	FTRACE_ENABLED	0x00000002
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #if !defined(_ASM)
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate #include <sys/thread.h>
487c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
497c478bd9Sstevel@tonic-gate #include <sys/types.h>
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /*
527c478bd9Sstevel@tonic-gate  * The record of a single event.
537c478bd9Sstevel@tonic-gate  *
547c478bd9Sstevel@tonic-gate  * Should fit nicely into a standard cache line.
557c478bd9Sstevel@tonic-gate  * Here, the 32-bit version is 32 bytes, and the 64-bit version is 64 bytes.
567c478bd9Sstevel@tonic-gate  */
577c478bd9Sstevel@tonic-gate typedef struct ftrace_record {
587c478bd9Sstevel@tonic-gate 	char		*ftr_event;
597c478bd9Sstevel@tonic-gate 	kthread_t	*ftr_thread;
607c478bd9Sstevel@tonic-gate 	uint64_t	ftr_tick;
617c478bd9Sstevel@tonic-gate 	caddr_t		ftr_caller;
627c478bd9Sstevel@tonic-gate 	ulong_t		ftr_data1;
637c478bd9Sstevel@tonic-gate 	ulong_t		ftr_data2;
647c478bd9Sstevel@tonic-gate 	ulong_t		ftr_data3;
657c478bd9Sstevel@tonic-gate #ifdef	_LP64
667c478bd9Sstevel@tonic-gate 	ulong_t		__pad;
677c478bd9Sstevel@tonic-gate #endif
687c478bd9Sstevel@tonic-gate } ftrace_record_t;
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate /*
717c478bd9Sstevel@tonic-gate  * Default per-CPU event ring buffer size.
727c478bd9Sstevel@tonic-gate  */
737c478bd9Sstevel@tonic-gate #define	FTRACE_NENT 1024
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate #ifdef _KERNEL
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate /*
787c478bd9Sstevel@tonic-gate  * Tunable parameters in /etc/system.
797c478bd9Sstevel@tonic-gate  */
807c478bd9Sstevel@tonic-gate extern int ftrace_atboot;	/* Whether to start fast tracing on boot. */
817c478bd9Sstevel@tonic-gate extern int ftrace_nent;		/* Size of the per-CPU event ring buffer. */
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate extern int		ftrace_cpu_setup(cpu_setup_t, int, void *);
847c478bd9Sstevel@tonic-gate extern void		ftrace_init(void);
857c478bd9Sstevel@tonic-gate extern int		ftrace_start(void);
867c478bd9Sstevel@tonic-gate extern int		ftrace_stop(void);
87*4df4bd60Sbs21162 extern void		ftrace_0(char *, caddr_t);
88*4df4bd60Sbs21162 extern void		ftrace_1(char *, ulong_t, caddr_t);
89*4df4bd60Sbs21162 extern void		ftrace_2(char *, ulong_t, ulong_t, caddr_t);
90*4df4bd60Sbs21162 extern void		ftrace_3(char *, ulong_t, ulong_t, ulong_t, caddr_t);
91*4df4bd60Sbs21162 extern void		ftrace_3_notick(char *, ulong_t, ulong_t, ulong_t,
92*4df4bd60Sbs21162     caddr_t);
93*4df4bd60Sbs21162 
94*4df4bd60Sbs21162 typedef	uintptr_t	ftrace_icookie_t;
95*4df4bd60Sbs21162 extern ftrace_icookie_t ftrace_interrupt_disable(void);
96*4df4bd60Sbs21162 extern void ftrace_interrupt_enable(ftrace_icookie_t);
97*4df4bd60Sbs21162 extern caddr_t caller(void);
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate #define	FTRACE_0(fmt)						\
1007c478bd9Sstevel@tonic-gate 	{							\
1017c478bd9Sstevel@tonic-gate 		if (CPU->cpu_ftrace.ftd_state & FTRACE_ENABLED)	\
102*4df4bd60Sbs21162 			ftrace_0(fmt, caller());		\
1037c478bd9Sstevel@tonic-gate 	}
1047c478bd9Sstevel@tonic-gate #define	FTRACE_1(fmt, d1) 					\
1057c478bd9Sstevel@tonic-gate 	{							\
1067c478bd9Sstevel@tonic-gate 		if (CPU->cpu_ftrace.ftd_state & FTRACE_ENABLED)	\
107*4df4bd60Sbs21162 			ftrace_1(fmt, d1, caller());		\
1087c478bd9Sstevel@tonic-gate 	}
1097c478bd9Sstevel@tonic-gate #define	FTRACE_2(fmt, d1, d2) 					\
1107c478bd9Sstevel@tonic-gate 	{							\
1117c478bd9Sstevel@tonic-gate 		if (CPU->cpu_ftrace.ftd_state & FTRACE_ENABLED)	\
112*4df4bd60Sbs21162 			ftrace_2(fmt, d1, d2, caller());	\
1137c478bd9Sstevel@tonic-gate 	}
1147c478bd9Sstevel@tonic-gate #define	FTRACE_3(fmt, d1, d2, d3) 				\
1157c478bd9Sstevel@tonic-gate 	{							\
1167c478bd9Sstevel@tonic-gate 		if (CPU->cpu_ftrace.ftd_state & FTRACE_ENABLED)	\
117*4df4bd60Sbs21162 			ftrace_3(fmt, d1, d2, d3, caller());	\
1187c478bd9Sstevel@tonic-gate 	}
1197c478bd9Sstevel@tonic-gate #define	FTRACE_START()	ftrace_start()
1207c478bd9Sstevel@tonic-gate #define	FTRACE_STOP()	ftrace_stop()
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate #endif	/* !defined(_ASM) */
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1277c478bd9Sstevel@tonic-gate }
1287c478bd9Sstevel@tonic-gate #endif
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate #endif	/* _SYS_FTRACE_H */
131