trace.h 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382
  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. };
  106. #define TRACE_BUF_SIZE 1024
  107. struct trace_array;
  108. /*
  109. * The CPU trace array - it consists of thousands of trace entries
  110. * plus some other descriptor data: (for example which task started
  111. * the trace, etc.)
  112. */
  113. struct trace_array_cpu {
  114. atomic_t disabled;
  115. void *buffer_page; /* ring buffer spare */
  116. unsigned long entries;
  117. unsigned long saved_latency;
  118. unsigned long critical_start;
  119. unsigned long critical_end;
  120. unsigned long critical_sequence;
  121. unsigned long nice;
  122. unsigned long policy;
  123. unsigned long rt_priority;
  124. unsigned long skipped_entries;
  125. cycle_t preempt_timestamp;
  126. pid_t pid;
  127. kuid_t uid;
  128. char comm[TASK_COMM_LEN];
  129. bool ignore_pid;
  130. };
  131. struct tracer;
  132. struct trace_option_dentry;
  133. struct trace_buffer {
  134. struct trace_array *tr;
  135. struct ring_buffer *buffer;
  136. struct trace_array_cpu __percpu *data;
  137. cycle_t time_start;
  138. int cpu;
  139. };
  140. #define TRACE_FLAGS_MAX_SIZE 32
  141. struct trace_options {
  142. struct tracer *tracer;
  143. struct trace_option_dentry *topts;
  144. };
  145. struct trace_pid_list {
  146. unsigned int nr_pids;
  147. int order;
  148. pid_t *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. };
  302. /* Makes more easy to define a tracer opt */
  303. #define TRACER_OPT(s, b) .name = #s, .bit = b
  304. struct trace_option_dentry {
  305. struct tracer_opt *opt;
  306. struct tracer_flags *flags;
  307. struct trace_array *tr;
  308. struct dentry *entry;
  309. };
  310. /**
  311. * struct tracer - a specific tracer and its callbacks to interact with tracefs
  312. * @name: the name chosen to select it on the available_tracers file
  313. * @init: called when one switches to this tracer (echo name > current_tracer)
  314. * @reset: called when one switches to another tracer
  315. * @start: called when tracing is unpaused (echo 1 > tracing_on)
  316. * @stop: called when tracing is paused (echo 0 > tracing_on)
  317. * @update_thresh: called when tracing_thresh is updated
  318. * @open: called when the trace file is opened
  319. * @pipe_open: called when the trace_pipe file is opened
  320. * @close: called when the trace file is released
  321. * @pipe_close: called when the trace_pipe file is released
  322. * @read: override the default read callback on trace_pipe
  323. * @splice_read: override the default splice_read callback on trace_pipe
  324. * @selftest: selftest to run on boot (see trace_selftest.c)
  325. * @print_headers: override the first lines that describe your columns
  326. * @print_line: callback that prints a trace
  327. * @set_flag: signals one of your private flags changed (trace_options file)
  328. * @flags: your private flags
  329. */
  330. struct tracer {
  331. const char *name;
  332. int (*init)(struct trace_array *tr);
  333. void (*reset)(struct trace_array *tr);
  334. void (*start)(struct trace_array *tr);
  335. void (*stop)(struct trace_array *tr);
  336. int (*update_thresh)(struct trace_array *tr);
  337. void (*open)(struct trace_iterator *iter);
  338. void (*pipe_open)(struct trace_iterator *iter);
  339. void (*close)(struct trace_iterator *iter);
  340. void (*pipe_close)(struct trace_iterator *iter);
  341. ssize_t (*read)(struct trace_iterator *iter,
  342. struct file *filp, char __user *ubuf,
  343. size_t cnt, loff_t *ppos);
  344. ssize_t (*splice_read)(struct trace_iterator *iter,
  345. struct file *filp,
  346. loff_t *ppos,
  347. struct pipe_inode_info *pipe,
  348. size_t len,
  349. unsigned int flags);
  350. #ifdef CONFIG_FTRACE_STARTUP_TEST
  351. int (*selftest)(struct tracer *trace,
  352. struct trace_array *tr);
  353. #endif
  354. void (*print_header)(struct seq_file *m);
  355. enum print_line_t (*print_line)(struct trace_iterator *iter);
  356. /* If you handled the flag setting, return 0 */
  357. int (*set_flag)(struct trace_array *tr,
  358. u32 old_flags, u32 bit, int set);
  359. /* Return 0 if OK with change, else return non-zero */
  360. int (*flag_changed)(struct trace_array *tr,
  361. u32 mask, int set);
  362. struct tracer *next;
  363. struct tracer_flags *flags;
  364. int enabled;
  365. int ref;
  366. bool print_max;
  367. bool allow_instances;
  368. #ifdef CONFIG_TRACER_MAX_TRACE
  369. bool use_max_tr;
  370. #endif
  371. };
  372. /* Only current can touch trace_recursion */
  373. /*
  374. * For function tracing recursion:
  375. * The order of these bits are important.
  376. *
  377. * When function tracing occurs, the following steps are made:
  378. * If arch does not support a ftrace feature:
  379. * call internal function (uses INTERNAL bits) which calls...
  380. * If callback is registered to the "global" list, the list
  381. * function is called and recursion checks the GLOBAL bits.
  382. * then this function calls...
  383. * The function callback, which can use the FTRACE bits to
  384. * check for recursion.
  385. *
  386. * Now if the arch does not suppport a feature, and it calls
  387. * the global list function which calls the ftrace callback
  388. * all three of these steps will do a recursion protection.
  389. * There's no reason to do one if the previous caller already
  390. * did. The recursion that we are protecting against will
  391. * go through the same steps again.
  392. *
  393. * To prevent the multiple recursion checks, if a recursion
  394. * bit is set that is higher than the MAX bit of the current
  395. * check, then we know that the check was made by the previous
  396. * caller, and we can skip the current check.
  397. */
  398. enum {
  399. TRACE_BUFFER_BIT,
  400. TRACE_BUFFER_NMI_BIT,
  401. TRACE_BUFFER_IRQ_BIT,
  402. TRACE_BUFFER_SIRQ_BIT,
  403. /* Start of function recursion bits */
  404. TRACE_FTRACE_BIT,
  405. TRACE_FTRACE_NMI_BIT,
  406. TRACE_FTRACE_IRQ_BIT,
  407. TRACE_FTRACE_SIRQ_BIT,
  408. /* INTERNAL_BITs must be greater than FTRACE_BITs */
  409. TRACE_INTERNAL_BIT,
  410. TRACE_INTERNAL_NMI_BIT,
  411. TRACE_INTERNAL_IRQ_BIT,
  412. TRACE_INTERNAL_SIRQ_BIT,
  413. TRACE_BRANCH_BIT,
  414. /*
  415. * Abuse of the trace_recursion.
  416. * As we need a way to maintain state if we are tracing the function
  417. * graph in irq because we want to trace a particular function that
  418. * was called in irq context but we have irq tracing off. Since this
  419. * can only be modified by current, we can reuse trace_recursion.
  420. */
  421. TRACE_IRQ_BIT,
  422. };
  423. #define trace_recursion_set(bit) do { (current)->trace_recursion |= (1<<(bit)); } while (0)
  424. #define trace_recursion_clear(bit) do { (current)->trace_recursion &= ~(1<<(bit)); } while (0)
  425. #define trace_recursion_test(bit) ((current)->trace_recursion & (1<<(bit)))
  426. #define TRACE_CONTEXT_BITS 4
  427. #define TRACE_FTRACE_START TRACE_FTRACE_BIT
  428. #define TRACE_FTRACE_MAX ((1 << (TRACE_FTRACE_START + TRACE_CONTEXT_BITS)) - 1)
  429. #define TRACE_LIST_START TRACE_INTERNAL_BIT
  430. #define TRACE_LIST_MAX ((1 << (TRACE_LIST_START + TRACE_CONTEXT_BITS)) - 1)
  431. #define TRACE_CONTEXT_MASK TRACE_LIST_MAX
  432. static __always_inline int trace_get_context_bit(void)
  433. {
  434. int bit;
  435. if (in_interrupt()) {
  436. if (in_nmi())
  437. bit = 0;
  438. else if (in_irq())
  439. bit = 1;
  440. else
  441. bit = 2;
  442. } else
  443. bit = 3;
  444. return bit;
  445. }
  446. static __always_inline int trace_test_and_set_recursion(int start, int max)
  447. {
  448. unsigned int val = current->trace_recursion;
  449. int bit;
  450. /* A previous recursion check was made */
  451. if ((val & TRACE_CONTEXT_MASK) > max)
  452. return 0;
  453. bit = trace_get_context_bit() + start;
  454. if (unlikely(val & (1 << bit)))
  455. return -1;
  456. val |= 1 << bit;
  457. current->trace_recursion = val;
  458. barrier();
  459. return bit;
  460. }
  461. static __always_inline void trace_clear_recursion(int bit)
  462. {
  463. unsigned int val = current->trace_recursion;
  464. if (!bit)
  465. return;
  466. bit = 1 << bit;
  467. val &= ~bit;
  468. barrier();
  469. current->trace_recursion = val;
  470. }
  471. static inline struct ring_buffer_iter *
  472. trace_buffer_iter(struct trace_iterator *iter, int cpu)
  473. {
  474. if (iter->buffer_iter && iter->buffer_iter[cpu])
  475. return iter->buffer_iter[cpu];
  476. return NULL;
  477. }
  478. int tracer_init(struct tracer *t, struct trace_array *tr);
  479. int tracing_is_enabled(void);
  480. void tracing_reset(struct trace_buffer *buf, int cpu);
  481. void tracing_reset_online_cpus(struct trace_buffer *buf);
  482. void tracing_reset_current(int cpu);
  483. void tracing_reset_all_online_cpus(void);
  484. int tracing_open_generic(struct inode *inode, struct file *filp);
  485. bool tracing_is_disabled(void);
  486. struct dentry *trace_create_file(const char *name,
  487. umode_t mode,
  488. struct dentry *parent,
  489. void *data,
  490. const struct file_operations *fops);
  491. struct dentry *tracing_init_dentry(void);
  492. struct ring_buffer_event;
  493. struct ring_buffer_event *
  494. trace_buffer_lock_reserve(struct ring_buffer *buffer,
  495. int type,
  496. unsigned long len,
  497. unsigned long flags,
  498. int pc);
  499. struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
  500. struct trace_array_cpu *data);
  501. struct trace_entry *trace_find_next_entry(struct trace_iterator *iter,
  502. int *ent_cpu, u64 *ent_ts);
  503. void __buffer_unlock_commit(struct ring_buffer *buffer,
  504. struct ring_buffer_event *event);
  505. int trace_empty(struct trace_iterator *iter);
  506. void *trace_find_next_entry_inc(struct trace_iterator *iter);
  507. void trace_init_global_iter(struct trace_iterator *iter);
  508. void tracing_iter_reset(struct trace_iterator *iter, int cpu);
  509. void trace_function(struct trace_array *tr,
  510. unsigned long ip,
  511. unsigned long parent_ip,
  512. unsigned long flags, int pc);
  513. void trace_graph_function(struct trace_array *tr,
  514. unsigned long ip,
  515. unsigned long parent_ip,
  516. unsigned long flags, int pc);
  517. void trace_latency_header(struct seq_file *m);
  518. void trace_default_header(struct seq_file *m);
  519. void print_trace_header(struct seq_file *m, struct trace_iterator *iter);
  520. int trace_empty(struct trace_iterator *iter);
  521. void trace_graph_return(struct ftrace_graph_ret *trace);
  522. int trace_graph_entry(struct ftrace_graph_ent *trace);
  523. void set_graph_array(struct trace_array *tr);
  524. void tracing_start_cmdline_record(void);
  525. void tracing_stop_cmdline_record(void);
  526. int register_tracer(struct tracer *type);
  527. int is_tracing_stopped(void);
  528. loff_t tracing_lseek(struct file *file, loff_t offset, int whence);
  529. extern cpumask_var_t __read_mostly tracing_buffer_mask;
  530. #define for_each_tracing_cpu(cpu) \
  531. for_each_cpu(cpu, tracing_buffer_mask)
  532. extern unsigned long nsecs_to_usecs(unsigned long nsecs);
  533. extern unsigned long tracing_thresh;
  534. #ifdef CONFIG_TRACER_MAX_TRACE
  535. void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
  536. void update_max_tr_single(struct trace_array *tr,
  537. struct task_struct *tsk, int cpu);
  538. #endif /* CONFIG_TRACER_MAX_TRACE */
  539. #ifdef CONFIG_STACKTRACE
  540. void ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags,
  541. int pc);
  542. void __trace_stack(struct trace_array *tr, unsigned long flags, int skip,
  543. int pc);
  544. #else
  545. static inline void ftrace_trace_userstack(struct ring_buffer *buffer,
  546. unsigned long flags, int pc)
  547. {
  548. }
  549. static inline void __trace_stack(struct trace_array *tr, unsigned long flags,
  550. int skip, int pc)
  551. {
  552. }
  553. #endif /* CONFIG_STACKTRACE */
  554. extern cycle_t ftrace_now(int cpu);
  555. extern void trace_find_cmdline(int pid, char comm[]);
  556. #ifdef CONFIG_DYNAMIC_FTRACE
  557. extern unsigned long ftrace_update_tot_cnt;
  558. #endif
  559. #define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
  560. extern int DYN_FTRACE_TEST_NAME(void);
  561. #define DYN_FTRACE_TEST_NAME2 trace_selftest_dynamic_test_func2
  562. extern int DYN_FTRACE_TEST_NAME2(void);
  563. extern bool ring_buffer_expanded;
  564. extern bool tracing_selftest_disabled;
  565. #ifdef CONFIG_FTRACE_STARTUP_TEST
  566. extern int trace_selftest_startup_function(struct tracer *trace,
  567. struct trace_array *tr);
  568. extern int trace_selftest_startup_function_graph(struct tracer *trace,
  569. struct trace_array *tr);
  570. extern int trace_selftest_startup_irqsoff(struct tracer *trace,
  571. struct trace_array *tr);
  572. extern int trace_selftest_startup_preemptoff(struct tracer *trace,
  573. struct trace_array *tr);
  574. extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
  575. struct trace_array *tr);
  576. extern int trace_selftest_startup_wakeup(struct tracer *trace,
  577. struct trace_array *tr);
  578. extern int trace_selftest_startup_nop(struct tracer *trace,
  579. struct trace_array *tr);
  580. extern int trace_selftest_startup_sched_switch(struct tracer *trace,
  581. struct trace_array *tr);
  582. extern int trace_selftest_startup_branch(struct tracer *trace,
  583. struct trace_array *tr);
  584. /*
  585. * Tracer data references selftest functions that only occur
  586. * on boot up. These can be __init functions. Thus, when selftests
  587. * are enabled, then the tracers need to reference __init functions.
  588. */
  589. #define __tracer_data __refdata
  590. #else
  591. /* Tracers are seldom changed. Optimize when selftests are disabled. */
  592. #define __tracer_data __read_mostly
  593. #endif /* CONFIG_FTRACE_STARTUP_TEST */
  594. extern void *head_page(struct trace_array_cpu *data);
  595. extern unsigned long long ns2usecs(cycle_t nsec);
  596. extern int
  597. trace_vbprintk(unsigned long ip, const char *fmt, va_list args);
  598. extern int
  599. trace_vprintk(unsigned long ip, const char *fmt, va_list args);
  600. extern int
  601. trace_array_vprintk(struct trace_array *tr,
  602. unsigned long ip, const char *fmt, va_list args);
  603. int trace_array_printk(struct trace_array *tr,
  604. unsigned long ip, const char *fmt, ...);
  605. int trace_array_printk_buf(struct ring_buffer *buffer,
  606. unsigned long ip, const char *fmt, ...);
  607. void trace_printk_seq(struct trace_seq *s);
  608. enum print_line_t print_trace_line(struct trace_iterator *iter);
  609. extern char trace_find_mark(unsigned long long duration);
  610. /* Standard output formatting function used for function return traces */
  611. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  612. /* Flag options */
  613. #define TRACE_GRAPH_PRINT_OVERRUN 0x1
  614. #define TRACE_GRAPH_PRINT_CPU 0x2
  615. #define TRACE_GRAPH_PRINT_OVERHEAD 0x4
  616. #define TRACE_GRAPH_PRINT_PROC 0x8
  617. #define TRACE_GRAPH_PRINT_DURATION 0x10
  618. #define TRACE_GRAPH_PRINT_ABS_TIME 0x20
  619. #define TRACE_GRAPH_PRINT_IRQS 0x40
  620. #define TRACE_GRAPH_PRINT_TAIL 0x80
  621. #define TRACE_GRAPH_SLEEP_TIME 0x100
  622. #define TRACE_GRAPH_GRAPH_TIME 0x200
  623. #define TRACE_GRAPH_PRINT_FILL_SHIFT 28
  624. #define TRACE_GRAPH_PRINT_FILL_MASK (0x3 << TRACE_GRAPH_PRINT_FILL_SHIFT)
  625. extern void ftrace_graph_sleep_time_control(bool enable);
  626. extern void ftrace_graph_graph_time_control(bool enable);
  627. extern enum print_line_t
  628. print_graph_function_flags(struct trace_iterator *iter, u32 flags);
  629. extern void print_graph_headers_flags(struct seq_file *s, u32 flags);
  630. extern void
  631. trace_print_graph_duration(unsigned long long duration, struct trace_seq *s);
  632. extern void graph_trace_open(struct trace_iterator *iter);
  633. extern void graph_trace_close(struct trace_iterator *iter);
  634. extern int __trace_graph_entry(struct trace_array *tr,
  635. struct ftrace_graph_ent *trace,
  636. unsigned long flags, int pc);
  637. extern void __trace_graph_return(struct trace_array *tr,
  638. struct ftrace_graph_ret *trace,
  639. unsigned long flags, int pc);
  640. #ifdef CONFIG_DYNAMIC_FTRACE
  641. /* TODO: make this variable */
  642. #define FTRACE_GRAPH_MAX_FUNCS 32
  643. extern int ftrace_graph_count;
  644. extern unsigned long ftrace_graph_funcs[FTRACE_GRAPH_MAX_FUNCS];
  645. extern int ftrace_graph_notrace_count;
  646. extern unsigned long ftrace_graph_notrace_funcs[FTRACE_GRAPH_MAX_FUNCS];
  647. static inline int ftrace_graph_addr(unsigned long addr)
  648. {
  649. int i;
  650. if (!ftrace_graph_count)
  651. return 1;
  652. for (i = 0; i < ftrace_graph_count; i++) {
  653. if (addr == ftrace_graph_funcs[i]) {
  654. /*
  655. * If no irqs are to be traced, but a set_graph_function
  656. * is set, and called by an interrupt handler, we still
  657. * want to trace it.
  658. */
  659. if (in_irq())
  660. trace_recursion_set(TRACE_IRQ_BIT);
  661. else
  662. trace_recursion_clear(TRACE_IRQ_BIT);
  663. return 1;
  664. }
  665. }
  666. return 0;
  667. }
  668. static inline int ftrace_graph_notrace_addr(unsigned long addr)
  669. {
  670. int i;
  671. if (!ftrace_graph_notrace_count)
  672. return 0;
  673. for (i = 0; i < ftrace_graph_notrace_count; i++) {
  674. if (addr == ftrace_graph_notrace_funcs[i])
  675. return 1;
  676. }
  677. return 0;
  678. }
  679. #else
  680. static inline int ftrace_graph_addr(unsigned long addr)
  681. {
  682. return 1;
  683. }
  684. static inline int ftrace_graph_notrace_addr(unsigned long addr)
  685. {
  686. return 0;
  687. }
  688. #endif /* CONFIG_DYNAMIC_FTRACE */
  689. #else /* CONFIG_FUNCTION_GRAPH_TRACER */
  690. static inline enum print_line_t
  691. print_graph_function_flags(struct trace_iterator *iter, u32 flags)
  692. {
  693. return TRACE_TYPE_UNHANDLED;
  694. }
  695. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  696. extern struct list_head ftrace_pids;
  697. #ifdef CONFIG_FUNCTION_TRACER
  698. extern bool ftrace_filter_param __initdata;
  699. static inline int ftrace_trace_task(struct task_struct *task)
  700. {
  701. if (list_empty(&ftrace_pids))
  702. return 1;
  703. return test_tsk_trace_trace(task);
  704. }
  705. extern int ftrace_is_dead(void);
  706. int ftrace_create_function_files(struct trace_array *tr,
  707. struct dentry *parent);
  708. void ftrace_destroy_function_files(struct trace_array *tr);
  709. void ftrace_init_global_array_ops(struct trace_array *tr);
  710. void ftrace_init_array_ops(struct trace_array *tr, ftrace_func_t func);
  711. void ftrace_reset_array_ops(struct trace_array *tr);
  712. int using_ftrace_ops_list_func(void);
  713. #else
  714. static inline int ftrace_trace_task(struct task_struct *task)
  715. {
  716. return 1;
  717. }
  718. static inline int ftrace_is_dead(void) { return 0; }
  719. static inline int
  720. ftrace_create_function_files(struct trace_array *tr,
  721. struct dentry *parent)
  722. {
  723. return 0;
  724. }
  725. static inline void ftrace_destroy_function_files(struct trace_array *tr) { }
  726. static inline __init void
  727. ftrace_init_global_array_ops(struct trace_array *tr) { }
  728. static inline void ftrace_reset_array_ops(struct trace_array *tr) { }
  729. /* ftace_func_t type is not defined, use macro instead of static inline */
  730. #define ftrace_init_array_ops(tr, func) do { } while (0)
  731. #endif /* CONFIG_FUNCTION_TRACER */
  732. #if defined(CONFIG_FUNCTION_TRACER) && defined(CONFIG_DYNAMIC_FTRACE)
  733. void ftrace_create_filter_files(struct ftrace_ops *ops,
  734. struct dentry *parent);
  735. void ftrace_destroy_filter_files(struct ftrace_ops *ops);
  736. #else
  737. /*
  738. * The ops parameter passed in is usually undefined.
  739. * This must be a macro.
  740. */
  741. #define ftrace_create_filter_files(ops, parent) do { } while (0)
  742. #define ftrace_destroy_filter_files(ops) do { } while (0)
  743. #endif /* CONFIG_FUNCTION_TRACER && CONFIG_DYNAMIC_FTRACE */
  744. bool ftrace_event_is_function(struct trace_event_call *call);
  745. /*
  746. * struct trace_parser - servers for reading the user input separated by spaces
  747. * @cont: set if the input is not complete - no final space char was found
  748. * @buffer: holds the parsed user input
  749. * @idx: user input length
  750. * @size: buffer size
  751. */
  752. struct trace_parser {
  753. bool cont;
  754. char *buffer;
  755. unsigned idx;
  756. unsigned size;
  757. };
  758. static inline bool trace_parser_loaded(struct trace_parser *parser)
  759. {
  760. return (parser->idx != 0);
  761. }
  762. static inline bool trace_parser_cont(struct trace_parser *parser)
  763. {
  764. return parser->cont;
  765. }
  766. static inline void trace_parser_clear(struct trace_parser *parser)
  767. {
  768. parser->cont = false;
  769. parser->idx = 0;
  770. }
  771. extern int trace_parser_get_init(struct trace_parser *parser, int size);
  772. extern void trace_parser_put(struct trace_parser *parser);
  773. extern int trace_get_user(struct trace_parser *parser, const char __user *ubuf,
  774. size_t cnt, loff_t *ppos);
  775. /*
  776. * Only create function graph options if function graph is configured.
  777. */
  778. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  779. # define FGRAPH_FLAGS \
  780. C(DISPLAY_GRAPH, "display-graph"),
  781. #else
  782. # define FGRAPH_FLAGS
  783. #endif
  784. #ifdef CONFIG_BRANCH_TRACER
  785. # define BRANCH_FLAGS \
  786. C(BRANCH, "branch"),
  787. #else
  788. # define BRANCH_FLAGS
  789. #endif
  790. #ifdef CONFIG_FUNCTION_TRACER
  791. # define FUNCTION_FLAGS \
  792. C(FUNCTION, "function-trace"),
  793. # define FUNCTION_DEFAULT_FLAGS TRACE_ITER_FUNCTION
  794. #else
  795. # define FUNCTION_FLAGS
  796. # define FUNCTION_DEFAULT_FLAGS 0UL
  797. #endif
  798. #ifdef CONFIG_STACKTRACE
  799. # define STACK_FLAGS \
  800. C(STACKTRACE, "stacktrace"),
  801. #else
  802. # define STACK_FLAGS
  803. #endif
  804. /*
  805. * trace_iterator_flags is an enumeration that defines bit
  806. * positions into trace_flags that controls the output.
  807. *
  808. * NOTE: These bits must match the trace_options array in
  809. * trace.c (this macro guarantees it).
  810. */
  811. #define TRACE_FLAGS \
  812. C(PRINT_PARENT, "print-parent"), \
  813. C(SYM_OFFSET, "sym-offset"), \
  814. C(SYM_ADDR, "sym-addr"), \
  815. C(VERBOSE, "verbose"), \
  816. C(RAW, "raw"), \
  817. C(HEX, "hex"), \
  818. C(BIN, "bin"), \
  819. C(BLOCK, "block"), \
  820. C(PRINTK, "trace_printk"), \
  821. C(ANNOTATE, "annotate"), \
  822. C(USERSTACKTRACE, "userstacktrace"), \
  823. C(SYM_USEROBJ, "sym-userobj"), \
  824. C(PRINTK_MSGONLY, "printk-msg-only"), \
  825. C(CONTEXT_INFO, "context-info"), /* Print pid/cpu/time */ \
  826. C(LATENCY_FMT, "latency-format"), \
  827. C(RECORD_CMD, "record-cmd"), \
  828. C(OVERWRITE, "overwrite"), \
  829. C(STOP_ON_FREE, "disable_on_free"), \
  830. C(IRQ_INFO, "irq-info"), \
  831. C(MARKERS, "markers"), \
  832. FUNCTION_FLAGS \
  833. FGRAPH_FLAGS \
  834. STACK_FLAGS \
  835. BRANCH_FLAGS
  836. /*
  837. * By defining C, we can make TRACE_FLAGS a list of bit names
  838. * that will define the bits for the flag masks.
  839. */
  840. #undef C
  841. #define C(a, b) TRACE_ITER_##a##_BIT
  842. enum trace_iterator_bits {
  843. TRACE_FLAGS
  844. /* Make sure we don't go more than we have bits for */
  845. TRACE_ITER_LAST_BIT
  846. };
  847. /*
  848. * By redefining C, we can make TRACE_FLAGS a list of masks that
  849. * use the bits as defined above.
  850. */
  851. #undef C
  852. #define C(a, b) TRACE_ITER_##a = (1 << TRACE_ITER_##a##_BIT)
  853. enum trace_iterator_flags { TRACE_FLAGS };
  854. /*
  855. * TRACE_ITER_SYM_MASK masks the options in trace_flags that
  856. * control the output of kernel symbols.
  857. */
  858. #define TRACE_ITER_SYM_MASK \
  859. (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR)
  860. extern struct tracer nop_trace;
  861. #ifdef CONFIG_BRANCH_TRACER
  862. extern int enable_branch_tracing(struct trace_array *tr);
  863. extern void disable_branch_tracing(void);
  864. static inline int trace_branch_enable(struct trace_array *tr)
  865. {
  866. if (tr->trace_flags & TRACE_ITER_BRANCH)
  867. return enable_branch_tracing(tr);
  868. return 0;
  869. }
  870. static inline void trace_branch_disable(void)
  871. {
  872. /* due to races, always disable */
  873. disable_branch_tracing();
  874. }
  875. #else
  876. static inline int trace_branch_enable(struct trace_array *tr)
  877. {
  878. return 0;
  879. }
  880. static inline void trace_branch_disable(void)
  881. {
  882. }
  883. #endif /* CONFIG_BRANCH_TRACER */
  884. /* set ring buffers to default size if not already done so */
  885. int tracing_update_buffers(void);
  886. struct ftrace_event_field {
  887. struct list_head link;
  888. const char *name;
  889. const char *type;
  890. int filter_type;
  891. int offset;
  892. int size;
  893. int is_signed;
  894. };
  895. struct event_filter {
  896. int n_preds; /* Number assigned */
  897. int a_preds; /* allocated */
  898. struct filter_pred *preds;
  899. struct filter_pred *root;
  900. char *filter_string;
  901. };
  902. struct event_subsystem {
  903. struct list_head list;
  904. const char *name;
  905. struct event_filter *filter;
  906. int ref_count;
  907. };
  908. struct trace_subsystem_dir {
  909. struct list_head list;
  910. struct event_subsystem *subsystem;
  911. struct trace_array *tr;
  912. struct dentry *entry;
  913. int ref_count;
  914. int nr_events;
  915. };
  916. #define FILTER_PRED_INVALID ((unsigned short)-1)
  917. #define FILTER_PRED_IS_RIGHT (1 << 15)
  918. #define FILTER_PRED_FOLD (1 << 15)
  919. /*
  920. * The max preds is the size of unsigned short with
  921. * two flags at the MSBs. One bit is used for both the IS_RIGHT
  922. * and FOLD flags. The other is reserved.
  923. *
  924. * 2^14 preds is way more than enough.
  925. */
  926. #define MAX_FILTER_PRED 16384
  927. struct filter_pred;
  928. struct regex;
  929. typedef int (*filter_pred_fn_t) (struct filter_pred *pred, void *event);
  930. typedef int (*regex_match_func)(char *str, struct regex *r, int len);
  931. enum regex_type {
  932. MATCH_FULL = 0,
  933. MATCH_FRONT_ONLY,
  934. MATCH_MIDDLE_ONLY,
  935. MATCH_END_ONLY,
  936. };
  937. struct regex {
  938. char pattern[MAX_FILTER_STR_VAL];
  939. int len;
  940. int field_len;
  941. regex_match_func match;
  942. };
  943. struct filter_pred {
  944. filter_pred_fn_t fn;
  945. u64 val;
  946. struct regex regex;
  947. unsigned short *ops;
  948. struct ftrace_event_field *field;
  949. int offset;
  950. int not;
  951. int op;
  952. unsigned short index;
  953. unsigned short parent;
  954. unsigned short left;
  955. unsigned short right;
  956. };
  957. extern enum regex_type
  958. filter_parse_regex(char *buff, int len, char **search, int *not);
  959. extern void print_event_filter(struct trace_event_file *file,
  960. struct trace_seq *s);
  961. extern int apply_event_filter(struct trace_event_file *file,
  962. char *filter_string);
  963. extern int apply_subsystem_event_filter(struct trace_subsystem_dir *dir,
  964. char *filter_string);
  965. extern void print_subsystem_event_filter(struct event_subsystem *system,
  966. struct trace_seq *s);
  967. extern int filter_assign_type(const char *type);
  968. extern int create_event_filter(struct trace_event_call *call,
  969. char *filter_str, bool set_str,
  970. struct event_filter **filterp);
  971. extern void free_event_filter(struct event_filter *filter);
  972. struct ftrace_event_field *
  973. trace_find_event_field(struct trace_event_call *call, char *name);
  974. extern void trace_event_enable_cmd_record(bool enable);
  975. extern int event_trace_add_tracer(struct dentry *parent, struct trace_array *tr);
  976. extern int event_trace_del_tracer(struct trace_array *tr);
  977. extern struct trace_event_file *find_event_file(struct trace_array *tr,
  978. const char *system,
  979. const char *event);
  980. static inline void *event_file_data(struct file *filp)
  981. {
  982. return ACCESS_ONCE(file_inode(filp)->i_private);
  983. }
  984. extern struct mutex event_mutex;
  985. extern struct list_head ftrace_events;
  986. extern const struct file_operations event_trigger_fops;
  987. extern int register_trigger_cmds(void);
  988. extern void clear_event_triggers(struct trace_array *tr);
  989. struct event_trigger_data {
  990. unsigned long count;
  991. int ref;
  992. struct event_trigger_ops *ops;
  993. struct event_command *cmd_ops;
  994. struct event_filter __rcu *filter;
  995. char *filter_str;
  996. void *private_data;
  997. struct list_head list;
  998. };
  999. /**
  1000. * struct event_trigger_ops - callbacks for trace event triggers
  1001. *
  1002. * The methods in this structure provide per-event trigger hooks for
  1003. * various trigger operations.
  1004. *
  1005. * All the methods below, except for @init() and @free(), must be
  1006. * implemented.
  1007. *
  1008. * @func: The trigger 'probe' function called when the triggering
  1009. * event occurs. The data passed into this callback is the data
  1010. * that was supplied to the event_command @reg() function that
  1011. * registered the trigger (see struct event_command).
  1012. *
  1013. * @init: An optional initialization function called for the trigger
  1014. * when the trigger is registered (via the event_command reg()
  1015. * function). This can be used to perform per-trigger
  1016. * initialization such as incrementing a per-trigger reference
  1017. * count, for instance. This is usually implemented by the
  1018. * generic utility function @event_trigger_init() (see
  1019. * trace_event_triggers.c).
  1020. *
  1021. * @free: An optional de-initialization function called for the
  1022. * trigger when the trigger is unregistered (via the
  1023. * event_command @reg() function). This can be used to perform
  1024. * per-trigger de-initialization such as decrementing a
  1025. * per-trigger reference count and freeing corresponding trigger
  1026. * data, for instance. This is usually implemented by the
  1027. * generic utility function @event_trigger_free() (see
  1028. * trace_event_triggers.c).
  1029. *
  1030. * @print: The callback function invoked to have the trigger print
  1031. * itself. This is usually implemented by a wrapper function
  1032. * that calls the generic utility function @event_trigger_print()
  1033. * (see trace_event_triggers.c).
  1034. */
  1035. struct event_trigger_ops {
  1036. void (*func)(struct event_trigger_data *data);
  1037. int (*init)(struct event_trigger_ops *ops,
  1038. struct event_trigger_data *data);
  1039. void (*free)(struct event_trigger_ops *ops,
  1040. struct event_trigger_data *data);
  1041. int (*print)(struct seq_file *m,
  1042. struct event_trigger_ops *ops,
  1043. struct event_trigger_data *data);
  1044. };
  1045. /**
  1046. * struct event_command - callbacks and data members for event commands
  1047. *
  1048. * Event commands are invoked by users by writing the command name
  1049. * into the 'trigger' file associated with a trace event. The
  1050. * parameters associated with a specific invocation of an event
  1051. * command are used to create an event trigger instance, which is
  1052. * added to the list of trigger instances associated with that trace
  1053. * event. When the event is hit, the set of triggers associated with
  1054. * that event is invoked.
  1055. *
  1056. * The data members in this structure provide per-event command data
  1057. * for various event commands.
  1058. *
  1059. * All the data members below, except for @post_trigger, must be set
  1060. * for each event command.
  1061. *
  1062. * @name: The unique name that identifies the event command. This is
  1063. * the name used when setting triggers via trigger files.
  1064. *
  1065. * @trigger_type: A unique id that identifies the event command
  1066. * 'type'. This value has two purposes, the first to ensure that
  1067. * only one trigger of the same type can be set at a given time
  1068. * for a particular event e.g. it doesn't make sense to have both
  1069. * a traceon and traceoff trigger attached to a single event at
  1070. * the same time, so traceon and traceoff have the same type
  1071. * though they have different names. The @trigger_type value is
  1072. * also used as a bit value for deferring the actual trigger
  1073. * action until after the current event is finished. Some
  1074. * commands need to do this if they themselves log to the trace
  1075. * buffer (see the @post_trigger() member below). @trigger_type
  1076. * values are defined by adding new values to the trigger_type
  1077. * enum in include/linux/trace_events.h.
  1078. *
  1079. * @post_trigger: A flag that says whether or not this command needs
  1080. * to have its action delayed until after the current event has
  1081. * been closed. Some triggers need to avoid being invoked while
  1082. * an event is currently in the process of being logged, since
  1083. * the trigger may itself log data into the trace buffer. Thus
  1084. * we make sure the current event is committed before invoking
  1085. * those triggers. To do that, the trigger invocation is split
  1086. * in two - the first part checks the filter using the current
  1087. * trace record; if a command has the @post_trigger flag set, it
  1088. * sets a bit for itself in the return value, otherwise it
  1089. * directly invokes the trigger. Once all commands have been
  1090. * either invoked or set their return flag, the current record is
  1091. * either committed or discarded. At that point, if any commands
  1092. * have deferred their triggers, those commands are finally
  1093. * invoked following the close of the current event. In other
  1094. * words, if the event_trigger_ops @func() probe implementation
  1095. * itself logs to the trace buffer, this flag should be set,
  1096. * otherwise it can be left unspecified.
  1097. *
  1098. * All the methods below, except for @set_filter(), must be
  1099. * implemented.
  1100. *
  1101. * @func: The callback function responsible for parsing and
  1102. * registering the trigger written to the 'trigger' file by the
  1103. * user. It allocates the trigger instance and registers it with
  1104. * the appropriate trace event. It makes use of the other
  1105. * event_command callback functions to orchestrate this, and is
  1106. * usually implemented by the generic utility function
  1107. * @event_trigger_callback() (see trace_event_triggers.c).
  1108. *
  1109. * @reg: Adds the trigger to the list of triggers associated with the
  1110. * event, and enables the event trigger itself, after
  1111. * initializing it (via the event_trigger_ops @init() function).
  1112. * This is also where commands can use the @trigger_type value to
  1113. * make the decision as to whether or not multiple instances of
  1114. * the trigger should be allowed. This is usually implemented by
  1115. * the generic utility function @register_trigger() (see
  1116. * trace_event_triggers.c).
  1117. *
  1118. * @unreg: Removes the trigger from the list of triggers associated
  1119. * with the event, and disables the event trigger itself, after
  1120. * initializing it (via the event_trigger_ops @free() function).
  1121. * This is usually implemented by the generic utility function
  1122. * @unregister_trigger() (see trace_event_triggers.c).
  1123. *
  1124. * @set_filter: An optional function called to parse and set a filter
  1125. * for the trigger. If no @set_filter() method is set for the
  1126. * event command, filters set by the user for the command will be
  1127. * ignored. This is usually implemented by the generic utility
  1128. * function @set_trigger_filter() (see trace_event_triggers.c).
  1129. *
  1130. * @get_trigger_ops: The callback function invoked to retrieve the
  1131. * event_trigger_ops implementation associated with the command.
  1132. */
  1133. struct event_command {
  1134. struct list_head list;
  1135. char *name;
  1136. enum event_trigger_type trigger_type;
  1137. bool post_trigger;
  1138. int (*func)(struct event_command *cmd_ops,
  1139. struct trace_event_file *file,
  1140. char *glob, char *cmd, char *params);
  1141. int (*reg)(char *glob,
  1142. struct event_trigger_ops *ops,
  1143. struct event_trigger_data *data,
  1144. struct trace_event_file *file);
  1145. void (*unreg)(char *glob,
  1146. struct event_trigger_ops *ops,
  1147. struct event_trigger_data *data,
  1148. struct trace_event_file *file);
  1149. int (*set_filter)(char *filter_str,
  1150. struct event_trigger_data *data,
  1151. struct trace_event_file *file);
  1152. struct event_trigger_ops *(*get_trigger_ops)(char *cmd, char *param);
  1153. };
  1154. extern int trace_event_enable_disable(struct trace_event_file *file,
  1155. int enable, int soft_disable);
  1156. extern int tracing_alloc_snapshot(void);
  1157. extern const char *__start___trace_bprintk_fmt[];
  1158. extern const char *__stop___trace_bprintk_fmt[];
  1159. extern const char *__start___tracepoint_str[];
  1160. extern const char *__stop___tracepoint_str[];
  1161. void trace_printk_control(bool enabled);
  1162. void trace_printk_init_buffers(void);
  1163. void trace_printk_start_comm(void);
  1164. int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
  1165. int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
  1166. /*
  1167. * Normal trace_printk() and friends allocates special buffers
  1168. * to do the manipulation, as well as saves the print formats
  1169. * into sections to display. But the trace infrastructure wants
  1170. * to use these without the added overhead at the price of being
  1171. * a bit slower (used mainly for warnings, where we don't care
  1172. * about performance). The internal_trace_puts() is for such
  1173. * a purpose.
  1174. */
  1175. #define internal_trace_puts(str) __trace_puts(_THIS_IP_, str, strlen(str))
  1176. #undef FTRACE_ENTRY
  1177. #define FTRACE_ENTRY(call, struct_name, id, tstruct, print, filter) \
  1178. extern struct trace_event_call \
  1179. __aligned(4) event_##call;
  1180. #undef FTRACE_ENTRY_DUP
  1181. #define FTRACE_ENTRY_DUP(call, struct_name, id, tstruct, print, filter) \
  1182. FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print), \
  1183. filter)
  1184. #include "trace_entries.h"
  1185. #if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_FUNCTION_TRACER)
  1186. int perf_ftrace_event_register(struct trace_event_call *call,
  1187. enum trace_reg type, void *data);
  1188. #else
  1189. #define perf_ftrace_event_register NULL
  1190. #endif
  1191. #ifdef CONFIG_FTRACE_SYSCALLS
  1192. void init_ftrace_syscalls(void);
  1193. #else
  1194. static inline void init_ftrace_syscalls(void) { }
  1195. #endif
  1196. #ifdef CONFIG_EVENT_TRACING
  1197. void trace_event_init(void);
  1198. void trace_event_enum_update(struct trace_enum_map **map, int len);
  1199. #else
  1200. static inline void __init trace_event_init(void) { }
  1201. static inline void trace_event_enum_update(struct trace_enum_map **map, int len) { }
  1202. #endif
  1203. extern struct trace_iterator *tracepoint_print_iter;
  1204. #endif /* _LINUX_KERNEL_TRACE_H */