trace.h 40 KB

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