trace.h 40 KB

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