trace.h 39 KB

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