1eda14cbcSMatt Macy /*
2eda14cbcSMatt Macy  * CDDL HEADER START
3eda14cbcSMatt Macy  *
4eda14cbcSMatt Macy  * The contents of this file are subject to the terms of the
5eda14cbcSMatt Macy  * Common Development and Distribution License (the "License").
6eda14cbcSMatt Macy  * You may not use this file except in compliance with the License.
7eda14cbcSMatt Macy  *
8eda14cbcSMatt Macy  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*271171e0SMartin Matuska  * or https://opensource.org/licenses/CDDL-1.0.
10eda14cbcSMatt Macy  * See the License for the specific language governing permissions
11eda14cbcSMatt Macy  * and limitations under the License.
12eda14cbcSMatt Macy  *
13eda14cbcSMatt Macy  * When distributing Covered Code, include this CDDL HEADER in each
14eda14cbcSMatt Macy  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15eda14cbcSMatt Macy  * If applicable, add the following below this CDDL HEADER, with the
16eda14cbcSMatt Macy  * fields enclosed by brackets "[]" replaced with your own identifying
17eda14cbcSMatt Macy  * information: Portions Copyright [yyyy] [name of copyright owner]
18eda14cbcSMatt Macy  *
19eda14cbcSMatt Macy  * CDDL HEADER END
20eda14cbcSMatt Macy  */
21eda14cbcSMatt Macy 
22eda14cbcSMatt Macy #if defined(_KERNEL)
23eda14cbcSMatt Macy 
24eda14cbcSMatt Macy /*
25eda14cbcSMatt Macy  * Calls to DTRACE_PROBE* are mapped to standard Linux kernel trace points
26eda14cbcSMatt Macy  * when they are available(when HAVE_DECLARE_EVENT_CLASS is defined).  The
27eda14cbcSMatt Macy  * tracepoint event class definitions are found in the general tracing
28eda14cbcSMatt Macy  * header file: include/sys/trace_*.h.  See include/sys/trace_vdev.h for
29eda14cbcSMatt Macy  * a good example.
30eda14cbcSMatt Macy  *
31eda14cbcSMatt Macy  * If tracepoints are not available, stub functions are generated which can
32eda14cbcSMatt Macy  * be traced using kprobes.  In this case, the DEFINE_DTRACE_PROBE* macros
33eda14cbcSMatt Macy  * are used to provide the stub functions and also the prototypes for
34eda14cbcSMatt Macy  * those functions.  The mechanism to do this relies on DEFINE_DTRACE_PROBE
35eda14cbcSMatt Macy  * macros defined in the general tracing headers(see trace_vdev.h) and
36eda14cbcSMatt Macy  * CREATE_TRACE_POINTS being defined only in module/zfs/trace.c.  When ZFS
37eda14cbcSMatt Macy  * source files include the general tracing headers, e.g.
38eda14cbcSMatt Macy  * module/zfs/vdev_removal.c including trace_vdev.h, DTRACE_PROBE calls
39eda14cbcSMatt Macy  * are mapped to stub functions calls and prototypes for those calls are
40eda14cbcSMatt Macy  * declared via DEFINE_DTRACE_PROBE*.  Only module/zfs/trace.c defines
41eda14cbcSMatt Macy  * CREATE_TRACE_POINTS.  That is followed by includes of all the general
42eda14cbcSMatt Macy  * tracing headers thereby defining all stub functions in one place via
43eda14cbcSMatt Macy  * the DEFINE_DTRACE_PROBE macros.
44eda14cbcSMatt Macy  *
45eda14cbcSMatt Macy  * When adding new DTRACE_PROBEs to zfs source, both a tracepoint event
46eda14cbcSMatt Macy  * class definition and a DEFINE_DTRACE_PROBE definition are needed to
47eda14cbcSMatt Macy  * avoid undefined function errors.
48eda14cbcSMatt Macy  */
49eda14cbcSMatt Macy 
50eda14cbcSMatt Macy #if defined(HAVE_DECLARE_EVENT_CLASS)
51eda14cbcSMatt Macy 
52eda14cbcSMatt Macy #undef TRACE_SYSTEM
53eda14cbcSMatt Macy #define	TRACE_SYSTEM zfs
54eda14cbcSMatt Macy 
55eda14cbcSMatt Macy #if !defined(_TRACE_ZFS_H) || defined(TRACE_HEADER_MULTI_READ)
56eda14cbcSMatt Macy #define	_TRACE_ZFS_H
57eda14cbcSMatt Macy 
58eda14cbcSMatt Macy #include <linux/tracepoint.h>
59eda14cbcSMatt Macy #include <sys/types.h>
60eda14cbcSMatt Macy 
61eda14cbcSMatt Macy /*
62eda14cbcSMatt Macy  * DTRACE_PROBE with 0 arguments is not currently available with
63eda14cbcSMatt Macy  *  tracepoint events
64eda14cbcSMatt Macy  */
65eda14cbcSMatt Macy #define	DTRACE_PROBE(name) \
66eda14cbcSMatt Macy 	((void)0)
67eda14cbcSMatt Macy 
68eda14cbcSMatt Macy #define	DTRACE_PROBE1(name, t1, arg1) \
69eda14cbcSMatt Macy 	trace_zfs_##name((arg1))
70eda14cbcSMatt Macy 
71eda14cbcSMatt Macy #define	DTRACE_PROBE2(name, t1, arg1, t2, arg2) \
72eda14cbcSMatt Macy 	trace_zfs_##name((arg1), (arg2))
73eda14cbcSMatt Macy 
74eda14cbcSMatt Macy #define	DTRACE_PROBE3(name, t1, arg1, t2, arg2, t3, arg3) \
75eda14cbcSMatt Macy 	trace_zfs_##name((arg1), (arg2), (arg3))
76eda14cbcSMatt Macy 
77eda14cbcSMatt Macy #define	DTRACE_PROBE4(name, t1, arg1, t2, arg2, t3, arg3, t4, arg4) \
78eda14cbcSMatt Macy 	trace_zfs_##name((arg1), (arg2), (arg3), (arg4))
79eda14cbcSMatt Macy 
80eda14cbcSMatt Macy #endif /* _TRACE_ZFS_H */
81eda14cbcSMatt Macy 
82eda14cbcSMatt Macy #undef TRACE_INCLUDE_PATH
83eda14cbcSMatt Macy #undef TRACE_INCLUDE_FILE
84eda14cbcSMatt Macy #define	TRACE_INCLUDE_PATH sys
85eda14cbcSMatt Macy #define	TRACE_INCLUDE_FILE trace
86eda14cbcSMatt Macy #include <trace/define_trace.h>
87eda14cbcSMatt Macy 
88eda14cbcSMatt Macy #else /* HAVE_DECLARE_EVENT_CLASS */
89eda14cbcSMatt Macy 
90eda14cbcSMatt Macy #define	DTRACE_PROBE(name) \
91eda14cbcSMatt Macy 	trace_zfs_##name()
92eda14cbcSMatt Macy 
93eda14cbcSMatt Macy #define	DTRACE_PROBE1(name, t1, arg1) \
94eda14cbcSMatt Macy 	trace_zfs_##name((uintptr_t)(arg1))
95eda14cbcSMatt Macy 
96eda14cbcSMatt Macy #define	DTRACE_PROBE2(name, t1, arg1, t2, arg2) \
97eda14cbcSMatt Macy 	trace_zfs_##name((uintptr_t)(arg1), (uintptr_t)(arg2))
98eda14cbcSMatt Macy 
99eda14cbcSMatt Macy #define	DTRACE_PROBE3(name, t1, arg1, t2, arg2, t3, arg3) \
100eda14cbcSMatt Macy 	trace_zfs_##name((uintptr_t)(arg1), (uintptr_t)(arg2), \
101eda14cbcSMatt Macy 	(uintptr_t)(arg3))
102eda14cbcSMatt Macy 
103eda14cbcSMatt Macy #define	DTRACE_PROBE4(name, t1, arg1, t2, arg2, t3, arg3, t4, arg4) \
104eda14cbcSMatt Macy 	trace_zfs_##name((uintptr_t)(arg1), (uintptr_t)(arg2), \
105eda14cbcSMatt Macy 	(uintptr_t)(arg3), (uintptr_t)(arg4))
106eda14cbcSMatt Macy 
107eda14cbcSMatt Macy #define	PROTO_DTRACE_PROBE(name)				\
108eda14cbcSMatt Macy 	noinline void trace_zfs_##name(void)
109eda14cbcSMatt Macy #define	PROTO_DTRACE_PROBE1(name)				\
110eda14cbcSMatt Macy 	noinline void trace_zfs_##name(uintptr_t)
111eda14cbcSMatt Macy #define	PROTO_DTRACE_PROBE2(name)				\
112eda14cbcSMatt Macy 	noinline void trace_zfs_##name(uintptr_t, uintptr_t)
113eda14cbcSMatt Macy #define	PROTO_DTRACE_PROBE3(name)				\
114eda14cbcSMatt Macy 	noinline void trace_zfs_##name(uintptr_t, uintptr_t,	\
115eda14cbcSMatt Macy 	uintptr_t)
116eda14cbcSMatt Macy #define	PROTO_DTRACE_PROBE4(name)				\
117eda14cbcSMatt Macy 	noinline void trace_zfs_##name(uintptr_t, uintptr_t,	\
118eda14cbcSMatt Macy 	uintptr_t, uintptr_t)
119eda14cbcSMatt Macy 
120eda14cbcSMatt Macy #if defined(CREATE_TRACE_POINTS)
121eda14cbcSMatt Macy 
122eda14cbcSMatt Macy #define	FUNC_DTRACE_PROBE(name)					\
123eda14cbcSMatt Macy PROTO_DTRACE_PROBE(name);					\
124eda14cbcSMatt Macy noinline void trace_zfs_##name(void) { }			\
125eda14cbcSMatt Macy EXPORT_SYMBOL(trace_zfs_##name)
126eda14cbcSMatt Macy 
127eda14cbcSMatt Macy #define	FUNC_DTRACE_PROBE1(name)				\
128eda14cbcSMatt Macy PROTO_DTRACE_PROBE1(name);					\
129eda14cbcSMatt Macy noinline void trace_zfs_##name(uintptr_t arg1) { }		\
130eda14cbcSMatt Macy EXPORT_SYMBOL(trace_zfs_##name)
131eda14cbcSMatt Macy 
132eda14cbcSMatt Macy #define	FUNC_DTRACE_PROBE2(name)				\
133eda14cbcSMatt Macy PROTO_DTRACE_PROBE2(name);					\
134eda14cbcSMatt Macy noinline void trace_zfs_##name(uintptr_t arg1,			\
135eda14cbcSMatt Macy     uintptr_t arg2) { }						\
136eda14cbcSMatt Macy EXPORT_SYMBOL(trace_zfs_##name)
137eda14cbcSMatt Macy 
138eda14cbcSMatt Macy #define	FUNC_DTRACE_PROBE3(name)				\
139eda14cbcSMatt Macy PROTO_DTRACE_PROBE3(name);					\
140eda14cbcSMatt Macy noinline void trace_zfs_##name(uintptr_t arg1,			\
141eda14cbcSMatt Macy     uintptr_t arg2, uintptr_t arg3) { }				\
142eda14cbcSMatt Macy EXPORT_SYMBOL(trace_zfs_##name)
143eda14cbcSMatt Macy 
144eda14cbcSMatt Macy #define	FUNC_DTRACE_PROBE4(name)				\
145eda14cbcSMatt Macy PROTO_DTRACE_PROBE4(name);					\
146eda14cbcSMatt Macy noinline void trace_zfs_##name(uintptr_t arg1,			\
147eda14cbcSMatt Macy     uintptr_t arg2, uintptr_t arg3, uintptr_t arg4) { }		\
148eda14cbcSMatt Macy EXPORT_SYMBOL(trace_zfs_##name)
149eda14cbcSMatt Macy 
150eda14cbcSMatt Macy #undef	DEFINE_DTRACE_PROBE
151eda14cbcSMatt Macy #define	DEFINE_DTRACE_PROBE(name)	FUNC_DTRACE_PROBE(name)
152eda14cbcSMatt Macy 
153eda14cbcSMatt Macy #undef	DEFINE_DTRACE_PROBE1
154eda14cbcSMatt Macy #define	DEFINE_DTRACE_PROBE1(name)	FUNC_DTRACE_PROBE1(name)
155eda14cbcSMatt Macy 
156eda14cbcSMatt Macy #undef	DEFINE_DTRACE_PROBE2
157eda14cbcSMatt Macy #define	DEFINE_DTRACE_PROBE2(name)	FUNC_DTRACE_PROBE2(name)
158eda14cbcSMatt Macy 
159eda14cbcSMatt Macy #undef	DEFINE_DTRACE_PROBE3
160eda14cbcSMatt Macy #define	DEFINE_DTRACE_PROBE3(name)	FUNC_DTRACE_PROBE3(name)
161eda14cbcSMatt Macy 
162eda14cbcSMatt Macy #undef	DEFINE_DTRACE_PROBE4
163eda14cbcSMatt Macy #define	DEFINE_DTRACE_PROBE4(name)	FUNC_DTRACE_PROBE4(name)
164eda14cbcSMatt Macy 
165eda14cbcSMatt Macy #else /* CREATE_TRACE_POINTS */
166eda14cbcSMatt Macy 
167eda14cbcSMatt Macy #define	DEFINE_DTRACE_PROBE(name)	PROTO_DTRACE_PROBE(name)
168eda14cbcSMatt Macy #define	DEFINE_DTRACE_PROBE1(name)	PROTO_DTRACE_PROBE1(name)
169eda14cbcSMatt Macy #define	DEFINE_DTRACE_PROBE2(name)	PROTO_DTRACE_PROBE2(name)
170eda14cbcSMatt Macy #define	DEFINE_DTRACE_PROBE3(name)	PROTO_DTRACE_PROBE3(name)
171eda14cbcSMatt Macy #define	DEFINE_DTRACE_PROBE4(name)	PROTO_DTRACE_PROBE4(name)
172eda14cbcSMatt Macy 
173eda14cbcSMatt Macy #endif /* CREATE_TRACE_POINTS */
174eda14cbcSMatt Macy #endif /* HAVE_DECLARE_EVENT_CLASS */
175eda14cbcSMatt Macy #endif /* _KERNEL */
176