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