trace.h 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384
  1. #ifndef _LINUX_KERNEL_TRACE_H
  2. #define _LINUX_KERNEL_TRACE_H
  3. #include <linux/fs.h>
  4. #include <linux/atomic.h>
  5. #include <linux/sched.h>
  6. #include <linux/clocksource.h>
  7. #include <linux/ring_buffer.h>
  8. #include <linux/mmiotrace.h>
  9. #include <linux/tracepoint.h>
  10. #include <linux/ftrace.h>
  11. #include <linux/hw_breakpoint.h>
  12. #include <linux/trace_seq.h>
  13. #include <linux/trace_events.h>
  14. #include <linux/compiler.h>
  15. #include <linux/trace_seq.h>
  16. #ifdef CONFIG_FTRACE_SYSCALLS
  17. #include <asm/unistd.h> /* For NR_SYSCALLS */
  18. #include <asm/syscall.h> /* some archs define it here */
  19. #endif
  20. enum trace_type {
  21. __TRACE_FIRST_TYPE = 0,
  22. TRACE_FN,
  23. TRACE_CTX,
  24. TRACE_WAKE,
  25. TRACE_STACK,
  26. TRACE_PRINT,
  27. TRACE_BPRINT,
  28. TRACE_MMIO_RW,
  29. TRACE_MMIO_MAP,
  30. TRACE_BRANCH,
  31. TRACE_GRAPH_RET,
  32. TRACE_GRAPH_ENT,
  33. TRACE_USER_STACK,
  34. TRACE_BLK,
  35. TRACE_BPUTS,
  36. __TRACE_LAST_TYPE,
  37. };
  38. #undef __field
  39. #define __field(type, item) type item;
  40. #undef __field_struct
  41. #define __field_struct(type, item) __field(type, item)
  42. #undef __field_desc
  43. #define __field_desc(type, container, item)
  44. #undef __array
  45. #define __array(type, item, size) type item[size];
  46. #undef __array_desc
  47. #define __array_desc(type, container, item, size)
  48. #undef __dynamic_array
  49. #define __dynamic_array(type, item) type item[];
  50. #undef F_STRUCT
  51. #define F_STRUCT(args...) args
  52. #undef FTRACE_ENTRY
  53. #define FTRACE_ENTRY(name, struct_name, id, tstruct, print, filter) \
  54. struct struct_name { \
  55. struct trace_entry ent; \
  56. tstruct \
  57. }
  58. #undef FTRACE_ENTRY_DUP
  59. #define FTRACE_ENTRY_DUP(name, name_struct, id, tstruct, printk, filter)
  60. #undef FTRACE_ENTRY_REG
  61. #define FTRACE_ENTRY_REG(name, struct_name, id, tstruct, print, \
  62. filter, regfn) \
  63. FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print), \
  64. filter)
  65. #include "trace_entries.h"
  66. /*
  67. * syscalls are special, and need special handling, this is why
  68. * they are not included in trace_entries.h
  69. */
  70. struct syscall_trace_enter {
  71. struct trace_entry ent;
  72. int nr;
  73. unsigned long args[];
  74. };
  75. struct syscall_trace_exit {
  76. struct trace_entry ent;
  77. int nr;
  78. long ret;
  79. };
  80. struct kprobe_trace_entry_head {
  81. struct trace_entry ent;
  82. unsigned long ip;
  83. };
  84. struct kretprobe_trace_entry_head {
  85. struct trace_entry ent;
  86. unsigned long func;
  87. unsigned long ret_ip;
  88. };
  89. /*
  90. * trace_flag_type is an enumeration that holds different
  91. * states when a trace occurs. These are:
  92. * IRQS_OFF - interrupts were disabled
  93. * IRQS_NOSUPPORT - arch does not support irqs_disabled_flags
  94. * NEED_RESCHED - reschedule is requested
  95. * HARDIRQ - inside an interrupt handler
  96. * SOFTIRQ - inside a softirq handler
  97. */
  98. enum trace_flag_type {
  99. TRACE_FLAG_IRQS_OFF = 0x01,
  100. TRACE_FLAG_IRQS_NOSUPPORT = 0x02,
  101. TRACE_FLAG_NEED_RESCHED = 0x04,
  102. TRACE_FLAG_HARDIRQ = 0x08,
  103. TRACE_FLAG_SOFTIRQ = 0x10,
  104. TRACE_FLAG_PREEMPT_RESCHED = 0x20,
  105. };
  106. #define TRACE_BUF_SIZE 1024
  107. struct trace_array;
  108. /*
  109. * The CPU trace array - it consists of thousands of trace entries
  110. * plus some other descriptor data: (for example which task started
  111. * the trace, etc.)
  112. */
  113. struct trace_array_cpu {
  114. atomic_t disabled;
  115. void *buffer_page; /* ring buffer spare */
  116. unsigned long entries;
  117. unsigned long saved_latency;
  118. unsigned long critical_start;
  119. unsigned long critical_end;
  120. unsigned long critical_sequence;
  121. unsigned long nice;
  122. unsigned long policy;
  123. unsigned long rt_priority;
  124. unsigned long skipped_entries;
  125. cycle_t preempt_timestamp;
  126. pid_t pid;
  127. kuid_t uid;
  128. char comm[TASK_COMM_LEN];
  129. bool ignore_pid;
  130. };
  131. struct tracer;
  132. struct trace_option_dentry;
  133. struct trace_buffer {
  134. struct trace_array *tr;
  135. struct ring_buffer *buffer;
  136. struct trace_array_cpu __percpu *data;
  137. cycle_t time_start;
  138. int cpu;
  139. };
  140. #define TRACE_FLAGS_MAX_SIZE 32
  141. struct trace_options {
  142. struct tracer *tracer;
  143. struct trace_option_dentry *topts;
  144. };
  145. struct trace_pid_list {
  146. unsigned int nr_pids;
  147. int order;
  148. pid_t *pids;
  149. };
  150. /*
  151. * The trace array - an array of per-CPU trace arrays. This is the
  152. * highest level data structure that individual tracers deal with.
  153. * They have on/off state as well:
  154. */
  155. struct trace_array {
  156. struct list_head list;
  157. char *name;
  158. struct trace_buffer trace_buffer;
  159. #ifdef CONFIG_TRACER_MAX_TRACE
  160. /*
  161. * The max_buffer is used to snapshot the trace when a maximum
  162. * latency is reached, or when the user initiates a snapshot.
  163. * Some tracers will use this to store a maximum trace while
  164. * it continues examining live traces.
  165. *
  166. * The buffers for the max_buffer are set up the same as the trace_buffer
  167. * When a snapshot is taken, the buffer of the max_buffer is swapped
  168. * with the buffer of the trace_buffer and the buffers are reset for
  169. * the trace_buffer so the tracing can continue.
  170. */
  171. struct trace_buffer max_buffer;
  172. bool allocated_snapshot;
  173. unsigned long max_latency;
  174. #endif
  175. struct trace_pid_list __rcu *filtered_pids;
  176. /*
  177. * max_lock is used to protect the swapping of buffers
  178. * when taking a max snapshot. The buffers themselves are
  179. * protected by per_cpu spinlocks. But the action of the swap
  180. * needs its own lock.
  181. *
  182. * This is defined as a arch_spinlock_t in order to help
  183. * with performance when lockdep debugging is enabled.
  184. *
  185. * It is also used in other places outside the update_max_tr
  186. * so it needs to be defined outside of the
  187. * CONFIG_TRACER_MAX_TRACE.
  188. */
  189. arch_spinlock_t max_lock;
  190. int buffer_disabled;
  191. #ifdef CONFIG_FTRACE_SYSCALLS
  192. int sys_refcount_enter;
  193. int sys_refcount_exit;
  194. struct trace_event_file __rcu *enter_syscall_files[NR_syscalls];
  195. struct trace_event_file __rcu *exit_syscall_files[NR_syscalls];
  196. #endif
  197. int stop_count;
  198. int clock_id;
  199. int nr_topts;
  200. struct tracer *current_trace;
  201. unsigned int trace_flags;
  202. unsigned char trace_flags_index[TRACE_FLAGS_MAX_SIZE];
  203. unsigned int flags;
  204. raw_spinlock_t start_lock;
  205. struct dentry *dir;
  206. struct dentry *options;
  207. struct dentry *percpu_dir;
  208. struct dentry *event_dir;
  209. struct trace_options *topts;
  210. struct list_head systems;
  211. struct list_head events;
  212. cpumask_var_t tracing_cpumask; /* only trace on set CPUs */
  213. int ref;
  214. #ifdef CONFIG_FUNCTION_TRACER
  215. struct ftrace_ops *ops;
  216. /* function tracing enabled */
  217. int function_enabled;
  218. #endif
  219. };
  220. enum {
  221. TRACE_ARRAY_FL_GLOBAL = (1 << 0)
  222. };
  223. extern struct list_head ftrace_trace_arrays;
  224. extern struct mutex trace_types_lock;
  225. extern int trace_array_get(struct trace_array *tr);
  226. extern void trace_array_put(struct trace_array *tr);
  227. /*
  228. * The global tracer (top) should be the first trace array added,
  229. * but we check the flag anyway.
  230. */
  231. static inline struct trace_array *top_trace_array(void)
  232. {
  233. struct trace_array *tr;
  234. if (list_empty(&ftrace_trace_arrays))
  235. return NULL;
  236. tr = list_entry(ftrace_trace_arrays.prev,
  237. typeof(*tr), list);
  238. WARN_ON(!(tr->flags & TRACE_ARRAY_FL_GLOBAL));
  239. return tr;
  240. }
  241. #define FTRACE_CMP_TYPE(var, type) \
  242. __builtin_types_compatible_p(typeof(var), type *)
  243. #undef IF_ASSIGN
  244. #define IF_ASSIGN(var, entry, etype, id) \
  245. if (FTRACE_CMP_TYPE(var, etype)) { \
  246. var = (typeof(var))(entry); \
  247. WARN_ON(id && (entry)->type != id); \
  248. break; \
  249. }
  250. /* Will cause compile errors if type is not found. */
  251. extern void __ftrace_bad_type(void);
  252. /*
  253. * The trace_assign_type is a verifier that the entry type is
  254. * the same as the type being assigned. To add new types simply
  255. * add a line with the following format:
  256. *
  257. * IF_ASSIGN(var, ent, type, id);
  258. *
  259. * Where "type" is the trace type that includes the trace_entry
  260. * as the "ent" item. And "id" is the trace identifier that is
  261. * used in the trace_type enum.
  262. *
  263. * If the type can have more than one id, then use zero.
  264. */
  265. #define trace_assign_type(var, ent) \
  266. do { \
  267. IF_ASSIGN(var, ent, struct ftrace_entry, TRACE_FN); \
  268. IF_ASSIGN(var, ent, struct ctx_switch_entry, 0); \
  269. IF_ASSIGN(var, ent, struct stack_entry, TRACE_STACK); \
  270. IF_ASSIGN(var, ent, struct userstack_entry, TRACE_USER_STACK);\
  271. IF_ASSIGN(var, ent, struct print_entry, TRACE_PRINT); \
  272. IF_ASSIGN(var, ent, struct bprint_entry, TRACE_BPRINT); \
  273. IF_ASSIGN(var, ent, struct bputs_entry, TRACE_BPUTS); \
  274. IF_ASSIGN(var, ent, struct trace_mmiotrace_rw, \
  275. TRACE_MMIO_RW); \
  276. IF_ASSIGN(var, ent, struct trace_mmiotrace_map, \
  277. TRACE_MMIO_MAP); \
  278. IF_ASSIGN(var, ent, struct trace_branch, TRACE_BRANCH); \
  279. IF_ASSIGN(var, ent, struct ftrace_graph_ent_entry, \
  280. TRACE_GRAPH_ENT); \
  281. IF_ASSIGN(var, ent, struct ftrace_graph_ret_entry, \
  282. TRACE_GRAPH_RET); \
  283. __ftrace_bad_type(); \
  284. } while (0)
  285. /*
  286. * An option specific to a tracer. This is a boolean value.
  287. * The bit is the bit index that sets its value on the
  288. * flags value in struct tracer_flags.
  289. */
  290. struct tracer_opt {
  291. const char *name; /* Will appear on the trace_options file */
  292. u32 bit; /* Mask assigned in val field in tracer_flags */
  293. };
  294. /*
  295. * The set of specific options for a tracer. Your tracer
  296. * have to set the initial value of the flags val.
  297. */
  298. struct tracer_flags {
  299. u32 val;
  300. struct tracer_opt *opts;
  301. };
  302. /* Makes more easy to define a tracer opt */
  303. #define TRACER_OPT(s, b) .name = #s, .bit = b
  304. struct trace_option_dentry {
  305. struct tracer_opt *opt;
  306. struct tracer_flags *flags;
  307. struct trace_array *tr;
  308. struct dentry *entry;
  309. };
  310. /**
  311. * struct tracer - a specific tracer and its callbacks to interact with tracefs
  312. * @name: the name chosen to select it on the available_tracers file
  313. * @init: called when one switches to this tracer (echo name > current_tracer)
  314. * @reset: called when one switches to another tracer
  315. * @start: called when tracing is unpaused (echo 1 > tracing_enabled)
  316. * @stop: called when tracing is paused (echo 0 > tracing_enabled)
  317. * @update_thresh: called when tracing_thresh is updated
  318. * @open: called when the trace file is opened
  319. * @pipe_open: called when the trace_pipe file is opened
  320. * @close: called when the trace file is released
  321. * @pipe_close: called when the trace_pipe file is released
  322. * @read: override the default read callback on trace_pipe
  323. * @splice_read: override the default splice_read callback on trace_pipe
  324. * @selftest: selftest to run on boot (see trace_selftest.c)
  325. * @print_headers: override the first lines that describe your columns
  326. * @print_line: callback that prints a trace
  327. * @set_flag: signals one of your private flags changed (trace_options file)
  328. * @flags: your private flags
  329. */
  330. struct tracer {
  331. const char *name;
  332. int (*init)(struct trace_array *tr);
  333. void (*reset)(struct trace_array *tr);
  334. void (*start)(struct trace_array *tr);
  335. void (*stop)(struct trace_array *tr);
  336. int (*update_thresh)(struct trace_array *tr);
  337. void (*open)(struct trace_iterator *iter);
  338. void (*pipe_open)(struct trace_iterator *iter);
  339. void (*close)(struct trace_iterator *iter);
  340. void (*pipe_close)(struct trace_iterator *iter);
  341. ssize_t (*read)(struct trace_iterator *iter,
  342. struct file *filp, char __user *ubuf,
  343. size_t cnt, loff_t *ppos);
  344. ssize_t (*splice_read)(struct trace_iterator *iter,
  345. struct file *filp,
  346. loff_t *ppos,
  347. struct pipe_inode_info *pipe,
  348. size_t len,
  349. unsigned int flags);
  350. #ifdef CONFIG_FTRACE_STARTUP_TEST
  351. int (*selftest)(struct tracer *trace,
  352. struct trace_array *tr);
  353. #endif
  354. void (*print_header)(struct seq_file *m);
  355. enum print_line_t (*print_line)(struct trace_iterator *iter);
  356. /* If you handled the flag setting, return 0 */
  357. int (*set_flag)(struct trace_array *tr,
  358. u32 old_flags, u32 bit, int set);
  359. /* Return 0 if OK with change, else return non-zero */
  360. int (*flag_changed)(struct trace_array *tr,
  361. u32 mask, int set);
  362. struct tracer *next;
  363. struct tracer_flags *flags;
  364. int enabled;
  365. int ref;
  366. bool print_max;
  367. bool allow_instances;
  368. #ifdef CONFIG_TRACER_MAX_TRACE
  369. bool use_max_tr;
  370. #endif
  371. };
  372. /* Only current can touch trace_recursion */
  373. /*
  374. * For function tracing recursion:
  375. * The order of these bits are important.
  376. *
  377. * When function tracing occurs, the following steps are made:
  378. * If arch does not support a ftrace feature:
  379. * call internal function (uses INTERNAL bits) which calls...
  380. * If callback is registered to the "global" list, the list
  381. * function is called and recursion checks the GLOBAL bits.
  382. * then this function calls...
  383. * The function callback, which can use the FTRACE bits to
  384. * check for recursion.
  385. *
  386. * Now if the arch does not suppport a feature, and it calls
  387. * the global list function which calls the ftrace callback
  388. * all three of these steps will do a recursion protection.
  389. * There's no reason to do one if the previous caller already
  390. * did. The recursion that we are protecting against will
  391. * go through the same steps again.
  392. *
  393. * To prevent the multiple recursion checks, if a recursion
  394. * bit is set that is higher than the MAX bit of the current
  395. * check, then we know that the check was made by the previous
  396. * caller, and we can skip the current check.
  397. */
  398. enum {
  399. TRACE_BUFFER_BIT,
  400. TRACE_BUFFER_NMI_BIT,
  401. TRACE_BUFFER_IRQ_BIT,
  402. TRACE_BUFFER_SIRQ_BIT,
  403. /* Start of function recursion bits */
  404. TRACE_FTRACE_BIT,
  405. TRACE_FTRACE_NMI_BIT,
  406. TRACE_FTRACE_IRQ_BIT,
  407. TRACE_FTRACE_SIRQ_BIT,
  408. /* INTERNAL_BITs must be greater than FTRACE_BITs */
  409. TRACE_INTERNAL_BIT,
  410. TRACE_INTERNAL_NMI_BIT,
  411. TRACE_INTERNAL_IRQ_BIT,
  412. TRACE_INTERNAL_SIRQ_BIT,
  413. TRACE_CONTROL_BIT,
  414. TRACE_BRANCH_BIT,
  415. /*
  416. * Abuse of the trace_recursion.
  417. * As we need a way to maintain state if we are tracing the function
  418. * graph in irq because we want to trace a particular function that
  419. * was called in irq context but we have irq tracing off. Since this
  420. * can only be modified by current, we can reuse trace_recursion.
  421. */
  422. TRACE_IRQ_BIT,
  423. };
  424. #define trace_recursion_set(bit) do { (current)->trace_recursion |= (1<<(bit)); } while (0)
  425. #define trace_recursion_clear(bit) do { (current)->trace_recursion &= ~(1<<(bit)); } while (0)
  426. #define trace_recursion_test(bit) ((current)->trace_recursion & (1<<(bit)))
  427. #define TRACE_CONTEXT_BITS 4
  428. #define TRACE_FTRACE_START TRACE_FTRACE_BIT
  429. #define TRACE_FTRACE_MAX ((1 << (TRACE_FTRACE_START + TRACE_CONTEXT_BITS)) - 1)
  430. #define TRACE_LIST_START TRACE_INTERNAL_BIT
  431. #define TRACE_LIST_MAX ((1 << (TRACE_LIST_START + TRACE_CONTEXT_BITS)) - 1)
  432. #define TRACE_CONTEXT_MASK TRACE_LIST_MAX
  433. static __always_inline int trace_get_context_bit(void)
  434. {
  435. int bit;
  436. if (in_interrupt()) {
  437. if (in_nmi())
  438. bit = 0;
  439. else if (in_irq())
  440. bit = 1;
  441. else
  442. bit = 2;
  443. } else
  444. bit = 3;
  445. return bit;
  446. }
  447. static __always_inline int trace_test_and_set_recursion(int start, int max)
  448. {
  449. unsigned int val = current->trace_recursion;
  450. int bit;
  451. /* A previous recursion check was made */
  452. if ((val & TRACE_CONTEXT_MASK) > max)
  453. return 0;
  454. bit = trace_get_context_bit() + start;
  455. if (unlikely(val & (1 << bit)))
  456. return -1;
  457. val |= 1 << bit;
  458. current->trace_recursion = val;
  459. barrier();
  460. return bit;
  461. }
  462. static __always_inline void trace_clear_recursion(int bit)
  463. {
  464. unsigned int val = current->trace_recursion;
  465. if (!bit)
  466. return;
  467. bit = 1 << bit;
  468. val &= ~bit;
  469. barrier();
  470. current->trace_recursion = val;
  471. }
  472. static inline struct ring_buffer_iter *
  473. trace_buffer_iter(struct trace_iterator *iter, int cpu)
  474. {
  475. if (iter->buffer_iter && iter->buffer_iter[cpu])
  476. return iter->buffer_iter[cpu];
  477. return NULL;
  478. }
  479. int tracer_init(struct tracer *t, struct trace_array *tr);
  480. int tracing_is_enabled(void);
  481. void tracing_reset(struct trace_buffer *buf, int cpu);
  482. void tracing_reset_online_cpus(struct trace_buffer *buf);
  483. void tracing_reset_current(int cpu);
  484. void tracing_reset_all_online_cpus(void);
  485. int tracing_open_generic(struct inode *inode, struct file *filp);
  486. bool tracing_is_disabled(void);
  487. struct dentry *trace_create_file(const char *name,
  488. umode_t mode,
  489. struct dentry *parent,
  490. void *data,
  491. const struct file_operations *fops);
  492. struct dentry *tracing_init_dentry(void);
  493. struct ring_buffer_event;
  494. struct ring_buffer_event *
  495. trace_buffer_lock_reserve(struct ring_buffer *buffer,
  496. int type,
  497. unsigned long len,
  498. unsigned long flags,
  499. int pc);
  500. struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
  501. struct trace_array_cpu *data);
  502. struct trace_entry *trace_find_next_entry(struct trace_iterator *iter,
  503. int *ent_cpu, u64 *ent_ts);
  504. void __buffer_unlock_commit(struct ring_buffer *buffer,
  505. struct ring_buffer_event *event);
  506. int trace_empty(struct trace_iterator *iter);
  507. void *trace_find_next_entry_inc(struct trace_iterator *iter);
  508. void trace_init_global_iter(struct trace_iterator *iter);
  509. void tracing_iter_reset(struct trace_iterator *iter, int cpu);
  510. void trace_function(struct trace_array *tr,
  511. unsigned long ip,
  512. unsigned long parent_ip,
  513. unsigned long flags, int pc);
  514. void trace_graph_function(struct trace_array *tr,
  515. unsigned long ip,
  516. unsigned long parent_ip,
  517. unsigned long flags, int pc);
  518. void trace_latency_header(struct seq_file *m);
  519. void trace_default_header(struct seq_file *m);
  520. void print_trace_header(struct seq_file *m, struct trace_iterator *iter);
  521. int trace_empty(struct trace_iterator *iter);
  522. void trace_graph_return(struct ftrace_graph_ret *trace);
  523. int trace_graph_entry(struct ftrace_graph_ent *trace);
  524. void set_graph_array(struct trace_array *tr);
  525. void tracing_start_cmdline_record(void);
  526. void tracing_stop_cmdline_record(void);
  527. int register_tracer(struct tracer *type);
  528. int is_tracing_stopped(void);
  529. loff_t tracing_lseek(struct file *file, loff_t offset, int whence);
  530. extern cpumask_var_t __read_mostly tracing_buffer_mask;
  531. #define for_each_tracing_cpu(cpu) \
  532. for_each_cpu(cpu, tracing_buffer_mask)
  533. extern unsigned long nsecs_to_usecs(unsigned long nsecs);
  534. extern unsigned long tracing_thresh;
  535. #ifdef CONFIG_TRACER_MAX_TRACE
  536. void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
  537. void update_max_tr_single(struct trace_array *tr,
  538. struct task_struct *tsk, int cpu);
  539. #endif /* CONFIG_TRACER_MAX_TRACE */
  540. #ifdef CONFIG_STACKTRACE
  541. void ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags,
  542. int pc);
  543. void __trace_stack(struct trace_array *tr, unsigned long flags, int skip,
  544. int pc);
  545. #else
  546. static inline void ftrace_trace_userstack(struct ring_buffer *buffer,
  547. unsigned long flags, int pc)
  548. {
  549. }
  550. static inline void __trace_stack(struct trace_array *tr, unsigned long flags,
  551. int skip, int pc)
  552. {
  553. }
  554. #endif /* CONFIG_STACKTRACE */
  555. extern cycle_t ftrace_now(int cpu);
  556. extern void trace_find_cmdline(int pid, char comm[]);
  557. #ifdef CONFIG_DYNAMIC_FTRACE
  558. extern unsigned long ftrace_update_tot_cnt;
  559. #endif
  560. #define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
  561. extern int DYN_FTRACE_TEST_NAME(void);
  562. #define DYN_FTRACE_TEST_NAME2 trace_selftest_dynamic_test_func2
  563. extern int DYN_FTRACE_TEST_NAME2(void);
  564. extern bool ring_buffer_expanded;
  565. extern bool tracing_selftest_disabled;
  566. #ifdef CONFIG_FTRACE_STARTUP_TEST
  567. extern int trace_selftest_startup_function(struct tracer *trace,
  568. struct trace_array *tr);
  569. extern int trace_selftest_startup_function_graph(struct tracer *trace,
  570. struct trace_array *tr);
  571. extern int trace_selftest_startup_irqsoff(struct tracer *trace,
  572. struct trace_array *tr);
  573. extern int trace_selftest_startup_preemptoff(struct tracer *trace,
  574. struct trace_array *tr);
  575. extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
  576. struct trace_array *tr);
  577. extern int trace_selftest_startup_wakeup(struct tracer *trace,
  578. struct trace_array *tr);
  579. extern int trace_selftest_startup_nop(struct tracer *trace,
  580. struct trace_array *tr);
  581. extern int trace_selftest_startup_sched_switch(struct tracer *trace,
  582. struct trace_array *tr);
  583. extern int trace_selftest_startup_branch(struct tracer *trace,
  584. struct trace_array *tr);
  585. /*
  586. * Tracer data references selftest functions that only occur
  587. * on boot up. These can be __init functions. Thus, when selftests
  588. * are enabled, then the tracers need to reference __init functions.
  589. */
  590. #define __tracer_data __refdata
  591. #else
  592. /* Tracers are seldom changed. Optimize when selftests are disabled. */
  593. #define __tracer_data __read_mostly
  594. #endif /* CONFIG_FTRACE_STARTUP_TEST */
  595. extern void *head_page(struct trace_array_cpu *data);
  596. extern unsigned long long ns2usecs(cycle_t nsec);
  597. extern int
  598. trace_vbprintk(unsigned long ip, const char *fmt, va_list args);
  599. extern int
  600. trace_vprintk(unsigned long ip, const char *fmt, va_list args);
  601. extern int
  602. trace_array_vprintk(struct trace_array *tr,
  603. unsigned long ip, const char *fmt, va_list args);
  604. int trace_array_printk(struct trace_array *tr,
  605. unsigned long ip, const char *fmt, ...);
  606. int trace_array_printk_buf(struct ring_buffer *buffer,
  607. unsigned long ip, const char *fmt, ...);
  608. void trace_printk_seq(struct trace_seq *s);
  609. enum print_line_t print_trace_line(struct trace_iterator *iter);
  610. extern char trace_find_mark(unsigned long long duration);
  611. /* Standard output formatting function used for function return traces */
  612. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  613. /* Flag options */
  614. #define TRACE_GRAPH_PRINT_OVERRUN 0x1
  615. #define TRACE_GRAPH_PRINT_CPU 0x2
  616. #define TRACE_GRAPH_PRINT_OVERHEAD 0x4
  617. #define TRACE_GRAPH_PRINT_PROC 0x8
  618. #define TRACE_GRAPH_PRINT_DURATION 0x10
  619. #define TRACE_GRAPH_PRINT_ABS_TIME 0x20
  620. #define TRACE_GRAPH_PRINT_IRQS 0x40
  621. #define TRACE_GRAPH_PRINT_TAIL 0x80
  622. #define TRACE_GRAPH_SLEEP_TIME 0x100
  623. #define TRACE_GRAPH_GRAPH_TIME 0x200
  624. #define TRACE_GRAPH_PRINT_FILL_SHIFT 28
  625. #define TRACE_GRAPH_PRINT_FILL_MASK (0x3 << TRACE_GRAPH_PRINT_FILL_SHIFT)
  626. extern void ftrace_graph_sleep_time_control(bool enable);
  627. extern void ftrace_graph_graph_time_control(bool enable);
  628. extern enum print_line_t
  629. print_graph_function_flags(struct trace_iterator *iter, u32 flags);
  630. extern void print_graph_headers_flags(struct seq_file *s, u32 flags);
  631. extern void
  632. trace_print_graph_duration(unsigned long long duration, struct trace_seq *s);
  633. extern void graph_trace_open(struct trace_iterator *iter);
  634. extern void graph_trace_close(struct trace_iterator *iter);
  635. extern int __trace_graph_entry(struct trace_array *tr,
  636. struct ftrace_graph_ent *trace,
  637. unsigned long flags, int pc);
  638. extern void __trace_graph_return(struct trace_array *tr,
  639. struct ftrace_graph_ret *trace,
  640. unsigned long flags, int pc);
  641. #ifdef CONFIG_DYNAMIC_FTRACE
  642. /* TODO: make this variable */
  643. #define FTRACE_GRAPH_MAX_FUNCS 32
  644. extern int ftrace_graph_count;
  645. extern unsigned long ftrace_graph_funcs[FTRACE_GRAPH_MAX_FUNCS];
  646. extern int ftrace_graph_notrace_count;
  647. extern unsigned long ftrace_graph_notrace_funcs[FTRACE_GRAPH_MAX_FUNCS];
  648. static inline int ftrace_graph_addr(unsigned long addr)
  649. {
  650. int i;
  651. if (!ftrace_graph_count)
  652. return 1;
  653. for (i = 0; i < ftrace_graph_count; i++) {
  654. if (addr == ftrace_graph_funcs[i]) {
  655. /*
  656. * If no irqs are to be traced, but a set_graph_function
  657. * is set, and called by an interrupt handler, we still
  658. * want to trace it.
  659. */
  660. if (in_irq())
  661. trace_recursion_set(TRACE_IRQ_BIT);
  662. else
  663. trace_recursion_clear(TRACE_IRQ_BIT);
  664. return 1;
  665. }
  666. }
  667. return 0;
  668. }
  669. static inline int ftrace_graph_notrace_addr(unsigned long addr)
  670. {
  671. int i;
  672. if (!ftrace_graph_notrace_count)
  673. return 0;
  674. for (i = 0; i < ftrace_graph_notrace_count; i++) {
  675. if (addr == ftrace_graph_notrace_funcs[i])
  676. return 1;
  677. }
  678. return 0;
  679. }
  680. #else
  681. static inline int ftrace_graph_addr(unsigned long addr)
  682. {
  683. return 1;
  684. }
  685. static inline int ftrace_graph_notrace_addr(unsigned long addr)
  686. {
  687. return 0;
  688. }
  689. #endif /* CONFIG_DYNAMIC_FTRACE */
  690. #else /* CONFIG_FUNCTION_GRAPH_TRACER */
  691. static inline enum print_line_t
  692. print_graph_function_flags(struct trace_iterator *iter, u32 flags)
  693. {
  694. return TRACE_TYPE_UNHANDLED;
  695. }
  696. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  697. extern struct list_head ftrace_pids;
  698. #ifdef CONFIG_FUNCTION_TRACER
  699. extern bool ftrace_filter_param __initdata;
  700. static inline int ftrace_trace_task(struct task_struct *task)
  701. {
  702. if (list_empty(&ftrace_pids))
  703. return 1;
  704. return test_tsk_trace_trace(task);
  705. }
  706. extern int ftrace_is_dead(void);
  707. int ftrace_create_function_files(struct trace_array *tr,
  708. struct dentry *parent);
  709. void ftrace_destroy_function_files(struct trace_array *tr);
  710. void ftrace_init_global_array_ops(struct trace_array *tr);
  711. void ftrace_init_array_ops(struct trace_array *tr, ftrace_func_t func);
  712. void ftrace_reset_array_ops(struct trace_array *tr);
  713. int using_ftrace_ops_list_func(void);
  714. #else
  715. static inline int ftrace_trace_task(struct task_struct *task)
  716. {
  717. return 1;
  718. }
  719. static inline int ftrace_is_dead(void) { return 0; }
  720. static inline int
  721. ftrace_create_function_files(struct trace_array *tr,
  722. struct dentry *parent)
  723. {
  724. return 0;
  725. }
  726. static inline void ftrace_destroy_function_files(struct trace_array *tr) { }
  727. static inline __init void
  728. ftrace_init_global_array_ops(struct trace_array *tr) { }
  729. static inline void ftrace_reset_array_ops(struct trace_array *tr) { }
  730. /* ftace_func_t type is not defined, use macro instead of static inline */
  731. #define ftrace_init_array_ops(tr, func) do { } while (0)
  732. #endif /* CONFIG_FUNCTION_TRACER */
  733. #if defined(CONFIG_FUNCTION_TRACER) && defined(CONFIG_DYNAMIC_FTRACE)
  734. void ftrace_create_filter_files(struct ftrace_ops *ops,
  735. struct dentry *parent);
  736. void ftrace_destroy_filter_files(struct ftrace_ops *ops);
  737. #else
  738. /*
  739. * The ops parameter passed in is usually undefined.
  740. * This must be a macro.
  741. */
  742. #define ftrace_create_filter_files(ops, parent) do { } while (0)
  743. #define ftrace_destroy_filter_files(ops) do { } while (0)
  744. #endif /* CONFIG_FUNCTION_TRACER && CONFIG_DYNAMIC_FTRACE */
  745. bool ftrace_event_is_function(struct trace_event_call *call);
  746. /*
  747. * struct trace_parser - servers for reading the user input separated by spaces
  748. * @cont: set if the input is not complete - no final space char was found
  749. * @buffer: holds the parsed user input
  750. * @idx: user input length
  751. * @size: buffer size
  752. */
  753. struct trace_parser {
  754. bool cont;
  755. char *buffer;
  756. unsigned idx;
  757. unsigned size;
  758. };
  759. static inline bool trace_parser_loaded(struct trace_parser *parser)
  760. {
  761. return (parser->idx != 0);
  762. }
  763. static inline bool trace_parser_cont(struct trace_parser *parser)
  764. {
  765. return parser->cont;
  766. }
  767. static inline void trace_parser_clear(struct trace_parser *parser)
  768. {
  769. parser->cont = false;
  770. parser->idx = 0;
  771. }
  772. extern int trace_parser_get_init(struct trace_parser *parser, int size);
  773. extern void trace_parser_put(struct trace_parser *parser);
  774. extern int trace_get_user(struct trace_parser *parser, const char __user *ubuf,
  775. size_t cnt, loff_t *ppos);
  776. /*
  777. * Only create function graph options if function graph is configured.
  778. */
  779. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  780. # define FGRAPH_FLAGS \
  781. C(DISPLAY_GRAPH, "display-graph"),
  782. #else
  783. # define FGRAPH_FLAGS
  784. #endif
  785. #ifdef CONFIG_BRANCH_TRACER
  786. # define BRANCH_FLAGS \
  787. C(BRANCH, "branch"),
  788. #else
  789. # define BRANCH_FLAGS
  790. #endif
  791. #ifdef CONFIG_FUNCTION_TRACER
  792. # define FUNCTION_FLAGS \
  793. C(FUNCTION, "function-trace"),
  794. # define FUNCTION_DEFAULT_FLAGS TRACE_ITER_FUNCTION
  795. #else
  796. # define FUNCTION_FLAGS
  797. # define FUNCTION_DEFAULT_FLAGS 0UL
  798. #endif
  799. #ifdef CONFIG_STACKTRACE
  800. # define STACK_FLAGS \
  801. C(STACKTRACE, "stacktrace"),
  802. #else
  803. # define STACK_FLAGS
  804. #endif
  805. /*
  806. * trace_iterator_flags is an enumeration that defines bit
  807. * positions into trace_flags that controls the output.
  808. *
  809. * NOTE: These bits must match the trace_options array in
  810. * trace.c (this macro guarantees it).
  811. */
  812. #define TRACE_FLAGS \
  813. C(PRINT_PARENT, "print-parent"), \
  814. C(SYM_OFFSET, "sym-offset"), \
  815. C(SYM_ADDR, "sym-addr"), \
  816. C(VERBOSE, "verbose"), \
  817. C(RAW, "raw"), \
  818. C(HEX, "hex"), \
  819. C(BIN, "bin"), \
  820. C(BLOCK, "block"), \
  821. C(PRINTK, "trace_printk"), \
  822. C(ANNOTATE, "annotate"), \
  823. C(USERSTACKTRACE, "userstacktrace"), \
  824. C(SYM_USEROBJ, "sym-userobj"), \
  825. C(PRINTK_MSGONLY, "printk-msg-only"), \
  826. C(CONTEXT_INFO, "context-info"), /* Print pid/cpu/time */ \
  827. C(LATENCY_FMT, "latency-format"), \
  828. C(RECORD_CMD, "record-cmd"), \
  829. C(OVERWRITE, "overwrite"), \
  830. C(STOP_ON_FREE, "disable_on_free"), \
  831. C(IRQ_INFO, "irq-info"), \
  832. C(MARKERS, "markers"), \
  833. FUNCTION_FLAGS \
  834. FGRAPH_FLAGS \
  835. STACK_FLAGS \
  836. BRANCH_FLAGS
  837. /*
  838. * By defining C, we can make TRACE_FLAGS a list of bit names
  839. * that will define the bits for the flag masks.
  840. */
  841. #undef C
  842. #define C(a, b) TRACE_ITER_##a##_BIT
  843. enum trace_iterator_bits {
  844. TRACE_FLAGS
  845. /* Make sure we don't go more than we have bits for */
  846. TRACE_ITER_LAST_BIT
  847. };
  848. /*
  849. * By redefining C, we can make TRACE_FLAGS a list of masks that
  850. * use the bits as defined above.
  851. */
  852. #undef C
  853. #define C(a, b) TRACE_ITER_##a = (1 << TRACE_ITER_##a##_BIT)
  854. enum trace_iterator_flags { TRACE_FLAGS };
  855. /*
  856. * TRACE_ITER_SYM_MASK masks the options in trace_flags that
  857. * control the output of kernel symbols.
  858. */
  859. #define TRACE_ITER_SYM_MASK \
  860. (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR)
  861. extern struct tracer nop_trace;
  862. #ifdef CONFIG_BRANCH_TRACER
  863. extern int enable_branch_tracing(struct trace_array *tr);
  864. extern void disable_branch_tracing(void);
  865. static inline int trace_branch_enable(struct trace_array *tr)
  866. {
  867. if (tr->trace_flags & TRACE_ITER_BRANCH)
  868. return enable_branch_tracing(tr);
  869. return 0;
  870. }
  871. static inline void trace_branch_disable(void)
  872. {
  873. /* due to races, always disable */
  874. disable_branch_tracing();
  875. }
  876. #else
  877. static inline int trace_branch_enable(struct trace_array *tr)
  878. {
  879. return 0;
  880. }
  881. static inline void trace_branch_disable(void)
  882. {
  883. }
  884. #endif /* CONFIG_BRANCH_TRACER */
  885. /* set ring buffers to default size if not already done so */
  886. int tracing_update_buffers(void);
  887. struct ftrace_event_field {
  888. struct list_head link;
  889. const char *name;
  890. const char *type;
  891. int filter_type;
  892. int offset;
  893. int size;
  894. int is_signed;
  895. };
  896. struct event_filter {
  897. int n_preds; /* Number assigned */
  898. int a_preds; /* allocated */
  899. struct filter_pred *preds;
  900. struct filter_pred *root;
  901. char *filter_string;
  902. };
  903. struct event_subsystem {
  904. struct list_head list;
  905. const char *name;
  906. struct event_filter *filter;
  907. int ref_count;
  908. };
  909. struct trace_subsystem_dir {
  910. struct list_head list;
  911. struct event_subsystem *subsystem;
  912. struct trace_array *tr;
  913. struct dentry *entry;
  914. int ref_count;
  915. int nr_events;
  916. };
  917. #define FILTER_PRED_INVALID ((unsigned short)-1)
  918. #define FILTER_PRED_IS_RIGHT (1 << 15)
  919. #define FILTER_PRED_FOLD (1 << 15)
  920. /*
  921. * The max preds is the size of unsigned short with
  922. * two flags at the MSBs. One bit is used for both the IS_RIGHT
  923. * and FOLD flags. The other is reserved.
  924. *
  925. * 2^14 preds is way more than enough.
  926. */
  927. #define MAX_FILTER_PRED 16384
  928. struct filter_pred;
  929. struct regex;
  930. typedef int (*filter_pred_fn_t) (struct filter_pred *pred, void *event);
  931. typedef int (*regex_match_func)(char *str, struct regex *r, int len);
  932. enum regex_type {
  933. MATCH_FULL = 0,
  934. MATCH_FRONT_ONLY,
  935. MATCH_MIDDLE_ONLY,
  936. MATCH_END_ONLY,
  937. };
  938. struct regex {
  939. char pattern[MAX_FILTER_STR_VAL];
  940. int len;
  941. int field_len;
  942. regex_match_func match;
  943. };
  944. struct filter_pred {
  945. filter_pred_fn_t fn;
  946. u64 val;
  947. struct regex regex;
  948. unsigned short *ops;
  949. struct ftrace_event_field *field;
  950. int offset;
  951. int not;
  952. int op;
  953. unsigned short index;
  954. unsigned short parent;
  955. unsigned short left;
  956. unsigned short right;
  957. };
  958. extern enum regex_type
  959. filter_parse_regex(char *buff, int len, char **search, int *not);
  960. extern void print_event_filter(struct trace_event_file *file,
  961. struct trace_seq *s);
  962. extern int apply_event_filter(struct trace_event_file *file,
  963. char *filter_string);
  964. extern int apply_subsystem_event_filter(struct trace_subsystem_dir *dir,
  965. char *filter_string);
  966. extern void print_subsystem_event_filter(struct event_subsystem *system,
  967. struct trace_seq *s);
  968. extern int filter_assign_type(const char *type);
  969. extern int create_event_filter(struct trace_event_call *call,
  970. char *filter_str, bool set_str,
  971. struct event_filter **filterp);
  972. extern void free_event_filter(struct event_filter *filter);
  973. struct ftrace_event_field *
  974. trace_find_event_field(struct trace_event_call *call, char *name);
  975. extern void trace_event_enable_cmd_record(bool enable);
  976. extern int event_trace_add_tracer(struct dentry *parent, struct trace_array *tr);
  977. extern int event_trace_del_tracer(struct trace_array *tr);
  978. extern struct trace_event_file *find_event_file(struct trace_array *tr,
  979. const char *system,
  980. const char *event);
  981. static inline void *event_file_data(struct file *filp)
  982. {
  983. return ACCESS_ONCE(file_inode(filp)->i_private);
  984. }
  985. extern struct mutex event_mutex;
  986. extern struct list_head ftrace_events;
  987. extern const struct file_operations event_trigger_fops;
  988. extern int register_trigger_cmds(void);
  989. extern void clear_event_triggers(struct trace_array *tr);
  990. struct event_trigger_data {
  991. unsigned long count;
  992. int ref;
  993. struct event_trigger_ops *ops;
  994. struct event_command *cmd_ops;
  995. struct event_filter __rcu *filter;
  996. char *filter_str;
  997. void *private_data;
  998. struct list_head list;
  999. };
  1000. /**
  1001. * struct event_trigger_ops - callbacks for trace event triggers
  1002. *
  1003. * The methods in this structure provide per-event trigger hooks for
  1004. * various trigger operations.
  1005. *
  1006. * All the methods below, except for @init() and @free(), must be
  1007. * implemented.
  1008. *
  1009. * @func: The trigger 'probe' function called when the triggering
  1010. * event occurs. The data passed into this callback is the data
  1011. * that was supplied to the event_command @reg() function that
  1012. * registered the trigger (see struct event_command).
  1013. *
  1014. * @init: An optional initialization function called for the trigger
  1015. * when the trigger is registered (via the event_command reg()
  1016. * function). This can be used to perform per-trigger
  1017. * initialization such as incrementing a per-trigger reference
  1018. * count, for instance. This is usually implemented by the
  1019. * generic utility function @event_trigger_init() (see
  1020. * trace_event_triggers.c).
  1021. *
  1022. * @free: An optional de-initialization function called for the
  1023. * trigger when the trigger is unregistered (via the
  1024. * event_command @reg() function). This can be used to perform
  1025. * per-trigger de-initialization such as decrementing a
  1026. * per-trigger reference count and freeing corresponding trigger
  1027. * data, for instance. This is usually implemented by the
  1028. * generic utility function @event_trigger_free() (see
  1029. * trace_event_triggers.c).
  1030. *
  1031. * @print: The callback function invoked to have the trigger print
  1032. * itself. This is usually implemented by a wrapper function
  1033. * that calls the generic utility function @event_trigger_print()
  1034. * (see trace_event_triggers.c).
  1035. */
  1036. struct event_trigger_ops {
  1037. void (*func)(struct event_trigger_data *data);
  1038. int (*init)(struct event_trigger_ops *ops,
  1039. struct event_trigger_data *data);
  1040. void (*free)(struct event_trigger_ops *ops,
  1041. struct event_trigger_data *data);
  1042. int (*print)(struct seq_file *m,
  1043. struct event_trigger_ops *ops,
  1044. struct event_trigger_data *data);
  1045. };
  1046. /**
  1047. * struct event_command - callbacks and data members for event commands
  1048. *
  1049. * Event commands are invoked by users by writing the command name
  1050. * into the 'trigger' file associated with a trace event. The
  1051. * parameters associated with a specific invocation of an event
  1052. * command are used to create an event trigger instance, which is
  1053. * added to the list of trigger instances associated with that trace
  1054. * event. When the event is hit, the set of triggers associated with
  1055. * that event is invoked.
  1056. *
  1057. * The data members in this structure provide per-event command data
  1058. * for various event commands.
  1059. *
  1060. * All the data members below, except for @post_trigger, must be set
  1061. * for each event command.
  1062. *
  1063. * @name: The unique name that identifies the event command. This is
  1064. * the name used when setting triggers via trigger files.
  1065. *
  1066. * @trigger_type: A unique id that identifies the event command
  1067. * 'type'. This value has two purposes, the first to ensure that
  1068. * only one trigger of the same type can be set at a given time
  1069. * for a particular event e.g. it doesn't make sense to have both
  1070. * a traceon and traceoff trigger attached to a single event at
  1071. * the same time, so traceon and traceoff have the same type
  1072. * though they have different names. The @trigger_type value is
  1073. * also used as a bit value for deferring the actual trigger
  1074. * action until after the current event is finished. Some
  1075. * commands need to do this if they themselves log to the trace
  1076. * buffer (see the @post_trigger() member below). @trigger_type
  1077. * values are defined by adding new values to the trigger_type
  1078. * enum in include/linux/trace_events.h.
  1079. *
  1080. * @post_trigger: A flag that says whether or not this command needs
  1081. * to have its action delayed until after the current event has
  1082. * been closed. Some triggers need to avoid being invoked while
  1083. * an event is currently in the process of being logged, since
  1084. * the trigger may itself log data into the trace buffer. Thus
  1085. * we make sure the current event is committed before invoking
  1086. * those triggers. To do that, the trigger invocation is split
  1087. * in two - the first part checks the filter using the current
  1088. * trace record; if a command has the @post_trigger flag set, it
  1089. * sets a bit for itself in the return value, otherwise it
  1090. * directly invokes the trigger. Once all commands have been
  1091. * either invoked or set their return flag, the current record is
  1092. * either committed or discarded. At that point, if any commands
  1093. * have deferred their triggers, those commands are finally
  1094. * invoked following the close of the current event. In other
  1095. * words, if the event_trigger_ops @func() probe implementation
  1096. * itself logs to the trace buffer, this flag should be set,
  1097. * otherwise it can be left unspecified.
  1098. *
  1099. * All the methods below, except for @set_filter(), must be
  1100. * implemented.
  1101. *
  1102. * @func: The callback function responsible for parsing and
  1103. * registering the trigger written to the 'trigger' file by the
  1104. * user. It allocates the trigger instance and registers it with
  1105. * the appropriate trace event. It makes use of the other
  1106. * event_command callback functions to orchestrate this, and is
  1107. * usually implemented by the generic utility function
  1108. * @event_trigger_callback() (see trace_event_triggers.c).
  1109. *
  1110. * @reg: Adds the trigger to the list of triggers associated with the
  1111. * event, and enables the event trigger itself, after
  1112. * initializing it (via the event_trigger_ops @init() function).
  1113. * This is also where commands can use the @trigger_type value to
  1114. * make the decision as to whether or not multiple instances of
  1115. * the trigger should be allowed. This is usually implemented by
  1116. * the generic utility function @register_trigger() (see
  1117. * trace_event_triggers.c).
  1118. *
  1119. * @unreg: Removes the trigger from the list of triggers associated
  1120. * with the event, and disables the event trigger itself, after
  1121. * initializing it (via the event_trigger_ops @free() function).
  1122. * This is usually implemented by the generic utility function
  1123. * @unregister_trigger() (see trace_event_triggers.c).
  1124. *
  1125. * @set_filter: An optional function called to parse and set a filter
  1126. * for the trigger. If no @set_filter() method is set for the
  1127. * event command, filters set by the user for the command will be
  1128. * ignored. This is usually implemented by the generic utility
  1129. * function @set_trigger_filter() (see trace_event_triggers.c).
  1130. *
  1131. * @get_trigger_ops: The callback function invoked to retrieve the
  1132. * event_trigger_ops implementation associated with the command.
  1133. */
  1134. struct event_command {
  1135. struct list_head list;
  1136. char *name;
  1137. enum event_trigger_type trigger_type;
  1138. bool post_trigger;
  1139. int (*func)(struct event_command *cmd_ops,
  1140. struct trace_event_file *file,
  1141. char *glob, char *cmd, char *params);
  1142. int (*reg)(char *glob,
  1143. struct event_trigger_ops *ops,
  1144. struct event_trigger_data *data,
  1145. struct trace_event_file *file);
  1146. void (*unreg)(char *glob,
  1147. struct event_trigger_ops *ops,
  1148. struct event_trigger_data *data,
  1149. struct trace_event_file *file);
  1150. int (*set_filter)(char *filter_str,
  1151. struct event_trigger_data *data,
  1152. struct trace_event_file *file);
  1153. struct event_trigger_ops *(*get_trigger_ops)(char *cmd, char *param);
  1154. };
  1155. extern int trace_event_enable_disable(struct trace_event_file *file,
  1156. int enable, int soft_disable);
  1157. extern int tracing_alloc_snapshot(void);
  1158. extern const char *__start___trace_bprintk_fmt[];
  1159. extern const char *__stop___trace_bprintk_fmt[];
  1160. extern const char *__start___tracepoint_str[];
  1161. extern const char *__stop___tracepoint_str[];
  1162. void trace_printk_control(bool enabled);
  1163. void trace_printk_init_buffers(void);
  1164. void trace_printk_start_comm(void);
  1165. int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
  1166. int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
  1167. /*
  1168. * Normal trace_printk() and friends allocates special buffers
  1169. * to do the manipulation, as well as saves the print formats
  1170. * into sections to display. But the trace infrastructure wants
  1171. * to use these without the added overhead at the price of being
  1172. * a bit slower (used mainly for warnings, where we don't care
  1173. * about performance). The internal_trace_puts() is for such
  1174. * a purpose.
  1175. */
  1176. #define internal_trace_puts(str) __trace_puts(_THIS_IP_, str, strlen(str))
  1177. #undef FTRACE_ENTRY
  1178. #define FTRACE_ENTRY(call, struct_name, id, tstruct, print, filter) \
  1179. extern struct trace_event_call \
  1180. __aligned(4) event_##call;
  1181. #undef FTRACE_ENTRY_DUP
  1182. #define FTRACE_ENTRY_DUP(call, struct_name, id, tstruct, print, filter) \
  1183. FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print), \
  1184. filter)
  1185. #include "trace_entries.h"
  1186. #if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_FUNCTION_TRACER)
  1187. int perf_ftrace_event_register(struct trace_event_call *call,
  1188. enum trace_reg type, void *data);
  1189. #else
  1190. #define perf_ftrace_event_register NULL
  1191. #endif
  1192. #ifdef CONFIG_FTRACE_SYSCALLS
  1193. void init_ftrace_syscalls(void);
  1194. #else
  1195. static inline void init_ftrace_syscalls(void) { }
  1196. #endif
  1197. #ifdef CONFIG_EVENT_TRACING
  1198. void trace_event_init(void);
  1199. void trace_event_enum_update(struct trace_enum_map **map, int len);
  1200. #else
  1201. static inline void __init trace_event_init(void) { }
  1202. static inline void trace_event_enum_update(struct trace_enum_map **map, int len) { }
  1203. #endif
  1204. extern struct trace_iterator *tracepoint_print_iter;
  1205. #endif /* _LINUX_KERNEL_TRACE_H */