trace.h 42 KB

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