trace.h 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633
  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. int pid_max;
  148. unsigned long *pids;
  149. };
  150. /*
  151. * The trace array - an array of per-CPU trace arrays. This is the
  152. * highest level data structure that individual tracers deal with.
  153. * They have on/off state as well:
  154. */
  155. struct trace_array {
  156. struct list_head list;
  157. char *name;
  158. struct trace_buffer trace_buffer;
  159. #ifdef CONFIG_TRACER_MAX_TRACE
  160. /*
  161. * The max_buffer is used to snapshot the trace when a maximum
  162. * latency is reached, or when the user initiates a snapshot.
  163. * Some tracers will use this to store a maximum trace while
  164. * it continues examining live traces.
  165. *
  166. * The buffers for the max_buffer are set up the same as the trace_buffer
  167. * When a snapshot is taken, the buffer of the max_buffer is swapped
  168. * with the buffer of the trace_buffer and the buffers are reset for
  169. * the trace_buffer so the tracing can continue.
  170. */
  171. struct trace_buffer max_buffer;
  172. bool allocated_snapshot;
  173. unsigned long max_latency;
  174. #endif
  175. struct trace_pid_list __rcu *filtered_pids;
  176. /*
  177. * max_lock is used to protect the swapping of buffers
  178. * when taking a max snapshot. The buffers themselves are
  179. * protected by per_cpu spinlocks. But the action of the swap
  180. * needs its own lock.
  181. *
  182. * This is defined as a arch_spinlock_t in order to help
  183. * with performance when lockdep debugging is enabled.
  184. *
  185. * It is also used in other places outside the update_max_tr
  186. * so it needs to be defined outside of the
  187. * CONFIG_TRACER_MAX_TRACE.
  188. */
  189. arch_spinlock_t max_lock;
  190. int buffer_disabled;
  191. #ifdef CONFIG_FTRACE_SYSCALLS
  192. int sys_refcount_enter;
  193. int sys_refcount_exit;
  194. struct trace_event_file __rcu *enter_syscall_files[NR_syscalls];
  195. struct trace_event_file __rcu *exit_syscall_files[NR_syscalls];
  196. #endif
  197. int stop_count;
  198. int clock_id;
  199. int nr_topts;
  200. struct tracer *current_trace;
  201. unsigned int trace_flags;
  202. unsigned char trace_flags_index[TRACE_FLAGS_MAX_SIZE];
  203. unsigned int flags;
  204. raw_spinlock_t start_lock;
  205. struct dentry *dir;
  206. struct dentry *options;
  207. struct dentry *percpu_dir;
  208. struct dentry *event_dir;
  209. struct trace_options *topts;
  210. struct list_head systems;
  211. struct list_head events;
  212. cpumask_var_t tracing_cpumask; /* only trace on set CPUs */
  213. int ref;
  214. #ifdef CONFIG_FUNCTION_TRACER
  215. struct ftrace_ops *ops;
  216. /* function tracing enabled */
  217. int function_enabled;
  218. #endif
  219. };
  220. enum {
  221. TRACE_ARRAY_FL_GLOBAL = (1 << 0)
  222. };
  223. extern struct list_head ftrace_trace_arrays;
  224. extern struct mutex trace_types_lock;
  225. extern int trace_array_get(struct trace_array *tr);
  226. extern void trace_array_put(struct trace_array *tr);
  227. /*
  228. * The global tracer (top) should be the first trace array added,
  229. * but we check the flag anyway.
  230. */
  231. static inline struct trace_array *top_trace_array(void)
  232. {
  233. struct trace_array *tr;
  234. if (list_empty(&ftrace_trace_arrays))
  235. return NULL;
  236. tr = list_entry(ftrace_trace_arrays.prev,
  237. typeof(*tr), list);
  238. WARN_ON(!(tr->flags & TRACE_ARRAY_FL_GLOBAL));
  239. return tr;
  240. }
  241. #define FTRACE_CMP_TYPE(var, type) \
  242. __builtin_types_compatible_p(typeof(var), type *)
  243. #undef IF_ASSIGN
  244. #define IF_ASSIGN(var, entry, etype, id) \
  245. if (FTRACE_CMP_TYPE(var, etype)) { \
  246. var = (typeof(var))(entry); \
  247. WARN_ON(id && (entry)->type != id); \
  248. break; \
  249. }
  250. /* Will cause compile errors if type is not found. */
  251. extern void __ftrace_bad_type(void);
  252. /*
  253. * The trace_assign_type is a verifier that the entry type is
  254. * the same as the type being assigned. To add new types simply
  255. * add a line with the following format:
  256. *
  257. * IF_ASSIGN(var, ent, type, id);
  258. *
  259. * Where "type" is the trace type that includes the trace_entry
  260. * as the "ent" item. And "id" is the trace identifier that is
  261. * used in the trace_type enum.
  262. *
  263. * If the type can have more than one id, then use zero.
  264. */
  265. #define trace_assign_type(var, ent) \
  266. do { \
  267. IF_ASSIGN(var, ent, struct ftrace_entry, TRACE_FN); \
  268. IF_ASSIGN(var, ent, struct ctx_switch_entry, 0); \
  269. IF_ASSIGN(var, ent, struct stack_entry, TRACE_STACK); \
  270. IF_ASSIGN(var, ent, struct userstack_entry, TRACE_USER_STACK);\
  271. IF_ASSIGN(var, ent, struct print_entry, TRACE_PRINT); \
  272. IF_ASSIGN(var, ent, struct bprint_entry, TRACE_BPRINT); \
  273. IF_ASSIGN(var, ent, struct bputs_entry, TRACE_BPUTS); \
  274. IF_ASSIGN(var, ent, struct trace_mmiotrace_rw, \
  275. TRACE_MMIO_RW); \
  276. IF_ASSIGN(var, ent, struct trace_mmiotrace_map, \
  277. TRACE_MMIO_MAP); \
  278. IF_ASSIGN(var, ent, struct trace_branch, TRACE_BRANCH); \
  279. IF_ASSIGN(var, ent, struct ftrace_graph_ent_entry, \
  280. TRACE_GRAPH_ENT); \
  281. IF_ASSIGN(var, ent, struct ftrace_graph_ret_entry, \
  282. TRACE_GRAPH_RET); \
  283. __ftrace_bad_type(); \
  284. } while (0)
  285. /*
  286. * An option specific to a tracer. This is a boolean value.
  287. * The bit is the bit index that sets its value on the
  288. * flags value in struct tracer_flags.
  289. */
  290. struct tracer_opt {
  291. const char *name; /* Will appear on the trace_options file */
  292. u32 bit; /* Mask assigned in val field in tracer_flags */
  293. };
  294. /*
  295. * The set of specific options for a tracer. Your tracer
  296. * have to set the initial value of the flags val.
  297. */
  298. struct tracer_flags {
  299. u32 val;
  300. struct tracer_opt *opts;
  301. struct tracer *trace;
  302. };
  303. /* Makes more easy to define a tracer opt */
  304. #define TRACER_OPT(s, b) .name = #s, .bit = b
  305. struct trace_option_dentry {
  306. struct tracer_opt *opt;
  307. struct tracer_flags *flags;
  308. struct trace_array *tr;
  309. struct dentry *entry;
  310. };
  311. /**
  312. * struct tracer - a specific tracer and its callbacks to interact with tracefs
  313. * @name: the name chosen to select it on the available_tracers file
  314. * @init: called when one switches to this tracer (echo name > current_tracer)
  315. * @reset: called when one switches to another tracer
  316. * @start: called when tracing is unpaused (echo 1 > tracing_on)
  317. * @stop: called when tracing is paused (echo 0 > tracing_on)
  318. * @update_thresh: called when tracing_thresh is updated
  319. * @open: called when the trace file is opened
  320. * @pipe_open: called when the trace_pipe file is opened
  321. * @close: called when the trace file is released
  322. * @pipe_close: called when the trace_pipe file is released
  323. * @read: override the default read callback on trace_pipe
  324. * @splice_read: override the default splice_read callback on trace_pipe
  325. * @selftest: selftest to run on boot (see trace_selftest.c)
  326. * @print_headers: override the first lines that describe your columns
  327. * @print_line: callback that prints a trace
  328. * @set_flag: signals one of your private flags changed (trace_options file)
  329. * @flags: your private flags
  330. */
  331. struct tracer {
  332. const char *name;
  333. int (*init)(struct trace_array *tr);
  334. void (*reset)(struct trace_array *tr);
  335. void (*start)(struct trace_array *tr);
  336. void (*stop)(struct trace_array *tr);
  337. int (*update_thresh)(struct trace_array *tr);
  338. void (*open)(struct trace_iterator *iter);
  339. void (*pipe_open)(struct trace_iterator *iter);
  340. void (*close)(struct trace_iterator *iter);
  341. void (*pipe_close)(struct trace_iterator *iter);
  342. ssize_t (*read)(struct trace_iterator *iter,
  343. struct file *filp, char __user *ubuf,
  344. size_t cnt, loff_t *ppos);
  345. ssize_t (*splice_read)(struct trace_iterator *iter,
  346. struct file *filp,
  347. loff_t *ppos,
  348. struct pipe_inode_info *pipe,
  349. size_t len,
  350. unsigned int flags);
  351. #ifdef CONFIG_FTRACE_STARTUP_TEST
  352. int (*selftest)(struct tracer *trace,
  353. struct trace_array *tr);
  354. #endif
  355. void (*print_header)(struct seq_file *m);
  356. enum print_line_t (*print_line)(struct trace_iterator *iter);
  357. /* If you handled the flag setting, return 0 */
  358. int (*set_flag)(struct trace_array *tr,
  359. u32 old_flags, u32 bit, int set);
  360. /* Return 0 if OK with change, else return non-zero */
  361. int (*flag_changed)(struct trace_array *tr,
  362. u32 mask, int set);
  363. struct tracer *next;
  364. struct tracer_flags *flags;
  365. int enabled;
  366. int ref;
  367. bool print_max;
  368. bool allow_instances;
  369. #ifdef CONFIG_TRACER_MAX_TRACE
  370. bool use_max_tr;
  371. #endif
  372. };
  373. /* Only current can touch trace_recursion */
  374. /*
  375. * For function tracing recursion:
  376. * The order of these bits are important.
  377. *
  378. * When function tracing occurs, the following steps are made:
  379. * If arch does not support a ftrace feature:
  380. * call internal function (uses INTERNAL bits) which calls...
  381. * If callback is registered to the "global" list, the list
  382. * function is called and recursion checks the GLOBAL bits.
  383. * then this function calls...
  384. * The function callback, which can use the FTRACE bits to
  385. * check for recursion.
  386. *
  387. * Now if the arch does not suppport a feature, and it calls
  388. * the global list function which calls the ftrace callback
  389. * all three of these steps will do a recursion protection.
  390. * There's no reason to do one if the previous caller already
  391. * did. The recursion that we are protecting against will
  392. * go through the same steps again.
  393. *
  394. * To prevent the multiple recursion checks, if a recursion
  395. * bit is set that is higher than the MAX bit of the current
  396. * check, then we know that the check was made by the previous
  397. * caller, and we can skip the current check.
  398. */
  399. enum {
  400. TRACE_BUFFER_BIT,
  401. TRACE_BUFFER_NMI_BIT,
  402. TRACE_BUFFER_IRQ_BIT,
  403. TRACE_BUFFER_SIRQ_BIT,
  404. /* Start of function recursion bits */
  405. TRACE_FTRACE_BIT,
  406. TRACE_FTRACE_NMI_BIT,
  407. TRACE_FTRACE_IRQ_BIT,
  408. TRACE_FTRACE_SIRQ_BIT,
  409. /* INTERNAL_BITs must be greater than FTRACE_BITs */
  410. TRACE_INTERNAL_BIT,
  411. TRACE_INTERNAL_NMI_BIT,
  412. TRACE_INTERNAL_IRQ_BIT,
  413. TRACE_INTERNAL_SIRQ_BIT,
  414. TRACE_BRANCH_BIT,
  415. /*
  416. * Abuse of the trace_recursion.
  417. * As we need a way to maintain state if we are tracing the function
  418. * graph in irq because we want to trace a particular function that
  419. * was called in irq context but we have irq tracing off. Since this
  420. * can only be modified by current, we can reuse trace_recursion.
  421. */
  422. TRACE_IRQ_BIT,
  423. };
  424. #define trace_recursion_set(bit) do { (current)->trace_recursion |= (1<<(bit)); } while (0)
  425. #define trace_recursion_clear(bit) do { (current)->trace_recursion &= ~(1<<(bit)); } while (0)
  426. #define trace_recursion_test(bit) ((current)->trace_recursion & (1<<(bit)))
  427. #define TRACE_CONTEXT_BITS 4
  428. #define TRACE_FTRACE_START TRACE_FTRACE_BIT
  429. #define TRACE_FTRACE_MAX ((1 << (TRACE_FTRACE_START + TRACE_CONTEXT_BITS)) - 1)
  430. #define TRACE_LIST_START TRACE_INTERNAL_BIT
  431. #define TRACE_LIST_MAX ((1 << (TRACE_LIST_START + TRACE_CONTEXT_BITS)) - 1)
  432. #define TRACE_CONTEXT_MASK TRACE_LIST_MAX
  433. static __always_inline int trace_get_context_bit(void)
  434. {
  435. int bit;
  436. if (in_interrupt()) {
  437. if (in_nmi())
  438. bit = 0;
  439. else if (in_irq())
  440. bit = 1;
  441. else
  442. bit = 2;
  443. } else
  444. bit = 3;
  445. return bit;
  446. }
  447. static __always_inline int trace_test_and_set_recursion(int start, int max)
  448. {
  449. unsigned int val = current->trace_recursion;
  450. int bit;
  451. /* A previous recursion check was made */
  452. if ((val & TRACE_CONTEXT_MASK) > max)
  453. return 0;
  454. bit = trace_get_context_bit() + start;
  455. if (unlikely(val & (1 << bit)))
  456. return -1;
  457. val |= 1 << bit;
  458. current->trace_recursion = val;
  459. barrier();
  460. return bit;
  461. }
  462. static __always_inline void trace_clear_recursion(int bit)
  463. {
  464. unsigned int val = current->trace_recursion;
  465. if (!bit)
  466. return;
  467. bit = 1 << bit;
  468. val &= ~bit;
  469. barrier();
  470. current->trace_recursion = val;
  471. }
  472. static inline struct ring_buffer_iter *
  473. trace_buffer_iter(struct trace_iterator *iter, int cpu)
  474. {
  475. if (iter->buffer_iter && iter->buffer_iter[cpu])
  476. return iter->buffer_iter[cpu];
  477. return NULL;
  478. }
  479. int tracer_init(struct tracer *t, struct trace_array *tr);
  480. int tracing_is_enabled(void);
  481. void tracing_reset(struct trace_buffer *buf, int cpu);
  482. void tracing_reset_online_cpus(struct trace_buffer *buf);
  483. void tracing_reset_current(int cpu);
  484. void tracing_reset_all_online_cpus(void);
  485. int tracing_open_generic(struct inode *inode, struct file *filp);
  486. bool tracing_is_disabled(void);
  487. struct dentry *trace_create_file(const char *name,
  488. umode_t mode,
  489. struct dentry *parent,
  490. void *data,
  491. const struct file_operations *fops);
  492. struct dentry *tracing_init_dentry(void);
  493. struct ring_buffer_event;
  494. struct ring_buffer_event *
  495. trace_buffer_lock_reserve(struct ring_buffer *buffer,
  496. int type,
  497. unsigned long len,
  498. unsigned long flags,
  499. int pc);
  500. struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
  501. struct trace_array_cpu *data);
  502. struct trace_entry *trace_find_next_entry(struct trace_iterator *iter,
  503. int *ent_cpu, u64 *ent_ts);
  504. void __buffer_unlock_commit(struct ring_buffer *buffer,
  505. struct ring_buffer_event *event);
  506. int trace_empty(struct trace_iterator *iter);
  507. void *trace_find_next_entry_inc(struct trace_iterator *iter);
  508. void trace_init_global_iter(struct trace_iterator *iter);
  509. void tracing_iter_reset(struct trace_iterator *iter, int cpu);
  510. void trace_function(struct trace_array *tr,
  511. unsigned long ip,
  512. unsigned long parent_ip,
  513. unsigned long flags, int pc);
  514. void trace_graph_function(struct trace_array *tr,
  515. unsigned long ip,
  516. unsigned long parent_ip,
  517. unsigned long flags, int pc);
  518. void trace_latency_header(struct seq_file *m);
  519. void trace_default_header(struct seq_file *m);
  520. void print_trace_header(struct seq_file *m, struct trace_iterator *iter);
  521. int trace_empty(struct trace_iterator *iter);
  522. void trace_graph_return(struct ftrace_graph_ret *trace);
  523. int trace_graph_entry(struct ftrace_graph_ent *trace);
  524. void set_graph_array(struct trace_array *tr);
  525. void tracing_start_cmdline_record(void);
  526. void tracing_stop_cmdline_record(void);
  527. int register_tracer(struct tracer *type);
  528. int is_tracing_stopped(void);
  529. loff_t tracing_lseek(struct file *file, loff_t offset, int whence);
  530. extern cpumask_var_t __read_mostly tracing_buffer_mask;
  531. #define for_each_tracing_cpu(cpu) \
  532. for_each_cpu(cpu, tracing_buffer_mask)
  533. extern unsigned long nsecs_to_usecs(unsigned long nsecs);
  534. extern unsigned long tracing_thresh;
  535. #ifdef CONFIG_TRACER_MAX_TRACE
  536. void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
  537. void update_max_tr_single(struct trace_array *tr,
  538. struct task_struct *tsk, int cpu);
  539. #endif /* CONFIG_TRACER_MAX_TRACE */
  540. #ifdef CONFIG_STACKTRACE
  541. void ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags,
  542. int pc);
  543. void __trace_stack(struct trace_array *tr, unsigned long flags, int skip,
  544. int pc);
  545. #else
  546. static inline void ftrace_trace_userstack(struct ring_buffer *buffer,
  547. unsigned long flags, int pc)
  548. {
  549. }
  550. static inline void __trace_stack(struct trace_array *tr, unsigned long flags,
  551. int skip, int pc)
  552. {
  553. }
  554. #endif /* CONFIG_STACKTRACE */
  555. extern cycle_t ftrace_now(int cpu);
  556. extern void trace_find_cmdline(int pid, char comm[]);
  557. extern void trace_event_follow_fork(struct trace_array *tr, bool enable);
  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. C(EVENT_FORK, "event-fork"), \
  835. FUNCTION_FLAGS \
  836. FGRAPH_FLAGS \
  837. STACK_FLAGS \
  838. BRANCH_FLAGS
  839. /*
  840. * By defining C, we can make TRACE_FLAGS a list of bit names
  841. * that will define the bits for the flag masks.
  842. */
  843. #undef C
  844. #define C(a, b) TRACE_ITER_##a##_BIT
  845. enum trace_iterator_bits {
  846. TRACE_FLAGS
  847. /* Make sure we don't go more than we have bits for */
  848. TRACE_ITER_LAST_BIT
  849. };
  850. /*
  851. * By redefining C, we can make TRACE_FLAGS a list of masks that
  852. * use the bits as defined above.
  853. */
  854. #undef C
  855. #define C(a, b) TRACE_ITER_##a = (1 << TRACE_ITER_##a##_BIT)
  856. enum trace_iterator_flags { TRACE_FLAGS };
  857. /*
  858. * TRACE_ITER_SYM_MASK masks the options in trace_flags that
  859. * control the output of kernel symbols.
  860. */
  861. #define TRACE_ITER_SYM_MASK \
  862. (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR)
  863. extern struct tracer nop_trace;
  864. #ifdef CONFIG_BRANCH_TRACER
  865. extern int enable_branch_tracing(struct trace_array *tr);
  866. extern void disable_branch_tracing(void);
  867. static inline int trace_branch_enable(struct trace_array *tr)
  868. {
  869. if (tr->trace_flags & TRACE_ITER_BRANCH)
  870. return enable_branch_tracing(tr);
  871. return 0;
  872. }
  873. static inline void trace_branch_disable(void)
  874. {
  875. /* due to races, always disable */
  876. disable_branch_tracing();
  877. }
  878. #else
  879. static inline int trace_branch_enable(struct trace_array *tr)
  880. {
  881. return 0;
  882. }
  883. static inline void trace_branch_disable(void)
  884. {
  885. }
  886. #endif /* CONFIG_BRANCH_TRACER */
  887. /* set ring buffers to default size if not already done so */
  888. int tracing_update_buffers(void);
  889. struct ftrace_event_field {
  890. struct list_head link;
  891. const char *name;
  892. const char *type;
  893. int filter_type;
  894. int offset;
  895. int size;
  896. int is_signed;
  897. };
  898. struct event_filter {
  899. int n_preds; /* Number assigned */
  900. int a_preds; /* allocated */
  901. struct filter_pred *preds;
  902. struct filter_pred *root;
  903. char *filter_string;
  904. };
  905. struct event_subsystem {
  906. struct list_head list;
  907. const char *name;
  908. struct event_filter *filter;
  909. int ref_count;
  910. };
  911. struct trace_subsystem_dir {
  912. struct list_head list;
  913. struct event_subsystem *subsystem;
  914. struct trace_array *tr;
  915. struct dentry *entry;
  916. int ref_count;
  917. int nr_events;
  918. };
  919. extern int call_filter_check_discard(struct trace_event_call *call, void *rec,
  920. struct ring_buffer *buffer,
  921. struct ring_buffer_event *event);
  922. void trace_buffer_unlock_commit_regs(struct trace_array *tr,
  923. struct ring_buffer *buffer,
  924. struct ring_buffer_event *event,
  925. unsigned long flags, int pc,
  926. struct pt_regs *regs);
  927. static inline void trace_buffer_unlock_commit(struct trace_array *tr,
  928. struct ring_buffer *buffer,
  929. struct ring_buffer_event *event,
  930. unsigned long flags, int pc)
  931. {
  932. trace_buffer_unlock_commit_regs(tr, buffer, event, flags, pc, NULL);
  933. }
  934. DECLARE_PER_CPU(struct ring_buffer_event *, trace_buffered_event);
  935. DECLARE_PER_CPU(int, trace_buffered_event_cnt);
  936. void trace_buffered_event_disable(void);
  937. void trace_buffered_event_enable(void);
  938. static inline void
  939. __trace_event_discard_commit(struct ring_buffer *buffer,
  940. struct ring_buffer_event *event)
  941. {
  942. if (this_cpu_read(trace_buffered_event) == event) {
  943. /* Simply release the temp buffer */
  944. this_cpu_dec(trace_buffered_event_cnt);
  945. return;
  946. }
  947. ring_buffer_discard_commit(buffer, event);
  948. }
  949. /*
  950. * Helper function for event_trigger_unlock_commit{_regs}().
  951. * If there are event triggers attached to this event that requires
  952. * filtering against its fields, then they wil be called as the
  953. * entry already holds the field information of the current event.
  954. *
  955. * It also checks if the event should be discarded or not.
  956. * It is to be discarded if the event is soft disabled and the
  957. * event was only recorded to process triggers, or if the event
  958. * filter is active and this event did not match the filters.
  959. *
  960. * Returns true if the event is discarded, false otherwise.
  961. */
  962. static inline bool
  963. __event_trigger_test_discard(struct trace_event_file *file,
  964. struct ring_buffer *buffer,
  965. struct ring_buffer_event *event,
  966. void *entry,
  967. enum event_trigger_type *tt)
  968. {
  969. unsigned long eflags = file->flags;
  970. if (eflags & EVENT_FILE_FL_TRIGGER_COND)
  971. *tt = event_triggers_call(file, entry);
  972. if (test_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &file->flags) ||
  973. (unlikely(file->flags & EVENT_FILE_FL_FILTERED) &&
  974. !filter_match_preds(file->filter, entry))) {
  975. __trace_event_discard_commit(buffer, event);
  976. return true;
  977. }
  978. return false;
  979. }
  980. /**
  981. * event_trigger_unlock_commit - handle triggers and finish event commit
  982. * @file: The file pointer assoctiated to the event
  983. * @buffer: The ring buffer that the event is being written to
  984. * @event: The event meta data in the ring buffer
  985. * @entry: The event itself
  986. * @irq_flags: The state of the interrupts at the start of the event
  987. * @pc: The state of the preempt count at the start of the event.
  988. *
  989. * This is a helper function to handle triggers that require data
  990. * from the event itself. It also tests the event against filters and
  991. * if the event is soft disabled and should be discarded.
  992. */
  993. static inline void
  994. event_trigger_unlock_commit(struct trace_event_file *file,
  995. struct ring_buffer *buffer,
  996. struct ring_buffer_event *event,
  997. void *entry, unsigned long irq_flags, int pc)
  998. {
  999. enum event_trigger_type tt = ETT_NONE;
  1000. if (!__event_trigger_test_discard(file, buffer, event, entry, &tt))
  1001. trace_buffer_unlock_commit(file->tr, buffer, event, irq_flags, pc);
  1002. if (tt)
  1003. event_triggers_post_call(file, tt, entry);
  1004. }
  1005. /**
  1006. * event_trigger_unlock_commit_regs - handle triggers and finish event commit
  1007. * @file: The file pointer assoctiated to the event
  1008. * @buffer: The ring buffer that the event is being written to
  1009. * @event: The event meta data in the ring buffer
  1010. * @entry: The event itself
  1011. * @irq_flags: The state of the interrupts at the start of the event
  1012. * @pc: The state of the preempt count at the start of the event.
  1013. *
  1014. * This is a helper function to handle triggers that require data
  1015. * from the event itself. It also tests the event against filters and
  1016. * if the event is soft disabled and should be discarded.
  1017. *
  1018. * Same as event_trigger_unlock_commit() but calls
  1019. * trace_buffer_unlock_commit_regs() instead of trace_buffer_unlock_commit().
  1020. */
  1021. static inline void
  1022. event_trigger_unlock_commit_regs(struct trace_event_file *file,
  1023. struct ring_buffer *buffer,
  1024. struct ring_buffer_event *event,
  1025. void *entry, unsigned long irq_flags, int pc,
  1026. struct pt_regs *regs)
  1027. {
  1028. enum event_trigger_type tt = ETT_NONE;
  1029. if (!__event_trigger_test_discard(file, buffer, event, entry, &tt))
  1030. trace_buffer_unlock_commit_regs(file->tr, buffer, event,
  1031. irq_flags, pc, regs);
  1032. if (tt)
  1033. event_triggers_post_call(file, tt, entry);
  1034. }
  1035. #define FILTER_PRED_INVALID ((unsigned short)-1)
  1036. #define FILTER_PRED_IS_RIGHT (1 << 15)
  1037. #define FILTER_PRED_FOLD (1 << 15)
  1038. /*
  1039. * The max preds is the size of unsigned short with
  1040. * two flags at the MSBs. One bit is used for both the IS_RIGHT
  1041. * and FOLD flags. The other is reserved.
  1042. *
  1043. * 2^14 preds is way more than enough.
  1044. */
  1045. #define MAX_FILTER_PRED 16384
  1046. struct filter_pred;
  1047. struct regex;
  1048. typedef int (*filter_pred_fn_t) (struct filter_pred *pred, void *event);
  1049. typedef int (*regex_match_func)(char *str, struct regex *r, int len);
  1050. enum regex_type {
  1051. MATCH_FULL = 0,
  1052. MATCH_FRONT_ONLY,
  1053. MATCH_MIDDLE_ONLY,
  1054. MATCH_END_ONLY,
  1055. };
  1056. struct regex {
  1057. char pattern[MAX_FILTER_STR_VAL];
  1058. int len;
  1059. int field_len;
  1060. regex_match_func match;
  1061. };
  1062. struct filter_pred {
  1063. filter_pred_fn_t fn;
  1064. u64 val;
  1065. struct regex regex;
  1066. unsigned short *ops;
  1067. struct ftrace_event_field *field;
  1068. int offset;
  1069. int not;
  1070. int op;
  1071. unsigned short index;
  1072. unsigned short parent;
  1073. unsigned short left;
  1074. unsigned short right;
  1075. };
  1076. static inline bool is_string_field(struct ftrace_event_field *field)
  1077. {
  1078. return field->filter_type == FILTER_DYN_STRING ||
  1079. field->filter_type == FILTER_STATIC_STRING ||
  1080. field->filter_type == FILTER_PTR_STRING;
  1081. }
  1082. static inline bool is_function_field(struct ftrace_event_field *field)
  1083. {
  1084. return field->filter_type == FILTER_TRACE_FN;
  1085. }
  1086. extern enum regex_type
  1087. filter_parse_regex(char *buff, int len, char **search, int *not);
  1088. extern void print_event_filter(struct trace_event_file *file,
  1089. struct trace_seq *s);
  1090. extern int apply_event_filter(struct trace_event_file *file,
  1091. char *filter_string);
  1092. extern int apply_subsystem_event_filter(struct trace_subsystem_dir *dir,
  1093. char *filter_string);
  1094. extern void print_subsystem_event_filter(struct event_subsystem *system,
  1095. struct trace_seq *s);
  1096. extern int filter_assign_type(const char *type);
  1097. extern int create_event_filter(struct trace_event_call *call,
  1098. char *filter_str, bool set_str,
  1099. struct event_filter **filterp);
  1100. extern void free_event_filter(struct event_filter *filter);
  1101. struct ftrace_event_field *
  1102. trace_find_event_field(struct trace_event_call *call, char *name);
  1103. extern void trace_event_enable_cmd_record(bool enable);
  1104. extern int event_trace_add_tracer(struct dentry *parent, struct trace_array *tr);
  1105. extern int event_trace_del_tracer(struct trace_array *tr);
  1106. extern struct trace_event_file *find_event_file(struct trace_array *tr,
  1107. const char *system,
  1108. const char *event);
  1109. static inline void *event_file_data(struct file *filp)
  1110. {
  1111. return ACCESS_ONCE(file_inode(filp)->i_private);
  1112. }
  1113. extern struct mutex event_mutex;
  1114. extern struct list_head ftrace_events;
  1115. extern const struct file_operations event_trigger_fops;
  1116. extern const struct file_operations event_hist_fops;
  1117. #ifdef CONFIG_HIST_TRIGGERS
  1118. extern int register_trigger_hist_cmd(void);
  1119. extern int register_trigger_hist_enable_disable_cmds(void);
  1120. #else
  1121. static inline int register_trigger_hist_cmd(void) { return 0; }
  1122. static inline int register_trigger_hist_enable_disable_cmds(void) { return 0; }
  1123. #endif
  1124. extern int register_trigger_cmds(void);
  1125. extern void clear_event_triggers(struct trace_array *tr);
  1126. struct event_trigger_data {
  1127. unsigned long count;
  1128. int ref;
  1129. struct event_trigger_ops *ops;
  1130. struct event_command *cmd_ops;
  1131. struct event_filter __rcu *filter;
  1132. char *filter_str;
  1133. void *private_data;
  1134. bool paused;
  1135. bool paused_tmp;
  1136. struct list_head list;
  1137. char *name;
  1138. struct list_head named_list;
  1139. struct event_trigger_data *named_data;
  1140. };
  1141. /* Avoid typos */
  1142. #define ENABLE_EVENT_STR "enable_event"
  1143. #define DISABLE_EVENT_STR "disable_event"
  1144. #define ENABLE_HIST_STR "enable_hist"
  1145. #define DISABLE_HIST_STR "disable_hist"
  1146. struct enable_trigger_data {
  1147. struct trace_event_file *file;
  1148. bool enable;
  1149. bool hist;
  1150. };
  1151. extern int event_enable_trigger_print(struct seq_file *m,
  1152. struct event_trigger_ops *ops,
  1153. struct event_trigger_data *data);
  1154. extern void event_enable_trigger_free(struct event_trigger_ops *ops,
  1155. struct event_trigger_data *data);
  1156. extern int event_enable_trigger_func(struct event_command *cmd_ops,
  1157. struct trace_event_file *file,
  1158. char *glob, char *cmd, char *param);
  1159. extern int event_enable_register_trigger(char *glob,
  1160. struct event_trigger_ops *ops,
  1161. struct event_trigger_data *data,
  1162. struct trace_event_file *file);
  1163. extern void event_enable_unregister_trigger(char *glob,
  1164. struct event_trigger_ops *ops,
  1165. struct event_trigger_data *test,
  1166. struct trace_event_file *file);
  1167. extern void trigger_data_free(struct event_trigger_data *data);
  1168. extern int event_trigger_init(struct event_trigger_ops *ops,
  1169. struct event_trigger_data *data);
  1170. extern int trace_event_trigger_enable_disable(struct trace_event_file *file,
  1171. int trigger_enable);
  1172. extern void update_cond_flag(struct trace_event_file *file);
  1173. extern void unregister_trigger(char *glob, struct event_trigger_ops *ops,
  1174. struct event_trigger_data *test,
  1175. struct trace_event_file *file);
  1176. extern int set_trigger_filter(char *filter_str,
  1177. struct event_trigger_data *trigger_data,
  1178. struct trace_event_file *file);
  1179. extern struct event_trigger_data *find_named_trigger(const char *name);
  1180. extern bool is_named_trigger(struct event_trigger_data *test);
  1181. extern int save_named_trigger(const char *name,
  1182. struct event_trigger_data *data);
  1183. extern void del_named_trigger(struct event_trigger_data *data);
  1184. extern void pause_named_trigger(struct event_trigger_data *data);
  1185. extern void unpause_named_trigger(struct event_trigger_data *data);
  1186. extern void set_named_trigger_data(struct event_trigger_data *data,
  1187. struct event_trigger_data *named_data);
  1188. extern int register_event_command(struct event_command *cmd);
  1189. extern int unregister_event_command(struct event_command *cmd);
  1190. extern int register_trigger_hist_enable_disable_cmds(void);
  1191. /**
  1192. * struct event_trigger_ops - callbacks for trace event triggers
  1193. *
  1194. * The methods in this structure provide per-event trigger hooks for
  1195. * various trigger operations.
  1196. *
  1197. * All the methods below, except for @init() and @free(), must be
  1198. * implemented.
  1199. *
  1200. * @func: The trigger 'probe' function called when the triggering
  1201. * event occurs. The data passed into this callback is the data
  1202. * that was supplied to the event_command @reg() function that
  1203. * registered the trigger (see struct event_command) along with
  1204. * the trace record, rec.
  1205. *
  1206. * @init: An optional initialization function called for the trigger
  1207. * when the trigger is registered (via the event_command reg()
  1208. * function). This can be used to perform per-trigger
  1209. * initialization such as incrementing a per-trigger reference
  1210. * count, for instance. This is usually implemented by the
  1211. * generic utility function @event_trigger_init() (see
  1212. * trace_event_triggers.c).
  1213. *
  1214. * @free: An optional de-initialization function called for the
  1215. * trigger when the trigger is unregistered (via the
  1216. * event_command @reg() function). This can be used to perform
  1217. * per-trigger de-initialization such as decrementing a
  1218. * per-trigger reference count and freeing corresponding trigger
  1219. * data, for instance. This is usually implemented by the
  1220. * generic utility function @event_trigger_free() (see
  1221. * trace_event_triggers.c).
  1222. *
  1223. * @print: The callback function invoked to have the trigger print
  1224. * itself. This is usually implemented by a wrapper function
  1225. * that calls the generic utility function @event_trigger_print()
  1226. * (see trace_event_triggers.c).
  1227. */
  1228. struct event_trigger_ops {
  1229. void (*func)(struct event_trigger_data *data,
  1230. void *rec);
  1231. int (*init)(struct event_trigger_ops *ops,
  1232. struct event_trigger_data *data);
  1233. void (*free)(struct event_trigger_ops *ops,
  1234. struct event_trigger_data *data);
  1235. int (*print)(struct seq_file *m,
  1236. struct event_trigger_ops *ops,
  1237. struct event_trigger_data *data);
  1238. };
  1239. /**
  1240. * struct event_command - callbacks and data members for event commands
  1241. *
  1242. * Event commands are invoked by users by writing the command name
  1243. * into the 'trigger' file associated with a trace event. The
  1244. * parameters associated with a specific invocation of an event
  1245. * command are used to create an event trigger instance, which is
  1246. * added to the list of trigger instances associated with that trace
  1247. * event. When the event is hit, the set of triggers associated with
  1248. * that event is invoked.
  1249. *
  1250. * The data members in this structure provide per-event command data
  1251. * for various event commands.
  1252. *
  1253. * All the data members below, except for @post_trigger, must be set
  1254. * for each event command.
  1255. *
  1256. * @name: The unique name that identifies the event command. This is
  1257. * the name used when setting triggers via trigger files.
  1258. *
  1259. * @trigger_type: A unique id that identifies the event command
  1260. * 'type'. This value has two purposes, the first to ensure that
  1261. * only one trigger of the same type can be set at a given time
  1262. * for a particular event e.g. it doesn't make sense to have both
  1263. * a traceon and traceoff trigger attached to a single event at
  1264. * the same time, so traceon and traceoff have the same type
  1265. * though they have different names. The @trigger_type value is
  1266. * also used as a bit value for deferring the actual trigger
  1267. * action until after the current event is finished. Some
  1268. * commands need to do this if they themselves log to the trace
  1269. * buffer (see the @post_trigger() member below). @trigger_type
  1270. * values are defined by adding new values to the trigger_type
  1271. * enum in include/linux/trace_events.h.
  1272. *
  1273. * @flags: See the enum event_command_flags below.
  1274. *
  1275. * All the methods below, except for @set_filter() and @unreg_all(),
  1276. * must be implemented.
  1277. *
  1278. * @func: The callback function responsible for parsing and
  1279. * registering the trigger written to the 'trigger' file by the
  1280. * user. It allocates the trigger instance and registers it with
  1281. * the appropriate trace event. It makes use of the other
  1282. * event_command callback functions to orchestrate this, and is
  1283. * usually implemented by the generic utility function
  1284. * @event_trigger_callback() (see trace_event_triggers.c).
  1285. *
  1286. * @reg: Adds the trigger to the list of triggers associated with the
  1287. * event, and enables the event trigger itself, after
  1288. * initializing it (via the event_trigger_ops @init() function).
  1289. * This is also where commands can use the @trigger_type value to
  1290. * make the decision as to whether or not multiple instances of
  1291. * the trigger should be allowed. This is usually implemented by
  1292. * the generic utility function @register_trigger() (see
  1293. * trace_event_triggers.c).
  1294. *
  1295. * @unreg: Removes the trigger from the list of triggers associated
  1296. * with the event, and disables the event trigger itself, after
  1297. * initializing it (via the event_trigger_ops @free() function).
  1298. * This is usually implemented by the generic utility function
  1299. * @unregister_trigger() (see trace_event_triggers.c).
  1300. *
  1301. * @unreg_all: An optional function called to remove all the triggers
  1302. * from the list of triggers associated with the event. Called
  1303. * when a trigger file is opened in truncate mode.
  1304. *
  1305. * @set_filter: An optional function called to parse and set a filter
  1306. * for the trigger. If no @set_filter() method is set for the
  1307. * event command, filters set by the user for the command will be
  1308. * ignored. This is usually implemented by the generic utility
  1309. * function @set_trigger_filter() (see trace_event_triggers.c).
  1310. *
  1311. * @get_trigger_ops: The callback function invoked to retrieve the
  1312. * event_trigger_ops implementation associated with the command.
  1313. */
  1314. struct event_command {
  1315. struct list_head list;
  1316. char *name;
  1317. enum event_trigger_type trigger_type;
  1318. int flags;
  1319. int (*func)(struct event_command *cmd_ops,
  1320. struct trace_event_file *file,
  1321. char *glob, char *cmd, char *params);
  1322. int (*reg)(char *glob,
  1323. struct event_trigger_ops *ops,
  1324. struct event_trigger_data *data,
  1325. struct trace_event_file *file);
  1326. void (*unreg)(char *glob,
  1327. struct event_trigger_ops *ops,
  1328. struct event_trigger_data *data,
  1329. struct trace_event_file *file);
  1330. void (*unreg_all)(struct trace_event_file *file);
  1331. int (*set_filter)(char *filter_str,
  1332. struct event_trigger_data *data,
  1333. struct trace_event_file *file);
  1334. struct event_trigger_ops *(*get_trigger_ops)(char *cmd, char *param);
  1335. };
  1336. /**
  1337. * enum event_command_flags - flags for struct event_command
  1338. *
  1339. * @POST_TRIGGER: A flag that says whether or not this command needs
  1340. * to have its action delayed until after the current event has
  1341. * been closed. Some triggers need to avoid being invoked while
  1342. * an event is currently in the process of being logged, since
  1343. * the trigger may itself log data into the trace buffer. Thus
  1344. * we make sure the current event is committed before invoking
  1345. * those triggers. To do that, the trigger invocation is split
  1346. * in two - the first part checks the filter using the current
  1347. * trace record; if a command has the @post_trigger flag set, it
  1348. * sets a bit for itself in the return value, otherwise it
  1349. * directly invokes the trigger. Once all commands have been
  1350. * either invoked or set their return flag, the current record is
  1351. * either committed or discarded. At that point, if any commands
  1352. * have deferred their triggers, those commands are finally
  1353. * invoked following the close of the current event. In other
  1354. * words, if the event_trigger_ops @func() probe implementation
  1355. * itself logs to the trace buffer, this flag should be set,
  1356. * otherwise it can be left unspecified.
  1357. *
  1358. * @NEEDS_REC: A flag that says whether or not this command needs
  1359. * access to the trace record in order to perform its function,
  1360. * regardless of whether or not it has a filter associated with
  1361. * it (filters make a trigger require access to the trace record
  1362. * but are not always present).
  1363. */
  1364. enum event_command_flags {
  1365. EVENT_CMD_FL_POST_TRIGGER = 1,
  1366. EVENT_CMD_FL_NEEDS_REC = 2,
  1367. };
  1368. static inline bool event_command_post_trigger(struct event_command *cmd_ops)
  1369. {
  1370. return cmd_ops->flags & EVENT_CMD_FL_POST_TRIGGER;
  1371. }
  1372. static inline bool event_command_needs_rec(struct event_command *cmd_ops)
  1373. {
  1374. return cmd_ops->flags & EVENT_CMD_FL_NEEDS_REC;
  1375. }
  1376. extern int trace_event_enable_disable(struct trace_event_file *file,
  1377. int enable, int soft_disable);
  1378. extern int tracing_alloc_snapshot(void);
  1379. extern const char *__start___trace_bprintk_fmt[];
  1380. extern const char *__stop___trace_bprintk_fmt[];
  1381. extern const char *__start___tracepoint_str[];
  1382. extern const char *__stop___tracepoint_str[];
  1383. void trace_printk_control(bool enabled);
  1384. void trace_printk_init_buffers(void);
  1385. void trace_printk_start_comm(void);
  1386. int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
  1387. int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
  1388. /*
  1389. * Normal trace_printk() and friends allocates special buffers
  1390. * to do the manipulation, as well as saves the print formats
  1391. * into sections to display. But the trace infrastructure wants
  1392. * to use these without the added overhead at the price of being
  1393. * a bit slower (used mainly for warnings, where we don't care
  1394. * about performance). The internal_trace_puts() is for such
  1395. * a purpose.
  1396. */
  1397. #define internal_trace_puts(str) __trace_puts(_THIS_IP_, str, strlen(str))
  1398. #undef FTRACE_ENTRY
  1399. #define FTRACE_ENTRY(call, struct_name, id, tstruct, print, filter) \
  1400. extern struct trace_event_call \
  1401. __aligned(4) event_##call;
  1402. #undef FTRACE_ENTRY_DUP
  1403. #define FTRACE_ENTRY_DUP(call, struct_name, id, tstruct, print, filter) \
  1404. FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print), \
  1405. filter)
  1406. #include "trace_entries.h"
  1407. #if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_FUNCTION_TRACER)
  1408. int perf_ftrace_event_register(struct trace_event_call *call,
  1409. enum trace_reg type, void *data);
  1410. #else
  1411. #define perf_ftrace_event_register NULL
  1412. #endif
  1413. #ifdef CONFIG_FTRACE_SYSCALLS
  1414. void init_ftrace_syscalls(void);
  1415. const char *get_syscall_name(int syscall);
  1416. #else
  1417. static inline void init_ftrace_syscalls(void) { }
  1418. static inline const char *get_syscall_name(int syscall)
  1419. {
  1420. return NULL;
  1421. }
  1422. #endif
  1423. #ifdef CONFIG_EVENT_TRACING
  1424. void trace_event_init(void);
  1425. void trace_event_enum_update(struct trace_enum_map **map, int len);
  1426. #else
  1427. static inline void __init trace_event_init(void) { }
  1428. static inline void trace_event_enum_update(struct trace_enum_map **map, int len) { }
  1429. #endif
  1430. extern struct trace_iterator *tracepoint_print_iter;
  1431. #endif /* _LINUX_KERNEL_TRACE_H */