blob: 9c3186578ce06d2b872e6e93ad1da0e27cf36152 [file] [log] [blame]
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -04001#ifndef _LINUX_TRACEPOINT_H
2#define _LINUX_TRACEPOINT_H
3
4/*
5 * Kernel Tracepoint API.
6 *
Mauro Carvalho Chehabec158722018-05-08 18:54:36 -03007 * See Documentation/trace/tracepoints.rst.
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -04008 *
Mathieu Desnoyersde7b2972014-04-08 17:26:21 -04009 * Copyright (C) 2008-2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -040010 *
11 * Heavily inspired from the Linux Kernel Markers.
12 *
13 * This file is released under the GPLv2.
14 * See the file COPYING for more details.
15 */
16
Steven Rostedt (Red Hat)f3775542016-02-15 12:36:14 -050017#include <linux/smp.h>
Joel Fernandes (Google)e6753f22018-07-30 15:24:22 -070018#include <linux/srcu.h>
Wu Zhangjinb70e4f02010-06-21 19:09:09 +080019#include <linux/errno.h>
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -040020#include <linux/types.h>
Steven Rostedt (Red Hat)f3775542016-02-15 12:36:14 -050021#include <linux/cpumask.h>
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -040022#include <linux/rcupdate.h>
Andi Kleenbd2a6342015-12-01 17:00:58 -080023#include <linux/tracepoint-defs.h>
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -040024
25struct module;
26struct tracepoint;
Mathieu Desnoyersde7b2972014-04-08 17:26:21 -040027struct notifier_block;
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -040028
Jeremy Linton00f4b652017-05-31 16:56:43 -050029struct trace_eval_map {
Steven Rostedt (Red Hat)0c564a52015-03-24 17:58:09 -040030 const char *system;
Jeremy Linton00f4b652017-05-31 16:56:43 -050031 const char *eval_string;
32 unsigned long eval_value;
Steven Rostedt (Red Hat)0c564a52015-03-24 17:58:09 -040033};
34
Steven Rostedt (Red Hat)7904b5c2015-09-22 17:13:19 -040035#define TRACEPOINT_DEFAULT_PRIO 10
36
Joel Fernandes (Google)e6753f22018-07-30 15:24:22 -070037extern struct srcu_struct tracepoint_srcu;
38
Steven Rostedt38516ab2010-04-20 17:04:50 -040039extern int
Mathieu Desnoyersde7b2972014-04-08 17:26:21 -040040tracepoint_probe_register(struct tracepoint *tp, void *probe, void *data);
41extern int
Steven Rostedt (Red Hat)7904b5c2015-09-22 17:13:19 -040042tracepoint_probe_register_prio(struct tracepoint *tp, void *probe, void *data,
43 int prio);
44extern int
Mathieu Desnoyersde7b2972014-04-08 17:26:21 -040045tracepoint_probe_unregister(struct tracepoint *tp, void *probe, void *data);
46extern void
47for_each_kernel_tracepoint(void (*fct)(struct tracepoint *tp, void *priv),
48 void *priv);
Steven Rostedt2e26ca72010-05-05 10:52:31 -040049
Mathieu Desnoyersb75ef8b2011-08-10 15:18:39 -040050#ifdef CONFIG_MODULES
51struct tp_module {
52 struct list_head list;
Steven Rostedt (Red Hat)eb7d0352014-04-08 20:09:40 -040053 struct module *mod;
Mathieu Desnoyersb75ef8b2011-08-10 15:18:39 -040054};
Mathieu Desnoyersde7b2972014-04-08 17:26:21 -040055
Steven Rostedt (Red Hat)45ab2812014-02-26 13:37:38 -050056bool trace_module_has_bad_taint(struct module *mod);
Mathieu Desnoyersde7b2972014-04-08 17:26:21 -040057extern int register_tracepoint_module_notifier(struct notifier_block *nb);
58extern int unregister_tracepoint_module_notifier(struct notifier_block *nb);
Steven Rostedt (Red Hat)45ab2812014-02-26 13:37:38 -050059#else
60static inline bool trace_module_has_bad_taint(struct module *mod)
61{
62 return false;
63}
Mathieu Desnoyersde7b2972014-04-08 17:26:21 -040064static inline
65int register_tracepoint_module_notifier(struct notifier_block *nb)
66{
67 return 0;
68}
69static inline
70int unregister_tracepoint_module_notifier(struct notifier_block *nb)
71{
72 return 0;
73}
Mathieu Desnoyersb75ef8b2011-08-10 15:18:39 -040074#endif /* CONFIG_MODULES */
75
Steven Rostedt2e26ca72010-05-05 10:52:31 -040076/*
77 * tracepoint_synchronize_unregister must be called between the last tracepoint
78 * probe unregistration and the end of module exit to make sure there is no
79 * caller executing a probe when it is freed.
80 */
Joel Fernandes (Google)e6753f22018-07-30 15:24:22 -070081#ifdef CONFIG_TRACEPOINTS
Steven Rostedt2e26ca72010-05-05 10:52:31 -040082static inline void tracepoint_synchronize_unregister(void)
83{
Joel Fernandes (Google)e6753f22018-07-30 15:24:22 -070084 synchronize_srcu(&tracepoint_srcu);
Paul E. McKenney74401722018-11-06 18:44:52 -080085 synchronize_rcu();
Steven Rostedt2e26ca72010-05-05 10:52:31 -040086}
Joel Fernandes (Google)e6753f22018-07-30 15:24:22 -070087#else
88static inline void tracepoint_synchronize_unregister(void)
89{ }
90#endif
Steven Rostedt2e26ca72010-05-05 10:52:31 -040091
Mathieu Desnoyersb725dfe2014-04-09 09:24:43 -040092#ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
Steven Rostedt (Red Hat)8cf868a2016-11-28 13:03:21 -050093extern int syscall_regfunc(void);
Mathieu Desnoyersb725dfe2014-04-09 09:24:43 -040094extern void syscall_unregfunc(void);
95#endif /* CONFIG_HAVE_SYSCALL_TRACEPOINTS */
96
Steven Rostedt2e26ca72010-05-05 10:52:31 -040097#define PARAMS(args...) args
98
Steven Rostedt (Red Hat)0c564a52015-03-24 17:58:09 -040099#define TRACE_DEFINE_ENUM(x)
Jeremy Linton4f0dfd72017-05-31 16:56:50 -0500100#define TRACE_DEFINE_SIZEOF(x)
Steven Rostedt (Red Hat)0c564a52015-03-24 17:58:09 -0400101
Mathieu Desnoyers9c0be3f2018-10-13 15:10:50 -0400102#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
103static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
104{
105 return offset_to_ptr(p);
106}
107
108#define __TRACEPOINT_ENTRY(name) \
109 asm(" .section \"__tracepoints_ptrs\", \"a\" \n" \
110 " .balign 4 \n" \
111 " .long __tracepoint_" #name " - . \n" \
112 " .previous \n")
113#else
114static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
115{
116 return *p;
117}
118
119#define __TRACEPOINT_ENTRY(name) \
120 static tracepoint_ptr_t __tracepoint_ptr_##name __used \
121 __attribute__((section("__tracepoints_ptrs"))) = \
122 &__tracepoint_##name
123#endif
124
Steven Rostedt2e26ca72010-05-05 10:52:31 -0400125#endif /* _LINUX_TRACEPOINT_H */
126
127/*
128 * Note: we keep the TRACE_EVENT and DECLARE_TRACE outside the include
129 * file ifdef protection.
130 * This is due to the way trace events work. If a file includes two
131 * trace event headers under one "CREATE_TRACE_POINTS" the first include
132 * will override the TRACE_EVENT and break the second include.
133 */
134
Steven Rostedtea20d922009-04-10 08:54:16 -0400135#ifndef DECLARE_TRACE
136
Steven Rostedt2939b042009-03-09 15:47:18 -0400137#define TP_PROTO(args...) args
Li Hong8cd09a52009-09-22 18:00:44 +0800138#define TP_ARGS(args...) args
Steven Rostedt287050d2010-12-02 16:46:18 -0500139#define TP_CONDITION(args...) args
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400140
Tal Shorerc63b7682015-08-01 15:27:57 +0300141/*
142 * Individual subsystem my have a separate configuration to
143 * enable their tracepoints. By default, this file will create
144 * the tracepoints if CONFIG_TRACEPOINT is defined. If a subsystem
145 * wants to be able to disable its tracepoints from being created
146 * it can define NOTRACE before including the tracepoint headers.
147 */
148#if defined(CONFIG_TRACEPOINTS) && !defined(NOTRACE)
149#define TRACEPOINTS_ENABLED
150#endif
151
152#ifdef TRACEPOINTS_ENABLED
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400153
154/*
155 * it_func[0] is never NULL because there is at least one element in the array
156 * when the array itself is non NULL.
Steven Rostedt38516ab2010-04-20 17:04:50 -0400157 *
158 * Note, the proto and args passed in includes "__data" as the first parameter.
159 * The reason for this is to handle the "void" prototype. If a tracepoint
160 * has a "void" prototype, then it is invalid to declare a function
161 * as "(void *, void)". The DECLARE_TRACE_NOARGS() will pass in just
162 * "void *data", where as the DECLARE_TRACE() will pass in "void *data, proto".
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400163 */
Joel Fernandes (Google)e6753f22018-07-30 15:24:22 -0700164#define __DO_TRACE(tp, proto, args, cond, rcuidle) \
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400165 do { \
Steven Rostedt38516ab2010-04-20 17:04:50 -0400166 struct tracepoint_func *it_func_ptr; \
167 void *it_func; \
168 void *__data; \
Zenghui Yu0c7a52e2018-11-28 03:35:23 +0000169 int __maybe_unused __idx = 0; \
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400170 \
Steven Rostedt287050d2010-12-02 16:46:18 -0500171 if (!(cond)) \
172 return; \
Joel Fernandes (Google)e6753f22018-07-30 15:24:22 -0700173 \
174 /* srcu can't be used from NMI */ \
175 WARN_ON_ONCE(rcuidle && in_nmi()); \
176 \
177 /* keep srcu and sched-rcu usage consistent */ \
178 preempt_disable_notrace(); \
179 \
180 /* \
181 * For rcuidle callers, use srcu since sched-rcu \
182 * doesn't work from the idle path. \
183 */ \
Steven Rostedt (VMware)865e63b2018-09-04 16:26:11 -0400184 if (rcuidle) { \
Zenghui Yu0c7a52e2018-11-28 03:35:23 +0000185 __idx = srcu_read_lock_notrace(&tracepoint_srcu);\
Steven Rostedt (VMware)865e63b2018-09-04 16:26:11 -0400186 rcu_irq_enter_irqson(); \
187 } \
Joel Fernandes (Google)e6753f22018-07-30 15:24:22 -0700188 \
189 it_func_ptr = rcu_dereference_raw((tp)->funcs); \
190 \
Steven Rostedt38516ab2010-04-20 17:04:50 -0400191 if (it_func_ptr) { \
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400192 do { \
Steven Rostedt38516ab2010-04-20 17:04:50 -0400193 it_func = (it_func_ptr)->func; \
194 __data = (it_func_ptr)->data; \
195 ((void(*)(proto))(it_func))(args); \
196 } while ((++it_func_ptr)->func); \
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400197 } \
Joel Fernandes (Google)e6753f22018-07-30 15:24:22 -0700198 \
Steven Rostedt (VMware)865e63b2018-09-04 16:26:11 -0400199 if (rcuidle) { \
200 rcu_irq_exit_irqson(); \
Zenghui Yu0c7a52e2018-11-28 03:35:23 +0000201 srcu_read_unlock_notrace(&tracepoint_srcu, __idx);\
Steven Rostedt (VMware)865e63b2018-09-04 16:26:11 -0400202 } \
Joel Fernandes (Google)e6753f22018-07-30 15:24:22 -0700203 \
204 preempt_enable_notrace(); \
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400205 } while (0)
206
Josh Triplett7ece55a2012-09-04 23:23:06 -0700207#ifndef MODULE
Steven Rostedt (VMware)d54b6ee2017-04-07 12:40:49 -0400208#define __DECLARE_TRACE_RCU(name, proto, args, cond, data_proto, data_args) \
Josh Triplett7ece55a2012-09-04 23:23:06 -0700209 static inline void trace_##name##_rcuidle(proto) \
210 { \
211 if (static_key_false(&__tracepoint_##name.key)) \
212 __DO_TRACE(&__tracepoint_##name, \
213 TP_PROTO(data_proto), \
214 TP_ARGS(data_args), \
Steven Rostedt (VMware)d54b6ee2017-04-07 12:40:49 -0400215 TP_CONDITION(cond), 1); \
Josh Triplett7ece55a2012-09-04 23:23:06 -0700216 }
217#else
218#define __DECLARE_TRACE_RCU(name, proto, args, cond, data_proto, data_args)
219#endif
220
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400221/*
222 * Make sure the alignment of the structure in the __tracepoints section will
223 * not add unwanted padding between the beginning of the section and the
224 * structure. Force alignment to the same alignment as the section start.
Dave Hansen3a630172014-08-07 10:52:04 -0700225 *
226 * When lockdep is enabled, we make sure to always do the RCU portions of
Mathieu Desnoyersa15920b2015-11-02 17:42:42 -0500227 * the tracepoint code, regardless of whether tracing is on. However,
228 * don't check if the condition is false, due to interaction with idle
229 * instrumentation. This lets us find RCU issues triggered with tracepoints
230 * even when this tracepoint is off. This code has no purpose other than
231 * poking RCU a bit.
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400232 */
Steven Rostedt2fbb90d2012-02-07 09:32:43 -0500233#define __DECLARE_TRACE(name, proto, args, cond, data_proto, data_args) \
Mathieu Desnoyers7e066fb2008-11-14 17:47:47 -0500234 extern struct tracepoint __tracepoint_##name; \
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400235 static inline void trace_##name(proto) \
236 { \
Ingo Molnarc5905af2012-02-24 08:31:31 +0100237 if (static_key_false(&__tracepoint_##name.key)) \
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400238 __DO_TRACE(&__tracepoint_##name, \
Steven Rostedt38516ab2010-04-20 17:04:50 -0400239 TP_PROTO(data_proto), \
Steven Rostedt287050d2010-12-02 16:46:18 -0500240 TP_ARGS(data_args), \
Steven Rostedt (VMware)d54b6ee2017-04-07 12:40:49 -0400241 TP_CONDITION(cond), 0); \
Steven Rostedt (Red Hat)a05d59a2015-02-06 14:30:50 -0500242 if (IS_ENABLED(CONFIG_LOCKDEP) && (cond)) { \
Dave Hansen3a630172014-08-07 10:52:04 -0700243 rcu_read_lock_sched_notrace(); \
244 rcu_dereference_sched(__tracepoint_##name.funcs);\
245 rcu_read_unlock_sched_notrace(); \
246 } \
Steven Rostedt2fbb90d2012-02-07 09:32:43 -0500247 } \
Josh Triplett7ece55a2012-09-04 23:23:06 -0700248 __DECLARE_TRACE_RCU(name, PARAMS(proto), PARAMS(args), \
249 PARAMS(cond), PARAMS(data_proto), PARAMS(data_args)) \
Steven Rostedt38516ab2010-04-20 17:04:50 -0400250 static inline int \
251 register_trace_##name(void (*probe)(data_proto), void *data) \
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400252 { \
Mathieu Desnoyersde7b2972014-04-08 17:26:21 -0400253 return tracepoint_probe_register(&__tracepoint_##name, \
254 (void *)probe, data); \
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400255 } \
Steven Rostedt38516ab2010-04-20 17:04:50 -0400256 static inline int \
Steven Rostedt (Red Hat)7904b5c2015-09-22 17:13:19 -0400257 register_trace_prio_##name(void (*probe)(data_proto), void *data,\
258 int prio) \
259 { \
260 return tracepoint_probe_register_prio(&__tracepoint_##name, \
261 (void *)probe, data, prio); \
262 } \
263 static inline int \
Steven Rostedt38516ab2010-04-20 17:04:50 -0400264 unregister_trace_##name(void (*probe)(data_proto), void *data) \
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400265 { \
Mathieu Desnoyersde7b2972014-04-08 17:26:21 -0400266 return tracepoint_probe_unregister(&__tracepoint_##name,\
267 (void *)probe, data); \
Mathieu Desnoyers53da59a2010-04-30 12:59:59 -0400268 } \
Steven Rostedt38516ab2010-04-20 17:04:50 -0400269 static inline void \
270 check_trace_callback_type_##name(void (*cb)(data_proto)) \
Mathieu Desnoyers53da59a2010-04-30 12:59:59 -0400271 { \
Steven Rostedt (Red Hat)7c65bbc2014-05-06 09:26:30 -0400272 } \
273 static inline bool \
274 trace_##name##_enabled(void) \
275 { \
276 return static_key_false(&__tracepoint_##name.key); \
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400277 }
278
Mathieu Desnoyers65498642011-01-26 17:26:22 -0500279/*
280 * We have no guarantee that gcc and the linker won't up-align the tracepoint
281 * structures, so we create an array of pointers that will be used for iteration
282 * on the tracepoints.
283 */
Jason Barond430d3d2011-03-16 17:29:47 -0400284#define DEFINE_TRACE_FN(name, reg, unreg) \
285 static const char __tpstrtab_##name[] \
286 __attribute__((section("__tracepoints_strings"))) = #name; \
287 struct tracepoint __tracepoint_##name \
Ard Biesheuvel46e0c9b2018-08-21 21:56:22 -0700288 __attribute__((section("__tracepoints"), used)) = \
Ingo Molnarc5905af2012-02-24 08:31:31 +0100289 { __tpstrtab_##name, STATIC_KEY_INIT_FALSE, reg, unreg, NULL };\
Ard Biesheuvel46e0c9b2018-08-21 21:56:22 -0700290 __TRACEPOINT_ENTRY(name);
Josh Stone97419872009-08-24 14:43:13 -0700291
292#define DEFINE_TRACE(name) \
293 DEFINE_TRACE_FN(name, NULL, NULL);
Mathieu Desnoyers7e066fb2008-11-14 17:47:47 -0500294
295#define EXPORT_TRACEPOINT_SYMBOL_GPL(name) \
296 EXPORT_SYMBOL_GPL(__tracepoint_##name)
297#define EXPORT_TRACEPOINT_SYMBOL(name) \
298 EXPORT_SYMBOL(__tracepoint_##name)
299
Tal Shorerc63b7682015-08-01 15:27:57 +0300300#else /* !TRACEPOINTS_ENABLED */
Steven Rostedt2fbb90d2012-02-07 09:32:43 -0500301#define __DECLARE_TRACE(name, proto, args, cond, data_proto, data_args) \
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400302 static inline void trace_##name(proto) \
303 { } \
Steven Rostedt2fbb90d2012-02-07 09:32:43 -0500304 static inline void trace_##name##_rcuidle(proto) \
305 { } \
Steven Rostedt38516ab2010-04-20 17:04:50 -0400306 static inline int \
307 register_trace_##name(void (*probe)(data_proto), \
308 void *data) \
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400309 { \
310 return -ENOSYS; \
311 } \
Steven Rostedt38516ab2010-04-20 17:04:50 -0400312 static inline int \
313 unregister_trace_##name(void (*probe)(data_proto), \
314 void *data) \
Mathieu Desnoyersc4209702008-11-14 17:47:44 -0500315 { \
316 return -ENOSYS; \
Mathieu Desnoyers53da59a2010-04-30 12:59:59 -0400317 } \
Steven Rostedt38516ab2010-04-20 17:04:50 -0400318 static inline void check_trace_callback_type_##name(void (*cb)(data_proto)) \
Mathieu Desnoyers53da59a2010-04-30 12:59:59 -0400319 { \
Steven Rostedt (Red Hat)7c65bbc2014-05-06 09:26:30 -0400320 } \
321 static inline bool \
322 trace_##name##_enabled(void) \
323 { \
324 return false; \
Mathieu Desnoyersc4209702008-11-14 17:47:44 -0500325 }
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400326
Josh Stone97419872009-08-24 14:43:13 -0700327#define DEFINE_TRACE_FN(name, reg, unreg)
Mathieu Desnoyers7e066fb2008-11-14 17:47:47 -0500328#define DEFINE_TRACE(name)
329#define EXPORT_TRACEPOINT_SYMBOL_GPL(name)
330#define EXPORT_TRACEPOINT_SYMBOL(name)
331
Tal Shorerc63b7682015-08-01 15:27:57 +0300332#endif /* TRACEPOINTS_ENABLED */
Steven Rostedt38516ab2010-04-20 17:04:50 -0400333
Steven Rostedt3c49b522014-07-25 16:05:29 -0400334#ifdef CONFIG_TRACING
335/**
336 * tracepoint_string - register constant persistent string to trace system
337 * @str - a constant persistent string that will be referenced in tracepoints
338 *
339 * If constant strings are being used in tracepoints, it is faster and
340 * more efficient to just save the pointer to the string and reference
341 * that with a printf "%s" instead of saving the string in the ring buffer
342 * and wasting space and time.
343 *
344 * The problem with the above approach is that userspace tools that read
345 * the binary output of the trace buffers do not have access to the string.
346 * Instead they just show the address of the string which is not very
347 * useful to users.
348 *
349 * With tracepoint_string(), the string will be registered to the tracing
350 * system and exported to userspace via the debugfs/tracing/printk_formats
351 * file that maps the string address to the string text. This way userspace
352 * tools that read the binary buffers have a way to map the pointers to
353 * the ASCII strings they represent.
354 *
355 * The @str used must be a constant string and persistent as it would not
356 * make sense to show a string that no longer exists. But it is still fine
357 * to be used with modules, because when modules are unloaded, if they
358 * had tracepoints, the ring buffers are cleared too. As long as the string
359 * does not change during the life of the module, it is fine to use
360 * tracepoint_string() within a module.
361 */
362#define tracepoint_string(str) \
363 ({ \
364 static const char *___tp_str __tracepoint_string = str; \
365 ___tp_str; \
366 })
367#define __tracepoint_string __attribute__((section("__tracepoint_str")))
368#else
369/*
370 * tracepoint_string() is used to save the string address for userspace
371 * tracing tools. When tracing isn't configured, there's no need to save
372 * anything.
373 */
374# define tracepoint_string(str) str
375# define __tracepoint_string
376#endif
377
Steven Rostedt38516ab2010-04-20 17:04:50 -0400378/*
379 * The need for the DECLARE_TRACE_NOARGS() is to handle the prototype
380 * (void). "void" is a special value in a function prototype and can
381 * not be combined with other arguments. Since the DECLARE_TRACE()
382 * macro adds a data element at the beginning of the prototype,
383 * we need a way to differentiate "(void *data, proto)" from
384 * "(void *data, void)". The second prototype is invalid.
385 *
386 * DECLARE_TRACE_NOARGS() passes "void" as the tracepoint prototype
387 * and "void *__data" as the callback prototype.
388 *
389 * DECLARE_TRACE() passes "proto" as the tracepoint protoype and
390 * "void *__data, proto" as the callback prototype.
391 */
392#define DECLARE_TRACE_NOARGS(name) \
Steven Rostedt (Red Hat)dc171472016-03-09 11:58:41 -0500393 __DECLARE_TRACE(name, void, , \
394 cpu_online(raw_smp_processor_id()), \
395 void *__data, __data)
Steven Rostedt38516ab2010-04-20 17:04:50 -0400396
397#define DECLARE_TRACE(name, proto, args) \
Steven Rostedt (Red Hat)dc171472016-03-09 11:58:41 -0500398 __DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), \
399 cpu_online(raw_smp_processor_id()), \
400 PARAMS(void *__data, proto), \
401 PARAMS(__data, args))
Steven Rostedt38516ab2010-04-20 17:04:50 -0400402
Steven Rostedt287050d2010-12-02 16:46:18 -0500403#define DECLARE_TRACE_CONDITION(name, proto, args, cond) \
Steven Rostedt (Red Hat)dc171472016-03-09 11:58:41 -0500404 __DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), \
405 cpu_online(raw_smp_processor_id()) && (PARAMS(cond)), \
Steven Rostedt287050d2010-12-02 16:46:18 -0500406 PARAMS(void *__data, proto), \
407 PARAMS(__data, args))
408
Frederic Weisbecker1ed0c592010-11-18 01:46:57 +0100409#define TRACE_EVENT_FLAGS(event, flag)
410
Peter Zijlstrad5b5f392013-11-14 16:23:04 +0100411#define TRACE_EVENT_PERF_PERM(event, expr...)
412
Steven Rostedtea20d922009-04-10 08:54:16 -0400413#endif /* DECLARE_TRACE */
Mathieu Desnoyers97e1c182008-07-18 12:16:16 -0400414
Steven Rostedtea20d922009-04-10 08:54:16 -0400415#ifndef TRACE_EVENT
Steven Rostedt823f9122009-03-10 12:58:51 -0400416/*
417 * For use with the TRACE_EVENT macro:
418 *
419 * We define a tracepoint, its arguments, its printk format
Viresh Kumar2621bca2013-12-02 15:15:37 +0530420 * and its 'fast binary record' layout.
Steven Rostedt823f9122009-03-10 12:58:51 -0400421 *
422 * Firstly, name your tracepoint via TRACE_EVENT(name : the
423 * 'subsystem_event' notation is fine.
424 *
425 * Think about this whole construct as the
426 * 'trace_sched_switch() function' from now on.
427 *
428 *
429 * TRACE_EVENT(sched_switch,
430 *
431 * *
432 * * A function has a regular function arguments
433 * * prototype, declare it via TP_PROTO():
434 * *
435 *
Steven Rostedtef180122009-03-10 14:10:56 -0400436 * TP_PROTO(struct rq *rq, struct task_struct *prev,
437 * struct task_struct *next),
Steven Rostedt823f9122009-03-10 12:58:51 -0400438 *
439 * *
440 * * Define the call signature of the 'function'.
441 * * (Design sidenote: we use this instead of a
442 * * TP_PROTO1/TP_PROTO2/TP_PROTO3 ugliness.)
443 * *
444 *
Steven Rostedtef180122009-03-10 14:10:56 -0400445 * TP_ARGS(rq, prev, next),
Steven Rostedt823f9122009-03-10 12:58:51 -0400446 *
447 * *
448 * * Fast binary tracing: define the trace record via
449 * * TP_STRUCT__entry(). You can think about it like a
450 * * regular C structure local variable definition.
451 * *
452 * * This is how the trace record is structured and will
453 * * be saved into the ring buffer. These are the fields
454 * * that will be exposed to user-space in
GeunSik Lim156f5a72009-06-02 15:01:37 +0900455 * * /sys/kernel/debug/tracing/events/<*>/format.
Steven Rostedt823f9122009-03-10 12:58:51 -0400456 * *
457 * * The declared 'local variable' is called '__entry'
458 * *
459 * * __field(pid_t, prev_prid) is equivalent to a standard declariton:
460 * *
461 * * pid_t prev_pid;
462 * *
463 * * __array(char, prev_comm, TASK_COMM_LEN) is equivalent to:
464 * *
465 * * char prev_comm[TASK_COMM_LEN];
466 * *
467 *
468 * TP_STRUCT__entry(
469 * __array( char, prev_comm, TASK_COMM_LEN )
470 * __field( pid_t, prev_pid )
471 * __field( int, prev_prio )
472 * __array( char, next_comm, TASK_COMM_LEN )
473 * __field( pid_t, next_pid )
474 * __field( int, next_prio )
475 * ),
476 *
477 * *
478 * * Assign the entry into the trace record, by embedding
479 * * a full C statement block into TP_fast_assign(). You
480 * * can refer to the trace record as '__entry' -
481 * * otherwise you can put arbitrary C code in here.
482 * *
483 * * Note: this C code will execute every time a trace event
484 * * happens, on an active tracepoint.
485 * *
486 *
Steven Rostedtef180122009-03-10 14:10:56 -0400487 * TP_fast_assign(
488 * memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN);
489 * __entry->prev_pid = prev->pid;
490 * __entry->prev_prio = prev->prio;
Steven Rostedt823f9122009-03-10 12:58:51 -0400491 * memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN);
492 * __entry->next_pid = next->pid;
Steven Rostedtef180122009-03-10 14:10:56 -0400493 * __entry->next_prio = next->prio;
Mathieu Desnoyersec6e7c32011-01-06 13:45:32 -0500494 * ),
Steven Rostedt823f9122009-03-10 12:58:51 -0400495 *
496 * *
497 * * Formatted output of a trace record via TP_printk().
498 * * This is how the tracepoint will appear under ftrace
499 * * plugins that make use of this tracepoint.
500 * *
501 * * (raw-binary tracing wont actually perform this step.)
502 * *
503 *
504 * TP_printk("task %s:%d [%d] ==> %s:%d [%d]",
505 * __entry->prev_comm, __entry->prev_pid, __entry->prev_prio,
506 * __entry->next_comm, __entry->next_pid, __entry->next_prio),
507 *
508 * );
509 *
510 * This macro construct is thus used for the regular printk format
511 * tracing setup, it is used to construct a function pointer based
512 * tracepoint callback (this is used by programmatic plugins and
513 * can also by used by generic instrumentation like SystemTap), and
514 * it is also used to expose a structured trace record in
GeunSik Lim156f5a72009-06-02 15:01:37 +0900515 * /sys/kernel/debug/tracing/events/.
Josh Stone97419872009-08-24 14:43:13 -0700516 *
517 * A set of (un)registration functions can be passed to the variant
518 * TRACE_EVENT_FN to perform any (un)registration work.
Steven Rostedt823f9122009-03-10 12:58:51 -0400519 */
520
Ingo Molnar091ad362009-11-26 09:04:55 +0100521#define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print)
Steven Rostedtff038f52009-11-18 20:27:27 -0500522#define DEFINE_EVENT(template, name, proto, args) \
523 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
Steven Rostedtf5abaa12013-06-20 11:44:44 -0400524#define DEFINE_EVENT_FN(template, name, proto, args, reg, unreg)\
525 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
Steven Rostedte5bc9722009-11-18 20:36:26 -0500526#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
527 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
Steven Rostedt287050d2010-12-02 16:46:18 -0500528#define DEFINE_EVENT_CONDITION(template, name, proto, \
529 args, cond) \
530 DECLARE_TRACE_CONDITION(name, PARAMS(proto), \
531 PARAMS(args), PARAMS(cond))
Steven Rostedtff038f52009-11-18 20:27:27 -0500532
Steven Rostedt30a8fec2009-03-10 12:41:38 -0400533#define TRACE_EVENT(name, proto, args, struct, assign, print) \
Steven Rostedtda4d0302009-03-09 17:14:30 -0400534 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
Josh Stone97419872009-08-24 14:43:13 -0700535#define TRACE_EVENT_FN(name, proto, args, struct, \
536 assign, print, reg, unreg) \
537 DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
Denis Kirjanov27011212015-12-14 23:18:05 +0300538#define TRACE_EVENT_FN_COND(name, proto, args, cond, struct, \
539 assign, print, reg, unreg) \
540 DECLARE_TRACE_CONDITION(name, PARAMS(proto), \
541 PARAMS(args), PARAMS(cond))
Steven Rostedt287050d2010-12-02 16:46:18 -0500542#define TRACE_EVENT_CONDITION(name, proto, args, cond, \
543 struct, assign, print) \
544 DECLARE_TRACE_CONDITION(name, PARAMS(proto), \
545 PARAMS(args), PARAMS(cond))
Steven Rostedt7cb2e3e2009-08-26 00:32:37 -0400546
Frederic Weisbecker1ed0c592010-11-18 01:46:57 +0100547#define TRACE_EVENT_FLAGS(event, flag)
548
Peter Zijlstrad5b5f392013-11-14 16:23:04 +0100549#define TRACE_EVENT_PERF_PERM(event, expr...)
550
Steven Rostedt7cb2e3e2009-08-26 00:32:37 -0400551#endif /* ifdef TRACE_EVENT (see note above) */