1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 #ifndef _LINUX_TRACEPOINT_H 3 #define _LINUX_TRACEPOINT_H 4 5 /* 6 * Kernel Tracepoint API. 7 * 8 * See Documentation/trace/tracepoints.rst. 9 * 10 * Copyright (C) 2008-2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> 11 * 12 * Heavily inspired from the Linux Kernel Markers. 13 */ 14 15 #include <linux/smp.h> 16 #include <linux/srcu.h> 17 #include <linux/errno.h> 18 #include <linux/types.h> 19 #include <linux/rcupdate.h> 20 #include <linux/rcupdate_trace.h> 21 #include <linux/tracepoint-defs.h> 22 #include <linux/static_call.h> 23 #include <linux/cfi.h> 24 25 struct module; 26 struct tracepoint; 27 struct notifier_block; 28 29 struct trace_eval_map { 30 const char *system; 31 const char *eval_string; 32 unsigned long eval_value; 33 }; 34 35 #define TRACEPOINT_DEFAULT_PRIO 10 36 37 extern int 38 tracepoint_probe_register(struct tracepoint *tp, void *probe, void *data); 39 extern int 40 tracepoint_probe_register_prio(struct tracepoint *tp, void *probe, void *data, 41 int prio); 42 extern int 43 tracepoint_probe_register_prio_may_exist(struct tracepoint *tp, void *probe, void *data, 44 int prio); 45 extern int 46 tracepoint_probe_unregister(struct tracepoint *tp, void *probe, void *data); 47 static inline int 48 tracepoint_probe_register_may_exist(struct tracepoint *tp, void *probe, 49 void *data) 50 { 51 return tracepoint_probe_register_prio_may_exist(tp, probe, data, 52 TRACEPOINT_DEFAULT_PRIO); 53 } 54 extern void 55 for_each_kernel_tracepoint(void (*fct)(struct tracepoint *tp, void *priv), 56 void *priv); 57 58 #ifdef CONFIG_MODULES 59 struct tp_module { 60 struct list_head list; 61 struct module *mod; 62 }; 63 64 bool trace_module_has_bad_taint(struct module *mod); 65 extern int register_tracepoint_module_notifier(struct notifier_block *nb); 66 extern int unregister_tracepoint_module_notifier(struct notifier_block *nb); 67 void for_each_module_tracepoint(void (*fct)(struct tracepoint *, 68 struct module *, void *), 69 void *priv); 70 void for_each_tracepoint_in_module(struct module *, 71 void (*fct)(struct tracepoint *, 72 struct module *, void *), 73 void *priv); 74 #else 75 static inline bool trace_module_has_bad_taint(struct module *mod) 76 { 77 return false; 78 } 79 static inline 80 int register_tracepoint_module_notifier(struct notifier_block *nb) 81 { 82 return 0; 83 } 84 static inline 85 int unregister_tracepoint_module_notifier(struct notifier_block *nb) 86 { 87 return 0; 88 } 89 static inline 90 void for_each_module_tracepoint(void (*fct)(struct tracepoint *, 91 struct module *, void *), 92 void *priv) 93 { 94 } 95 static inline 96 void for_each_tracepoint_in_module(struct module *mod, 97 void (*fct)(struct tracepoint *, 98 struct module *, void *), 99 void *priv) 100 { 101 } 102 #endif /* CONFIG_MODULES */ 103 104 /* 105 * tracepoint_synchronize_unregister must be called between the last tracepoint 106 * probe unregistration and the end of module exit to make sure there is no 107 * caller executing a probe when it is freed. 108 * 109 * An alternative is to use the following for batch reclaim associated 110 * with a given tracepoint: 111 * 112 * - tracepoint_is_faultable() == false: call_srcu() 113 * - tracepoint_is_faultable() == true: call_rcu_tasks_trace() 114 */ 115 #ifdef CONFIG_TRACEPOINTS 116 extern struct srcu_struct tracepoint_srcu; 117 static inline void tracepoint_synchronize_unregister(void) 118 { 119 synchronize_rcu_tasks_trace(); 120 synchronize_srcu(&tracepoint_srcu); 121 } 122 static inline bool tracepoint_is_faultable(struct tracepoint *tp) 123 { 124 return tp->ext && tp->ext->faultable; 125 } 126 /* 127 * Run RCU callback with the appropriate grace period wait for non-faultable 128 * tracepoints, e.g., those used in atomic context. 129 */ 130 static inline void call_tracepoint_unregister_atomic(struct rcu_head *rcu, rcu_callback_t func) 131 { 132 call_srcu(&tracepoint_srcu, rcu, func); 133 } 134 /* 135 * Run RCU callback with the appropriate grace period wait for faultable 136 * tracepoints, e.g., those used in syscall context. 137 */ 138 static inline void call_tracepoint_unregister_syscall(struct rcu_head *rcu, rcu_callback_t func) 139 { 140 call_rcu_tasks_trace(rcu, func); 141 } 142 #else 143 static inline void tracepoint_synchronize_unregister(void) 144 { } 145 static inline bool tracepoint_is_faultable(struct tracepoint *tp) 146 { 147 return false; 148 } 149 static inline void call_tracepoint_unregister_atomic(struct rcu_head *rcu, rcu_callback_t func) 150 { } 151 static inline void call_tracepoint_unregister_syscall(struct rcu_head *rcu, rcu_callback_t func) 152 { } 153 #endif 154 155 #ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS 156 extern int syscall_regfunc(void); 157 extern void syscall_unregfunc(void); 158 #endif /* CONFIG_HAVE_SYSCALL_TRACEPOINTS */ 159 160 #ifndef PARAMS 161 #define PARAMS(args...) args 162 #endif 163 164 #define TRACE_DEFINE_ENUM(x) 165 #define TRACE_DEFINE_SIZEOF(x) 166 167 #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS 168 static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p) 169 { 170 return offset_to_ptr(p); 171 } 172 173 #define __TRACEPOINT_ENTRY(name) \ 174 asm(" .section \"__tracepoints_ptrs\", \"a\" \n" \ 175 " .balign 4 \n" \ 176 " .long __tracepoint_" #name " - . \n" \ 177 " .previous \n") 178 #else 179 static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p) 180 { 181 return *p; 182 } 183 184 #define __TRACEPOINT_ENTRY(name) \ 185 static tracepoint_ptr_t __tracepoint_ptr_##name __used \ 186 __section("__tracepoints_ptrs") = &__tracepoint_##name 187 #endif 188 189 #endif /* _LINUX_TRACEPOINT_H */ 190 191 /* 192 * Note: we keep the TRACE_EVENT and DECLARE_TRACE outside the include 193 * file ifdef protection. 194 * This is due to the way trace events work. If a file includes two 195 * trace event headers under one "CREATE_TRACE_POINTS" the first include 196 * will override the TRACE_EVENT and break the second include. 197 */ 198 199 #ifndef DECLARE_TRACE 200 201 #define TP_PROTO(args...) args 202 #define TP_ARGS(args...) args 203 #define TP_CONDITION(args...) args 204 205 /* 206 * Individual subsystem may have a separate configuration to 207 * enable their tracepoints. By default, this file will create 208 * the tracepoints if CONFIG_TRACEPOINTS is defined. If a subsystem 209 * wants to be able to disable its tracepoints from being created 210 * it can define NOTRACE before including the tracepoint headers. 211 */ 212 #if defined(CONFIG_TRACEPOINTS) && !defined(NOTRACE) 213 #define TRACEPOINTS_ENABLED 214 #endif 215 216 #ifdef TRACEPOINTS_ENABLED 217 218 #ifdef CONFIG_HAVE_STATIC_CALL 219 #define __DO_TRACE_CALL(name, args) \ 220 do { \ 221 struct tracepoint_func *it_func_ptr; \ 222 void *__data; \ 223 it_func_ptr = \ 224 rcu_dereference_raw((&__tracepoint_##name)->funcs); \ 225 if (it_func_ptr) { \ 226 __data = (it_func_ptr)->data; \ 227 static_call(tp_func_##name)(__data, args); \ 228 } \ 229 } while (0) 230 #else 231 #define __DO_TRACE_CALL(name, args) __traceiter_##name(NULL, args) 232 #endif /* CONFIG_HAVE_STATIC_CALL */ 233 234 /* 235 * Declare an exported function that Rust code can call to trigger this 236 * tracepoint. This function does not include the static branch; that is done 237 * in Rust to avoid a function call when the tracepoint is disabled. 238 */ 239 #define DEFINE_RUST_DO_TRACE(name, proto, args) 240 #define __DEFINE_RUST_DO_TRACE(name, proto, args) \ 241 notrace void rust_do_trace_##name(proto) \ 242 { \ 243 __do_trace_##name(args); \ 244 } 245 246 /* 247 * When a tracepoint is used, it's name is added to the __tracepoint_check 248 * section. This section is only used at build time to make sure all 249 * defined tracepoints are used. It is discarded after the build. 250 */ 251 # define TRACEPOINT_CHECK(name) \ 252 static const char __used __section("__tracepoint_check") \ 253 __trace_check_##name[] = #name; 254 255 /* 256 * Make sure the alignment of the structure in the __tracepoints section will 257 * not add unwanted padding between the beginning of the section and the 258 * structure. Force alignment to the same alignment as the section start. 259 * 260 * When lockdep is enabled, we make sure to always test if RCU is 261 * "watching" regardless if the tracepoint is enabled or not. Tracepoints 262 * require RCU to be active, and it should always warn at the tracepoint 263 * site if it is not watching, as it will need to be active when the 264 * tracepoint is enabled. 265 */ 266 #define __DECLARE_TRACE_COMMON(name, proto, args, data_proto) \ 267 extern int __traceiter_##name(data_proto); \ 268 DECLARE_STATIC_CALL(tp_func_##name, __traceiter_##name); \ 269 extern struct tracepoint __tracepoint_##name; \ 270 extern void rust_do_trace_##name(proto); \ 271 static inline int \ 272 register_trace_##name(void (*probe)(data_proto), void *data) \ 273 { \ 274 return tracepoint_probe_register(&__tracepoint_##name, \ 275 (void *)probe, data); \ 276 } \ 277 static inline int \ 278 register_trace_prio_##name(void (*probe)(data_proto), void *data,\ 279 int prio) \ 280 { \ 281 return tracepoint_probe_register_prio(&__tracepoint_##name, \ 282 (void *)probe, data, prio); \ 283 } \ 284 static inline int \ 285 unregister_trace_##name(void (*probe)(data_proto), void *data) \ 286 { \ 287 return tracepoint_probe_unregister(&__tracepoint_##name,\ 288 (void *)probe, data); \ 289 } \ 290 static inline void \ 291 check_trace_callback_type_##name(void (*cb)(data_proto)) \ 292 { \ 293 } \ 294 static inline bool \ 295 trace_##name##_enabled(void) \ 296 { \ 297 if (IS_ENABLED(CONFIG_LOCKDEP)) { \ 298 WARN_ONCE(!rcu_is_watching(), \ 299 "RCU not watching for tracepoint"); \ 300 } \ 301 return static_branch_unlikely(&__tracepoint_##name.key);\ 302 } 303 304 #define __DECLARE_TRACE(name, proto, args, cond, data_proto) \ 305 __DECLARE_TRACE_COMMON(name, PARAMS(proto), PARAMS(args), PARAMS(data_proto)) \ 306 static inline void __do_trace_##name(proto) \ 307 { \ 308 TRACEPOINT_CHECK(name) \ 309 if (cond) { \ 310 guard(srcu_fast_notrace)(&tracepoint_srcu); \ 311 __DO_TRACE_CALL(name, TP_ARGS(args)); \ 312 } \ 313 } \ 314 static inline void trace_##name(proto) \ 315 { \ 316 if (static_branch_unlikely(&__tracepoint_##name.key)) \ 317 __do_trace_##name(args); \ 318 if (IS_ENABLED(CONFIG_LOCKDEP) && (cond)) { \ 319 WARN_ONCE(!rcu_is_watching(), \ 320 "RCU not watching for tracepoint"); \ 321 } \ 322 } \ 323 static inline void trace_call__##name(proto) \ 324 { \ 325 __do_trace_##name(args); \ 326 } 327 328 #define __DECLARE_TRACE_SYSCALL(name, proto, args, data_proto) \ 329 __DECLARE_TRACE_COMMON(name, PARAMS(proto), PARAMS(args), PARAMS(data_proto)) \ 330 static inline void __do_trace_##name(proto) \ 331 { \ 332 TRACEPOINT_CHECK(name) \ 333 guard(rcu_tasks_trace)(); \ 334 __DO_TRACE_CALL(name, TP_ARGS(args)); \ 335 } \ 336 static inline void trace_##name(proto) \ 337 { \ 338 might_fault(); \ 339 if (static_branch_unlikely(&__tracepoint_##name.key)) \ 340 __do_trace_##name(args); \ 341 if (IS_ENABLED(CONFIG_LOCKDEP)) { \ 342 WARN_ONCE(!rcu_is_watching(), \ 343 "RCU not watching for tracepoint"); \ 344 } \ 345 } \ 346 static inline void trace_call__##name(proto) \ 347 { \ 348 might_fault(); \ 349 __do_trace_##name(args); \ 350 } 351 352 /* 353 * We have no guarantee that gcc and the linker won't up-align the tracepoint 354 * structures, so we create an array of pointers that will be used for iteration 355 * on the tracepoints. 356 * 357 * it_func[0] is never NULL because there is at least one element in the array 358 * when the array itself is non NULL. 359 */ 360 #define __DEFINE_TRACE_EXT(_name, _ext, proto, args) \ 361 static const char __tpstrtab_##_name[] \ 362 __section("__tracepoints_strings") = #_name; \ 363 extern struct static_call_key STATIC_CALL_KEY(tp_func_##_name); \ 364 int __traceiter_##_name(void *__data, proto); \ 365 void __probestub_##_name(void *__data, proto); \ 366 struct tracepoint __tracepoint_##_name __used \ 367 __section("__tracepoints") = { \ 368 .name = __tpstrtab_##_name, \ 369 .key = STATIC_KEY_FALSE_INIT, \ 370 .static_call_key = &STATIC_CALL_KEY(tp_func_##_name), \ 371 .static_call_tramp = STATIC_CALL_TRAMP_ADDR(tp_func_##_name), \ 372 .iterator = &__traceiter_##_name, \ 373 .probestub = &__probestub_##_name, \ 374 .funcs = NULL, \ 375 .ext = _ext, \ 376 }; \ 377 __TRACEPOINT_ENTRY(_name); \ 378 int __traceiter_##_name(void *__data, proto) \ 379 { \ 380 struct tracepoint_func *it_func_ptr; \ 381 void *it_func; \ 382 \ 383 it_func_ptr = \ 384 rcu_dereference_raw((&__tracepoint_##_name)->funcs); \ 385 if (it_func_ptr) { \ 386 do { \ 387 it_func = READ_ONCE((it_func_ptr)->func); \ 388 __data = (it_func_ptr)->data; \ 389 ((void(*)(void *, proto))(it_func))(__data, args); \ 390 } while ((++it_func_ptr)->func); \ 391 } \ 392 return 0; \ 393 } \ 394 void __probestub_##_name(void *__data, proto) \ 395 { \ 396 } \ 397 /* \ 398 * Annotate the probestub 'CFI_NOSEAL' to stop objtool from \ 399 * requesting the kernel remove the ENDBR, because the only \ 400 * references to the function are in the __tracepoint section, \ 401 * that objtool doesn't scan. \ 402 */ \ 403 CFI_NOSEAL(__probestub_##_name); \ 404 DEFINE_STATIC_CALL(tp_func_##_name, __traceiter_##_name); \ 405 DEFINE_RUST_DO_TRACE(_name, TP_PROTO(proto), TP_ARGS(args)) 406 407 #define DEFINE_TRACE_FN(_name, _reg, _unreg, _proto, _args) \ 408 static struct tracepoint_ext __tracepoint_ext_##_name = { \ 409 .regfunc = _reg, \ 410 .unregfunc = _unreg, \ 411 .faultable = false, \ 412 }; \ 413 __DEFINE_TRACE_EXT(_name, &__tracepoint_ext_##_name, PARAMS(_proto), PARAMS(_args)); 414 415 #define DEFINE_TRACE_SYSCALL(_name, _reg, _unreg, _proto, _args) \ 416 static struct tracepoint_ext __tracepoint_ext_##_name = { \ 417 .regfunc = _reg, \ 418 .unregfunc = _unreg, \ 419 .faultable = true, \ 420 }; \ 421 __DEFINE_TRACE_EXT(_name, &__tracepoint_ext_##_name, PARAMS(_proto), PARAMS(_args)); 422 423 #define DEFINE_TRACE(_name, _proto, _args) \ 424 __DEFINE_TRACE_EXT(_name, NULL, PARAMS(_proto), PARAMS(_args)); 425 426 #define EXPORT_TRACEPOINT_SYMBOL_GPL(name) \ 427 TRACEPOINT_CHECK(name) \ 428 EXPORT_SYMBOL_GPL(__tracepoint_##name); \ 429 EXPORT_SYMBOL_GPL(__traceiter_##name); \ 430 EXPORT_STATIC_CALL_GPL(tp_func_##name) 431 #define EXPORT_TRACEPOINT_SYMBOL(name) \ 432 TRACEPOINT_CHECK(name) \ 433 EXPORT_SYMBOL(__tracepoint_##name); \ 434 EXPORT_SYMBOL(__traceiter_##name); \ 435 EXPORT_STATIC_CALL(tp_func_##name) 436 437 438 #else /* !TRACEPOINTS_ENABLED */ 439 #define __DECLARE_TRACE_COMMON(name, proto, args, data_proto) \ 440 static inline void trace_##name(proto) \ 441 { } \ 442 static inline void trace_call__##name(proto) \ 443 { } \ 444 static inline int \ 445 register_trace_##name(void (*probe)(data_proto), \ 446 void *data) \ 447 { \ 448 return -ENOSYS; \ 449 } \ 450 static inline int \ 451 unregister_trace_##name(void (*probe)(data_proto), \ 452 void *data) \ 453 { \ 454 return -ENOSYS; \ 455 } \ 456 static inline void check_trace_callback_type_##name(void (*cb)(data_proto)) \ 457 { \ 458 } \ 459 static inline bool \ 460 trace_##name##_enabled(void) \ 461 { \ 462 return false; \ 463 } 464 465 #define __DECLARE_TRACE(name, proto, args, cond, data_proto) \ 466 __DECLARE_TRACE_COMMON(name, PARAMS(proto), PARAMS(args), PARAMS(data_proto)) 467 468 #define __DECLARE_TRACE_SYSCALL(name, proto, args, data_proto) \ 469 __DECLARE_TRACE_COMMON(name, PARAMS(proto), PARAMS(args), PARAMS(data_proto)) 470 471 #define DEFINE_TRACE_FN(name, reg, unreg, proto, args) 472 #define DEFINE_TRACE_SYSCALL(name, reg, unreg, proto, args) 473 #define DEFINE_TRACE(name, proto, args) 474 #define EXPORT_TRACEPOINT_SYMBOL_GPL(name) 475 #define EXPORT_TRACEPOINT_SYMBOL(name) 476 477 #endif /* TRACEPOINTS_ENABLED */ 478 479 #ifdef CONFIG_TRACING 480 /** 481 * tracepoint_string - register constant persistent string to trace system 482 * @str - a constant persistent string that will be referenced in tracepoints 483 * 484 * If constant strings are being used in tracepoints, it is faster and 485 * more efficient to just save the pointer to the string and reference 486 * that with a printf "%s" instead of saving the string in the ring buffer 487 * and wasting space and time. 488 * 489 * The problem with the above approach is that userspace tools that read 490 * the binary output of the trace buffers do not have access to the string. 491 * Instead they just show the address of the string which is not very 492 * useful to users. 493 * 494 * With tracepoint_string(), the string will be registered to the tracing 495 * system and exported to userspace via the debugfs/tracing/printk_formats 496 * file that maps the string address to the string text. This way userspace 497 * tools that read the binary buffers have a way to map the pointers to 498 * the ASCII strings they represent. 499 * 500 * The @str used must be a constant string and persistent as it would not 501 * make sense to show a string that no longer exists. But it is still fine 502 * to be used with modules, because when modules are unloaded, if they 503 * had tracepoints, the ring buffers are cleared too. As long as the string 504 * does not change during the life of the module, it is fine to use 505 * tracepoint_string() within a module. 506 */ 507 #define tracepoint_string(str) \ 508 ({ \ 509 static const char *___tp_str __tracepoint_string = str; \ 510 ___tp_str; \ 511 }) 512 #define __tracepoint_string __used __section("__tracepoint_str") 513 #else 514 /* 515 * tracepoint_string() is used to save the string address for userspace 516 * tracing tools. When tracing isn't configured, there's no need to save 517 * anything. 518 */ 519 # define tracepoint_string(str) str 520 # define __tracepoint_string 521 #endif 522 523 #define DECLARE_TRACE(name, proto, args) \ 524 __DECLARE_TRACE(name##_tp, PARAMS(proto), PARAMS(args), \ 525 cpu_online(raw_smp_processor_id()), \ 526 PARAMS(void *__data, proto)) 527 528 #define DECLARE_TRACE_CONDITION(name, proto, args, cond) \ 529 __DECLARE_TRACE(name##_tp, PARAMS(proto), PARAMS(args), \ 530 cpu_online(raw_smp_processor_id()) && (PARAMS(cond)), \ 531 PARAMS(void *__data, proto)) 532 533 #define DECLARE_TRACE_SYSCALL(name, proto, args) \ 534 __DECLARE_TRACE_SYSCALL(name##_tp, PARAMS(proto), PARAMS(args), \ 535 PARAMS(void *__data, proto)) 536 537 #define DECLARE_TRACE_EVENT(name, proto, args) \ 538 __DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), \ 539 cpu_online(raw_smp_processor_id()), \ 540 PARAMS(void *__data, proto)) 541 542 #define DECLARE_TRACE_EVENT_CONDITION(name, proto, args, cond) \ 543 __DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), \ 544 cpu_online(raw_smp_processor_id()) && (PARAMS(cond)), \ 545 PARAMS(void *__data, proto)) 546 547 #define DECLARE_TRACE_EVENT_SYSCALL(name, proto, args) \ 548 __DECLARE_TRACE_SYSCALL(name, PARAMS(proto), PARAMS(args), \ 549 PARAMS(void *__data, proto)) 550 551 #define TRACE_EVENT_FLAGS(event, flag) 552 553 #define TRACE_EVENT_PERF_PERM(event, expr...) 554 555 #endif /* DECLARE_TRACE */ 556 557 #ifndef TRACE_EVENT 558 /* 559 * For use with the TRACE_EVENT macro: 560 * 561 * We define a tracepoint, its arguments, its printk format 562 * and its 'fast binary record' layout. 563 * 564 * Firstly, name your tracepoint via TRACE_EVENT(name : the 565 * 'subsystem_event' notation is fine. 566 * 567 * Think about this whole construct as the 568 * 'trace_sched_switch() function' from now on. 569 * 570 * 571 * TRACE_EVENT(sched_switch, 572 * 573 * * 574 * * A function has a regular function arguments 575 * * prototype, declare it via TP_PROTO(): 576 * * 577 * 578 * TP_PROTO(struct rq *rq, struct task_struct *prev, 579 * struct task_struct *next), 580 * 581 * * 582 * * Define the call signature of the 'function'. 583 * * (Design sidenote: we use this instead of a 584 * * TP_PROTO1/TP_PROTO2/TP_PROTO3 ugliness.) 585 * * 586 * 587 * TP_ARGS(rq, prev, next), 588 * 589 * * 590 * * Fast binary tracing: define the trace record via 591 * * TP_STRUCT__entry(). You can think about it like a 592 * * regular C structure local variable definition. 593 * * 594 * * This is how the trace record is structured and will 595 * * be saved into the ring buffer. These are the fields 596 * * that will be exposed to user-space in 597 * * /sys/kernel/tracing/events/<*>/format. 598 * * 599 * * The declared 'local variable' is called '__entry' 600 * * 601 * * __field(pid_t, prev_pid) is equivalent to a standard declaration: 602 * * 603 * * pid_t prev_pid; 604 * * 605 * * __array(char, prev_comm, TASK_COMM_LEN) is equivalent to: 606 * * 607 * * char prev_comm[TASK_COMM_LEN]; 608 * * 609 * 610 * TP_STRUCT__entry( 611 * __array( char, prev_comm, TASK_COMM_LEN ) 612 * __field( pid_t, prev_pid ) 613 * __field( int, prev_prio ) 614 * __array( char, next_comm, TASK_COMM_LEN ) 615 * __field( pid_t, next_pid ) 616 * __field( int, next_prio ) 617 * ), 618 * 619 * * 620 * * Assign the entry into the trace record, by embedding 621 * * a full C statement block into TP_fast_assign(). You 622 * * can refer to the trace record as '__entry' - 623 * * otherwise you can put arbitrary C code in here. 624 * * 625 * * Note: this C code will execute every time a trace event 626 * * happens, on an active tracepoint. 627 * * 628 * 629 * TP_fast_assign( 630 * memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN); 631 * __entry->prev_pid = prev->pid; 632 * __entry->prev_prio = prev->prio; 633 * memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN); 634 * __entry->next_pid = next->pid; 635 * __entry->next_prio = next->prio; 636 * ), 637 * 638 * * 639 * * Formatted output of a trace record via TP_printk(). 640 * * This is how the tracepoint will appear under ftrace 641 * * plugins that make use of this tracepoint. 642 * * 643 * * (raw-binary tracing wont actually perform this step.) 644 * * 645 * 646 * TP_printk("task %s:%d [%d] ==> %s:%d [%d]", 647 * __entry->prev_comm, __entry->prev_pid, __entry->prev_prio, 648 * __entry->next_comm, __entry->next_pid, __entry->next_prio), 649 * 650 * ); 651 * 652 * This macro construct is thus used for the regular printk format 653 * tracing setup, it is used to construct a function pointer based 654 * tracepoint callback (this is used by programmatic plugins and 655 * can also by used by generic instrumentation like SystemTap), and 656 * it is also used to expose a structured trace record in 657 * /sys/kernel/tracing/events/. 658 * 659 * A set of (un)registration functions can be passed to the variant 660 * TRACE_EVENT_FN to perform any (un)registration work. 661 */ 662 663 #define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) 664 #define DEFINE_EVENT(template, name, proto, args) \ 665 DECLARE_TRACE_EVENT(name, PARAMS(proto), PARAMS(args)) 666 #define DEFINE_EVENT_FN(template, name, proto, args, reg, unreg)\ 667 DECLARE_TRACE_EVENT(name, PARAMS(proto), PARAMS(args)) 668 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ 669 DECLARE_TRACE_EVENT(name, PARAMS(proto), PARAMS(args)) 670 #define DEFINE_EVENT_CONDITION(template, name, proto, \ 671 args, cond) \ 672 DECLARE_TRACE_EVENT_CONDITION(name, PARAMS(proto), \ 673 PARAMS(args), PARAMS(cond)) 674 675 #define TRACE_EVENT(name, proto, args, struct, assign, print) \ 676 DECLARE_TRACE_EVENT(name, PARAMS(proto), PARAMS(args)) 677 #define TRACE_EVENT_FN(name, proto, args, struct, \ 678 assign, print, reg, unreg) \ 679 DECLARE_TRACE_EVENT(name, PARAMS(proto), PARAMS(args)) 680 #define TRACE_EVENT_FN_COND(name, proto, args, cond, struct, \ 681 assign, print, reg, unreg) \ 682 DECLARE_TRACE_EVENT_CONDITION(name, PARAMS(proto), \ 683 PARAMS(args), PARAMS(cond)) 684 #define TRACE_EVENT_CONDITION(name, proto, args, cond, \ 685 struct, assign, print) \ 686 DECLARE_TRACE_EVENT_CONDITION(name, PARAMS(proto), \ 687 PARAMS(args), PARAMS(cond)) 688 #define TRACE_EVENT_SYSCALL(name, proto, args, struct, assign, \ 689 print, reg, unreg) \ 690 DECLARE_TRACE_EVENT_SYSCALL(name, PARAMS(proto), PARAMS(args)) 691 692 #define TRACE_EVENT_FLAGS(event, flag) 693 694 #define TRACE_EVENT_PERF_PERM(event, expr...) 695 696 #define DECLARE_EVENT_NOP(name, proto, args) \ 697 static inline void trace_##name(proto) \ 698 { } \ 699 static inline bool trace_##name##_enabled(void) \ 700 { \ 701 return false; \ 702 } 703 704 #define TRACE_EVENT_NOP(name, proto, args, struct, assign, print) \ 705 DECLARE_EVENT_NOP(name, PARAMS(proto), PARAMS(args)) 706 707 #define DECLARE_EVENT_CLASS_NOP(name, proto, args, tstruct, assign, print) 708 #define DEFINE_EVENT_NOP(template, name, proto, args) \ 709 DECLARE_EVENT_NOP(name, PARAMS(proto), PARAMS(args)) 710 711 #endif /* ifdef TRACE_EVENT (see note above) */ 712