trace.h 44 KB

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