trace.h 44 KB

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