trace.h 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601
  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. TRACE_FLAG_NMI = 0x40,
  106. };
  107. #define TRACE_BUF_SIZE 1024
  108. struct trace_array;
  109. /*
  110. * The CPU trace array - it consists of thousands of trace entries
  111. * plus some other descriptor data: (for example which task started
  112. * the trace, etc.)
  113. */
  114. struct trace_array_cpu {
  115. atomic_t disabled;
  116. void *buffer_page; /* ring buffer spare */
  117. unsigned long entries;
  118. unsigned long saved_latency;
  119. unsigned long critical_start;
  120. unsigned long critical_end;
  121. unsigned long critical_sequence;
  122. unsigned long nice;
  123. unsigned long policy;
  124. unsigned long rt_priority;
  125. unsigned long skipped_entries;
  126. cycle_t preempt_timestamp;
  127. pid_t pid;
  128. kuid_t uid;
  129. char comm[TASK_COMM_LEN];
  130. bool ignore_pid;
  131. };
  132. struct tracer;
  133. struct trace_option_dentry;
  134. struct trace_buffer {
  135. struct trace_array *tr;
  136. struct ring_buffer *buffer;
  137. struct trace_array_cpu __percpu *data;
  138. cycle_t time_start;
  139. int cpu;
  140. };
  141. #define TRACE_FLAGS_MAX_SIZE 32
  142. struct trace_options {
  143. struct tracer *tracer;
  144. struct trace_option_dentry *topts;
  145. };
  146. struct trace_pid_list {
  147. int pid_max;
  148. unsigned long *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. extern void trace_event_follow_fork(struct trace_array *tr, bool enable);
  558. #ifdef CONFIG_DYNAMIC_FTRACE
  559. extern unsigned long ftrace_update_tot_cnt;
  560. #endif
  561. #define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
  562. extern int DYN_FTRACE_TEST_NAME(void);
  563. #define DYN_FTRACE_TEST_NAME2 trace_selftest_dynamic_test_func2
  564. extern int DYN_FTRACE_TEST_NAME2(void);
  565. extern bool ring_buffer_expanded;
  566. extern bool tracing_selftest_disabled;
  567. #ifdef CONFIG_FTRACE_STARTUP_TEST
  568. extern int trace_selftest_startup_function(struct tracer *trace,
  569. struct trace_array *tr);
  570. extern int trace_selftest_startup_function_graph(struct tracer *trace,
  571. struct trace_array *tr);
  572. extern int trace_selftest_startup_irqsoff(struct tracer *trace,
  573. struct trace_array *tr);
  574. extern int trace_selftest_startup_preemptoff(struct tracer *trace,
  575. struct trace_array *tr);
  576. extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
  577. struct trace_array *tr);
  578. extern int trace_selftest_startup_wakeup(struct tracer *trace,
  579. struct trace_array *tr);
  580. extern int trace_selftest_startup_nop(struct tracer *trace,
  581. struct trace_array *tr);
  582. extern int trace_selftest_startup_sched_switch(struct tracer *trace,
  583. struct trace_array *tr);
  584. extern int trace_selftest_startup_branch(struct tracer *trace,
  585. struct trace_array *tr);
  586. /*
  587. * Tracer data references selftest functions that only occur
  588. * on boot up. These can be __init functions. Thus, when selftests
  589. * are enabled, then the tracers need to reference __init functions.
  590. */
  591. #define __tracer_data __refdata
  592. #else
  593. /* Tracers are seldom changed. Optimize when selftests are disabled. */
  594. #define __tracer_data __read_mostly
  595. #endif /* CONFIG_FTRACE_STARTUP_TEST */
  596. extern void *head_page(struct trace_array_cpu *data);
  597. extern unsigned long long ns2usecs(cycle_t nsec);
  598. extern int
  599. trace_vbprintk(unsigned long ip, const char *fmt, va_list args);
  600. extern int
  601. trace_vprintk(unsigned long ip, const char *fmt, va_list args);
  602. extern int
  603. trace_array_vprintk(struct trace_array *tr,
  604. unsigned long ip, const char *fmt, va_list args);
  605. int trace_array_printk(struct trace_array *tr,
  606. unsigned long ip, const char *fmt, ...);
  607. int trace_array_printk_buf(struct ring_buffer *buffer,
  608. unsigned long ip, const char *fmt, ...);
  609. void trace_printk_seq(struct trace_seq *s);
  610. enum print_line_t print_trace_line(struct trace_iterator *iter);
  611. extern char trace_find_mark(unsigned long long duration);
  612. /* Standard output formatting function used for function return traces */
  613. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  614. /* Flag options */
  615. #define TRACE_GRAPH_PRINT_OVERRUN 0x1
  616. #define TRACE_GRAPH_PRINT_CPU 0x2
  617. #define TRACE_GRAPH_PRINT_OVERHEAD 0x4
  618. #define TRACE_GRAPH_PRINT_PROC 0x8
  619. #define TRACE_GRAPH_PRINT_DURATION 0x10
  620. #define TRACE_GRAPH_PRINT_ABS_TIME 0x20
  621. #define TRACE_GRAPH_PRINT_IRQS 0x40
  622. #define TRACE_GRAPH_PRINT_TAIL 0x80
  623. #define TRACE_GRAPH_SLEEP_TIME 0x100
  624. #define TRACE_GRAPH_GRAPH_TIME 0x200
  625. #define TRACE_GRAPH_PRINT_FILL_SHIFT 28
  626. #define TRACE_GRAPH_PRINT_FILL_MASK (0x3 << TRACE_GRAPH_PRINT_FILL_SHIFT)
  627. extern void ftrace_graph_sleep_time_control(bool enable);
  628. extern void ftrace_graph_graph_time_control(bool enable);
  629. extern enum print_line_t
  630. print_graph_function_flags(struct trace_iterator *iter, u32 flags);
  631. extern void print_graph_headers_flags(struct seq_file *s, u32 flags);
  632. extern void
  633. trace_print_graph_duration(unsigned long long duration, struct trace_seq *s);
  634. extern void graph_trace_open(struct trace_iterator *iter);
  635. extern void graph_trace_close(struct trace_iterator *iter);
  636. extern int __trace_graph_entry(struct trace_array *tr,
  637. struct ftrace_graph_ent *trace,
  638. unsigned long flags, int pc);
  639. extern void __trace_graph_return(struct trace_array *tr,
  640. struct ftrace_graph_ret *trace,
  641. unsigned long flags, int pc);
  642. #ifdef CONFIG_DYNAMIC_FTRACE
  643. /* TODO: make this variable */
  644. #define FTRACE_GRAPH_MAX_FUNCS 32
  645. extern int ftrace_graph_count;
  646. extern unsigned long ftrace_graph_funcs[FTRACE_GRAPH_MAX_FUNCS];
  647. extern int ftrace_graph_notrace_count;
  648. extern unsigned long ftrace_graph_notrace_funcs[FTRACE_GRAPH_MAX_FUNCS];
  649. static inline int ftrace_graph_addr(unsigned long addr)
  650. {
  651. int i;
  652. if (!ftrace_graph_count)
  653. return 1;
  654. for (i = 0; i < ftrace_graph_count; i++) {
  655. if (addr == ftrace_graph_funcs[i]) {
  656. /*
  657. * If no irqs are to be traced, but a set_graph_function
  658. * is set, and called by an interrupt handler, we still
  659. * want to trace it.
  660. */
  661. if (in_irq())
  662. trace_recursion_set(TRACE_IRQ_BIT);
  663. else
  664. trace_recursion_clear(TRACE_IRQ_BIT);
  665. return 1;
  666. }
  667. }
  668. return 0;
  669. }
  670. static inline int ftrace_graph_notrace_addr(unsigned long addr)
  671. {
  672. int i;
  673. if (!ftrace_graph_notrace_count)
  674. return 0;
  675. for (i = 0; i < ftrace_graph_notrace_count; i++) {
  676. if (addr == ftrace_graph_notrace_funcs[i])
  677. return 1;
  678. }
  679. return 0;
  680. }
  681. #else
  682. static inline int ftrace_graph_addr(unsigned long addr)
  683. {
  684. return 1;
  685. }
  686. static inline int ftrace_graph_notrace_addr(unsigned long addr)
  687. {
  688. return 0;
  689. }
  690. #endif /* CONFIG_DYNAMIC_FTRACE */
  691. #else /* CONFIG_FUNCTION_GRAPH_TRACER */
  692. static inline enum print_line_t
  693. print_graph_function_flags(struct trace_iterator *iter, u32 flags)
  694. {
  695. return TRACE_TYPE_UNHANDLED;
  696. }
  697. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  698. extern struct list_head ftrace_pids;
  699. #ifdef CONFIG_FUNCTION_TRACER
  700. extern bool ftrace_filter_param __initdata;
  701. static inline int ftrace_trace_task(struct task_struct *task)
  702. {
  703. if (list_empty(&ftrace_pids))
  704. return 1;
  705. return test_tsk_trace_trace(task);
  706. }
  707. extern int ftrace_is_dead(void);
  708. int ftrace_create_function_files(struct trace_array *tr,
  709. struct dentry *parent);
  710. void ftrace_destroy_function_files(struct trace_array *tr);
  711. void ftrace_init_global_array_ops(struct trace_array *tr);
  712. void ftrace_init_array_ops(struct trace_array *tr, ftrace_func_t func);
  713. void ftrace_reset_array_ops(struct trace_array *tr);
  714. int using_ftrace_ops_list_func(void);
  715. #else
  716. static inline int ftrace_trace_task(struct task_struct *task)
  717. {
  718. return 1;
  719. }
  720. static inline int ftrace_is_dead(void) { return 0; }
  721. static inline int
  722. ftrace_create_function_files(struct trace_array *tr,
  723. struct dentry *parent)
  724. {
  725. return 0;
  726. }
  727. static inline void ftrace_destroy_function_files(struct trace_array *tr) { }
  728. static inline __init void
  729. ftrace_init_global_array_ops(struct trace_array *tr) { }
  730. static inline void ftrace_reset_array_ops(struct trace_array *tr) { }
  731. /* ftace_func_t type is not defined, use macro instead of static inline */
  732. #define ftrace_init_array_ops(tr, func) do { } while (0)
  733. #endif /* CONFIG_FUNCTION_TRACER */
  734. #if defined(CONFIG_FUNCTION_TRACER) && defined(CONFIG_DYNAMIC_FTRACE)
  735. void ftrace_create_filter_files(struct ftrace_ops *ops,
  736. struct dentry *parent);
  737. void ftrace_destroy_filter_files(struct ftrace_ops *ops);
  738. #else
  739. /*
  740. * The ops parameter passed in is usually undefined.
  741. * This must be a macro.
  742. */
  743. #define ftrace_create_filter_files(ops, parent) do { } while (0)
  744. #define ftrace_destroy_filter_files(ops) do { } while (0)
  745. #endif /* CONFIG_FUNCTION_TRACER && CONFIG_DYNAMIC_FTRACE */
  746. bool ftrace_event_is_function(struct trace_event_call *call);
  747. /*
  748. * struct trace_parser - servers for reading the user input separated by spaces
  749. * @cont: set if the input is not complete - no final space char was found
  750. * @buffer: holds the parsed user input
  751. * @idx: user input length
  752. * @size: buffer size
  753. */
  754. struct trace_parser {
  755. bool cont;
  756. char *buffer;
  757. unsigned idx;
  758. unsigned size;
  759. };
  760. static inline bool trace_parser_loaded(struct trace_parser *parser)
  761. {
  762. return (parser->idx != 0);
  763. }
  764. static inline bool trace_parser_cont(struct trace_parser *parser)
  765. {
  766. return parser->cont;
  767. }
  768. static inline void trace_parser_clear(struct trace_parser *parser)
  769. {
  770. parser->cont = false;
  771. parser->idx = 0;
  772. }
  773. extern int trace_parser_get_init(struct trace_parser *parser, int size);
  774. extern void trace_parser_put(struct trace_parser *parser);
  775. extern int trace_get_user(struct trace_parser *parser, const char __user *ubuf,
  776. size_t cnt, loff_t *ppos);
  777. /*
  778. * Only create function graph options if function graph is configured.
  779. */
  780. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  781. # define FGRAPH_FLAGS \
  782. C(DISPLAY_GRAPH, "display-graph"),
  783. #else
  784. # define FGRAPH_FLAGS
  785. #endif
  786. #ifdef CONFIG_BRANCH_TRACER
  787. # define BRANCH_FLAGS \
  788. C(BRANCH, "branch"),
  789. #else
  790. # define BRANCH_FLAGS
  791. #endif
  792. #ifdef CONFIG_FUNCTION_TRACER
  793. # define FUNCTION_FLAGS \
  794. C(FUNCTION, "function-trace"),
  795. # define FUNCTION_DEFAULT_FLAGS TRACE_ITER_FUNCTION
  796. #else
  797. # define FUNCTION_FLAGS
  798. # define FUNCTION_DEFAULT_FLAGS 0UL
  799. #endif
  800. #ifdef CONFIG_STACKTRACE
  801. # define STACK_FLAGS \
  802. C(STACKTRACE, "stacktrace"),
  803. #else
  804. # define STACK_FLAGS
  805. #endif
  806. /*
  807. * trace_iterator_flags is an enumeration that defines bit
  808. * positions into trace_flags that controls the output.
  809. *
  810. * NOTE: These bits must match the trace_options array in
  811. * trace.c (this macro guarantees it).
  812. */
  813. #define TRACE_FLAGS \
  814. C(PRINT_PARENT, "print-parent"), \
  815. C(SYM_OFFSET, "sym-offset"), \
  816. C(SYM_ADDR, "sym-addr"), \
  817. C(VERBOSE, "verbose"), \
  818. C(RAW, "raw"), \
  819. C(HEX, "hex"), \
  820. C(BIN, "bin"), \
  821. C(BLOCK, "block"), \
  822. C(PRINTK, "trace_printk"), \
  823. C(ANNOTATE, "annotate"), \
  824. C(USERSTACKTRACE, "userstacktrace"), \
  825. C(SYM_USEROBJ, "sym-userobj"), \
  826. C(PRINTK_MSGONLY, "printk-msg-only"), \
  827. C(CONTEXT_INFO, "context-info"), /* Print pid/cpu/time */ \
  828. C(LATENCY_FMT, "latency-format"), \
  829. C(RECORD_CMD, "record-cmd"), \
  830. C(OVERWRITE, "overwrite"), \
  831. C(STOP_ON_FREE, "disable_on_free"), \
  832. C(IRQ_INFO, "irq-info"), \
  833. C(MARKERS, "markers"), \
  834. C(EVENT_FORK, "event-fork"), \
  835. FUNCTION_FLAGS \
  836. FGRAPH_FLAGS \
  837. STACK_FLAGS \
  838. BRANCH_FLAGS
  839. /*
  840. * By defining C, we can make TRACE_FLAGS a list of bit names
  841. * that will define the bits for the flag masks.
  842. */
  843. #undef C
  844. #define C(a, b) TRACE_ITER_##a##_BIT
  845. enum trace_iterator_bits {
  846. TRACE_FLAGS
  847. /* Make sure we don't go more than we have bits for */
  848. TRACE_ITER_LAST_BIT
  849. };
  850. /*
  851. * By redefining C, we can make TRACE_FLAGS a list of masks that
  852. * use the bits as defined above.
  853. */
  854. #undef C
  855. #define C(a, b) TRACE_ITER_##a = (1 << TRACE_ITER_##a##_BIT)
  856. enum trace_iterator_flags { TRACE_FLAGS };
  857. /*
  858. * TRACE_ITER_SYM_MASK masks the options in trace_flags that
  859. * control the output of kernel symbols.
  860. */
  861. #define TRACE_ITER_SYM_MASK \
  862. (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR)
  863. extern struct tracer nop_trace;
  864. #ifdef CONFIG_BRANCH_TRACER
  865. extern int enable_branch_tracing(struct trace_array *tr);
  866. extern void disable_branch_tracing(void);
  867. static inline int trace_branch_enable(struct trace_array *tr)
  868. {
  869. if (tr->trace_flags & TRACE_ITER_BRANCH)
  870. return enable_branch_tracing(tr);
  871. return 0;
  872. }
  873. static inline void trace_branch_disable(void)
  874. {
  875. /* due to races, always disable */
  876. disable_branch_tracing();
  877. }
  878. #else
  879. static inline int trace_branch_enable(struct trace_array *tr)
  880. {
  881. return 0;
  882. }
  883. static inline void trace_branch_disable(void)
  884. {
  885. }
  886. #endif /* CONFIG_BRANCH_TRACER */
  887. /* set ring buffers to default size if not already done so */
  888. int tracing_update_buffers(void);
  889. struct ftrace_event_field {
  890. struct list_head link;
  891. const char *name;
  892. const char *type;
  893. int filter_type;
  894. int offset;
  895. int size;
  896. int is_signed;
  897. };
  898. struct event_filter {
  899. int n_preds; /* Number assigned */
  900. int a_preds; /* allocated */
  901. struct filter_pred *preds;
  902. struct filter_pred *root;
  903. char *filter_string;
  904. };
  905. struct event_subsystem {
  906. struct list_head list;
  907. const char *name;
  908. struct event_filter *filter;
  909. int ref_count;
  910. };
  911. struct trace_subsystem_dir {
  912. struct list_head list;
  913. struct event_subsystem *subsystem;
  914. struct trace_array *tr;
  915. struct dentry *entry;
  916. int ref_count;
  917. int nr_events;
  918. };
  919. extern int call_filter_check_discard(struct trace_event_call *call, void *rec,
  920. struct ring_buffer *buffer,
  921. struct ring_buffer_event *event);
  922. /*
  923. * Helper function for event_trigger_unlock_commit{_regs}().
  924. * If there are event triggers attached to this event that requires
  925. * filtering against its fields, then they wil be called as the
  926. * entry already holds the field information of the current event.
  927. *
  928. * It also checks if the event should be discarded or not.
  929. * It is to be discarded if the event is soft disabled and the
  930. * event was only recorded to process triggers, or if the event
  931. * filter is active and this event did not match the filters.
  932. *
  933. * Returns true if the event is discarded, false otherwise.
  934. */
  935. static inline bool
  936. __event_trigger_test_discard(struct trace_event_file *file,
  937. struct ring_buffer *buffer,
  938. struct ring_buffer_event *event,
  939. void *entry,
  940. enum event_trigger_type *tt)
  941. {
  942. unsigned long eflags = file->flags;
  943. if (eflags & EVENT_FILE_FL_TRIGGER_COND)
  944. *tt = event_triggers_call(file, entry);
  945. if (test_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &file->flags) ||
  946. (unlikely(file->flags & EVENT_FILE_FL_FILTERED) &&
  947. !filter_match_preds(file->filter, entry))) {
  948. ring_buffer_discard_commit(buffer, event);
  949. return true;
  950. }
  951. return false;
  952. }
  953. /**
  954. * event_trigger_unlock_commit - handle triggers and finish event commit
  955. * @file: The file pointer assoctiated to the event
  956. * @buffer: The ring buffer that the event is being written to
  957. * @event: The event meta data in the ring buffer
  958. * @entry: The event itself
  959. * @irq_flags: The state of the interrupts at the start of the event
  960. * @pc: The state of the preempt count at the start of the event.
  961. *
  962. * This is a helper function to handle triggers that require data
  963. * from the event itself. It also tests the event against filters and
  964. * if the event is soft disabled and should be discarded.
  965. */
  966. static inline void
  967. event_trigger_unlock_commit(struct trace_event_file *file,
  968. struct ring_buffer *buffer,
  969. struct ring_buffer_event *event,
  970. void *entry, unsigned long irq_flags, int pc)
  971. {
  972. enum event_trigger_type tt = ETT_NONE;
  973. if (!__event_trigger_test_discard(file, buffer, event, entry, &tt))
  974. trace_buffer_unlock_commit(file->tr, buffer, event, irq_flags, pc);
  975. if (tt)
  976. event_triggers_post_call(file, tt, entry);
  977. }
  978. /**
  979. * event_trigger_unlock_commit_regs - handle triggers and finish event commit
  980. * @file: The file pointer assoctiated to the event
  981. * @buffer: The ring buffer that the event is being written to
  982. * @event: The event meta data in the ring buffer
  983. * @entry: The event itself
  984. * @irq_flags: The state of the interrupts at the start of the event
  985. * @pc: The state of the preempt count at the start of the event.
  986. *
  987. * This is a helper function to handle triggers that require data
  988. * from the event itself. It also tests the event against filters and
  989. * if the event is soft disabled and should be discarded.
  990. *
  991. * Same as event_trigger_unlock_commit() but calls
  992. * trace_buffer_unlock_commit_regs() instead of trace_buffer_unlock_commit().
  993. */
  994. static inline void
  995. event_trigger_unlock_commit_regs(struct trace_event_file *file,
  996. struct ring_buffer *buffer,
  997. struct ring_buffer_event *event,
  998. void *entry, unsigned long irq_flags, int pc,
  999. struct pt_regs *regs)
  1000. {
  1001. enum event_trigger_type tt = ETT_NONE;
  1002. if (!__event_trigger_test_discard(file, buffer, event, entry, &tt))
  1003. trace_buffer_unlock_commit_regs(file->tr, buffer, event,
  1004. irq_flags, pc, regs);
  1005. if (tt)
  1006. event_triggers_post_call(file, tt, entry);
  1007. }
  1008. #define FILTER_PRED_INVALID ((unsigned short)-1)
  1009. #define FILTER_PRED_IS_RIGHT (1 << 15)
  1010. #define FILTER_PRED_FOLD (1 << 15)
  1011. /*
  1012. * The max preds is the size of unsigned short with
  1013. * two flags at the MSBs. One bit is used for both the IS_RIGHT
  1014. * and FOLD flags. The other is reserved.
  1015. *
  1016. * 2^14 preds is way more than enough.
  1017. */
  1018. #define MAX_FILTER_PRED 16384
  1019. struct filter_pred;
  1020. struct regex;
  1021. typedef int (*filter_pred_fn_t) (struct filter_pred *pred, void *event);
  1022. typedef int (*regex_match_func)(char *str, struct regex *r, int len);
  1023. enum regex_type {
  1024. MATCH_FULL = 0,
  1025. MATCH_FRONT_ONLY,
  1026. MATCH_MIDDLE_ONLY,
  1027. MATCH_END_ONLY,
  1028. };
  1029. struct regex {
  1030. char pattern[MAX_FILTER_STR_VAL];
  1031. int len;
  1032. int field_len;
  1033. regex_match_func match;
  1034. };
  1035. struct filter_pred {
  1036. filter_pred_fn_t fn;
  1037. u64 val;
  1038. struct regex regex;
  1039. unsigned short *ops;
  1040. struct ftrace_event_field *field;
  1041. int offset;
  1042. int not;
  1043. int op;
  1044. unsigned short index;
  1045. unsigned short parent;
  1046. unsigned short left;
  1047. unsigned short right;
  1048. };
  1049. static inline bool is_string_field(struct ftrace_event_field *field)
  1050. {
  1051. return field->filter_type == FILTER_DYN_STRING ||
  1052. field->filter_type == FILTER_STATIC_STRING ||
  1053. field->filter_type == FILTER_PTR_STRING;
  1054. }
  1055. static inline bool is_function_field(struct ftrace_event_field *field)
  1056. {
  1057. return field->filter_type == FILTER_TRACE_FN;
  1058. }
  1059. extern enum regex_type
  1060. filter_parse_regex(char *buff, int len, char **search, int *not);
  1061. extern void print_event_filter(struct trace_event_file *file,
  1062. struct trace_seq *s);
  1063. extern int apply_event_filter(struct trace_event_file *file,
  1064. char *filter_string);
  1065. extern int apply_subsystem_event_filter(struct trace_subsystem_dir *dir,
  1066. char *filter_string);
  1067. extern void print_subsystem_event_filter(struct event_subsystem *system,
  1068. struct trace_seq *s);
  1069. extern int filter_assign_type(const char *type);
  1070. extern int create_event_filter(struct trace_event_call *call,
  1071. char *filter_str, bool set_str,
  1072. struct event_filter **filterp);
  1073. extern void free_event_filter(struct event_filter *filter);
  1074. struct ftrace_event_field *
  1075. trace_find_event_field(struct trace_event_call *call, char *name);
  1076. extern void trace_event_enable_cmd_record(bool enable);
  1077. extern int event_trace_add_tracer(struct dentry *parent, struct trace_array *tr);
  1078. extern int event_trace_del_tracer(struct trace_array *tr);
  1079. extern struct trace_event_file *find_event_file(struct trace_array *tr,
  1080. const char *system,
  1081. const char *event);
  1082. static inline void *event_file_data(struct file *filp)
  1083. {
  1084. return ACCESS_ONCE(file_inode(filp)->i_private);
  1085. }
  1086. extern struct mutex event_mutex;
  1087. extern struct list_head ftrace_events;
  1088. extern const struct file_operations event_trigger_fops;
  1089. extern const struct file_operations event_hist_fops;
  1090. #ifdef CONFIG_HIST_TRIGGERS
  1091. extern int register_trigger_hist_cmd(void);
  1092. extern int register_trigger_hist_enable_disable_cmds(void);
  1093. #else
  1094. static inline int register_trigger_hist_cmd(void) { return 0; }
  1095. static inline int register_trigger_hist_enable_disable_cmds(void) { return 0; }
  1096. #endif
  1097. extern int register_trigger_cmds(void);
  1098. extern void clear_event_triggers(struct trace_array *tr);
  1099. struct event_trigger_data {
  1100. unsigned long count;
  1101. int ref;
  1102. struct event_trigger_ops *ops;
  1103. struct event_command *cmd_ops;
  1104. struct event_filter __rcu *filter;
  1105. char *filter_str;
  1106. void *private_data;
  1107. bool paused;
  1108. bool paused_tmp;
  1109. struct list_head list;
  1110. char *name;
  1111. struct list_head named_list;
  1112. struct event_trigger_data *named_data;
  1113. };
  1114. /* Avoid typos */
  1115. #define ENABLE_EVENT_STR "enable_event"
  1116. #define DISABLE_EVENT_STR "disable_event"
  1117. #define ENABLE_HIST_STR "enable_hist"
  1118. #define DISABLE_HIST_STR "disable_hist"
  1119. struct enable_trigger_data {
  1120. struct trace_event_file *file;
  1121. bool enable;
  1122. bool hist;
  1123. };
  1124. extern int event_enable_trigger_print(struct seq_file *m,
  1125. struct event_trigger_ops *ops,
  1126. struct event_trigger_data *data);
  1127. extern void event_enable_trigger_free(struct event_trigger_ops *ops,
  1128. struct event_trigger_data *data);
  1129. extern int event_enable_trigger_func(struct event_command *cmd_ops,
  1130. struct trace_event_file *file,
  1131. char *glob, char *cmd, char *param);
  1132. extern int event_enable_register_trigger(char *glob,
  1133. struct event_trigger_ops *ops,
  1134. struct event_trigger_data *data,
  1135. struct trace_event_file *file);
  1136. extern void event_enable_unregister_trigger(char *glob,
  1137. struct event_trigger_ops *ops,
  1138. struct event_trigger_data *test,
  1139. struct trace_event_file *file);
  1140. extern void trigger_data_free(struct event_trigger_data *data);
  1141. extern int event_trigger_init(struct event_trigger_ops *ops,
  1142. struct event_trigger_data *data);
  1143. extern int trace_event_trigger_enable_disable(struct trace_event_file *file,
  1144. int trigger_enable);
  1145. extern void update_cond_flag(struct trace_event_file *file);
  1146. extern void unregister_trigger(char *glob, struct event_trigger_ops *ops,
  1147. struct event_trigger_data *test,
  1148. struct trace_event_file *file);
  1149. extern int set_trigger_filter(char *filter_str,
  1150. struct event_trigger_data *trigger_data,
  1151. struct trace_event_file *file);
  1152. extern struct event_trigger_data *find_named_trigger(const char *name);
  1153. extern bool is_named_trigger(struct event_trigger_data *test);
  1154. extern int save_named_trigger(const char *name,
  1155. struct event_trigger_data *data);
  1156. extern void del_named_trigger(struct event_trigger_data *data);
  1157. extern void pause_named_trigger(struct event_trigger_data *data);
  1158. extern void unpause_named_trigger(struct event_trigger_data *data);
  1159. extern void set_named_trigger_data(struct event_trigger_data *data,
  1160. struct event_trigger_data *named_data);
  1161. extern int register_event_command(struct event_command *cmd);
  1162. extern int unregister_event_command(struct event_command *cmd);
  1163. extern int register_trigger_hist_enable_disable_cmds(void);
  1164. /**
  1165. * struct event_trigger_ops - callbacks for trace event triggers
  1166. *
  1167. * The methods in this structure provide per-event trigger hooks for
  1168. * various trigger operations.
  1169. *
  1170. * All the methods below, except for @init() and @free(), must be
  1171. * implemented.
  1172. *
  1173. * @func: The trigger 'probe' function called when the triggering
  1174. * event occurs. The data passed into this callback is the data
  1175. * that was supplied to the event_command @reg() function that
  1176. * registered the trigger (see struct event_command) along with
  1177. * the trace record, rec.
  1178. *
  1179. * @init: An optional initialization function called for the trigger
  1180. * when the trigger is registered (via the event_command reg()
  1181. * function). This can be used to perform per-trigger
  1182. * initialization such as incrementing a per-trigger reference
  1183. * count, for instance. This is usually implemented by the
  1184. * generic utility function @event_trigger_init() (see
  1185. * trace_event_triggers.c).
  1186. *
  1187. * @free: An optional de-initialization function called for the
  1188. * trigger when the trigger is unregistered (via the
  1189. * event_command @reg() function). This can be used to perform
  1190. * per-trigger de-initialization such as decrementing a
  1191. * per-trigger reference count and freeing corresponding trigger
  1192. * data, for instance. This is usually implemented by the
  1193. * generic utility function @event_trigger_free() (see
  1194. * trace_event_triggers.c).
  1195. *
  1196. * @print: The callback function invoked to have the trigger print
  1197. * itself. This is usually implemented by a wrapper function
  1198. * that calls the generic utility function @event_trigger_print()
  1199. * (see trace_event_triggers.c).
  1200. */
  1201. struct event_trigger_ops {
  1202. void (*func)(struct event_trigger_data *data,
  1203. void *rec);
  1204. int (*init)(struct event_trigger_ops *ops,
  1205. struct event_trigger_data *data);
  1206. void (*free)(struct event_trigger_ops *ops,
  1207. struct event_trigger_data *data);
  1208. int (*print)(struct seq_file *m,
  1209. struct event_trigger_ops *ops,
  1210. struct event_trigger_data *data);
  1211. };
  1212. /**
  1213. * struct event_command - callbacks and data members for event commands
  1214. *
  1215. * Event commands are invoked by users by writing the command name
  1216. * into the 'trigger' file associated with a trace event. The
  1217. * parameters associated with a specific invocation of an event
  1218. * command are used to create an event trigger instance, which is
  1219. * added to the list of trigger instances associated with that trace
  1220. * event. When the event is hit, the set of triggers associated with
  1221. * that event is invoked.
  1222. *
  1223. * The data members in this structure provide per-event command data
  1224. * for various event commands.
  1225. *
  1226. * All the data members below, except for @post_trigger, must be set
  1227. * for each event command.
  1228. *
  1229. * @name: The unique name that identifies the event command. This is
  1230. * the name used when setting triggers via trigger files.
  1231. *
  1232. * @trigger_type: A unique id that identifies the event command
  1233. * 'type'. This value has two purposes, the first to ensure that
  1234. * only one trigger of the same type can be set at a given time
  1235. * for a particular event e.g. it doesn't make sense to have both
  1236. * a traceon and traceoff trigger attached to a single event at
  1237. * the same time, so traceon and traceoff have the same type
  1238. * though they have different names. The @trigger_type value is
  1239. * also used as a bit value for deferring the actual trigger
  1240. * action until after the current event is finished. Some
  1241. * commands need to do this if they themselves log to the trace
  1242. * buffer (see the @post_trigger() member below). @trigger_type
  1243. * values are defined by adding new values to the trigger_type
  1244. * enum in include/linux/trace_events.h.
  1245. *
  1246. * @flags: See the enum event_command_flags below.
  1247. *
  1248. * All the methods below, except for @set_filter() and @unreg_all(),
  1249. * must be implemented.
  1250. *
  1251. * @func: The callback function responsible for parsing and
  1252. * registering the trigger written to the 'trigger' file by the
  1253. * user. It allocates the trigger instance and registers it with
  1254. * the appropriate trace event. It makes use of the other
  1255. * event_command callback functions to orchestrate this, and is
  1256. * usually implemented by the generic utility function
  1257. * @event_trigger_callback() (see trace_event_triggers.c).
  1258. *
  1259. * @reg: Adds the trigger to the list of triggers associated with the
  1260. * event, and enables the event trigger itself, after
  1261. * initializing it (via the event_trigger_ops @init() function).
  1262. * This is also where commands can use the @trigger_type value to
  1263. * make the decision as to whether or not multiple instances of
  1264. * the trigger should be allowed. This is usually implemented by
  1265. * the generic utility function @register_trigger() (see
  1266. * trace_event_triggers.c).
  1267. *
  1268. * @unreg: Removes the trigger from the list of triggers associated
  1269. * with the event, and disables the event trigger itself, after
  1270. * initializing it (via the event_trigger_ops @free() function).
  1271. * This is usually implemented by the generic utility function
  1272. * @unregister_trigger() (see trace_event_triggers.c).
  1273. *
  1274. * @unreg_all: An optional function called to remove all the triggers
  1275. * from the list of triggers associated with the event. Called
  1276. * when a trigger file is opened in truncate mode.
  1277. *
  1278. * @set_filter: An optional function called to parse and set a filter
  1279. * for the trigger. If no @set_filter() method is set for the
  1280. * event command, filters set by the user for the command will be
  1281. * ignored. This is usually implemented by the generic utility
  1282. * function @set_trigger_filter() (see trace_event_triggers.c).
  1283. *
  1284. * @get_trigger_ops: The callback function invoked to retrieve the
  1285. * event_trigger_ops implementation associated with the command.
  1286. */
  1287. struct event_command {
  1288. struct list_head list;
  1289. char *name;
  1290. enum event_trigger_type trigger_type;
  1291. int flags;
  1292. int (*func)(struct event_command *cmd_ops,
  1293. struct trace_event_file *file,
  1294. char *glob, char *cmd, char *params);
  1295. int (*reg)(char *glob,
  1296. struct event_trigger_ops *ops,
  1297. struct event_trigger_data *data,
  1298. struct trace_event_file *file);
  1299. void (*unreg)(char *glob,
  1300. struct event_trigger_ops *ops,
  1301. struct event_trigger_data *data,
  1302. struct trace_event_file *file);
  1303. void (*unreg_all)(struct trace_event_file *file);
  1304. int (*set_filter)(char *filter_str,
  1305. struct event_trigger_data *data,
  1306. struct trace_event_file *file);
  1307. struct event_trigger_ops *(*get_trigger_ops)(char *cmd, char *param);
  1308. };
  1309. /**
  1310. * enum event_command_flags - flags for struct event_command
  1311. *
  1312. * @POST_TRIGGER: A flag that says whether or not this command needs
  1313. * to have its action delayed until after the current event has
  1314. * been closed. Some triggers need to avoid being invoked while
  1315. * an event is currently in the process of being logged, since
  1316. * the trigger may itself log data into the trace buffer. Thus
  1317. * we make sure the current event is committed before invoking
  1318. * those triggers. To do that, the trigger invocation is split
  1319. * in two - the first part checks the filter using the current
  1320. * trace record; if a command has the @post_trigger flag set, it
  1321. * sets a bit for itself in the return value, otherwise it
  1322. * directly invokes the trigger. Once all commands have been
  1323. * either invoked or set their return flag, the current record is
  1324. * either committed or discarded. At that point, if any commands
  1325. * have deferred their triggers, those commands are finally
  1326. * invoked following the close of the current event. In other
  1327. * words, if the event_trigger_ops @func() probe implementation
  1328. * itself logs to the trace buffer, this flag should be set,
  1329. * otherwise it can be left unspecified.
  1330. *
  1331. * @NEEDS_REC: A flag that says whether or not this command needs
  1332. * access to the trace record in order to perform its function,
  1333. * regardless of whether or not it has a filter associated with
  1334. * it (filters make a trigger require access to the trace record
  1335. * but are not always present).
  1336. */
  1337. enum event_command_flags {
  1338. EVENT_CMD_FL_POST_TRIGGER = 1,
  1339. EVENT_CMD_FL_NEEDS_REC = 2,
  1340. };
  1341. static inline bool event_command_post_trigger(struct event_command *cmd_ops)
  1342. {
  1343. return cmd_ops->flags & EVENT_CMD_FL_POST_TRIGGER;
  1344. }
  1345. static inline bool event_command_needs_rec(struct event_command *cmd_ops)
  1346. {
  1347. return cmd_ops->flags & EVENT_CMD_FL_NEEDS_REC;
  1348. }
  1349. extern int trace_event_enable_disable(struct trace_event_file *file,
  1350. int enable, int soft_disable);
  1351. extern int tracing_alloc_snapshot(void);
  1352. extern const char *__start___trace_bprintk_fmt[];
  1353. extern const char *__stop___trace_bprintk_fmt[];
  1354. extern const char *__start___tracepoint_str[];
  1355. extern const char *__stop___tracepoint_str[];
  1356. void trace_printk_control(bool enabled);
  1357. void trace_printk_init_buffers(void);
  1358. void trace_printk_start_comm(void);
  1359. int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
  1360. int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
  1361. /*
  1362. * Normal trace_printk() and friends allocates special buffers
  1363. * to do the manipulation, as well as saves the print formats
  1364. * into sections to display. But the trace infrastructure wants
  1365. * to use these without the added overhead at the price of being
  1366. * a bit slower (used mainly for warnings, where we don't care
  1367. * about performance). The internal_trace_puts() is for such
  1368. * a purpose.
  1369. */
  1370. #define internal_trace_puts(str) __trace_puts(_THIS_IP_, str, strlen(str))
  1371. #undef FTRACE_ENTRY
  1372. #define FTRACE_ENTRY(call, struct_name, id, tstruct, print, filter) \
  1373. extern struct trace_event_call \
  1374. __aligned(4) event_##call;
  1375. #undef FTRACE_ENTRY_DUP
  1376. #define FTRACE_ENTRY_DUP(call, struct_name, id, tstruct, print, filter) \
  1377. FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print), \
  1378. filter)
  1379. #include "trace_entries.h"
  1380. #if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_FUNCTION_TRACER)
  1381. int perf_ftrace_event_register(struct trace_event_call *call,
  1382. enum trace_reg type, void *data);
  1383. #else
  1384. #define perf_ftrace_event_register NULL
  1385. #endif
  1386. #ifdef CONFIG_FTRACE_SYSCALLS
  1387. void init_ftrace_syscalls(void);
  1388. const char *get_syscall_name(int syscall);
  1389. #else
  1390. static inline void init_ftrace_syscalls(void) { }
  1391. static inline const char *get_syscall_name(int syscall)
  1392. {
  1393. return NULL;
  1394. }
  1395. #endif
  1396. #ifdef CONFIG_EVENT_TRACING
  1397. void trace_event_init(void);
  1398. void trace_event_enum_update(struct trace_enum_map **map, int len);
  1399. #else
  1400. static inline void __init trace_event_init(void) { }
  1401. static inline void trace_event_enum_update(struct trace_enum_map **map, int len) { }
  1402. #endif
  1403. extern struct trace_iterator *tracepoint_print_iter;
  1404. #endif /* _LINUX_KERNEL_TRACE_H */