trace_events.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_TRACE_EVENT_H
  3. #define _LINUX_TRACE_EVENT_H
  4. #include <linux/ring_buffer.h>
  5. #include <linux/trace_seq.h>
  6. #include <linux/percpu.h>
  7. #include <linux/hardirq.h>
  8. #include <linux/perf_event.h>
  9. #include <linux/tracepoint.h>
  10. struct trace_array;
  11. struct array_buffer;
  12. struct tracer;
  13. struct dentry;
  14. struct bpf_prog;
  15. const char *trace_print_flags_seq(struct trace_seq *p, const char *delim,
  16. unsigned long flags,
  17. const struct trace_print_flags *flag_array);
  18. const char *trace_print_symbols_seq(struct trace_seq *p, unsigned long val,
  19. const struct trace_print_flags *symbol_array);
  20. #if BITS_PER_LONG == 32
  21. const char *trace_print_flags_seq_u64(struct trace_seq *p, const char *delim,
  22. unsigned long long flags,
  23. const struct trace_print_flags_u64 *flag_array);
  24. const char *trace_print_symbols_seq_u64(struct trace_seq *p,
  25. unsigned long long val,
  26. const struct trace_print_flags_u64
  27. *symbol_array);
  28. #endif
  29. const char *trace_print_bitmask_seq(struct trace_seq *p, void *bitmask_ptr,
  30. unsigned int bitmask_size);
  31. const char *trace_print_hex_seq(struct trace_seq *p,
  32. const unsigned char *buf, int len,
  33. bool concatenate);
  34. const char *trace_print_array_seq(struct trace_seq *p,
  35. const void *buf, int count,
  36. size_t el_size);
  37. const char *
  38. trace_print_hex_dump_seq(struct trace_seq *p, const char *prefix_str,
  39. int prefix_type, int rowsize, int groupsize,
  40. const void *buf, size_t len, bool ascii);
  41. struct trace_iterator;
  42. struct trace_event;
  43. int trace_raw_output_prep(struct trace_iterator *iter,
  44. struct trace_event *event);
  45. /*
  46. * The trace entry - the most basic unit of tracing. This is what
  47. * is printed in the end as a single line in the trace output, such as:
  48. *
  49. * bash-15816 [01] 235.197585: idle_cpu <- irq_enter
  50. */
  51. struct trace_entry {
  52. unsigned short type;
  53. unsigned char flags;
  54. unsigned char preempt_count;
  55. int pid;
  56. };
  57. #define TRACE_EVENT_TYPE_MAX \
  58. ((1 << (sizeof(((struct trace_entry *)0)->type) * 8)) - 1)
  59. /*
  60. * Trace iterator - used by printout routines who present trace
  61. * results to users and which routines might sleep, etc:
  62. */
  63. struct trace_iterator {
  64. struct trace_array *tr;
  65. struct tracer *trace;
  66. struct array_buffer *array_buffer;
  67. void *private;
  68. int cpu_file;
  69. struct mutex mutex;
  70. struct ring_buffer_iter **buffer_iter;
  71. unsigned long iter_flags;
  72. void *temp; /* temp holder */
  73. unsigned int temp_size;
  74. /* trace_seq for __print_flags() and __print_symbolic() etc. */
  75. struct trace_seq tmp_seq;
  76. cpumask_var_t started;
  77. /* it's true when current open file is snapshot */
  78. bool snapshot;
  79. /* The below is zeroed out in pipe_read */
  80. struct trace_seq seq;
  81. struct trace_entry *ent;
  82. unsigned long lost_events;
  83. int leftover;
  84. int ent_size;
  85. int cpu;
  86. u64 ts;
  87. loff_t pos;
  88. long idx;
  89. /* All new field here will be zeroed out in pipe_read */
  90. };
  91. enum trace_iter_flags {
  92. TRACE_FILE_LAT_FMT = 1,
  93. TRACE_FILE_ANNOTATE = 2,
  94. TRACE_FILE_TIME_IN_NS = 4,
  95. };
  96. typedef enum print_line_t (*trace_print_func)(struct trace_iterator *iter,
  97. int flags, struct trace_event *event);
  98. struct trace_event_functions {
  99. trace_print_func trace;
  100. trace_print_func raw;
  101. trace_print_func hex;
  102. trace_print_func binary;
  103. };
  104. struct trace_event {
  105. struct hlist_node node;
  106. struct list_head list;
  107. int type;
  108. struct trace_event_functions *funcs;
  109. };
  110. extern int register_trace_event(struct trace_event *event);
  111. extern int unregister_trace_event(struct trace_event *event);
  112. /* Return values for print_line callback */
  113. enum print_line_t {
  114. TRACE_TYPE_PARTIAL_LINE = 0, /* Retry after flushing the seq */
  115. TRACE_TYPE_HANDLED = 1,
  116. TRACE_TYPE_UNHANDLED = 2, /* Relay to other output functions */
  117. TRACE_TYPE_NO_CONSUME = 3 /* Handled but ask to not consume */
  118. };
  119. enum print_line_t trace_handle_return(struct trace_seq *s);
  120. void tracing_generic_entry_update(struct trace_entry *entry,
  121. unsigned short type,
  122. unsigned long flags,
  123. int pc);
  124. struct trace_event_file;
  125. struct ring_buffer_event *
  126. trace_event_buffer_lock_reserve(struct trace_buffer **current_buffer,
  127. struct trace_event_file *trace_file,
  128. int type, unsigned long len,
  129. unsigned long flags, int pc);
  130. #define TRACE_RECORD_CMDLINE BIT(0)
  131. #define TRACE_RECORD_TGID BIT(1)
  132. void tracing_record_taskinfo(struct task_struct *task, int flags);
  133. void tracing_record_taskinfo_sched_switch(struct task_struct *prev,
  134. struct task_struct *next, int flags);
  135. void tracing_record_cmdline(struct task_struct *task);
  136. void tracing_record_tgid(struct task_struct *task);
  137. int trace_output_call(struct trace_iterator *iter, char *name, char *fmt, ...);
  138. struct event_filter;
  139. enum trace_reg {
  140. TRACE_REG_REGISTER,
  141. TRACE_REG_UNREGISTER,
  142. #ifdef CONFIG_PERF_EVENTS
  143. TRACE_REG_PERF_REGISTER,
  144. TRACE_REG_PERF_UNREGISTER,
  145. TRACE_REG_PERF_OPEN,
  146. TRACE_REG_PERF_CLOSE,
  147. /*
  148. * These (ADD/DEL) use a 'boolean' return value, where 1 (true) means a
  149. * custom action was taken and the default action is not to be
  150. * performed.
  151. */
  152. TRACE_REG_PERF_ADD,
  153. TRACE_REG_PERF_DEL,
  154. #endif
  155. };
  156. struct trace_event_call;
  157. #define TRACE_FUNCTION_TYPE ((const char *)~0UL)
  158. struct trace_event_fields {
  159. const char *type;
  160. union {
  161. struct {
  162. const char *name;
  163. const int size;
  164. const int align;
  165. const int is_signed;
  166. const int filter_type;
  167. };
  168. int (*define_fields)(struct trace_event_call *);
  169. };
  170. };
  171. struct trace_event_class {
  172. const char *system;
  173. void *probe;
  174. #ifdef CONFIG_PERF_EVENTS
  175. void *perf_probe;
  176. #endif
  177. int (*reg)(struct trace_event_call *event,
  178. enum trace_reg type, void *data);
  179. struct trace_event_fields *fields_array;
  180. struct list_head *(*get_fields)(struct trace_event_call *);
  181. struct list_head fields;
  182. int (*raw_init)(struct trace_event_call *);
  183. };
  184. extern int trace_event_reg(struct trace_event_call *event,
  185. enum trace_reg type, void *data);
  186. struct trace_event_buffer {
  187. struct trace_buffer *buffer;
  188. struct ring_buffer_event *event;
  189. struct trace_event_file *trace_file;
  190. void *entry;
  191. unsigned long flags;
  192. int pc;
  193. struct pt_regs *regs;
  194. };
  195. void *trace_event_buffer_reserve(struct trace_event_buffer *fbuffer,
  196. struct trace_event_file *trace_file,
  197. unsigned long len);
  198. void trace_event_buffer_commit(struct trace_event_buffer *fbuffer);
  199. enum {
  200. TRACE_EVENT_FL_FILTERED_BIT,
  201. TRACE_EVENT_FL_CAP_ANY_BIT,
  202. TRACE_EVENT_FL_NO_SET_FILTER_BIT,
  203. TRACE_EVENT_FL_IGNORE_ENABLE_BIT,
  204. TRACE_EVENT_FL_TRACEPOINT_BIT,
  205. TRACE_EVENT_FL_KPROBE_BIT,
  206. TRACE_EVENT_FL_UPROBE_BIT,
  207. };
  208. /*
  209. * Event flags:
  210. * FILTERED - The event has a filter attached
  211. * CAP_ANY - Any user can enable for perf
  212. * NO_SET_FILTER - Set when filter has error and is to be ignored
  213. * IGNORE_ENABLE - For trace internal events, do not enable with debugfs file
  214. * TRACEPOINT - Event is a tracepoint
  215. * KPROBE - Event is a kprobe
  216. * UPROBE - Event is a uprobe
  217. */
  218. enum {
  219. TRACE_EVENT_FL_FILTERED = (1 << TRACE_EVENT_FL_FILTERED_BIT),
  220. TRACE_EVENT_FL_CAP_ANY = (1 << TRACE_EVENT_FL_CAP_ANY_BIT),
  221. TRACE_EVENT_FL_NO_SET_FILTER = (1 << TRACE_EVENT_FL_NO_SET_FILTER_BIT),
  222. TRACE_EVENT_FL_IGNORE_ENABLE = (1 << TRACE_EVENT_FL_IGNORE_ENABLE_BIT),
  223. TRACE_EVENT_FL_TRACEPOINT = (1 << TRACE_EVENT_FL_TRACEPOINT_BIT),
  224. TRACE_EVENT_FL_KPROBE = (1 << TRACE_EVENT_FL_KPROBE_BIT),
  225. TRACE_EVENT_FL_UPROBE = (1 << TRACE_EVENT_FL_UPROBE_BIT),
  226. };
  227. #define TRACE_EVENT_FL_UKPROBE (TRACE_EVENT_FL_KPROBE | TRACE_EVENT_FL_UPROBE)
  228. struct trace_event_call {
  229. struct list_head list;
  230. struct trace_event_class *class;
  231. union {
  232. char *name;
  233. /* Set TRACE_EVENT_FL_TRACEPOINT flag when using "tp" */
  234. struct tracepoint *tp;
  235. };
  236. struct trace_event event;
  237. char *print_fmt;
  238. struct event_filter *filter;
  239. void *mod;
  240. void *data;
  241. /*
  242. * bit 0: filter_active
  243. * bit 1: allow trace by non root (cap any)
  244. * bit 2: failed to apply filter
  245. * bit 3: trace internal event (do not enable)
  246. * bit 4: Event was enabled by module
  247. * bit 5: use call filter rather than file filter
  248. * bit 6: Event is a tracepoint
  249. */
  250. int flags; /* static flags of different events */
  251. #ifdef CONFIG_PERF_EVENTS
  252. int perf_refcount;
  253. struct hlist_head __percpu *perf_events;
  254. struct bpf_prog_array __rcu *prog_array;
  255. int (*perf_perm)(struct trace_event_call *,
  256. struct perf_event *);
  257. #endif
  258. };
  259. #ifdef CONFIG_PERF_EVENTS
  260. static inline bool bpf_prog_array_valid(struct trace_event_call *call)
  261. {
  262. /*
  263. * This inline function checks whether call->prog_array
  264. * is valid or not. The function is called in various places,
  265. * outside rcu_read_lock/unlock, as a heuristic to speed up execution.
  266. *
  267. * If this function returns true, and later call->prog_array
  268. * becomes false inside rcu_read_lock/unlock region,
  269. * we bail out then. If this function return false,
  270. * there is a risk that we might miss a few events if the checking
  271. * were delayed until inside rcu_read_lock/unlock region and
  272. * call->prog_array happened to become non-NULL then.
  273. *
  274. * Here, READ_ONCE() is used instead of rcu_access_pointer().
  275. * rcu_access_pointer() requires the actual definition of
  276. * "struct bpf_prog_array" while READ_ONCE() only needs
  277. * a declaration of the same type.
  278. */
  279. return !!READ_ONCE(call->prog_array);
  280. }
  281. #endif
  282. static inline const char *
  283. trace_event_name(struct trace_event_call *call)
  284. {
  285. if (call->flags & TRACE_EVENT_FL_TRACEPOINT)
  286. return call->tp ? call->tp->name : NULL;
  287. else
  288. return call->name;
  289. }
  290. static inline struct list_head *
  291. trace_get_fields(struct trace_event_call *event_call)
  292. {
  293. if (!event_call->class->get_fields)
  294. return &event_call->class->fields;
  295. return event_call->class->get_fields(event_call);
  296. }
  297. struct trace_array;
  298. struct trace_subsystem_dir;
  299. enum {
  300. EVENT_FILE_FL_ENABLED_BIT,
  301. EVENT_FILE_FL_RECORDED_CMD_BIT,
  302. EVENT_FILE_FL_RECORDED_TGID_BIT,
  303. EVENT_FILE_FL_FILTERED_BIT,
  304. EVENT_FILE_FL_NO_SET_FILTER_BIT,
  305. EVENT_FILE_FL_SOFT_MODE_BIT,
  306. EVENT_FILE_FL_SOFT_DISABLED_BIT,
  307. EVENT_FILE_FL_TRIGGER_MODE_BIT,
  308. EVENT_FILE_FL_TRIGGER_COND_BIT,
  309. EVENT_FILE_FL_PID_FILTER_BIT,
  310. EVENT_FILE_FL_WAS_ENABLED_BIT,
  311. };
  312. extern struct trace_event_file *trace_get_event_file(const char *instance,
  313. const char *system,
  314. const char *event);
  315. extern void trace_put_event_file(struct trace_event_file *file);
  316. #define MAX_DYNEVENT_CMD_LEN (2048)
  317. enum dynevent_type {
  318. DYNEVENT_TYPE_SYNTH = 1,
  319. DYNEVENT_TYPE_KPROBE,
  320. DYNEVENT_TYPE_NONE,
  321. };
  322. struct dynevent_cmd;
  323. typedef int (*dynevent_create_fn_t)(struct dynevent_cmd *cmd);
  324. struct dynevent_cmd {
  325. struct seq_buf seq;
  326. const char *event_name;
  327. unsigned int n_fields;
  328. enum dynevent_type type;
  329. dynevent_create_fn_t run_command;
  330. void *private_data;
  331. };
  332. extern int dynevent_create(struct dynevent_cmd *cmd);
  333. extern int synth_event_delete(const char *name);
  334. extern void synth_event_cmd_init(struct dynevent_cmd *cmd,
  335. char *buf, int maxlen);
  336. extern int __synth_event_gen_cmd_start(struct dynevent_cmd *cmd,
  337. const char *name,
  338. struct module *mod, ...);
  339. #define synth_event_gen_cmd_start(cmd, name, mod, ...) \
  340. __synth_event_gen_cmd_start(cmd, name, mod, ## __VA_ARGS__, NULL)
  341. struct synth_field_desc {
  342. const char *type;
  343. const char *name;
  344. };
  345. extern int synth_event_gen_cmd_array_start(struct dynevent_cmd *cmd,
  346. const char *name,
  347. struct module *mod,
  348. struct synth_field_desc *fields,
  349. unsigned int n_fields);
  350. extern int synth_event_create(const char *name,
  351. struct synth_field_desc *fields,
  352. unsigned int n_fields, struct module *mod);
  353. extern int synth_event_add_field(struct dynevent_cmd *cmd,
  354. const char *type,
  355. const char *name);
  356. extern int synth_event_add_field_str(struct dynevent_cmd *cmd,
  357. const char *type_name);
  358. extern int synth_event_add_fields(struct dynevent_cmd *cmd,
  359. struct synth_field_desc *fields,
  360. unsigned int n_fields);
  361. #define synth_event_gen_cmd_end(cmd) \
  362. dynevent_create(cmd)
  363. struct synth_event;
  364. struct synth_event_trace_state {
  365. struct trace_event_buffer fbuffer;
  366. struct synth_trace_event *entry;
  367. struct trace_buffer *buffer;
  368. struct synth_event *event;
  369. unsigned int cur_field;
  370. unsigned int n_u64;
  371. bool disabled;
  372. bool add_next;
  373. bool add_name;
  374. };
  375. extern int synth_event_trace(struct trace_event_file *file,
  376. unsigned int n_vals, ...);
  377. extern int synth_event_trace_array(struct trace_event_file *file, u64 *vals,
  378. unsigned int n_vals);
  379. extern int synth_event_trace_start(struct trace_event_file *file,
  380. struct synth_event_trace_state *trace_state);
  381. extern int synth_event_add_next_val(u64 val,
  382. struct synth_event_trace_state *trace_state);
  383. extern int synth_event_add_val(const char *field_name, u64 val,
  384. struct synth_event_trace_state *trace_state);
  385. extern int synth_event_trace_end(struct synth_event_trace_state *trace_state);
  386. extern int kprobe_event_delete(const char *name);
  387. extern void kprobe_event_cmd_init(struct dynevent_cmd *cmd,
  388. char *buf, int maxlen);
  389. #define kprobe_event_gen_cmd_start(cmd, name, loc, ...) \
  390. __kprobe_event_gen_cmd_start(cmd, false, name, loc, ## __VA_ARGS__, NULL)
  391. #define kretprobe_event_gen_cmd_start(cmd, name, loc, ...) \
  392. __kprobe_event_gen_cmd_start(cmd, true, name, loc, ## __VA_ARGS__, NULL)
  393. extern int __kprobe_event_gen_cmd_start(struct dynevent_cmd *cmd,
  394. bool kretprobe,
  395. const char *name,
  396. const char *loc, ...);
  397. #define kprobe_event_add_fields(cmd, ...) \
  398. __kprobe_event_add_fields(cmd, ## __VA_ARGS__, NULL)
  399. #define kprobe_event_add_field(cmd, field) \
  400. __kprobe_event_add_fields(cmd, field, NULL)
  401. extern int __kprobe_event_add_fields(struct dynevent_cmd *cmd, ...);
  402. #define kprobe_event_gen_cmd_end(cmd) \
  403. dynevent_create(cmd)
  404. #define kretprobe_event_gen_cmd_end(cmd) \
  405. dynevent_create(cmd)
  406. /*
  407. * Event file flags:
  408. * ENABLED - The event is enabled
  409. * RECORDED_CMD - The comms should be recorded at sched_switch
  410. * RECORDED_TGID - The tgids should be recorded at sched_switch
  411. * FILTERED - The event has a filter attached
  412. * NO_SET_FILTER - Set when filter has error and is to be ignored
  413. * SOFT_MODE - The event is enabled/disabled by SOFT_DISABLED
  414. * SOFT_DISABLED - When set, do not trace the event (even though its
  415. * tracepoint may be enabled)
  416. * TRIGGER_MODE - When set, invoke the triggers associated with the event
  417. * TRIGGER_COND - When set, one or more triggers has an associated filter
  418. * PID_FILTER - When set, the event is filtered based on pid
  419. * WAS_ENABLED - Set when enabled to know to clear trace on module removal
  420. */
  421. enum {
  422. EVENT_FILE_FL_ENABLED = (1 << EVENT_FILE_FL_ENABLED_BIT),
  423. EVENT_FILE_FL_RECORDED_CMD = (1 << EVENT_FILE_FL_RECORDED_CMD_BIT),
  424. EVENT_FILE_FL_RECORDED_TGID = (1 << EVENT_FILE_FL_RECORDED_TGID_BIT),
  425. EVENT_FILE_FL_FILTERED = (1 << EVENT_FILE_FL_FILTERED_BIT),
  426. EVENT_FILE_FL_NO_SET_FILTER = (1 << EVENT_FILE_FL_NO_SET_FILTER_BIT),
  427. EVENT_FILE_FL_SOFT_MODE = (1 << EVENT_FILE_FL_SOFT_MODE_BIT),
  428. EVENT_FILE_FL_SOFT_DISABLED = (1 << EVENT_FILE_FL_SOFT_DISABLED_BIT),
  429. EVENT_FILE_FL_TRIGGER_MODE = (1 << EVENT_FILE_FL_TRIGGER_MODE_BIT),
  430. EVENT_FILE_FL_TRIGGER_COND = (1 << EVENT_FILE_FL_TRIGGER_COND_BIT),
  431. EVENT_FILE_FL_PID_FILTER = (1 << EVENT_FILE_FL_PID_FILTER_BIT),
  432. EVENT_FILE_FL_WAS_ENABLED = (1 << EVENT_FILE_FL_WAS_ENABLED_BIT),
  433. };
  434. struct trace_event_file {
  435. struct list_head list;
  436. struct trace_event_call *event_call;
  437. struct event_filter __rcu *filter;
  438. struct dentry *dir;
  439. struct trace_array *tr;
  440. struct trace_subsystem_dir *system;
  441. struct list_head triggers;
  442. /*
  443. * 32 bit flags:
  444. * bit 0: enabled
  445. * bit 1: enabled cmd record
  446. * bit 2: enable/disable with the soft disable bit
  447. * bit 3: soft disabled
  448. * bit 4: trigger enabled
  449. *
  450. * Note: The bits must be set atomically to prevent races
  451. * from other writers. Reads of flags do not need to be in
  452. * sync as they occur in critical sections. But the way flags
  453. * is currently used, these changes do not affect the code
  454. * except that when a change is made, it may have a slight
  455. * delay in propagating the changes to other CPUs due to
  456. * caching and such. Which is mostly OK ;-)
  457. */
  458. unsigned long flags;
  459. atomic_t sm_ref; /* soft-mode reference counter */
  460. atomic_t tm_ref; /* trigger-mode reference counter */
  461. };
  462. #define __TRACE_EVENT_FLAGS(name, value) \
  463. static int __init trace_init_flags_##name(void) \
  464. { \
  465. event_##name.flags |= value; \
  466. return 0; \
  467. } \
  468. early_initcall(trace_init_flags_##name);
  469. #define __TRACE_EVENT_PERF_PERM(name, expr...) \
  470. static int perf_perm_##name(struct trace_event_call *tp_event, \
  471. struct perf_event *p_event) \
  472. { \
  473. return ({ expr; }); \
  474. } \
  475. static int __init trace_init_perf_perm_##name(void) \
  476. { \
  477. event_##name.perf_perm = &perf_perm_##name; \
  478. return 0; \
  479. } \
  480. early_initcall(trace_init_perf_perm_##name);
  481. #define PERF_MAX_TRACE_SIZE 2048
  482. #define MAX_FILTER_STR_VAL 256U /* Should handle KSYM_SYMBOL_LEN */
  483. enum event_trigger_type {
  484. ETT_NONE = (0),
  485. ETT_TRACE_ONOFF = (1 << 0),
  486. ETT_SNAPSHOT = (1 << 1),
  487. ETT_STACKTRACE = (1 << 2),
  488. ETT_EVENT_ENABLE = (1 << 3),
  489. ETT_EVENT_HIST = (1 << 4),
  490. ETT_HIST_ENABLE = (1 << 5),
  491. };
  492. extern int filter_match_preds(struct event_filter *filter, void *rec);
  493. extern enum event_trigger_type
  494. event_triggers_call(struct trace_event_file *file, void *rec,
  495. struct ring_buffer_event *event);
  496. extern void
  497. event_triggers_post_call(struct trace_event_file *file,
  498. enum event_trigger_type tt);
  499. bool trace_event_ignore_this_pid(struct trace_event_file *trace_file);
  500. /**
  501. * trace_trigger_soft_disabled - do triggers and test if soft disabled
  502. * @file: The file pointer of the event to test
  503. *
  504. * If any triggers without filters are attached to this event, they
  505. * will be called here. If the event is soft disabled and has no
  506. * triggers that require testing the fields, it will return true,
  507. * otherwise false.
  508. */
  509. static inline bool
  510. trace_trigger_soft_disabled(struct trace_event_file *file)
  511. {
  512. unsigned long eflags = file->flags;
  513. if (!(eflags & EVENT_FILE_FL_TRIGGER_COND)) {
  514. if (eflags & EVENT_FILE_FL_TRIGGER_MODE)
  515. event_triggers_call(file, NULL, NULL);
  516. if (eflags & EVENT_FILE_FL_SOFT_DISABLED)
  517. return true;
  518. if (eflags & EVENT_FILE_FL_PID_FILTER)
  519. return trace_event_ignore_this_pid(file);
  520. }
  521. return false;
  522. }
  523. #ifdef CONFIG_BPF_EVENTS
  524. unsigned int trace_call_bpf(struct trace_event_call *call, void *ctx);
  525. int perf_event_attach_bpf_prog(struct perf_event *event, struct bpf_prog *prog);
  526. void perf_event_detach_bpf_prog(struct perf_event *event);
  527. int perf_event_query_prog_array(struct perf_event *event, void __user *info);
  528. int bpf_probe_register(struct bpf_raw_event_map *btp, struct bpf_prog *prog);
  529. int bpf_probe_unregister(struct bpf_raw_event_map *btp, struct bpf_prog *prog);
  530. struct bpf_raw_event_map *bpf_get_raw_tracepoint(const char *name);
  531. void bpf_put_raw_tracepoint(struct bpf_raw_event_map *btp);
  532. int bpf_get_perf_event_info(const struct perf_event *event, u32 *prog_id,
  533. u32 *fd_type, const char **buf,
  534. u64 *probe_offset, u64 *probe_addr);
  535. #else
  536. static inline unsigned int trace_call_bpf(struct trace_event_call *call, void *ctx)
  537. {
  538. return 1;
  539. }
  540. static inline int
  541. perf_event_attach_bpf_prog(struct perf_event *event, struct bpf_prog *prog)
  542. {
  543. return -EOPNOTSUPP;
  544. }
  545. static inline void perf_event_detach_bpf_prog(struct perf_event *event) { }
  546. static inline int
  547. perf_event_query_prog_array(struct perf_event *event, void __user *info)
  548. {
  549. return -EOPNOTSUPP;
  550. }
  551. static inline int bpf_probe_register(struct bpf_raw_event_map *btp, struct bpf_prog *p)
  552. {
  553. return -EOPNOTSUPP;
  554. }
  555. static inline int bpf_probe_unregister(struct bpf_raw_event_map *btp, struct bpf_prog *p)
  556. {
  557. return -EOPNOTSUPP;
  558. }
  559. static inline struct bpf_raw_event_map *bpf_get_raw_tracepoint(const char *name)
  560. {
  561. return NULL;
  562. }
  563. static inline void bpf_put_raw_tracepoint(struct bpf_raw_event_map *btp)
  564. {
  565. }
  566. static inline int bpf_get_perf_event_info(const struct perf_event *event,
  567. u32 *prog_id, u32 *fd_type,
  568. const char **buf, u64 *probe_offset,
  569. u64 *probe_addr)
  570. {
  571. return -EOPNOTSUPP;
  572. }
  573. #endif
  574. enum {
  575. FILTER_OTHER = 0,
  576. FILTER_STATIC_STRING,
  577. FILTER_DYN_STRING,
  578. FILTER_PTR_STRING,
  579. FILTER_TRACE_FN,
  580. FILTER_COMM,
  581. FILTER_CPU,
  582. };
  583. extern int trace_event_raw_init(struct trace_event_call *call);
  584. extern int trace_define_field(struct trace_event_call *call, const char *type,
  585. const char *name, int offset, int size,
  586. int is_signed, int filter_type);
  587. extern int trace_add_event_call(struct trace_event_call *call);
  588. extern int trace_remove_event_call(struct trace_event_call *call);
  589. extern int trace_event_get_offsets(struct trace_event_call *call);
  590. #define is_signed_type(type) (((type)(-1)) < (type)1)
  591. int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set);
  592. int trace_set_clr_event(const char *system, const char *event, int set);
  593. int trace_array_set_clr_event(struct trace_array *tr, const char *system,
  594. const char *event, bool enable);
  595. /*
  596. * The double __builtin_constant_p is because gcc will give us an error
  597. * if we try to allocate the static variable to fmt if it is not a
  598. * constant. Even with the outer if statement optimizing out.
  599. */
  600. #define event_trace_printk(ip, fmt, args...) \
  601. do { \
  602. __trace_printk_check_format(fmt, ##args); \
  603. tracing_record_cmdline(current); \
  604. if (__builtin_constant_p(fmt)) { \
  605. static const char *trace_printk_fmt \
  606. __section("__trace_printk_fmt") = \
  607. __builtin_constant_p(fmt) ? fmt : NULL; \
  608. \
  609. __trace_bprintk(ip, trace_printk_fmt, ##args); \
  610. } else \
  611. __trace_printk(ip, fmt, ##args); \
  612. } while (0)
  613. #ifdef CONFIG_PERF_EVENTS
  614. struct perf_event;
  615. DECLARE_PER_CPU(struct pt_regs, perf_trace_regs);
  616. DECLARE_PER_CPU(int, bpf_kprobe_override);
  617. extern int perf_trace_init(struct perf_event *event);
  618. extern void perf_trace_destroy(struct perf_event *event);
  619. extern int perf_trace_add(struct perf_event *event, int flags);
  620. extern void perf_trace_del(struct perf_event *event, int flags);
  621. #ifdef CONFIG_KPROBE_EVENTS
  622. extern int perf_kprobe_init(struct perf_event *event, bool is_retprobe);
  623. extern void perf_kprobe_destroy(struct perf_event *event);
  624. extern int bpf_get_kprobe_info(const struct perf_event *event,
  625. u32 *fd_type, const char **symbol,
  626. u64 *probe_offset, u64 *probe_addr,
  627. bool perf_type_tracepoint);
  628. #endif
  629. #ifdef CONFIG_UPROBE_EVENTS
  630. extern int perf_uprobe_init(struct perf_event *event,
  631. unsigned long ref_ctr_offset, bool is_retprobe);
  632. extern void perf_uprobe_destroy(struct perf_event *event);
  633. extern int bpf_get_uprobe_info(const struct perf_event *event,
  634. u32 *fd_type, const char **filename,
  635. u64 *probe_offset, bool perf_type_tracepoint);
  636. #endif
  637. extern int ftrace_profile_set_filter(struct perf_event *event, int event_id,
  638. char *filter_str);
  639. extern void ftrace_profile_free_filter(struct perf_event *event);
  640. void perf_trace_buf_update(void *record, u16 type);
  641. void *perf_trace_buf_alloc(int size, struct pt_regs **regs, int *rctxp);
  642. void bpf_trace_run1(struct bpf_prog *prog, u64 arg1);
  643. void bpf_trace_run2(struct bpf_prog *prog, u64 arg1, u64 arg2);
  644. void bpf_trace_run3(struct bpf_prog *prog, u64 arg1, u64 arg2,
  645. u64 arg3);
  646. void bpf_trace_run4(struct bpf_prog *prog, u64 arg1, u64 arg2,
  647. u64 arg3, u64 arg4);
  648. void bpf_trace_run5(struct bpf_prog *prog, u64 arg1, u64 arg2,
  649. u64 arg3, u64 arg4, u64 arg5);
  650. void bpf_trace_run6(struct bpf_prog *prog, u64 arg1, u64 arg2,
  651. u64 arg3, u64 arg4, u64 arg5, u64 arg6);
  652. void bpf_trace_run7(struct bpf_prog *prog, u64 arg1, u64 arg2,
  653. u64 arg3, u64 arg4, u64 arg5, u64 arg6, u64 arg7);
  654. void bpf_trace_run8(struct bpf_prog *prog, u64 arg1, u64 arg2,
  655. u64 arg3, u64 arg4, u64 arg5, u64 arg6, u64 arg7,
  656. u64 arg8);
  657. void bpf_trace_run9(struct bpf_prog *prog, u64 arg1, u64 arg2,
  658. u64 arg3, u64 arg4, u64 arg5, u64 arg6, u64 arg7,
  659. u64 arg8, u64 arg9);
  660. void bpf_trace_run10(struct bpf_prog *prog, u64 arg1, u64 arg2,
  661. u64 arg3, u64 arg4, u64 arg5, u64 arg6, u64 arg7,
  662. u64 arg8, u64 arg9, u64 arg10);
  663. void bpf_trace_run11(struct bpf_prog *prog, u64 arg1, u64 arg2,
  664. u64 arg3, u64 arg4, u64 arg5, u64 arg6, u64 arg7,
  665. u64 arg8, u64 arg9, u64 arg10, u64 arg11);
  666. void bpf_trace_run12(struct bpf_prog *prog, u64 arg1, u64 arg2,
  667. u64 arg3, u64 arg4, u64 arg5, u64 arg6, u64 arg7,
  668. u64 arg8, u64 arg9, u64 arg10, u64 arg11, u64 arg12);
  669. void perf_trace_run_bpf_submit(void *raw_data, int size, int rctx,
  670. struct trace_event_call *call, u64 count,
  671. struct pt_regs *regs, struct hlist_head *head,
  672. struct task_struct *task);
  673. static inline void
  674. perf_trace_buf_submit(void *raw_data, int size, int rctx, u16 type,
  675. u64 count, struct pt_regs *regs, void *head,
  676. struct task_struct *task)
  677. {
  678. perf_tp_event(type, count, raw_data, size, regs, head, rctx, task);
  679. }
  680. #endif
  681. #endif /* _LINUX_TRACE_EVENT_H */