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