trace.h 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812
  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. cpumask_var_t tracing_cpumask; /* only trace on set CPUs */
  228. int ref;
  229. #ifdef CONFIG_FUNCTION_TRACER
  230. struct ftrace_ops *ops;
  231. struct trace_pid_list __rcu *function_pids;
  232. #ifdef CONFIG_DYNAMIC_FTRACE
  233. /* All of these are protected by the ftrace_lock */
  234. struct list_head func_probes;
  235. struct list_head mod_trace;
  236. struct list_head mod_notrace;
  237. #endif
  238. /* function tracing enabled */
  239. int function_enabled;
  240. #endif
  241. };
  242. enum {
  243. TRACE_ARRAY_FL_GLOBAL = (1 << 0)
  244. };
  245. extern struct list_head ftrace_trace_arrays;
  246. extern struct mutex trace_types_lock;
  247. extern int trace_array_get(struct trace_array *tr);
  248. extern void trace_array_put(struct trace_array *tr);
  249. /*
  250. * The global tracer (top) should be the first trace array added,
  251. * but we check the flag anyway.
  252. */
  253. static inline struct trace_array *top_trace_array(void)
  254. {
  255. struct trace_array *tr;
  256. if (list_empty(&ftrace_trace_arrays))
  257. return NULL;
  258. tr = list_entry(ftrace_trace_arrays.prev,
  259. typeof(*tr), list);
  260. WARN_ON(!(tr->flags & TRACE_ARRAY_FL_GLOBAL));
  261. return tr;
  262. }
  263. #define FTRACE_CMP_TYPE(var, type) \
  264. __builtin_types_compatible_p(typeof(var), type *)
  265. #undef IF_ASSIGN
  266. #define IF_ASSIGN(var, entry, etype, id) \
  267. if (FTRACE_CMP_TYPE(var, etype)) { \
  268. var = (typeof(var))(entry); \
  269. WARN_ON(id && (entry)->type != id); \
  270. break; \
  271. }
  272. /* Will cause compile errors if type is not found. */
  273. extern void __ftrace_bad_type(void);
  274. /*
  275. * The trace_assign_type is a verifier that the entry type is
  276. * the same as the type being assigned. To add new types simply
  277. * add a line with the following format:
  278. *
  279. * IF_ASSIGN(var, ent, type, id);
  280. *
  281. * Where "type" is the trace type that includes the trace_entry
  282. * as the "ent" item. And "id" is the trace identifier that is
  283. * used in the trace_type enum.
  284. *
  285. * If the type can have more than one id, then use zero.
  286. */
  287. #define trace_assign_type(var, ent) \
  288. do { \
  289. IF_ASSIGN(var, ent, struct ftrace_entry, TRACE_FN); \
  290. IF_ASSIGN(var, ent, struct ctx_switch_entry, 0); \
  291. IF_ASSIGN(var, ent, struct stack_entry, TRACE_STACK); \
  292. IF_ASSIGN(var, ent, struct userstack_entry, TRACE_USER_STACK);\
  293. IF_ASSIGN(var, ent, struct print_entry, TRACE_PRINT); \
  294. IF_ASSIGN(var, ent, struct bprint_entry, TRACE_BPRINT); \
  295. IF_ASSIGN(var, ent, struct bputs_entry, TRACE_BPUTS); \
  296. IF_ASSIGN(var, ent, struct hwlat_entry, TRACE_HWLAT); \
  297. IF_ASSIGN(var, ent, struct raw_data_entry, TRACE_RAW_DATA);\
  298. IF_ASSIGN(var, ent, struct trace_mmiotrace_rw, \
  299. TRACE_MMIO_RW); \
  300. IF_ASSIGN(var, ent, struct trace_mmiotrace_map, \
  301. TRACE_MMIO_MAP); \
  302. IF_ASSIGN(var, ent, struct trace_branch, TRACE_BRANCH); \
  303. IF_ASSIGN(var, ent, struct ftrace_graph_ent_entry, \
  304. TRACE_GRAPH_ENT); \
  305. IF_ASSIGN(var, ent, struct ftrace_graph_ret_entry, \
  306. TRACE_GRAPH_RET); \
  307. __ftrace_bad_type(); \
  308. } while (0)
  309. /*
  310. * An option specific to a tracer. This is a boolean value.
  311. * The bit is the bit index that sets its value on the
  312. * flags value in struct tracer_flags.
  313. */
  314. struct tracer_opt {
  315. const char *name; /* Will appear on the trace_options file */
  316. u32 bit; /* Mask assigned in val field in tracer_flags */
  317. };
  318. /*
  319. * The set of specific options for a tracer. Your tracer
  320. * have to set the initial value of the flags val.
  321. */
  322. struct tracer_flags {
  323. u32 val;
  324. struct tracer_opt *opts;
  325. struct tracer *trace;
  326. };
  327. /* Makes more easy to define a tracer opt */
  328. #define TRACER_OPT(s, b) .name = #s, .bit = b
  329. struct trace_option_dentry {
  330. struct tracer_opt *opt;
  331. struct tracer_flags *flags;
  332. struct trace_array *tr;
  333. struct dentry *entry;
  334. };
  335. /**
  336. * struct tracer - a specific tracer and its callbacks to interact with tracefs
  337. * @name: the name chosen to select it on the available_tracers file
  338. * @init: called when one switches to this tracer (echo name > current_tracer)
  339. * @reset: called when one switches to another tracer
  340. * @start: called when tracing is unpaused (echo 1 > tracing_on)
  341. * @stop: called when tracing is paused (echo 0 > tracing_on)
  342. * @update_thresh: called when tracing_thresh is updated
  343. * @open: called when the trace file is opened
  344. * @pipe_open: called when the trace_pipe file is opened
  345. * @close: called when the trace file is released
  346. * @pipe_close: called when the trace_pipe file is released
  347. * @read: override the default read callback on trace_pipe
  348. * @splice_read: override the default splice_read callback on trace_pipe
  349. * @selftest: selftest to run on boot (see trace_selftest.c)
  350. * @print_headers: override the first lines that describe your columns
  351. * @print_line: callback that prints a trace
  352. * @set_flag: signals one of your private flags changed (trace_options file)
  353. * @flags: your private flags
  354. */
  355. struct tracer {
  356. const char *name;
  357. int (*init)(struct trace_array *tr);
  358. void (*reset)(struct trace_array *tr);
  359. void (*start)(struct trace_array *tr);
  360. void (*stop)(struct trace_array *tr);
  361. int (*update_thresh)(struct trace_array *tr);
  362. void (*open)(struct trace_iterator *iter);
  363. void (*pipe_open)(struct trace_iterator *iter);
  364. void (*close)(struct trace_iterator *iter);
  365. void (*pipe_close)(struct trace_iterator *iter);
  366. ssize_t (*read)(struct trace_iterator *iter,
  367. struct file *filp, char __user *ubuf,
  368. size_t cnt, loff_t *ppos);
  369. ssize_t (*splice_read)(struct trace_iterator *iter,
  370. struct file *filp,
  371. loff_t *ppos,
  372. struct pipe_inode_info *pipe,
  373. size_t len,
  374. unsigned int flags);
  375. #ifdef CONFIG_FTRACE_STARTUP_TEST
  376. int (*selftest)(struct tracer *trace,
  377. struct trace_array *tr);
  378. #endif
  379. void (*print_header)(struct seq_file *m);
  380. enum print_line_t (*print_line)(struct trace_iterator *iter);
  381. /* If you handled the flag setting, return 0 */
  382. int (*set_flag)(struct trace_array *tr,
  383. u32 old_flags, u32 bit, int set);
  384. /* Return 0 if OK with change, else return non-zero */
  385. int (*flag_changed)(struct trace_array *tr,
  386. u32 mask, int set);
  387. struct tracer *next;
  388. struct tracer_flags *flags;
  389. int enabled;
  390. int ref;
  391. bool print_max;
  392. bool allow_instances;
  393. #ifdef CONFIG_TRACER_MAX_TRACE
  394. bool use_max_tr;
  395. #endif
  396. /* True if tracer cannot be enabled in kernel param */
  397. bool noboot;
  398. };
  399. /* Only current can touch trace_recursion */
  400. /*
  401. * For function tracing recursion:
  402. * The order of these bits are important.
  403. *
  404. * When function tracing occurs, the following steps are made:
  405. * If arch does not support a ftrace feature:
  406. * call internal function (uses INTERNAL bits) which calls...
  407. * If callback is registered to the "global" list, the list
  408. * function is called and recursion checks the GLOBAL bits.
  409. * then this function calls...
  410. * The function callback, which can use the FTRACE bits to
  411. * check for recursion.
  412. *
  413. * Now if the arch does not suppport a feature, and it calls
  414. * the global list function which calls the ftrace callback
  415. * all three of these steps will do a recursion protection.
  416. * There's no reason to do one if the previous caller already
  417. * did. The recursion that we are protecting against will
  418. * go through the same steps again.
  419. *
  420. * To prevent the multiple recursion checks, if a recursion
  421. * bit is set that is higher than the MAX bit of the current
  422. * check, then we know that the check was made by the previous
  423. * caller, and we can skip the current check.
  424. */
  425. enum {
  426. TRACE_BUFFER_BIT,
  427. TRACE_BUFFER_NMI_BIT,
  428. TRACE_BUFFER_IRQ_BIT,
  429. TRACE_BUFFER_SIRQ_BIT,
  430. /* Start of function recursion bits */
  431. TRACE_FTRACE_BIT,
  432. TRACE_FTRACE_NMI_BIT,
  433. TRACE_FTRACE_IRQ_BIT,
  434. TRACE_FTRACE_SIRQ_BIT,
  435. /* INTERNAL_BITs must be greater than FTRACE_BITs */
  436. TRACE_INTERNAL_BIT,
  437. TRACE_INTERNAL_NMI_BIT,
  438. TRACE_INTERNAL_IRQ_BIT,
  439. TRACE_INTERNAL_SIRQ_BIT,
  440. TRACE_BRANCH_BIT,
  441. /*
  442. * Abuse of the trace_recursion.
  443. * As we need a way to maintain state if we are tracing the function
  444. * graph in irq because we want to trace a particular function that
  445. * was called in irq context but we have irq tracing off. Since this
  446. * can only be modified by current, we can reuse trace_recursion.
  447. */
  448. TRACE_IRQ_BIT,
  449. };
  450. #define trace_recursion_set(bit) do { (current)->trace_recursion |= (1<<(bit)); } while (0)
  451. #define trace_recursion_clear(bit) do { (current)->trace_recursion &= ~(1<<(bit)); } while (0)
  452. #define trace_recursion_test(bit) ((current)->trace_recursion & (1<<(bit)))
  453. #define TRACE_CONTEXT_BITS 4
  454. #define TRACE_FTRACE_START TRACE_FTRACE_BIT
  455. #define TRACE_FTRACE_MAX ((1 << (TRACE_FTRACE_START + TRACE_CONTEXT_BITS)) - 1)
  456. #define TRACE_LIST_START TRACE_INTERNAL_BIT
  457. #define TRACE_LIST_MAX ((1 << (TRACE_LIST_START + TRACE_CONTEXT_BITS)) - 1)
  458. #define TRACE_CONTEXT_MASK TRACE_LIST_MAX
  459. static __always_inline int trace_get_context_bit(void)
  460. {
  461. int bit;
  462. if (in_interrupt()) {
  463. if (in_nmi())
  464. bit = 0;
  465. else if (in_irq())
  466. bit = 1;
  467. else
  468. bit = 2;
  469. } else
  470. bit = 3;
  471. return bit;
  472. }
  473. static __always_inline int trace_test_and_set_recursion(int start, int max)
  474. {
  475. unsigned int val = current->trace_recursion;
  476. int bit;
  477. /* A previous recursion check was made */
  478. if ((val & TRACE_CONTEXT_MASK) > max)
  479. return 0;
  480. bit = trace_get_context_bit() + start;
  481. if (unlikely(val & (1 << bit)))
  482. return -1;
  483. val |= 1 << bit;
  484. current->trace_recursion = val;
  485. barrier();
  486. return bit;
  487. }
  488. static __always_inline void trace_clear_recursion(int bit)
  489. {
  490. unsigned int val = current->trace_recursion;
  491. if (!bit)
  492. return;
  493. bit = 1 << bit;
  494. val &= ~bit;
  495. barrier();
  496. current->trace_recursion = val;
  497. }
  498. static inline struct ring_buffer_iter *
  499. trace_buffer_iter(struct trace_iterator *iter, int cpu)
  500. {
  501. if (iter->buffer_iter && iter->buffer_iter[cpu])
  502. return iter->buffer_iter[cpu];
  503. return NULL;
  504. }
  505. int tracer_init(struct tracer *t, struct trace_array *tr);
  506. int tracing_is_enabled(void);
  507. void tracing_reset(struct trace_buffer *buf, int cpu);
  508. void tracing_reset_online_cpus(struct trace_buffer *buf);
  509. void tracing_reset_current(int cpu);
  510. void tracing_reset_all_online_cpus(void);
  511. int tracing_open_generic(struct inode *inode, struct file *filp);
  512. bool tracing_is_disabled(void);
  513. int tracer_tracing_is_on(struct trace_array *tr);
  514. void tracer_tracing_on(struct trace_array *tr);
  515. void tracer_tracing_off(struct trace_array *tr);
  516. struct dentry *trace_create_file(const char *name,
  517. umode_t mode,
  518. struct dentry *parent,
  519. void *data,
  520. const struct file_operations *fops);
  521. struct dentry *tracing_init_dentry(void);
  522. struct ring_buffer_event;
  523. struct ring_buffer_event *
  524. trace_buffer_lock_reserve(struct ring_buffer *buffer,
  525. int type,
  526. unsigned long len,
  527. unsigned long flags,
  528. int pc);
  529. struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
  530. struct trace_array_cpu *data);
  531. struct trace_entry *trace_find_next_entry(struct trace_iterator *iter,
  532. int *ent_cpu, u64 *ent_ts);
  533. void trace_buffer_unlock_commit_nostack(struct ring_buffer *buffer,
  534. struct ring_buffer_event *event);
  535. int trace_empty(struct trace_iterator *iter);
  536. void *trace_find_next_entry_inc(struct trace_iterator *iter);
  537. void trace_init_global_iter(struct trace_iterator *iter);
  538. void tracing_iter_reset(struct trace_iterator *iter, int cpu);
  539. void trace_function(struct trace_array *tr,
  540. unsigned long ip,
  541. unsigned long parent_ip,
  542. unsigned long flags, int pc);
  543. void trace_graph_function(struct trace_array *tr,
  544. unsigned long ip,
  545. unsigned long parent_ip,
  546. unsigned long flags, int pc);
  547. void trace_latency_header(struct seq_file *m);
  548. void trace_default_header(struct seq_file *m);
  549. void print_trace_header(struct seq_file *m, struct trace_iterator *iter);
  550. int trace_empty(struct trace_iterator *iter);
  551. void trace_graph_return(struct ftrace_graph_ret *trace);
  552. int trace_graph_entry(struct ftrace_graph_ent *trace);
  553. void set_graph_array(struct trace_array *tr);
  554. void tracing_start_cmdline_record(void);
  555. void tracing_stop_cmdline_record(void);
  556. void tracing_start_tgid_record(void);
  557. void tracing_stop_tgid_record(void);
  558. int register_tracer(struct tracer *type);
  559. int is_tracing_stopped(void);
  560. loff_t tracing_lseek(struct file *file, loff_t offset, int whence);
  561. extern cpumask_var_t __read_mostly tracing_buffer_mask;
  562. #define for_each_tracing_cpu(cpu) \
  563. for_each_cpu(cpu, tracing_buffer_mask)
  564. extern unsigned long nsecs_to_usecs(unsigned long nsecs);
  565. extern unsigned long tracing_thresh;
  566. /* PID filtering */
  567. extern int pid_max;
  568. bool trace_find_filtered_pid(struct trace_pid_list *filtered_pids,
  569. pid_t search_pid);
  570. bool trace_ignore_this_task(struct trace_pid_list *filtered_pids,
  571. struct task_struct *task);
  572. void trace_filter_add_remove_task(struct trace_pid_list *pid_list,
  573. struct task_struct *self,
  574. struct task_struct *task);
  575. void *trace_pid_next(struct trace_pid_list *pid_list, void *v, loff_t *pos);
  576. void *trace_pid_start(struct trace_pid_list *pid_list, loff_t *pos);
  577. int trace_pid_show(struct seq_file *m, void *v);
  578. void trace_free_pid_list(struct trace_pid_list *pid_list);
  579. int trace_pid_write(struct trace_pid_list *filtered_pids,
  580. struct trace_pid_list **new_pid_list,
  581. const char __user *ubuf, size_t cnt);
  582. #ifdef CONFIG_TRACER_MAX_TRACE
  583. void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
  584. void update_max_tr_single(struct trace_array *tr,
  585. struct task_struct *tsk, int cpu);
  586. #endif /* CONFIG_TRACER_MAX_TRACE */
  587. #ifdef CONFIG_STACKTRACE
  588. void ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags,
  589. int pc);
  590. void __trace_stack(struct trace_array *tr, unsigned long flags, int skip,
  591. int pc);
  592. #else
  593. static inline void ftrace_trace_userstack(struct ring_buffer *buffer,
  594. unsigned long flags, int pc)
  595. {
  596. }
  597. static inline void __trace_stack(struct trace_array *tr, unsigned long flags,
  598. int skip, int pc)
  599. {
  600. }
  601. #endif /* CONFIG_STACKTRACE */
  602. extern u64 ftrace_now(int cpu);
  603. extern void trace_find_cmdline(int pid, char comm[]);
  604. extern int trace_find_tgid(int pid);
  605. extern void trace_event_follow_fork(struct trace_array *tr, bool enable);
  606. #ifdef CONFIG_DYNAMIC_FTRACE
  607. extern unsigned long ftrace_update_tot_cnt;
  608. void ftrace_init_trace_array(struct trace_array *tr);
  609. #else
  610. static inline void ftrace_init_trace_array(struct trace_array *tr) { }
  611. #endif
  612. #define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
  613. extern int DYN_FTRACE_TEST_NAME(void);
  614. #define DYN_FTRACE_TEST_NAME2 trace_selftest_dynamic_test_func2
  615. extern int DYN_FTRACE_TEST_NAME2(void);
  616. extern bool ring_buffer_expanded;
  617. extern bool tracing_selftest_disabled;
  618. #ifdef CONFIG_FTRACE_STARTUP_TEST
  619. extern int trace_selftest_startup_function(struct tracer *trace,
  620. struct trace_array *tr);
  621. extern int trace_selftest_startup_function_graph(struct tracer *trace,
  622. struct trace_array *tr);
  623. extern int trace_selftest_startup_irqsoff(struct tracer *trace,
  624. struct trace_array *tr);
  625. extern int trace_selftest_startup_preemptoff(struct tracer *trace,
  626. struct trace_array *tr);
  627. extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
  628. struct trace_array *tr);
  629. extern int trace_selftest_startup_wakeup(struct tracer *trace,
  630. struct trace_array *tr);
  631. extern int trace_selftest_startup_nop(struct tracer *trace,
  632. struct trace_array *tr);
  633. extern int trace_selftest_startup_sched_switch(struct tracer *trace,
  634. struct trace_array *tr);
  635. extern int trace_selftest_startup_branch(struct tracer *trace,
  636. struct trace_array *tr);
  637. /*
  638. * Tracer data references selftest functions that only occur
  639. * on boot up. These can be __init functions. Thus, when selftests
  640. * are enabled, then the tracers need to reference __init functions.
  641. */
  642. #define __tracer_data __refdata
  643. #else
  644. /* Tracers are seldom changed. Optimize when selftests are disabled. */
  645. #define __tracer_data __read_mostly
  646. #endif /* CONFIG_FTRACE_STARTUP_TEST */
  647. extern void *head_page(struct trace_array_cpu *data);
  648. extern unsigned long long ns2usecs(u64 nsec);
  649. extern int
  650. trace_vbprintk(unsigned long ip, const char *fmt, va_list args);
  651. extern int
  652. trace_vprintk(unsigned long ip, const char *fmt, va_list args);
  653. extern int
  654. trace_array_vprintk(struct trace_array *tr,
  655. unsigned long ip, const char *fmt, va_list args);
  656. int trace_array_printk(struct trace_array *tr,
  657. unsigned long ip, const char *fmt, ...);
  658. int trace_array_printk_buf(struct ring_buffer *buffer,
  659. unsigned long ip, const char *fmt, ...);
  660. void trace_printk_seq(struct trace_seq *s);
  661. enum print_line_t print_trace_line(struct trace_iterator *iter);
  662. extern char trace_find_mark(unsigned long long duration);
  663. struct ftrace_hash;
  664. struct ftrace_mod_load {
  665. struct list_head list;
  666. char *func;
  667. char *module;
  668. int enable;
  669. };
  670. enum {
  671. FTRACE_HASH_FL_MOD = (1 << 0),
  672. };
  673. struct ftrace_hash {
  674. unsigned long size_bits;
  675. struct hlist_head *buckets;
  676. unsigned long count;
  677. unsigned long flags;
  678. struct rcu_head rcu;
  679. };
  680. struct ftrace_func_entry *
  681. ftrace_lookup_ip(struct ftrace_hash *hash, unsigned long ip);
  682. static __always_inline bool ftrace_hash_empty(struct ftrace_hash *hash)
  683. {
  684. return !hash || !(hash->count || (hash->flags & FTRACE_HASH_FL_MOD));
  685. }
  686. /* Standard output formatting function used for function return traces */
  687. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  688. /* Flag options */
  689. #define TRACE_GRAPH_PRINT_OVERRUN 0x1
  690. #define TRACE_GRAPH_PRINT_CPU 0x2
  691. #define TRACE_GRAPH_PRINT_OVERHEAD 0x4
  692. #define TRACE_GRAPH_PRINT_PROC 0x8
  693. #define TRACE_GRAPH_PRINT_DURATION 0x10
  694. #define TRACE_GRAPH_PRINT_ABS_TIME 0x20
  695. #define TRACE_GRAPH_PRINT_IRQS 0x40
  696. #define TRACE_GRAPH_PRINT_TAIL 0x80
  697. #define TRACE_GRAPH_SLEEP_TIME 0x100
  698. #define TRACE_GRAPH_GRAPH_TIME 0x200
  699. #define TRACE_GRAPH_PRINT_FILL_SHIFT 28
  700. #define TRACE_GRAPH_PRINT_FILL_MASK (0x3 << TRACE_GRAPH_PRINT_FILL_SHIFT)
  701. extern void ftrace_graph_sleep_time_control(bool enable);
  702. extern void ftrace_graph_graph_time_control(bool enable);
  703. extern enum print_line_t
  704. print_graph_function_flags(struct trace_iterator *iter, u32 flags);
  705. extern void print_graph_headers_flags(struct seq_file *s, u32 flags);
  706. extern void
  707. trace_print_graph_duration(unsigned long long duration, struct trace_seq *s);
  708. extern void graph_trace_open(struct trace_iterator *iter);
  709. extern void graph_trace_close(struct trace_iterator *iter);
  710. extern int __trace_graph_entry(struct trace_array *tr,
  711. struct ftrace_graph_ent *trace,
  712. unsigned long flags, int pc);
  713. extern void __trace_graph_return(struct trace_array *tr,
  714. struct ftrace_graph_ret *trace,
  715. unsigned long flags, int pc);
  716. #ifdef CONFIG_DYNAMIC_FTRACE
  717. extern struct ftrace_hash *ftrace_graph_hash;
  718. extern struct ftrace_hash *ftrace_graph_notrace_hash;
  719. static inline int ftrace_graph_addr(unsigned long addr)
  720. {
  721. int ret = 0;
  722. preempt_disable_notrace();
  723. if (ftrace_hash_empty(ftrace_graph_hash)) {
  724. ret = 1;
  725. goto out;
  726. }
  727. if (ftrace_lookup_ip(ftrace_graph_hash, addr)) {
  728. /*
  729. * If no irqs are to be traced, but a set_graph_function
  730. * is set, and called by an interrupt handler, we still
  731. * want to trace it.
  732. */
  733. if (in_irq())
  734. trace_recursion_set(TRACE_IRQ_BIT);
  735. else
  736. trace_recursion_clear(TRACE_IRQ_BIT);
  737. ret = 1;
  738. }
  739. out:
  740. preempt_enable_notrace();
  741. return ret;
  742. }
  743. static inline int ftrace_graph_notrace_addr(unsigned long addr)
  744. {
  745. int ret = 0;
  746. preempt_disable_notrace();
  747. if (ftrace_lookup_ip(ftrace_graph_notrace_hash, addr))
  748. ret = 1;
  749. preempt_enable_notrace();
  750. return ret;
  751. }
  752. #else
  753. static inline int ftrace_graph_addr(unsigned long addr)
  754. {
  755. return 1;
  756. }
  757. static inline int ftrace_graph_notrace_addr(unsigned long addr)
  758. {
  759. return 0;
  760. }
  761. #endif /* CONFIG_DYNAMIC_FTRACE */
  762. extern unsigned int fgraph_max_depth;
  763. static inline bool ftrace_graph_ignore_func(struct ftrace_graph_ent *trace)
  764. {
  765. /* trace it when it is-nested-in or is a function enabled. */
  766. return !(trace->depth || ftrace_graph_addr(trace->func)) ||
  767. (trace->depth < 0) ||
  768. (fgraph_max_depth && trace->depth >= fgraph_max_depth);
  769. }
  770. #else /* CONFIG_FUNCTION_GRAPH_TRACER */
  771. static inline enum print_line_t
  772. print_graph_function_flags(struct trace_iterator *iter, u32 flags)
  773. {
  774. return TRACE_TYPE_UNHANDLED;
  775. }
  776. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  777. extern struct list_head ftrace_pids;
  778. #ifdef CONFIG_FUNCTION_TRACER
  779. struct ftrace_func_command {
  780. struct list_head list;
  781. char *name;
  782. int (*func)(struct trace_array *tr,
  783. struct ftrace_hash *hash,
  784. char *func, char *cmd,
  785. char *params, int enable);
  786. };
  787. extern bool ftrace_filter_param __initdata;
  788. static inline int ftrace_trace_task(struct trace_array *tr)
  789. {
  790. return !this_cpu_read(tr->trace_buffer.data->ftrace_ignore_pid);
  791. }
  792. extern int ftrace_is_dead(void);
  793. int ftrace_create_function_files(struct trace_array *tr,
  794. struct dentry *parent);
  795. void ftrace_destroy_function_files(struct trace_array *tr);
  796. void ftrace_init_global_array_ops(struct trace_array *tr);
  797. void ftrace_init_array_ops(struct trace_array *tr, ftrace_func_t func);
  798. void ftrace_reset_array_ops(struct trace_array *tr);
  799. int using_ftrace_ops_list_func(void);
  800. void ftrace_init_tracefs(struct trace_array *tr, struct dentry *d_tracer);
  801. void ftrace_init_tracefs_toplevel(struct trace_array *tr,
  802. struct dentry *d_tracer);
  803. void ftrace_clear_pids(struct trace_array *tr);
  804. int init_function_trace(void);
  805. void ftrace_pid_follow_fork(struct trace_array *tr, bool enable);
  806. #else
  807. static inline int ftrace_trace_task(struct trace_array *tr)
  808. {
  809. return 1;
  810. }
  811. static inline int ftrace_is_dead(void) { return 0; }
  812. static inline int
  813. ftrace_create_function_files(struct trace_array *tr,
  814. struct dentry *parent)
  815. {
  816. return 0;
  817. }
  818. static inline void ftrace_destroy_function_files(struct trace_array *tr) { }
  819. static inline __init void
  820. ftrace_init_global_array_ops(struct trace_array *tr) { }
  821. static inline void ftrace_reset_array_ops(struct trace_array *tr) { }
  822. static inline void ftrace_init_tracefs(struct trace_array *tr, struct dentry *d) { }
  823. static inline void ftrace_init_tracefs_toplevel(struct trace_array *tr, struct dentry *d) { }
  824. static inline void ftrace_clear_pids(struct trace_array *tr) { }
  825. static inline int init_function_trace(void) { return 0; }
  826. static inline void ftrace_pid_follow_fork(struct trace_array *tr, bool enable) { }
  827. /* ftace_func_t type is not defined, use macro instead of static inline */
  828. #define ftrace_init_array_ops(tr, func) do { } while (0)
  829. #endif /* CONFIG_FUNCTION_TRACER */
  830. #if defined(CONFIG_FUNCTION_TRACER) && defined(CONFIG_DYNAMIC_FTRACE)
  831. struct ftrace_probe_ops {
  832. void (*func)(unsigned long ip,
  833. unsigned long parent_ip,
  834. struct trace_array *tr,
  835. struct ftrace_probe_ops *ops,
  836. void *data);
  837. int (*init)(struct ftrace_probe_ops *ops,
  838. struct trace_array *tr,
  839. unsigned long ip, void *init_data,
  840. void **data);
  841. void (*free)(struct ftrace_probe_ops *ops,
  842. struct trace_array *tr,
  843. unsigned long ip, void *data);
  844. int (*print)(struct seq_file *m,
  845. unsigned long ip,
  846. struct ftrace_probe_ops *ops,
  847. void *data);
  848. };
  849. struct ftrace_func_mapper;
  850. typedef int (*ftrace_mapper_func)(void *data);
  851. struct ftrace_func_mapper *allocate_ftrace_func_mapper(void);
  852. void **ftrace_func_mapper_find_ip(struct ftrace_func_mapper *mapper,
  853. unsigned long ip);
  854. int ftrace_func_mapper_add_ip(struct ftrace_func_mapper *mapper,
  855. unsigned long ip, void *data);
  856. void *ftrace_func_mapper_remove_ip(struct ftrace_func_mapper *mapper,
  857. unsigned long ip);
  858. void free_ftrace_func_mapper(struct ftrace_func_mapper *mapper,
  859. ftrace_mapper_func free_func);
  860. extern int
  861. register_ftrace_function_probe(char *glob, struct trace_array *tr,
  862. struct ftrace_probe_ops *ops, void *data);
  863. extern int
  864. unregister_ftrace_function_probe_func(char *glob, struct trace_array *tr,
  865. struct ftrace_probe_ops *ops);
  866. extern void clear_ftrace_function_probes(struct trace_array *tr);
  867. int register_ftrace_command(struct ftrace_func_command *cmd);
  868. int unregister_ftrace_command(struct ftrace_func_command *cmd);
  869. void ftrace_create_filter_files(struct ftrace_ops *ops,
  870. struct dentry *parent);
  871. void ftrace_destroy_filter_files(struct ftrace_ops *ops);
  872. #else
  873. struct ftrace_func_command;
  874. static inline __init int register_ftrace_command(struct ftrace_func_command *cmd)
  875. {
  876. return -EINVAL;
  877. }
  878. static inline __init int unregister_ftrace_command(char *cmd_name)
  879. {
  880. return -EINVAL;
  881. }
  882. static inline void clear_ftrace_function_probes(struct trace_array *tr)
  883. {
  884. }
  885. /*
  886. * The ops parameter passed in is usually undefined.
  887. * This must be a macro.
  888. */
  889. #define ftrace_create_filter_files(ops, parent) do { } while (0)
  890. #define ftrace_destroy_filter_files(ops) do { } while (0)
  891. #endif /* CONFIG_FUNCTION_TRACER && CONFIG_DYNAMIC_FTRACE */
  892. bool ftrace_event_is_function(struct trace_event_call *call);
  893. /*
  894. * struct trace_parser - servers for reading the user input separated by spaces
  895. * @cont: set if the input is not complete - no final space char was found
  896. * @buffer: holds the parsed user input
  897. * @idx: user input length
  898. * @size: buffer size
  899. */
  900. struct trace_parser {
  901. bool cont;
  902. char *buffer;
  903. unsigned idx;
  904. unsigned size;
  905. };
  906. static inline bool trace_parser_loaded(struct trace_parser *parser)
  907. {
  908. return (parser->idx != 0);
  909. }
  910. static inline bool trace_parser_cont(struct trace_parser *parser)
  911. {
  912. return parser->cont;
  913. }
  914. static inline void trace_parser_clear(struct trace_parser *parser)
  915. {
  916. parser->cont = false;
  917. parser->idx = 0;
  918. }
  919. extern int trace_parser_get_init(struct trace_parser *parser, int size);
  920. extern void trace_parser_put(struct trace_parser *parser);
  921. extern int trace_get_user(struct trace_parser *parser, const char __user *ubuf,
  922. size_t cnt, loff_t *ppos);
  923. /*
  924. * Only create function graph options if function graph is configured.
  925. */
  926. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  927. # define FGRAPH_FLAGS \
  928. C(DISPLAY_GRAPH, "display-graph"),
  929. #else
  930. # define FGRAPH_FLAGS
  931. #endif
  932. #ifdef CONFIG_BRANCH_TRACER
  933. # define BRANCH_FLAGS \
  934. C(BRANCH, "branch"),
  935. #else
  936. # define BRANCH_FLAGS
  937. #endif
  938. #ifdef CONFIG_FUNCTION_TRACER
  939. # define FUNCTION_FLAGS \
  940. C(FUNCTION, "function-trace"), \
  941. C(FUNC_FORK, "function-fork"),
  942. # define FUNCTION_DEFAULT_FLAGS TRACE_ITER_FUNCTION
  943. #else
  944. # define FUNCTION_FLAGS
  945. # define FUNCTION_DEFAULT_FLAGS 0UL
  946. # define TRACE_ITER_FUNC_FORK 0UL
  947. #endif
  948. #ifdef CONFIG_STACKTRACE
  949. # define STACK_FLAGS \
  950. C(STACKTRACE, "stacktrace"),
  951. #else
  952. # define STACK_FLAGS
  953. #endif
  954. /*
  955. * trace_iterator_flags is an enumeration that defines bit
  956. * positions into trace_flags that controls the output.
  957. *
  958. * NOTE: These bits must match the trace_options array in
  959. * trace.c (this macro guarantees it).
  960. */
  961. #define TRACE_FLAGS \
  962. C(PRINT_PARENT, "print-parent"), \
  963. C(SYM_OFFSET, "sym-offset"), \
  964. C(SYM_ADDR, "sym-addr"), \
  965. C(VERBOSE, "verbose"), \
  966. C(RAW, "raw"), \
  967. C(HEX, "hex"), \
  968. C(BIN, "bin"), \
  969. C(BLOCK, "block"), \
  970. C(PRINTK, "trace_printk"), \
  971. C(ANNOTATE, "annotate"), \
  972. C(USERSTACKTRACE, "userstacktrace"), \
  973. C(SYM_USEROBJ, "sym-userobj"), \
  974. C(PRINTK_MSGONLY, "printk-msg-only"), \
  975. C(CONTEXT_INFO, "context-info"), /* Print pid/cpu/time */ \
  976. C(LATENCY_FMT, "latency-format"), \
  977. C(RECORD_CMD, "record-cmd"), \
  978. C(RECORD_TGID, "record-tgid"), \
  979. C(OVERWRITE, "overwrite"), \
  980. C(STOP_ON_FREE, "disable_on_free"), \
  981. C(IRQ_INFO, "irq-info"), \
  982. C(MARKERS, "markers"), \
  983. C(EVENT_FORK, "event-fork"), \
  984. FUNCTION_FLAGS \
  985. FGRAPH_FLAGS \
  986. STACK_FLAGS \
  987. BRANCH_FLAGS
  988. /*
  989. * By defining C, we can make TRACE_FLAGS a list of bit names
  990. * that will define the bits for the flag masks.
  991. */
  992. #undef C
  993. #define C(a, b) TRACE_ITER_##a##_BIT
  994. enum trace_iterator_bits {
  995. TRACE_FLAGS
  996. /* Make sure we don't go more than we have bits for */
  997. TRACE_ITER_LAST_BIT
  998. };
  999. /*
  1000. * By redefining C, we can make TRACE_FLAGS a list of masks that
  1001. * use the bits as defined above.
  1002. */
  1003. #undef C
  1004. #define C(a, b) TRACE_ITER_##a = (1 << TRACE_ITER_##a##_BIT)
  1005. enum trace_iterator_flags { TRACE_FLAGS };
  1006. /*
  1007. * TRACE_ITER_SYM_MASK masks the options in trace_flags that
  1008. * control the output of kernel symbols.
  1009. */
  1010. #define TRACE_ITER_SYM_MASK \
  1011. (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR)
  1012. extern struct tracer nop_trace;
  1013. #ifdef CONFIG_BRANCH_TRACER
  1014. extern int enable_branch_tracing(struct trace_array *tr);
  1015. extern void disable_branch_tracing(void);
  1016. static inline int trace_branch_enable(struct trace_array *tr)
  1017. {
  1018. if (tr->trace_flags & TRACE_ITER_BRANCH)
  1019. return enable_branch_tracing(tr);
  1020. return 0;
  1021. }
  1022. static inline void trace_branch_disable(void)
  1023. {
  1024. /* due to races, always disable */
  1025. disable_branch_tracing();
  1026. }
  1027. #else
  1028. static inline int trace_branch_enable(struct trace_array *tr)
  1029. {
  1030. return 0;
  1031. }
  1032. static inline void trace_branch_disable(void)
  1033. {
  1034. }
  1035. #endif /* CONFIG_BRANCH_TRACER */
  1036. /* set ring buffers to default size if not already done so */
  1037. int tracing_update_buffers(void);
  1038. struct ftrace_event_field {
  1039. struct list_head link;
  1040. const char *name;
  1041. const char *type;
  1042. int filter_type;
  1043. int offset;
  1044. int size;
  1045. int is_signed;
  1046. };
  1047. struct event_filter {
  1048. int n_preds; /* Number assigned */
  1049. int a_preds; /* allocated */
  1050. struct filter_pred __rcu *preds;
  1051. struct filter_pred __rcu *root;
  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);
  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, entry);
  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, entry);
  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. unsigned short index;
  1222. unsigned short parent;
  1223. unsigned short left;
  1224. unsigned short right;
  1225. };
  1226. static inline bool is_string_field(struct ftrace_event_field *field)
  1227. {
  1228. return field->filter_type == FILTER_DYN_STRING ||
  1229. field->filter_type == FILTER_STATIC_STRING ||
  1230. field->filter_type == FILTER_PTR_STRING ||
  1231. field->filter_type == FILTER_COMM;
  1232. }
  1233. static inline bool is_function_field(struct ftrace_event_field *field)
  1234. {
  1235. return field->filter_type == FILTER_TRACE_FN;
  1236. }
  1237. extern enum regex_type
  1238. filter_parse_regex(char *buff, int len, char **search, int *not);
  1239. extern void print_event_filter(struct trace_event_file *file,
  1240. struct trace_seq *s);
  1241. extern int apply_event_filter(struct trace_event_file *file,
  1242. char *filter_string);
  1243. extern int apply_subsystem_event_filter(struct trace_subsystem_dir *dir,
  1244. char *filter_string);
  1245. extern void print_subsystem_event_filter(struct event_subsystem *system,
  1246. struct trace_seq *s);
  1247. extern int filter_assign_type(const char *type);
  1248. extern int create_event_filter(struct trace_event_call *call,
  1249. char *filter_str, bool set_str,
  1250. struct event_filter **filterp);
  1251. extern void free_event_filter(struct event_filter *filter);
  1252. struct ftrace_event_field *
  1253. trace_find_event_field(struct trace_event_call *call, char *name);
  1254. extern void trace_event_enable_cmd_record(bool enable);
  1255. extern void trace_event_enable_tgid_record(bool enable);
  1256. extern int event_trace_add_tracer(struct dentry *parent, struct trace_array *tr);
  1257. extern int event_trace_del_tracer(struct trace_array *tr);
  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 int register_event_command(struct event_command *cmd);
  1341. extern int unregister_event_command(struct event_command *cmd);
  1342. extern int register_trigger_hist_enable_disable_cmds(void);
  1343. /**
  1344. * struct event_trigger_ops - callbacks for trace event triggers
  1345. *
  1346. * The methods in this structure provide per-event trigger hooks for
  1347. * various trigger operations.
  1348. *
  1349. * All the methods below, except for @init() and @free(), must be
  1350. * implemented.
  1351. *
  1352. * @func: The trigger 'probe' function called when the triggering
  1353. * event occurs. The data passed into this callback is the data
  1354. * that was supplied to the event_command @reg() function that
  1355. * registered the trigger (see struct event_command) along with
  1356. * the trace record, rec.
  1357. *
  1358. * @init: An optional initialization function called for the trigger
  1359. * when the trigger is registered (via the event_command reg()
  1360. * function). This can be used to perform per-trigger
  1361. * initialization such as incrementing a per-trigger reference
  1362. * count, for instance. This is usually implemented by the
  1363. * generic utility function @event_trigger_init() (see
  1364. * trace_event_triggers.c).
  1365. *
  1366. * @free: An optional de-initialization function called for the
  1367. * trigger when the trigger is unregistered (via the
  1368. * event_command @reg() function). This can be used to perform
  1369. * per-trigger de-initialization such as decrementing a
  1370. * per-trigger reference count and freeing corresponding trigger
  1371. * data, for instance. This is usually implemented by the
  1372. * generic utility function @event_trigger_free() (see
  1373. * trace_event_triggers.c).
  1374. *
  1375. * @print: The callback function invoked to have the trigger print
  1376. * itself. This is usually implemented by a wrapper function
  1377. * that calls the generic utility function @event_trigger_print()
  1378. * (see trace_event_triggers.c).
  1379. */
  1380. struct event_trigger_ops {
  1381. void (*func)(struct event_trigger_data *data,
  1382. void *rec);
  1383. int (*init)(struct event_trigger_ops *ops,
  1384. struct event_trigger_data *data);
  1385. void (*free)(struct event_trigger_ops *ops,
  1386. struct event_trigger_data *data);
  1387. int (*print)(struct seq_file *m,
  1388. struct event_trigger_ops *ops,
  1389. struct event_trigger_data *data);
  1390. };
  1391. /**
  1392. * struct event_command - callbacks and data members for event commands
  1393. *
  1394. * Event commands are invoked by users by writing the command name
  1395. * into the 'trigger' file associated with a trace event. The
  1396. * parameters associated with a specific invocation of an event
  1397. * command are used to create an event trigger instance, which is
  1398. * added to the list of trigger instances associated with that trace
  1399. * event. When the event is hit, the set of triggers associated with
  1400. * that event is invoked.
  1401. *
  1402. * The data members in this structure provide per-event command data
  1403. * for various event commands.
  1404. *
  1405. * All the data members below, except for @post_trigger, must be set
  1406. * for each event command.
  1407. *
  1408. * @name: The unique name that identifies the event command. This is
  1409. * the name used when setting triggers via trigger files.
  1410. *
  1411. * @trigger_type: A unique id that identifies the event command
  1412. * 'type'. This value has two purposes, the first to ensure that
  1413. * only one trigger of the same type can be set at a given time
  1414. * for a particular event e.g. it doesn't make sense to have both
  1415. * a traceon and traceoff trigger attached to a single event at
  1416. * the same time, so traceon and traceoff have the same type
  1417. * though they have different names. The @trigger_type value is
  1418. * also used as a bit value for deferring the actual trigger
  1419. * action until after the current event is finished. Some
  1420. * commands need to do this if they themselves log to the trace
  1421. * buffer (see the @post_trigger() member below). @trigger_type
  1422. * values are defined by adding new values to the trigger_type
  1423. * enum in include/linux/trace_events.h.
  1424. *
  1425. * @flags: See the enum event_command_flags below.
  1426. *
  1427. * All the methods below, except for @set_filter() and @unreg_all(),
  1428. * must be implemented.
  1429. *
  1430. * @func: The callback function responsible for parsing and
  1431. * registering the trigger written to the 'trigger' file by the
  1432. * user. It allocates the trigger instance and registers it with
  1433. * the appropriate trace event. It makes use of the other
  1434. * event_command callback functions to orchestrate this, and is
  1435. * usually implemented by the generic utility function
  1436. * @event_trigger_callback() (see trace_event_triggers.c).
  1437. *
  1438. * @reg: Adds the trigger to the list of triggers associated with the
  1439. * event, and enables the event trigger itself, after
  1440. * initializing it (via the event_trigger_ops @init() function).
  1441. * This is also where commands can use the @trigger_type value to
  1442. * make the decision as to whether or not multiple instances of
  1443. * the trigger should be allowed. This is usually implemented by
  1444. * the generic utility function @register_trigger() (see
  1445. * trace_event_triggers.c).
  1446. *
  1447. * @unreg: Removes the trigger from the list of triggers associated
  1448. * with the event, and disables the event trigger itself, after
  1449. * initializing it (via the event_trigger_ops @free() function).
  1450. * This is usually implemented by the generic utility function
  1451. * @unregister_trigger() (see trace_event_triggers.c).
  1452. *
  1453. * @unreg_all: An optional function called to remove all the triggers
  1454. * from the list of triggers associated with the event. Called
  1455. * when a trigger file is opened in truncate mode.
  1456. *
  1457. * @set_filter: An optional function called to parse and set a filter
  1458. * for the trigger. If no @set_filter() method is set for the
  1459. * event command, filters set by the user for the command will be
  1460. * ignored. This is usually implemented by the generic utility
  1461. * function @set_trigger_filter() (see trace_event_triggers.c).
  1462. *
  1463. * @get_trigger_ops: The callback function invoked to retrieve the
  1464. * event_trigger_ops implementation associated with the command.
  1465. */
  1466. struct event_command {
  1467. struct list_head list;
  1468. char *name;
  1469. enum event_trigger_type trigger_type;
  1470. int flags;
  1471. int (*func)(struct event_command *cmd_ops,
  1472. struct trace_event_file *file,
  1473. char *glob, char *cmd, char *params);
  1474. int (*reg)(char *glob,
  1475. struct event_trigger_ops *ops,
  1476. struct event_trigger_data *data,
  1477. struct trace_event_file *file);
  1478. void (*unreg)(char *glob,
  1479. struct event_trigger_ops *ops,
  1480. struct event_trigger_data *data,
  1481. struct trace_event_file *file);
  1482. void (*unreg_all)(struct trace_event_file *file);
  1483. int (*set_filter)(char *filter_str,
  1484. struct event_trigger_data *data,
  1485. struct trace_event_file *file);
  1486. struct event_trigger_ops *(*get_trigger_ops)(char *cmd, char *param);
  1487. };
  1488. /**
  1489. * enum event_command_flags - flags for struct event_command
  1490. *
  1491. * @POST_TRIGGER: A flag that says whether or not this command needs
  1492. * to have its action delayed until after the current event has
  1493. * been closed. Some triggers need to avoid being invoked while
  1494. * an event is currently in the process of being logged, since
  1495. * the trigger may itself log data into the trace buffer. Thus
  1496. * we make sure the current event is committed before invoking
  1497. * those triggers. To do that, the trigger invocation is split
  1498. * in two - the first part checks the filter using the current
  1499. * trace record; if a command has the @post_trigger flag set, it
  1500. * sets a bit for itself in the return value, otherwise it
  1501. * directly invokes the trigger. Once all commands have been
  1502. * either invoked or set their return flag, the current record is
  1503. * either committed or discarded. At that point, if any commands
  1504. * have deferred their triggers, those commands are finally
  1505. * invoked following the close of the current event. In other
  1506. * words, if the event_trigger_ops @func() probe implementation
  1507. * itself logs to the trace buffer, this flag should be set,
  1508. * otherwise it can be left unspecified.
  1509. *
  1510. * @NEEDS_REC: A flag that says whether or not this command needs
  1511. * access to the trace record in order to perform its function,
  1512. * regardless of whether or not it has a filter associated with
  1513. * it (filters make a trigger require access to the trace record
  1514. * but are not always present).
  1515. */
  1516. enum event_command_flags {
  1517. EVENT_CMD_FL_POST_TRIGGER = 1,
  1518. EVENT_CMD_FL_NEEDS_REC = 2,
  1519. };
  1520. static inline bool event_command_post_trigger(struct event_command *cmd_ops)
  1521. {
  1522. return cmd_ops->flags & EVENT_CMD_FL_POST_TRIGGER;
  1523. }
  1524. static inline bool event_command_needs_rec(struct event_command *cmd_ops)
  1525. {
  1526. return cmd_ops->flags & EVENT_CMD_FL_NEEDS_REC;
  1527. }
  1528. extern int trace_event_enable_disable(struct trace_event_file *file,
  1529. int enable, int soft_disable);
  1530. extern int tracing_alloc_snapshot(void);
  1531. extern const char *__start___trace_bprintk_fmt[];
  1532. extern const char *__stop___trace_bprintk_fmt[];
  1533. extern const char *__start___tracepoint_str[];
  1534. extern const char *__stop___tracepoint_str[];
  1535. void trace_printk_control(bool enabled);
  1536. void trace_printk_init_buffers(void);
  1537. void trace_printk_start_comm(void);
  1538. int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
  1539. int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
  1540. /*
  1541. * Normal trace_printk() and friends allocates special buffers
  1542. * to do the manipulation, as well as saves the print formats
  1543. * into sections to display. But the trace infrastructure wants
  1544. * to use these without the added overhead at the price of being
  1545. * a bit slower (used mainly for warnings, where we don't care
  1546. * about performance). The internal_trace_puts() is for such
  1547. * a purpose.
  1548. */
  1549. #define internal_trace_puts(str) __trace_puts(_THIS_IP_, str, strlen(str))
  1550. #undef FTRACE_ENTRY
  1551. #define FTRACE_ENTRY(call, struct_name, id, tstruct, print, filter) \
  1552. extern struct trace_event_call \
  1553. __aligned(4) event_##call;
  1554. #undef FTRACE_ENTRY_DUP
  1555. #define FTRACE_ENTRY_DUP(call, struct_name, id, tstruct, print, filter) \
  1556. FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print), \
  1557. filter)
  1558. #undef FTRACE_ENTRY_PACKED
  1559. #define FTRACE_ENTRY_PACKED(call, struct_name, id, tstruct, print, filter) \
  1560. FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print), \
  1561. filter)
  1562. #include "trace_entries.h"
  1563. #if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_FUNCTION_TRACER)
  1564. int perf_ftrace_event_register(struct trace_event_call *call,
  1565. enum trace_reg type, void *data);
  1566. #else
  1567. #define perf_ftrace_event_register NULL
  1568. #endif
  1569. #ifdef CONFIG_FTRACE_SYSCALLS
  1570. void init_ftrace_syscalls(void);
  1571. const char *get_syscall_name(int syscall);
  1572. #else
  1573. static inline void init_ftrace_syscalls(void) { }
  1574. static inline const char *get_syscall_name(int syscall)
  1575. {
  1576. return NULL;
  1577. }
  1578. #endif
  1579. #ifdef CONFIG_EVENT_TRACING
  1580. void trace_event_init(void);
  1581. void trace_event_eval_update(struct trace_eval_map **map, int len);
  1582. #else
  1583. static inline void __init trace_event_init(void) { }
  1584. static inline void trace_event_eval_update(struct trace_eval_map **map, int len) { }
  1585. #endif
  1586. extern struct trace_iterator *tracepoint_print_iter;
  1587. #endif /* _LINUX_KERNEL_TRACE_H */