trace.h 57 KB

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