trace.h 40 KB

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