trace.h 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034
  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. #ifdef CONFIG_FTRACE_SYSCALLS
  15. #include <asm/unistd.h> /* For NR_SYSCALLS */
  16. #include <asm/syscall.h> /* some archs define it here */
  17. #endif
  18. enum trace_type {
  19. __TRACE_FIRST_TYPE = 0,
  20. TRACE_FN,
  21. TRACE_CTX,
  22. TRACE_WAKE,
  23. TRACE_STACK,
  24. TRACE_PRINT,
  25. TRACE_BPRINT,
  26. TRACE_MMIO_RW,
  27. TRACE_MMIO_MAP,
  28. TRACE_BRANCH,
  29. TRACE_GRAPH_RET,
  30. TRACE_GRAPH_ENT,
  31. TRACE_USER_STACK,
  32. TRACE_BLK,
  33. __TRACE_LAST_TYPE,
  34. };
  35. #undef __field
  36. #define __field(type, item) type item;
  37. #undef __field_struct
  38. #define __field_struct(type, item) __field(type, item)
  39. #undef __field_desc
  40. #define __field_desc(type, container, item)
  41. #undef __array
  42. #define __array(type, item, size) type item[size];
  43. #undef __array_desc
  44. #define __array_desc(type, container, item, size)
  45. #undef __dynamic_array
  46. #define __dynamic_array(type, item) type item[];
  47. #undef F_STRUCT
  48. #define F_STRUCT(args...) args
  49. #undef FTRACE_ENTRY
  50. #define FTRACE_ENTRY(name, struct_name, id, tstruct, print, filter) \
  51. struct struct_name { \
  52. struct trace_entry ent; \
  53. tstruct \
  54. }
  55. #undef TP_ARGS
  56. #define TP_ARGS(args...) args
  57. #undef FTRACE_ENTRY_DUP
  58. #define FTRACE_ENTRY_DUP(name, name_struct, id, tstruct, printk, filter)
  59. #undef FTRACE_ENTRY_REG
  60. #define FTRACE_ENTRY_REG(name, struct_name, id, tstruct, print, \
  61. filter, regfn) \
  62. FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print), \
  63. filter)
  64. #include "trace_entries.h"
  65. /*
  66. * syscalls are special, and need special handling, this is why
  67. * they are not included in trace_entries.h
  68. */
  69. struct syscall_trace_enter {
  70. struct trace_entry ent;
  71. int nr;
  72. unsigned long args[];
  73. };
  74. struct syscall_trace_exit {
  75. struct trace_entry ent;
  76. int nr;
  77. long ret;
  78. };
  79. struct kprobe_trace_entry_head {
  80. struct trace_entry ent;
  81. unsigned long ip;
  82. };
  83. struct kretprobe_trace_entry_head {
  84. struct trace_entry ent;
  85. unsigned long func;
  86. unsigned long ret_ip;
  87. };
  88. struct uprobe_trace_entry_head {
  89. struct trace_entry ent;
  90. unsigned long ip;
  91. };
  92. /*
  93. * trace_flag_type is an enumeration that holds different
  94. * states when a trace occurs. These are:
  95. * IRQS_OFF - interrupts were disabled
  96. * IRQS_NOSUPPORT - arch does not support irqs_disabled_flags
  97. * NEED_RESCHED - reschedule is requested
  98. * HARDIRQ - inside an interrupt handler
  99. * SOFTIRQ - inside a softirq handler
  100. */
  101. enum trace_flag_type {
  102. TRACE_FLAG_IRQS_OFF = 0x01,
  103. TRACE_FLAG_IRQS_NOSUPPORT = 0x02,
  104. TRACE_FLAG_NEED_RESCHED = 0x04,
  105. TRACE_FLAG_HARDIRQ = 0x08,
  106. TRACE_FLAG_SOFTIRQ = 0x10,
  107. };
  108. #define TRACE_BUF_SIZE 1024
  109. struct trace_array;
  110. struct trace_cpu {
  111. struct trace_array *tr;
  112. struct dentry *dir;
  113. int cpu;
  114. };
  115. /*
  116. * The CPU trace array - it consists of thousands of trace entries
  117. * plus some other descriptor data: (for example which task started
  118. * the trace, etc.)
  119. */
  120. struct trace_array_cpu {
  121. struct trace_cpu trace_cpu;
  122. atomic_t disabled;
  123. void *buffer_page; /* ring buffer spare */
  124. unsigned long entries;
  125. unsigned long saved_latency;
  126. unsigned long critical_start;
  127. unsigned long critical_end;
  128. unsigned long critical_sequence;
  129. unsigned long nice;
  130. unsigned long policy;
  131. unsigned long rt_priority;
  132. unsigned long skipped_entries;
  133. cycle_t preempt_timestamp;
  134. pid_t pid;
  135. kuid_t uid;
  136. char comm[TASK_COMM_LEN];
  137. };
  138. struct tracer;
  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 ring_buffer *buffer;
  146. struct list_head list;
  147. char *name;
  148. int cpu;
  149. int buffer_disabled;
  150. struct trace_cpu trace_cpu; /* place holder */
  151. #ifdef CONFIG_FTRACE_SYSCALLS
  152. int sys_refcount_enter;
  153. int sys_refcount_exit;
  154. DECLARE_BITMAP(enabled_enter_syscalls, NR_syscalls);
  155. DECLARE_BITMAP(enabled_exit_syscalls, NR_syscalls);
  156. #endif
  157. int stop_count;
  158. int clock_id;
  159. struct tracer *current_trace;
  160. unsigned int flags;
  161. cycle_t time_start;
  162. raw_spinlock_t start_lock;
  163. struct dentry *dir;
  164. struct dentry *options;
  165. struct dentry *percpu_dir;
  166. struct dentry *event_dir;
  167. struct list_head systems;
  168. struct list_head events;
  169. struct task_struct *waiter;
  170. struct trace_array_cpu *data;
  171. };
  172. enum {
  173. TRACE_ARRAY_FL_GLOBAL = (1 << 0)
  174. };
  175. extern struct list_head ftrace_trace_arrays;
  176. /*
  177. * The global tracer (top) should be the first trace array added,
  178. * but we check the flag anyway.
  179. */
  180. static inline struct trace_array *top_trace_array(void)
  181. {
  182. struct trace_array *tr;
  183. tr = list_entry(ftrace_trace_arrays.prev,
  184. typeof(*tr), list);
  185. WARN_ON(!(tr->flags & TRACE_ARRAY_FL_GLOBAL));
  186. return tr;
  187. }
  188. #define FTRACE_CMP_TYPE(var, type) \
  189. __builtin_types_compatible_p(typeof(var), type *)
  190. #undef IF_ASSIGN
  191. #define IF_ASSIGN(var, entry, etype, id) \
  192. if (FTRACE_CMP_TYPE(var, etype)) { \
  193. var = (typeof(var))(entry); \
  194. WARN_ON(id && (entry)->type != id); \
  195. break; \
  196. }
  197. /* Will cause compile errors if type is not found. */
  198. extern void __ftrace_bad_type(void);
  199. /*
  200. * The trace_assign_type is a verifier that the entry type is
  201. * the same as the type being assigned. To add new types simply
  202. * add a line with the following format:
  203. *
  204. * IF_ASSIGN(var, ent, type, id);
  205. *
  206. * Where "type" is the trace type that includes the trace_entry
  207. * as the "ent" item. And "id" is the trace identifier that is
  208. * used in the trace_type enum.
  209. *
  210. * If the type can have more than one id, then use zero.
  211. */
  212. #define trace_assign_type(var, ent) \
  213. do { \
  214. IF_ASSIGN(var, ent, struct ftrace_entry, TRACE_FN); \
  215. IF_ASSIGN(var, ent, struct ctx_switch_entry, 0); \
  216. IF_ASSIGN(var, ent, struct stack_entry, TRACE_STACK); \
  217. IF_ASSIGN(var, ent, struct userstack_entry, TRACE_USER_STACK);\
  218. IF_ASSIGN(var, ent, struct print_entry, TRACE_PRINT); \
  219. IF_ASSIGN(var, ent, struct bprint_entry, TRACE_BPRINT); \
  220. IF_ASSIGN(var, ent, struct trace_mmiotrace_rw, \
  221. TRACE_MMIO_RW); \
  222. IF_ASSIGN(var, ent, struct trace_mmiotrace_map, \
  223. TRACE_MMIO_MAP); \
  224. IF_ASSIGN(var, ent, struct trace_branch, TRACE_BRANCH); \
  225. IF_ASSIGN(var, ent, struct ftrace_graph_ent_entry, \
  226. TRACE_GRAPH_ENT); \
  227. IF_ASSIGN(var, ent, struct ftrace_graph_ret_entry, \
  228. TRACE_GRAPH_RET); \
  229. __ftrace_bad_type(); \
  230. } while (0)
  231. /*
  232. * An option specific to a tracer. This is a boolean value.
  233. * The bit is the bit index that sets its value on the
  234. * flags value in struct tracer_flags.
  235. */
  236. struct tracer_opt {
  237. const char *name; /* Will appear on the trace_options file */
  238. u32 bit; /* Mask assigned in val field in tracer_flags */
  239. };
  240. /*
  241. * The set of specific options for a tracer. Your tracer
  242. * have to set the initial value of the flags val.
  243. */
  244. struct tracer_flags {
  245. u32 val;
  246. struct tracer_opt *opts;
  247. };
  248. /* Makes more easy to define a tracer opt */
  249. #define TRACER_OPT(s, b) .name = #s, .bit = b
  250. /**
  251. * struct tracer - a specific tracer and its callbacks to interact with debugfs
  252. * @name: the name chosen to select it on the available_tracers file
  253. * @init: called when one switches to this tracer (echo name > current_tracer)
  254. * @reset: called when one switches to another tracer
  255. * @start: called when tracing is unpaused (echo 1 > tracing_enabled)
  256. * @stop: called when tracing is paused (echo 0 > tracing_enabled)
  257. * @open: called when the trace file is opened
  258. * @pipe_open: called when the trace_pipe file is opened
  259. * @wait_pipe: override how the user waits for traces on trace_pipe
  260. * @close: called when the trace file is released
  261. * @pipe_close: called when the trace_pipe file is released
  262. * @read: override the default read callback on trace_pipe
  263. * @splice_read: override the default splice_read callback on trace_pipe
  264. * @selftest: selftest to run on boot (see trace_selftest.c)
  265. * @print_headers: override the first lines that describe your columns
  266. * @print_line: callback that prints a trace
  267. * @set_flag: signals one of your private flags changed (trace_options file)
  268. * @flags: your private flags
  269. */
  270. struct tracer {
  271. const char *name;
  272. int (*init)(struct trace_array *tr);
  273. void (*reset)(struct trace_array *tr);
  274. void (*start)(struct trace_array *tr);
  275. void (*stop)(struct trace_array *tr);
  276. void (*open)(struct trace_iterator *iter);
  277. void (*pipe_open)(struct trace_iterator *iter);
  278. void (*wait_pipe)(struct trace_iterator *iter);
  279. void (*close)(struct trace_iterator *iter);
  280. void (*pipe_close)(struct trace_iterator *iter);
  281. ssize_t (*read)(struct trace_iterator *iter,
  282. struct file *filp, char __user *ubuf,
  283. size_t cnt, loff_t *ppos);
  284. ssize_t (*splice_read)(struct trace_iterator *iter,
  285. struct file *filp,
  286. loff_t *ppos,
  287. struct pipe_inode_info *pipe,
  288. size_t len,
  289. unsigned int flags);
  290. #ifdef CONFIG_FTRACE_STARTUP_TEST
  291. int (*selftest)(struct tracer *trace,
  292. struct trace_array *tr);
  293. #endif
  294. void (*print_header)(struct seq_file *m);
  295. enum print_line_t (*print_line)(struct trace_iterator *iter);
  296. /* If you handled the flag setting, return 0 */
  297. int (*set_flag)(u32 old_flags, u32 bit, int set);
  298. /* Return 0 if OK with change, else return non-zero */
  299. int (*flag_changed)(struct tracer *tracer,
  300. u32 mask, int set);
  301. struct tracer *next;
  302. struct tracer_flags *flags;
  303. bool print_max;
  304. bool use_max_tr;
  305. bool allocated_snapshot;
  306. bool enabled;
  307. };
  308. /* Only current can touch trace_recursion */
  309. /*
  310. * For function tracing recursion:
  311. * The order of these bits are important.
  312. *
  313. * When function tracing occurs, the following steps are made:
  314. * If arch does not support a ftrace feature:
  315. * call internal function (uses INTERNAL bits) which calls...
  316. * If callback is registered to the "global" list, the list
  317. * function is called and recursion checks the GLOBAL bits.
  318. * then this function calls...
  319. * The function callback, which can use the FTRACE bits to
  320. * check for recursion.
  321. *
  322. * Now if the arch does not suppport a feature, and it calls
  323. * the global list function which calls the ftrace callback
  324. * all three of these steps will do a recursion protection.
  325. * There's no reason to do one if the previous caller already
  326. * did. The recursion that we are protecting against will
  327. * go through the same steps again.
  328. *
  329. * To prevent the multiple recursion checks, if a recursion
  330. * bit is set that is higher than the MAX bit of the current
  331. * check, then we know that the check was made by the previous
  332. * caller, and we can skip the current check.
  333. */
  334. enum {
  335. TRACE_BUFFER_BIT,
  336. TRACE_BUFFER_NMI_BIT,
  337. TRACE_BUFFER_IRQ_BIT,
  338. TRACE_BUFFER_SIRQ_BIT,
  339. /* Start of function recursion bits */
  340. TRACE_FTRACE_BIT,
  341. TRACE_FTRACE_NMI_BIT,
  342. TRACE_FTRACE_IRQ_BIT,
  343. TRACE_FTRACE_SIRQ_BIT,
  344. /* GLOBAL_BITs must be greater than FTRACE_BITs */
  345. TRACE_GLOBAL_BIT,
  346. TRACE_GLOBAL_NMI_BIT,
  347. TRACE_GLOBAL_IRQ_BIT,
  348. TRACE_GLOBAL_SIRQ_BIT,
  349. /* INTERNAL_BITs must be greater than GLOBAL_BITs */
  350. TRACE_INTERNAL_BIT,
  351. TRACE_INTERNAL_NMI_BIT,
  352. TRACE_INTERNAL_IRQ_BIT,
  353. TRACE_INTERNAL_SIRQ_BIT,
  354. TRACE_CONTROL_BIT,
  355. /*
  356. * Abuse of the trace_recursion.
  357. * As we need a way to maintain state if we are tracing the function
  358. * graph in irq because we want to trace a particular function that
  359. * was called in irq context but we have irq tracing off. Since this
  360. * can only be modified by current, we can reuse trace_recursion.
  361. */
  362. TRACE_IRQ_BIT,
  363. };
  364. #define trace_recursion_set(bit) do { (current)->trace_recursion |= (1<<(bit)); } while (0)
  365. #define trace_recursion_clear(bit) do { (current)->trace_recursion &= ~(1<<(bit)); } while (0)
  366. #define trace_recursion_test(bit) ((current)->trace_recursion & (1<<(bit)))
  367. #define TRACE_CONTEXT_BITS 4
  368. #define TRACE_FTRACE_START TRACE_FTRACE_BIT
  369. #define TRACE_FTRACE_MAX ((1 << (TRACE_FTRACE_START + TRACE_CONTEXT_BITS)) - 1)
  370. #define TRACE_GLOBAL_START TRACE_GLOBAL_BIT
  371. #define TRACE_GLOBAL_MAX ((1 << (TRACE_GLOBAL_START + TRACE_CONTEXT_BITS)) - 1)
  372. #define TRACE_LIST_START TRACE_INTERNAL_BIT
  373. #define TRACE_LIST_MAX ((1 << (TRACE_LIST_START + TRACE_CONTEXT_BITS)) - 1)
  374. #define TRACE_CONTEXT_MASK TRACE_LIST_MAX
  375. static __always_inline int trace_get_context_bit(void)
  376. {
  377. int bit;
  378. if (in_interrupt()) {
  379. if (in_nmi())
  380. bit = 0;
  381. else if (in_irq())
  382. bit = 1;
  383. else
  384. bit = 2;
  385. } else
  386. bit = 3;
  387. return bit;
  388. }
  389. static __always_inline int trace_test_and_set_recursion(int start, int max)
  390. {
  391. unsigned int val = current->trace_recursion;
  392. int bit;
  393. /* A previous recursion check was made */
  394. if ((val & TRACE_CONTEXT_MASK) > max)
  395. return 0;
  396. bit = trace_get_context_bit() + start;
  397. if (unlikely(val & (1 << bit)))
  398. return -1;
  399. val |= 1 << bit;
  400. current->trace_recursion = val;
  401. barrier();
  402. return bit;
  403. }
  404. static __always_inline void trace_clear_recursion(int bit)
  405. {
  406. unsigned int val = current->trace_recursion;
  407. if (!bit)
  408. return;
  409. bit = 1 << bit;
  410. val &= ~bit;
  411. barrier();
  412. current->trace_recursion = val;
  413. }
  414. static inline struct ring_buffer_iter *
  415. trace_buffer_iter(struct trace_iterator *iter, int cpu)
  416. {
  417. if (iter->buffer_iter && iter->buffer_iter[cpu])
  418. return iter->buffer_iter[cpu];
  419. return NULL;
  420. }
  421. int tracer_init(struct tracer *t, struct trace_array *tr);
  422. int tracing_is_enabled(void);
  423. void tracing_reset(struct trace_array *tr, int cpu);
  424. void tracing_reset_online_cpus(struct trace_array *tr);
  425. void tracing_reset_current(int cpu);
  426. void tracing_reset_current_online_cpus(void);
  427. int tracing_open_generic(struct inode *inode, struct file *filp);
  428. struct dentry *trace_create_file(const char *name,
  429. umode_t mode,
  430. struct dentry *parent,
  431. void *data,
  432. const struct file_operations *fops);
  433. struct dentry *tracing_init_dentry_tr(struct trace_array *tr);
  434. struct dentry *tracing_init_dentry(void);
  435. struct ring_buffer_event;
  436. struct ring_buffer_event *
  437. trace_buffer_lock_reserve(struct ring_buffer *buffer,
  438. int type,
  439. unsigned long len,
  440. unsigned long flags,
  441. int pc);
  442. struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
  443. struct trace_array_cpu *data);
  444. struct trace_entry *trace_find_next_entry(struct trace_iterator *iter,
  445. int *ent_cpu, u64 *ent_ts);
  446. void __buffer_unlock_commit(struct ring_buffer *buffer,
  447. struct ring_buffer_event *event);
  448. int trace_empty(struct trace_iterator *iter);
  449. void *trace_find_next_entry_inc(struct trace_iterator *iter);
  450. void trace_init_global_iter(struct trace_iterator *iter);
  451. void tracing_iter_reset(struct trace_iterator *iter, int cpu);
  452. void poll_wait_pipe(struct trace_iterator *iter);
  453. void ftrace(struct trace_array *tr,
  454. struct trace_array_cpu *data,
  455. unsigned long ip,
  456. unsigned long parent_ip,
  457. unsigned long flags, int pc);
  458. void tracing_sched_switch_trace(struct trace_array *tr,
  459. struct task_struct *prev,
  460. struct task_struct *next,
  461. unsigned long flags, int pc);
  462. void tracing_sched_wakeup_trace(struct trace_array *tr,
  463. struct task_struct *wakee,
  464. struct task_struct *cur,
  465. unsigned long flags, int pc);
  466. void trace_function(struct trace_array *tr,
  467. unsigned long ip,
  468. unsigned long parent_ip,
  469. unsigned long flags, int pc);
  470. void trace_graph_function(struct trace_array *tr,
  471. unsigned long ip,
  472. unsigned long parent_ip,
  473. unsigned long flags, int pc);
  474. void trace_latency_header(struct seq_file *m);
  475. void trace_default_header(struct seq_file *m);
  476. void print_trace_header(struct seq_file *m, struct trace_iterator *iter);
  477. int trace_empty(struct trace_iterator *iter);
  478. void trace_graph_return(struct ftrace_graph_ret *trace);
  479. int trace_graph_entry(struct ftrace_graph_ent *trace);
  480. void set_graph_array(struct trace_array *tr);
  481. void tracing_start_cmdline_record(void);
  482. void tracing_stop_cmdline_record(void);
  483. void tracing_sched_switch_assign_trace(struct trace_array *tr);
  484. void tracing_stop_sched_switch_record(void);
  485. void tracing_start_sched_switch_record(void);
  486. int register_tracer(struct tracer *type);
  487. int is_tracing_stopped(void);
  488. extern cpumask_var_t __read_mostly tracing_buffer_mask;
  489. #define for_each_tracing_cpu(cpu) \
  490. for_each_cpu(cpu, tracing_buffer_mask)
  491. extern unsigned long nsecs_to_usecs(unsigned long nsecs);
  492. extern unsigned long tracing_thresh;
  493. #ifdef CONFIG_TRACER_MAX_TRACE
  494. extern unsigned long tracing_max_latency;
  495. void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
  496. void update_max_tr_single(struct trace_array *tr,
  497. struct task_struct *tsk, int cpu);
  498. #endif /* CONFIG_TRACER_MAX_TRACE */
  499. #ifdef CONFIG_STACKTRACE
  500. void ftrace_trace_stack(struct ring_buffer *buffer, unsigned long flags,
  501. int skip, int pc);
  502. void ftrace_trace_stack_regs(struct ring_buffer *buffer, unsigned long flags,
  503. int skip, int pc, struct pt_regs *regs);
  504. void ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags,
  505. int pc);
  506. void __trace_stack(struct trace_array *tr, unsigned long flags, int skip,
  507. int pc);
  508. #else
  509. static inline void ftrace_trace_stack(struct ring_buffer *buffer,
  510. unsigned long flags, int skip, int pc)
  511. {
  512. }
  513. static inline void ftrace_trace_stack_regs(struct ring_buffer *buffer,
  514. unsigned long flags, int skip,
  515. int pc, struct pt_regs *regs)
  516. {
  517. }
  518. static inline void ftrace_trace_userstack(struct ring_buffer *buffer,
  519. unsigned long flags, int pc)
  520. {
  521. }
  522. static inline void __trace_stack(struct trace_array *tr, unsigned long flags,
  523. int skip, int pc)
  524. {
  525. }
  526. #endif /* CONFIG_STACKTRACE */
  527. extern cycle_t ftrace_now(int cpu);
  528. extern void trace_find_cmdline(int pid, char comm[]);
  529. #ifdef CONFIG_DYNAMIC_FTRACE
  530. extern unsigned long ftrace_update_tot_cnt;
  531. #endif
  532. #define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
  533. extern int DYN_FTRACE_TEST_NAME(void);
  534. #define DYN_FTRACE_TEST_NAME2 trace_selftest_dynamic_test_func2
  535. extern int DYN_FTRACE_TEST_NAME2(void);
  536. extern int ring_buffer_expanded;
  537. extern bool tracing_selftest_disabled;
  538. DECLARE_PER_CPU(int, ftrace_cpu_disabled);
  539. #ifdef CONFIG_FTRACE_STARTUP_TEST
  540. extern int trace_selftest_startup_function(struct tracer *trace,
  541. struct trace_array *tr);
  542. extern int trace_selftest_startup_function_graph(struct tracer *trace,
  543. struct trace_array *tr);
  544. extern int trace_selftest_startup_irqsoff(struct tracer *trace,
  545. struct trace_array *tr);
  546. extern int trace_selftest_startup_preemptoff(struct tracer *trace,
  547. struct trace_array *tr);
  548. extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
  549. struct trace_array *tr);
  550. extern int trace_selftest_startup_wakeup(struct tracer *trace,
  551. struct trace_array *tr);
  552. extern int trace_selftest_startup_nop(struct tracer *trace,
  553. struct trace_array *tr);
  554. extern int trace_selftest_startup_sched_switch(struct tracer *trace,
  555. struct trace_array *tr);
  556. extern int trace_selftest_startup_branch(struct tracer *trace,
  557. struct trace_array *tr);
  558. #endif /* CONFIG_FTRACE_STARTUP_TEST */
  559. extern void *head_page(struct trace_array_cpu *data);
  560. extern unsigned long long ns2usecs(cycle_t nsec);
  561. extern int
  562. trace_vbprintk(unsigned long ip, const char *fmt, va_list args);
  563. extern int
  564. trace_vprintk(unsigned long ip, const char *fmt, va_list args);
  565. extern int
  566. trace_array_vprintk(struct trace_array *tr,
  567. unsigned long ip, const char *fmt, va_list args);
  568. int trace_array_printk(struct trace_array *tr,
  569. unsigned long ip, const char *fmt, ...);
  570. void trace_printk_seq(struct trace_seq *s);
  571. enum print_line_t print_trace_line(struct trace_iterator *iter);
  572. extern unsigned long trace_flags;
  573. extern int trace_clock_id;
  574. /* Standard output formatting function used for function return traces */
  575. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  576. /* Flag options */
  577. #define TRACE_GRAPH_PRINT_OVERRUN 0x1
  578. #define TRACE_GRAPH_PRINT_CPU 0x2
  579. #define TRACE_GRAPH_PRINT_OVERHEAD 0x4
  580. #define TRACE_GRAPH_PRINT_PROC 0x8
  581. #define TRACE_GRAPH_PRINT_DURATION 0x10
  582. #define TRACE_GRAPH_PRINT_ABS_TIME 0x20
  583. extern enum print_line_t
  584. print_graph_function_flags(struct trace_iterator *iter, u32 flags);
  585. extern void print_graph_headers_flags(struct seq_file *s, u32 flags);
  586. extern enum print_line_t
  587. trace_print_graph_duration(unsigned long long duration, struct trace_seq *s);
  588. extern void graph_trace_open(struct trace_iterator *iter);
  589. extern void graph_trace_close(struct trace_iterator *iter);
  590. extern int __trace_graph_entry(struct trace_array *tr,
  591. struct ftrace_graph_ent *trace,
  592. unsigned long flags, int pc);
  593. extern void __trace_graph_return(struct trace_array *tr,
  594. struct ftrace_graph_ret *trace,
  595. unsigned long flags, int pc);
  596. #ifdef CONFIG_DYNAMIC_FTRACE
  597. /* TODO: make this variable */
  598. #define FTRACE_GRAPH_MAX_FUNCS 32
  599. extern int ftrace_graph_filter_enabled;
  600. extern int ftrace_graph_count;
  601. extern unsigned long ftrace_graph_funcs[FTRACE_GRAPH_MAX_FUNCS];
  602. static inline int ftrace_graph_addr(unsigned long addr)
  603. {
  604. int i;
  605. if (!ftrace_graph_filter_enabled)
  606. return 1;
  607. for (i = 0; i < ftrace_graph_count; i++) {
  608. if (addr == ftrace_graph_funcs[i]) {
  609. /*
  610. * If no irqs are to be traced, but a set_graph_function
  611. * is set, and called by an interrupt handler, we still
  612. * want to trace it.
  613. */
  614. if (in_irq())
  615. trace_recursion_set(TRACE_IRQ_BIT);
  616. else
  617. trace_recursion_clear(TRACE_IRQ_BIT);
  618. return 1;
  619. }
  620. }
  621. return 0;
  622. }
  623. #else
  624. static inline int ftrace_graph_addr(unsigned long addr)
  625. {
  626. return 1;
  627. }
  628. #endif /* CONFIG_DYNAMIC_FTRACE */
  629. #else /* CONFIG_FUNCTION_GRAPH_TRACER */
  630. static inline enum print_line_t
  631. print_graph_function_flags(struct trace_iterator *iter, u32 flags)
  632. {
  633. return TRACE_TYPE_UNHANDLED;
  634. }
  635. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  636. extern struct list_head ftrace_pids;
  637. #ifdef CONFIG_FUNCTION_TRACER
  638. static inline int ftrace_trace_task(struct task_struct *task)
  639. {
  640. if (list_empty(&ftrace_pids))
  641. return 1;
  642. return test_tsk_trace_trace(task);
  643. }
  644. extern int ftrace_is_dead(void);
  645. #else
  646. static inline int ftrace_trace_task(struct task_struct *task)
  647. {
  648. return 1;
  649. }
  650. static inline int ftrace_is_dead(void) { return 0; }
  651. #endif
  652. int ftrace_event_is_function(struct ftrace_event_call *call);
  653. /*
  654. * struct trace_parser - servers for reading the user input separated by spaces
  655. * @cont: set if the input is not complete - no final space char was found
  656. * @buffer: holds the parsed user input
  657. * @idx: user input length
  658. * @size: buffer size
  659. */
  660. struct trace_parser {
  661. bool cont;
  662. char *buffer;
  663. unsigned idx;
  664. unsigned size;
  665. };
  666. static inline bool trace_parser_loaded(struct trace_parser *parser)
  667. {
  668. return (parser->idx != 0);
  669. }
  670. static inline bool trace_parser_cont(struct trace_parser *parser)
  671. {
  672. return parser->cont;
  673. }
  674. static inline void trace_parser_clear(struct trace_parser *parser)
  675. {
  676. parser->cont = false;
  677. parser->idx = 0;
  678. }
  679. extern int trace_parser_get_init(struct trace_parser *parser, int size);
  680. extern void trace_parser_put(struct trace_parser *parser);
  681. extern int trace_get_user(struct trace_parser *parser, const char __user *ubuf,
  682. size_t cnt, loff_t *ppos);
  683. /*
  684. * trace_iterator_flags is an enumeration that defines bit
  685. * positions into trace_flags that controls the output.
  686. *
  687. * NOTE: These bits must match the trace_options array in
  688. * trace.c.
  689. */
  690. enum trace_iterator_flags {
  691. TRACE_ITER_PRINT_PARENT = 0x01,
  692. TRACE_ITER_SYM_OFFSET = 0x02,
  693. TRACE_ITER_SYM_ADDR = 0x04,
  694. TRACE_ITER_VERBOSE = 0x08,
  695. TRACE_ITER_RAW = 0x10,
  696. TRACE_ITER_HEX = 0x20,
  697. TRACE_ITER_BIN = 0x40,
  698. TRACE_ITER_BLOCK = 0x80,
  699. TRACE_ITER_STACKTRACE = 0x100,
  700. TRACE_ITER_PRINTK = 0x200,
  701. TRACE_ITER_PREEMPTONLY = 0x400,
  702. TRACE_ITER_BRANCH = 0x800,
  703. TRACE_ITER_ANNOTATE = 0x1000,
  704. TRACE_ITER_USERSTACKTRACE = 0x2000,
  705. TRACE_ITER_SYM_USEROBJ = 0x4000,
  706. TRACE_ITER_PRINTK_MSGONLY = 0x8000,
  707. TRACE_ITER_CONTEXT_INFO = 0x10000, /* Print pid/cpu/time */
  708. TRACE_ITER_LATENCY_FMT = 0x20000,
  709. TRACE_ITER_SLEEP_TIME = 0x40000,
  710. TRACE_ITER_GRAPH_TIME = 0x80000,
  711. TRACE_ITER_RECORD_CMD = 0x100000,
  712. TRACE_ITER_OVERWRITE = 0x200000,
  713. TRACE_ITER_STOP_ON_FREE = 0x400000,
  714. TRACE_ITER_IRQ_INFO = 0x800000,
  715. TRACE_ITER_MARKERS = 0x1000000,
  716. };
  717. /*
  718. * TRACE_ITER_SYM_MASK masks the options in trace_flags that
  719. * control the output of kernel symbols.
  720. */
  721. #define TRACE_ITER_SYM_MASK \
  722. (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR)
  723. extern struct tracer nop_trace;
  724. #ifdef CONFIG_BRANCH_TRACER
  725. extern int enable_branch_tracing(struct trace_array *tr);
  726. extern void disable_branch_tracing(void);
  727. static inline int trace_branch_enable(struct trace_array *tr)
  728. {
  729. if (trace_flags & TRACE_ITER_BRANCH)
  730. return enable_branch_tracing(tr);
  731. return 0;
  732. }
  733. static inline void trace_branch_disable(void)
  734. {
  735. /* due to races, always disable */
  736. disable_branch_tracing();
  737. }
  738. #else
  739. static inline int trace_branch_enable(struct trace_array *tr)
  740. {
  741. return 0;
  742. }
  743. static inline void trace_branch_disable(void)
  744. {
  745. }
  746. #endif /* CONFIG_BRANCH_TRACER */
  747. /* set ring buffers to default size if not already done so */
  748. int tracing_update_buffers(void);
  749. /* trace event type bit fields, not numeric */
  750. enum {
  751. TRACE_EVENT_TYPE_PRINTF = 1,
  752. TRACE_EVENT_TYPE_RAW = 2,
  753. };
  754. struct ftrace_event_field {
  755. struct list_head link;
  756. const char *name;
  757. const char *type;
  758. int filter_type;
  759. int offset;
  760. int size;
  761. int is_signed;
  762. };
  763. struct event_filter {
  764. int n_preds; /* Number assigned */
  765. int a_preds; /* allocated */
  766. struct filter_pred *preds;
  767. struct filter_pred *root;
  768. char *filter_string;
  769. };
  770. struct event_subsystem {
  771. struct list_head list;
  772. const char *name;
  773. struct event_filter *filter;
  774. int ref_count;
  775. };
  776. struct ftrace_subsystem_dir {
  777. struct list_head list;
  778. struct event_subsystem *subsystem;
  779. struct trace_array *tr;
  780. struct dentry *entry;
  781. int ref_count;
  782. int nr_events;
  783. };
  784. #define FILTER_PRED_INVALID ((unsigned short)-1)
  785. #define FILTER_PRED_IS_RIGHT (1 << 15)
  786. #define FILTER_PRED_FOLD (1 << 15)
  787. /*
  788. * The max preds is the size of unsigned short with
  789. * two flags at the MSBs. One bit is used for both the IS_RIGHT
  790. * and FOLD flags. The other is reserved.
  791. *
  792. * 2^14 preds is way more than enough.
  793. */
  794. #define MAX_FILTER_PRED 16384
  795. struct filter_pred;
  796. struct regex;
  797. typedef int (*filter_pred_fn_t) (struct filter_pred *pred, void *event);
  798. typedef int (*regex_match_func)(char *str, struct regex *r, int len);
  799. enum regex_type {
  800. MATCH_FULL = 0,
  801. MATCH_FRONT_ONLY,
  802. MATCH_MIDDLE_ONLY,
  803. MATCH_END_ONLY,
  804. };
  805. struct regex {
  806. char pattern[MAX_FILTER_STR_VAL];
  807. int len;
  808. int field_len;
  809. regex_match_func match;
  810. };
  811. struct filter_pred {
  812. filter_pred_fn_t fn;
  813. u64 val;
  814. struct regex regex;
  815. unsigned short *ops;
  816. struct ftrace_event_field *field;
  817. int offset;
  818. int not;
  819. int op;
  820. unsigned short index;
  821. unsigned short parent;
  822. unsigned short left;
  823. unsigned short right;
  824. };
  825. extern struct list_head ftrace_common_fields;
  826. extern enum regex_type
  827. filter_parse_regex(char *buff, int len, char **search, int *not);
  828. extern void print_event_filter(struct ftrace_event_call *call,
  829. struct trace_seq *s);
  830. extern int apply_event_filter(struct ftrace_event_call *call,
  831. char *filter_string);
  832. extern int apply_subsystem_event_filter(struct ftrace_subsystem_dir *dir,
  833. char *filter_string);
  834. extern void print_subsystem_event_filter(struct event_subsystem *system,
  835. struct trace_seq *s);
  836. extern int filter_assign_type(const char *type);
  837. struct list_head *
  838. trace_get_fields(struct ftrace_event_call *event_call);
  839. static inline int
  840. filter_check_discard(struct ftrace_event_call *call, void *rec,
  841. struct ring_buffer *buffer,
  842. struct ring_buffer_event *event)
  843. {
  844. if (unlikely(call->flags & TRACE_EVENT_FL_FILTERED) &&
  845. !filter_match_preds(call->filter, rec)) {
  846. ring_buffer_discard_commit(buffer, event);
  847. return 1;
  848. }
  849. return 0;
  850. }
  851. extern void trace_event_enable_cmd_record(bool enable);
  852. extern int event_trace_add_tracer(struct dentry *parent, struct trace_array *tr);
  853. extern int event_trace_del_tracer(struct trace_array *tr);
  854. extern struct mutex event_mutex;
  855. extern struct list_head ftrace_events;
  856. extern const char *__start___trace_bprintk_fmt[];
  857. extern const char *__stop___trace_bprintk_fmt[];
  858. void trace_printk_init_buffers(void);
  859. void trace_printk_start_comm(void);
  860. int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
  861. int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
  862. #undef FTRACE_ENTRY
  863. #define FTRACE_ENTRY(call, struct_name, id, tstruct, print, filter) \
  864. extern struct ftrace_event_call \
  865. __attribute__((__aligned__(4))) event_##call;
  866. #undef FTRACE_ENTRY_DUP
  867. #define FTRACE_ENTRY_DUP(call, struct_name, id, tstruct, print, filter) \
  868. FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print), \
  869. filter)
  870. #include "trace_entries.h"
  871. #if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_FUNCTION_TRACER)
  872. int perf_ftrace_event_register(struct ftrace_event_call *call,
  873. enum trace_reg type, void *data);
  874. #else
  875. #define perf_ftrace_event_register NULL
  876. #endif
  877. #endif /* _LINUX_KERNEL_TRACE_H */