trace.h 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822
  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. int time_stamp_abs_ref;
  242. struct list_head hist_vars;
  243. };
  244. enum {
  245. TRACE_ARRAY_FL_GLOBAL = (1 << 0)
  246. };
  247. extern struct list_head ftrace_trace_arrays;
  248. extern struct mutex trace_types_lock;
  249. extern int trace_array_get(struct trace_array *tr);
  250. extern void trace_array_put(struct trace_array *tr);
  251. extern int tracing_set_time_stamp_abs(struct trace_array *tr, bool abs);
  252. extern int tracing_set_clock(struct trace_array *tr, const char *clockstr);
  253. extern bool trace_clock_in_ns(struct trace_array *tr);
  254. /*
  255. * The global tracer (top) should be the first trace array added,
  256. * but we check the flag anyway.
  257. */
  258. static inline struct trace_array *top_trace_array(void)
  259. {
  260. struct trace_array *tr;
  261. if (list_empty(&ftrace_trace_arrays))
  262. return NULL;
  263. tr = list_entry(ftrace_trace_arrays.prev,
  264. typeof(*tr), list);
  265. WARN_ON(!(tr->flags & TRACE_ARRAY_FL_GLOBAL));
  266. return tr;
  267. }
  268. #define FTRACE_CMP_TYPE(var, type) \
  269. __builtin_types_compatible_p(typeof(var), type *)
  270. #undef IF_ASSIGN
  271. #define IF_ASSIGN(var, entry, etype, id) \
  272. if (FTRACE_CMP_TYPE(var, etype)) { \
  273. var = (typeof(var))(entry); \
  274. WARN_ON(id && (entry)->type != id); \
  275. break; \
  276. }
  277. /* Will cause compile errors if type is not found. */
  278. extern void __ftrace_bad_type(void);
  279. /*
  280. * The trace_assign_type is a verifier that the entry type is
  281. * the same as the type being assigned. To add new types simply
  282. * add a line with the following format:
  283. *
  284. * IF_ASSIGN(var, ent, type, id);
  285. *
  286. * Where "type" is the trace type that includes the trace_entry
  287. * as the "ent" item. And "id" is the trace identifier that is
  288. * used in the trace_type enum.
  289. *
  290. * If the type can have more than one id, then use zero.
  291. */
  292. #define trace_assign_type(var, ent) \
  293. do { \
  294. IF_ASSIGN(var, ent, struct ftrace_entry, TRACE_FN); \
  295. IF_ASSIGN(var, ent, struct ctx_switch_entry, 0); \
  296. IF_ASSIGN(var, ent, struct stack_entry, TRACE_STACK); \
  297. IF_ASSIGN(var, ent, struct userstack_entry, TRACE_USER_STACK);\
  298. IF_ASSIGN(var, ent, struct print_entry, TRACE_PRINT); \
  299. IF_ASSIGN(var, ent, struct bprint_entry, TRACE_BPRINT); \
  300. IF_ASSIGN(var, ent, struct bputs_entry, TRACE_BPUTS); \
  301. IF_ASSIGN(var, ent, struct hwlat_entry, TRACE_HWLAT); \
  302. IF_ASSIGN(var, ent, struct raw_data_entry, TRACE_RAW_DATA);\
  303. IF_ASSIGN(var, ent, struct trace_mmiotrace_rw, \
  304. TRACE_MMIO_RW); \
  305. IF_ASSIGN(var, ent, struct trace_mmiotrace_map, \
  306. TRACE_MMIO_MAP); \
  307. IF_ASSIGN(var, ent, struct trace_branch, TRACE_BRANCH); \
  308. IF_ASSIGN(var, ent, struct ftrace_graph_ent_entry, \
  309. TRACE_GRAPH_ENT); \
  310. IF_ASSIGN(var, ent, struct ftrace_graph_ret_entry, \
  311. TRACE_GRAPH_RET); \
  312. __ftrace_bad_type(); \
  313. } while (0)
  314. /*
  315. * An option specific to a tracer. This is a boolean value.
  316. * The bit is the bit index that sets its value on the
  317. * flags value in struct tracer_flags.
  318. */
  319. struct tracer_opt {
  320. const char *name; /* Will appear on the trace_options file */
  321. u32 bit; /* Mask assigned in val field in tracer_flags */
  322. };
  323. /*
  324. * The set of specific options for a tracer. Your tracer
  325. * have to set the initial value of the flags val.
  326. */
  327. struct tracer_flags {
  328. u32 val;
  329. struct tracer_opt *opts;
  330. struct tracer *trace;
  331. };
  332. /* Makes more easy to define a tracer opt */
  333. #define TRACER_OPT(s, b) .name = #s, .bit = b
  334. struct trace_option_dentry {
  335. struct tracer_opt *opt;
  336. struct tracer_flags *flags;
  337. struct trace_array *tr;
  338. struct dentry *entry;
  339. };
  340. /**
  341. * struct tracer - a specific tracer and its callbacks to interact with tracefs
  342. * @name: the name chosen to select it on the available_tracers file
  343. * @init: called when one switches to this tracer (echo name > current_tracer)
  344. * @reset: called when one switches to another tracer
  345. * @start: called when tracing is unpaused (echo 1 > tracing_on)
  346. * @stop: called when tracing is paused (echo 0 > tracing_on)
  347. * @update_thresh: called when tracing_thresh is updated
  348. * @open: called when the trace file is opened
  349. * @pipe_open: called when the trace_pipe file is opened
  350. * @close: called when the trace file is released
  351. * @pipe_close: called when the trace_pipe file is released
  352. * @read: override the default read callback on trace_pipe
  353. * @splice_read: override the default splice_read callback on trace_pipe
  354. * @selftest: selftest to run on boot (see trace_selftest.c)
  355. * @print_headers: override the first lines that describe your columns
  356. * @print_line: callback that prints a trace
  357. * @set_flag: signals one of your private flags changed (trace_options file)
  358. * @flags: your private flags
  359. */
  360. struct tracer {
  361. const char *name;
  362. int (*init)(struct trace_array *tr);
  363. void (*reset)(struct trace_array *tr);
  364. void (*start)(struct trace_array *tr);
  365. void (*stop)(struct trace_array *tr);
  366. int (*update_thresh)(struct trace_array *tr);
  367. void (*open)(struct trace_iterator *iter);
  368. void (*pipe_open)(struct trace_iterator *iter);
  369. void (*close)(struct trace_iterator *iter);
  370. void (*pipe_close)(struct trace_iterator *iter);
  371. ssize_t (*read)(struct trace_iterator *iter,
  372. struct file *filp, char __user *ubuf,
  373. size_t cnt, loff_t *ppos);
  374. ssize_t (*splice_read)(struct trace_iterator *iter,
  375. struct file *filp,
  376. loff_t *ppos,
  377. struct pipe_inode_info *pipe,
  378. size_t len,
  379. unsigned int flags);
  380. #ifdef CONFIG_FTRACE_STARTUP_TEST
  381. int (*selftest)(struct tracer *trace,
  382. struct trace_array *tr);
  383. #endif
  384. void (*print_header)(struct seq_file *m);
  385. enum print_line_t (*print_line)(struct trace_iterator *iter);
  386. /* If you handled the flag setting, return 0 */
  387. int (*set_flag)(struct trace_array *tr,
  388. u32 old_flags, u32 bit, int set);
  389. /* Return 0 if OK with change, else return non-zero */
  390. int (*flag_changed)(struct trace_array *tr,
  391. u32 mask, int set);
  392. struct tracer *next;
  393. struct tracer_flags *flags;
  394. int enabled;
  395. int ref;
  396. bool print_max;
  397. bool allow_instances;
  398. #ifdef CONFIG_TRACER_MAX_TRACE
  399. bool use_max_tr;
  400. #endif
  401. /* True if tracer cannot be enabled in kernel param */
  402. bool noboot;
  403. };
  404. /* Only current can touch trace_recursion */
  405. /*
  406. * For function tracing recursion:
  407. * The order of these bits are important.
  408. *
  409. * When function tracing occurs, the following steps are made:
  410. * If arch does not support a ftrace feature:
  411. * call internal function (uses INTERNAL bits) which calls...
  412. * If callback is registered to the "global" list, the list
  413. * function is called and recursion checks the GLOBAL bits.
  414. * then this function calls...
  415. * The function callback, which can use the FTRACE bits to
  416. * check for recursion.
  417. *
  418. * Now if the arch does not suppport a feature, and it calls
  419. * the global list function which calls the ftrace callback
  420. * all three of these steps will do a recursion protection.
  421. * There's no reason to do one if the previous caller already
  422. * did. The recursion that we are protecting against will
  423. * go through the same steps again.
  424. *
  425. * To prevent the multiple recursion checks, if a recursion
  426. * bit is set that is higher than the MAX bit of the current
  427. * check, then we know that the check was made by the previous
  428. * caller, and we can skip the current check.
  429. */
  430. enum {
  431. TRACE_BUFFER_BIT,
  432. TRACE_BUFFER_NMI_BIT,
  433. TRACE_BUFFER_IRQ_BIT,
  434. TRACE_BUFFER_SIRQ_BIT,
  435. /* Start of function recursion bits */
  436. TRACE_FTRACE_BIT,
  437. TRACE_FTRACE_NMI_BIT,
  438. TRACE_FTRACE_IRQ_BIT,
  439. TRACE_FTRACE_SIRQ_BIT,
  440. /* INTERNAL_BITs must be greater than FTRACE_BITs */
  441. TRACE_INTERNAL_BIT,
  442. TRACE_INTERNAL_NMI_BIT,
  443. TRACE_INTERNAL_IRQ_BIT,
  444. TRACE_INTERNAL_SIRQ_BIT,
  445. TRACE_BRANCH_BIT,
  446. /*
  447. * Abuse of the trace_recursion.
  448. * As we need a way to maintain state if we are tracing the function
  449. * graph in irq because we want to trace a particular function that
  450. * was called in irq context but we have irq tracing off. Since this
  451. * can only be modified by current, we can reuse trace_recursion.
  452. */
  453. TRACE_IRQ_BIT,
  454. };
  455. #define trace_recursion_set(bit) do { (current)->trace_recursion |= (1<<(bit)); } while (0)
  456. #define trace_recursion_clear(bit) do { (current)->trace_recursion &= ~(1<<(bit)); } while (0)
  457. #define trace_recursion_test(bit) ((current)->trace_recursion & (1<<(bit)))
  458. #define TRACE_CONTEXT_BITS 4
  459. #define TRACE_FTRACE_START TRACE_FTRACE_BIT
  460. #define TRACE_FTRACE_MAX ((1 << (TRACE_FTRACE_START + TRACE_CONTEXT_BITS)) - 1)
  461. #define TRACE_LIST_START TRACE_INTERNAL_BIT
  462. #define TRACE_LIST_MAX ((1 << (TRACE_LIST_START + TRACE_CONTEXT_BITS)) - 1)
  463. #define TRACE_CONTEXT_MASK TRACE_LIST_MAX
  464. static __always_inline int trace_get_context_bit(void)
  465. {
  466. int bit;
  467. if (in_interrupt()) {
  468. if (in_nmi())
  469. bit = 0;
  470. else if (in_irq())
  471. bit = 1;
  472. else
  473. bit = 2;
  474. } else
  475. bit = 3;
  476. return bit;
  477. }
  478. static __always_inline int trace_test_and_set_recursion(int start, int max)
  479. {
  480. unsigned int val = current->trace_recursion;
  481. int bit;
  482. /* A previous recursion check was made */
  483. if ((val & TRACE_CONTEXT_MASK) > max)
  484. return 0;
  485. bit = trace_get_context_bit() + start;
  486. if (unlikely(val & (1 << bit)))
  487. return -1;
  488. val |= 1 << bit;
  489. current->trace_recursion = val;
  490. barrier();
  491. return bit;
  492. }
  493. static __always_inline void trace_clear_recursion(int bit)
  494. {
  495. unsigned int val = current->trace_recursion;
  496. if (!bit)
  497. return;
  498. bit = 1 << bit;
  499. val &= ~bit;
  500. barrier();
  501. current->trace_recursion = val;
  502. }
  503. static inline struct ring_buffer_iter *
  504. trace_buffer_iter(struct trace_iterator *iter, int cpu)
  505. {
  506. if (iter->buffer_iter && iter->buffer_iter[cpu])
  507. return iter->buffer_iter[cpu];
  508. return NULL;
  509. }
  510. int tracer_init(struct tracer *t, struct trace_array *tr);
  511. int tracing_is_enabled(void);
  512. void tracing_reset(struct trace_buffer *buf, int cpu);
  513. void tracing_reset_online_cpus(struct trace_buffer *buf);
  514. void tracing_reset_current(int cpu);
  515. void tracing_reset_all_online_cpus(void);
  516. int tracing_open_generic(struct inode *inode, struct file *filp);
  517. bool tracing_is_disabled(void);
  518. int tracer_tracing_is_on(struct trace_array *tr);
  519. void tracer_tracing_on(struct trace_array *tr);
  520. void tracer_tracing_off(struct trace_array *tr);
  521. struct dentry *trace_create_file(const char *name,
  522. umode_t mode,
  523. struct dentry *parent,
  524. void *data,
  525. const struct file_operations *fops);
  526. struct dentry *tracing_init_dentry(void);
  527. struct ring_buffer_event;
  528. struct ring_buffer_event *
  529. trace_buffer_lock_reserve(struct ring_buffer *buffer,
  530. int type,
  531. unsigned long len,
  532. unsigned long flags,
  533. int pc);
  534. struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
  535. struct trace_array_cpu *data);
  536. struct trace_entry *trace_find_next_entry(struct trace_iterator *iter,
  537. int *ent_cpu, u64 *ent_ts);
  538. void trace_buffer_unlock_commit_nostack(struct ring_buffer *buffer,
  539. struct ring_buffer_event *event);
  540. int trace_empty(struct trace_iterator *iter);
  541. void *trace_find_next_entry_inc(struct trace_iterator *iter);
  542. void trace_init_global_iter(struct trace_iterator *iter);
  543. void tracing_iter_reset(struct trace_iterator *iter, int cpu);
  544. void trace_function(struct trace_array *tr,
  545. unsigned long ip,
  546. unsigned long parent_ip,
  547. unsigned long flags, int pc);
  548. void trace_graph_function(struct trace_array *tr,
  549. unsigned long ip,
  550. unsigned long parent_ip,
  551. unsigned long flags, int pc);
  552. void trace_latency_header(struct seq_file *m);
  553. void trace_default_header(struct seq_file *m);
  554. void print_trace_header(struct seq_file *m, struct trace_iterator *iter);
  555. int trace_empty(struct trace_iterator *iter);
  556. void trace_graph_return(struct ftrace_graph_ret *trace);
  557. int trace_graph_entry(struct ftrace_graph_ent *trace);
  558. void set_graph_array(struct trace_array *tr);
  559. void tracing_start_cmdline_record(void);
  560. void tracing_stop_cmdline_record(void);
  561. void tracing_start_tgid_record(void);
  562. void tracing_stop_tgid_record(void);
  563. int register_tracer(struct tracer *type);
  564. int is_tracing_stopped(void);
  565. loff_t tracing_lseek(struct file *file, loff_t offset, int whence);
  566. extern cpumask_var_t __read_mostly tracing_buffer_mask;
  567. #define for_each_tracing_cpu(cpu) \
  568. for_each_cpu(cpu, tracing_buffer_mask)
  569. extern unsigned long nsecs_to_usecs(unsigned long nsecs);
  570. extern unsigned long tracing_thresh;
  571. /* PID filtering */
  572. extern int pid_max;
  573. bool trace_find_filtered_pid(struct trace_pid_list *filtered_pids,
  574. pid_t search_pid);
  575. bool trace_ignore_this_task(struct trace_pid_list *filtered_pids,
  576. struct task_struct *task);
  577. void trace_filter_add_remove_task(struct trace_pid_list *pid_list,
  578. struct task_struct *self,
  579. struct task_struct *task);
  580. void *trace_pid_next(struct trace_pid_list *pid_list, void *v, loff_t *pos);
  581. void *trace_pid_start(struct trace_pid_list *pid_list, loff_t *pos);
  582. int trace_pid_show(struct seq_file *m, void *v);
  583. void trace_free_pid_list(struct trace_pid_list *pid_list);
  584. int trace_pid_write(struct trace_pid_list *filtered_pids,
  585. struct trace_pid_list **new_pid_list,
  586. const char __user *ubuf, size_t cnt);
  587. #ifdef CONFIG_TRACER_MAX_TRACE
  588. void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
  589. void update_max_tr_single(struct trace_array *tr,
  590. struct task_struct *tsk, int cpu);
  591. #endif /* CONFIG_TRACER_MAX_TRACE */
  592. #ifdef CONFIG_STACKTRACE
  593. void ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags,
  594. int pc);
  595. void __trace_stack(struct trace_array *tr, unsigned long flags, int skip,
  596. int pc);
  597. #else
  598. static inline void ftrace_trace_userstack(struct ring_buffer *buffer,
  599. unsigned long flags, int pc)
  600. {
  601. }
  602. static inline void __trace_stack(struct trace_array *tr, unsigned long flags,
  603. int skip, int pc)
  604. {
  605. }
  606. #endif /* CONFIG_STACKTRACE */
  607. extern u64 ftrace_now(int cpu);
  608. extern void trace_find_cmdline(int pid, char comm[]);
  609. extern int trace_find_tgid(int pid);
  610. extern void trace_event_follow_fork(struct trace_array *tr, bool enable);
  611. #ifdef CONFIG_DYNAMIC_FTRACE
  612. extern unsigned long ftrace_update_tot_cnt;
  613. void ftrace_init_trace_array(struct trace_array *tr);
  614. #else
  615. static inline void ftrace_init_trace_array(struct trace_array *tr) { }
  616. #endif
  617. #define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
  618. extern int DYN_FTRACE_TEST_NAME(void);
  619. #define DYN_FTRACE_TEST_NAME2 trace_selftest_dynamic_test_func2
  620. extern int DYN_FTRACE_TEST_NAME2(void);
  621. extern bool ring_buffer_expanded;
  622. extern bool tracing_selftest_disabled;
  623. #ifdef CONFIG_FTRACE_STARTUP_TEST
  624. extern int trace_selftest_startup_function(struct tracer *trace,
  625. struct trace_array *tr);
  626. extern int trace_selftest_startup_function_graph(struct tracer *trace,
  627. struct trace_array *tr);
  628. extern int trace_selftest_startup_irqsoff(struct tracer *trace,
  629. struct trace_array *tr);
  630. extern int trace_selftest_startup_preemptoff(struct tracer *trace,
  631. struct trace_array *tr);
  632. extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
  633. struct trace_array *tr);
  634. extern int trace_selftest_startup_wakeup(struct tracer *trace,
  635. struct trace_array *tr);
  636. extern int trace_selftest_startup_nop(struct tracer *trace,
  637. struct trace_array *tr);
  638. extern int trace_selftest_startup_branch(struct tracer *trace,
  639. struct trace_array *tr);
  640. /*
  641. * Tracer data references selftest functions that only occur
  642. * on boot up. These can be __init functions. Thus, when selftests
  643. * are enabled, then the tracers need to reference __init functions.
  644. */
  645. #define __tracer_data __refdata
  646. #else
  647. /* Tracers are seldom changed. Optimize when selftests are disabled. */
  648. #define __tracer_data __read_mostly
  649. #endif /* CONFIG_FTRACE_STARTUP_TEST */
  650. extern void *head_page(struct trace_array_cpu *data);
  651. extern unsigned long long ns2usecs(u64 nsec);
  652. extern int
  653. trace_vbprintk(unsigned long ip, const char *fmt, va_list args);
  654. extern int
  655. trace_vprintk(unsigned long ip, const char *fmt, va_list args);
  656. extern int
  657. trace_array_vprintk(struct trace_array *tr,
  658. unsigned long ip, const char *fmt, va_list args);
  659. int trace_array_printk(struct trace_array *tr,
  660. unsigned long ip, const char *fmt, ...);
  661. int trace_array_printk_buf(struct ring_buffer *buffer,
  662. unsigned long ip, const char *fmt, ...);
  663. void trace_printk_seq(struct trace_seq *s);
  664. enum print_line_t print_trace_line(struct trace_iterator *iter);
  665. extern char trace_find_mark(unsigned long long duration);
  666. struct ftrace_hash;
  667. struct ftrace_mod_load {
  668. struct list_head list;
  669. char *func;
  670. char *module;
  671. int enable;
  672. };
  673. enum {
  674. FTRACE_HASH_FL_MOD = (1 << 0),
  675. };
  676. struct ftrace_hash {
  677. unsigned long size_bits;
  678. struct hlist_head *buckets;
  679. unsigned long count;
  680. unsigned long flags;
  681. struct rcu_head rcu;
  682. };
  683. struct ftrace_func_entry *
  684. ftrace_lookup_ip(struct ftrace_hash *hash, unsigned long ip);
  685. static __always_inline bool ftrace_hash_empty(struct ftrace_hash *hash)
  686. {
  687. return !hash || !(hash->count || (hash->flags & FTRACE_HASH_FL_MOD));
  688. }
  689. /* Standard output formatting function used for function return traces */
  690. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  691. /* Flag options */
  692. #define TRACE_GRAPH_PRINT_OVERRUN 0x1
  693. #define TRACE_GRAPH_PRINT_CPU 0x2
  694. #define TRACE_GRAPH_PRINT_OVERHEAD 0x4
  695. #define TRACE_GRAPH_PRINT_PROC 0x8
  696. #define TRACE_GRAPH_PRINT_DURATION 0x10
  697. #define TRACE_GRAPH_PRINT_ABS_TIME 0x20
  698. #define TRACE_GRAPH_PRINT_IRQS 0x40
  699. #define TRACE_GRAPH_PRINT_TAIL 0x80
  700. #define TRACE_GRAPH_SLEEP_TIME 0x100
  701. #define TRACE_GRAPH_GRAPH_TIME 0x200
  702. #define TRACE_GRAPH_PRINT_FILL_SHIFT 28
  703. #define TRACE_GRAPH_PRINT_FILL_MASK (0x3 << TRACE_GRAPH_PRINT_FILL_SHIFT)
  704. extern void ftrace_graph_sleep_time_control(bool enable);
  705. extern void ftrace_graph_graph_time_control(bool enable);
  706. extern enum print_line_t
  707. print_graph_function_flags(struct trace_iterator *iter, u32 flags);
  708. extern void print_graph_headers_flags(struct seq_file *s, u32 flags);
  709. extern void
  710. trace_print_graph_duration(unsigned long long duration, struct trace_seq *s);
  711. extern void graph_trace_open(struct trace_iterator *iter);
  712. extern void graph_trace_close(struct trace_iterator *iter);
  713. extern int __trace_graph_entry(struct trace_array *tr,
  714. struct ftrace_graph_ent *trace,
  715. unsigned long flags, int pc);
  716. extern void __trace_graph_return(struct trace_array *tr,
  717. struct ftrace_graph_ret *trace,
  718. unsigned long flags, int pc);
  719. #ifdef CONFIG_DYNAMIC_FTRACE
  720. extern struct ftrace_hash *ftrace_graph_hash;
  721. extern struct ftrace_hash *ftrace_graph_notrace_hash;
  722. static inline int ftrace_graph_addr(unsigned long addr)
  723. {
  724. int ret = 0;
  725. preempt_disable_notrace();
  726. if (ftrace_hash_empty(ftrace_graph_hash)) {
  727. ret = 1;
  728. goto out;
  729. }
  730. if (ftrace_lookup_ip(ftrace_graph_hash, addr)) {
  731. /*
  732. * If no irqs are to be traced, but a set_graph_function
  733. * is set, and called by an interrupt handler, we still
  734. * want to trace it.
  735. */
  736. if (in_irq())
  737. trace_recursion_set(TRACE_IRQ_BIT);
  738. else
  739. trace_recursion_clear(TRACE_IRQ_BIT);
  740. ret = 1;
  741. }
  742. out:
  743. preempt_enable_notrace();
  744. return ret;
  745. }
  746. static inline int ftrace_graph_notrace_addr(unsigned long addr)
  747. {
  748. int ret = 0;
  749. preempt_disable_notrace();
  750. if (ftrace_lookup_ip(ftrace_graph_notrace_hash, addr))
  751. ret = 1;
  752. preempt_enable_notrace();
  753. return ret;
  754. }
  755. #else
  756. static inline int ftrace_graph_addr(unsigned long addr)
  757. {
  758. return 1;
  759. }
  760. static inline int ftrace_graph_notrace_addr(unsigned long addr)
  761. {
  762. return 0;
  763. }
  764. #endif /* CONFIG_DYNAMIC_FTRACE */
  765. extern unsigned int fgraph_max_depth;
  766. static inline bool ftrace_graph_ignore_func(struct ftrace_graph_ent *trace)
  767. {
  768. /* trace it when it is-nested-in or is a function enabled. */
  769. return !(trace->depth || ftrace_graph_addr(trace->func)) ||
  770. (trace->depth < 0) ||
  771. (fgraph_max_depth && trace->depth >= fgraph_max_depth);
  772. }
  773. #else /* CONFIG_FUNCTION_GRAPH_TRACER */
  774. static inline enum print_line_t
  775. print_graph_function_flags(struct trace_iterator *iter, u32 flags)
  776. {
  777. return TRACE_TYPE_UNHANDLED;
  778. }
  779. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  780. extern struct list_head ftrace_pids;
  781. #ifdef CONFIG_FUNCTION_TRACER
  782. struct ftrace_func_command {
  783. struct list_head list;
  784. char *name;
  785. int (*func)(struct trace_array *tr,
  786. struct ftrace_hash *hash,
  787. char *func, char *cmd,
  788. char *params, int enable);
  789. };
  790. extern bool ftrace_filter_param __initdata;
  791. static inline int ftrace_trace_task(struct trace_array *tr)
  792. {
  793. return !this_cpu_read(tr->trace_buffer.data->ftrace_ignore_pid);
  794. }
  795. extern int ftrace_is_dead(void);
  796. int ftrace_create_function_files(struct trace_array *tr,
  797. struct dentry *parent);
  798. void ftrace_destroy_function_files(struct trace_array *tr);
  799. void ftrace_init_global_array_ops(struct trace_array *tr);
  800. void ftrace_init_array_ops(struct trace_array *tr, ftrace_func_t func);
  801. void ftrace_reset_array_ops(struct trace_array *tr);
  802. int using_ftrace_ops_list_func(void);
  803. void ftrace_init_tracefs(struct trace_array *tr, struct dentry *d_tracer);
  804. void ftrace_init_tracefs_toplevel(struct trace_array *tr,
  805. struct dentry *d_tracer);
  806. void ftrace_clear_pids(struct trace_array *tr);
  807. int init_function_trace(void);
  808. void ftrace_pid_follow_fork(struct trace_array *tr, bool enable);
  809. #else
  810. static inline int ftrace_trace_task(struct trace_array *tr)
  811. {
  812. return 1;
  813. }
  814. static inline int ftrace_is_dead(void) { return 0; }
  815. static inline int
  816. ftrace_create_function_files(struct trace_array *tr,
  817. struct dentry *parent)
  818. {
  819. return 0;
  820. }
  821. static inline void ftrace_destroy_function_files(struct trace_array *tr) { }
  822. static inline __init void
  823. ftrace_init_global_array_ops(struct trace_array *tr) { }
  824. static inline void ftrace_reset_array_ops(struct trace_array *tr) { }
  825. static inline void ftrace_init_tracefs(struct trace_array *tr, struct dentry *d) { }
  826. static inline void ftrace_init_tracefs_toplevel(struct trace_array *tr, struct dentry *d) { }
  827. static inline void ftrace_clear_pids(struct trace_array *tr) { }
  828. static inline int init_function_trace(void) { return 0; }
  829. static inline void ftrace_pid_follow_fork(struct trace_array *tr, bool enable) { }
  830. /* ftace_func_t type is not defined, use macro instead of static inline */
  831. #define ftrace_init_array_ops(tr, func) do { } while (0)
  832. #endif /* CONFIG_FUNCTION_TRACER */
  833. #if defined(CONFIG_FUNCTION_TRACER) && defined(CONFIG_DYNAMIC_FTRACE)
  834. struct ftrace_probe_ops {
  835. void (*func)(unsigned long ip,
  836. unsigned long parent_ip,
  837. struct trace_array *tr,
  838. struct ftrace_probe_ops *ops,
  839. void *data);
  840. int (*init)(struct ftrace_probe_ops *ops,
  841. struct trace_array *tr,
  842. unsigned long ip, void *init_data,
  843. void **data);
  844. void (*free)(struct ftrace_probe_ops *ops,
  845. struct trace_array *tr,
  846. unsigned long ip, void *data);
  847. int (*print)(struct seq_file *m,
  848. unsigned long ip,
  849. struct ftrace_probe_ops *ops,
  850. void *data);
  851. };
  852. struct ftrace_func_mapper;
  853. typedef int (*ftrace_mapper_func)(void *data);
  854. struct ftrace_func_mapper *allocate_ftrace_func_mapper(void);
  855. void **ftrace_func_mapper_find_ip(struct ftrace_func_mapper *mapper,
  856. unsigned long ip);
  857. int ftrace_func_mapper_add_ip(struct ftrace_func_mapper *mapper,
  858. unsigned long ip, void *data);
  859. void *ftrace_func_mapper_remove_ip(struct ftrace_func_mapper *mapper,
  860. unsigned long ip);
  861. void free_ftrace_func_mapper(struct ftrace_func_mapper *mapper,
  862. ftrace_mapper_func free_func);
  863. extern int
  864. register_ftrace_function_probe(char *glob, struct trace_array *tr,
  865. struct ftrace_probe_ops *ops, void *data);
  866. extern int
  867. unregister_ftrace_function_probe_func(char *glob, struct trace_array *tr,
  868. struct ftrace_probe_ops *ops);
  869. extern void clear_ftrace_function_probes(struct trace_array *tr);
  870. int register_ftrace_command(struct ftrace_func_command *cmd);
  871. int unregister_ftrace_command(struct ftrace_func_command *cmd);
  872. void ftrace_create_filter_files(struct ftrace_ops *ops,
  873. struct dentry *parent);
  874. void ftrace_destroy_filter_files(struct ftrace_ops *ops);
  875. #else
  876. struct ftrace_func_command;
  877. static inline __init int register_ftrace_command(struct ftrace_func_command *cmd)
  878. {
  879. return -EINVAL;
  880. }
  881. static inline __init int unregister_ftrace_command(char *cmd_name)
  882. {
  883. return -EINVAL;
  884. }
  885. static inline void clear_ftrace_function_probes(struct trace_array *tr)
  886. {
  887. }
  888. /*
  889. * The ops parameter passed in is usually undefined.
  890. * This must be a macro.
  891. */
  892. #define ftrace_create_filter_files(ops, parent) do { } while (0)
  893. #define ftrace_destroy_filter_files(ops) do { } while (0)
  894. #endif /* CONFIG_FUNCTION_TRACER && CONFIG_DYNAMIC_FTRACE */
  895. bool ftrace_event_is_function(struct trace_event_call *call);
  896. /*
  897. * struct trace_parser - servers for reading the user input separated by spaces
  898. * @cont: set if the input is not complete - no final space char was found
  899. * @buffer: holds the parsed user input
  900. * @idx: user input length
  901. * @size: buffer size
  902. */
  903. struct trace_parser {
  904. bool cont;
  905. char *buffer;
  906. unsigned idx;
  907. unsigned size;
  908. };
  909. static inline bool trace_parser_loaded(struct trace_parser *parser)
  910. {
  911. return (parser->idx != 0);
  912. }
  913. static inline bool trace_parser_cont(struct trace_parser *parser)
  914. {
  915. return parser->cont;
  916. }
  917. static inline void trace_parser_clear(struct trace_parser *parser)
  918. {
  919. parser->cont = false;
  920. parser->idx = 0;
  921. }
  922. extern int trace_parser_get_init(struct trace_parser *parser, int size);
  923. extern void trace_parser_put(struct trace_parser *parser);
  924. extern int trace_get_user(struct trace_parser *parser, const char __user *ubuf,
  925. size_t cnt, loff_t *ppos);
  926. /*
  927. * Only create function graph options if function graph is configured.
  928. */
  929. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  930. # define FGRAPH_FLAGS \
  931. C(DISPLAY_GRAPH, "display-graph"),
  932. #else
  933. # define FGRAPH_FLAGS
  934. #endif
  935. #ifdef CONFIG_BRANCH_TRACER
  936. # define BRANCH_FLAGS \
  937. C(BRANCH, "branch"),
  938. #else
  939. # define BRANCH_FLAGS
  940. #endif
  941. #ifdef CONFIG_FUNCTION_TRACER
  942. # define FUNCTION_FLAGS \
  943. C(FUNCTION, "function-trace"), \
  944. C(FUNC_FORK, "function-fork"),
  945. # define FUNCTION_DEFAULT_FLAGS TRACE_ITER_FUNCTION
  946. #else
  947. # define FUNCTION_FLAGS
  948. # define FUNCTION_DEFAULT_FLAGS 0UL
  949. # define TRACE_ITER_FUNC_FORK 0UL
  950. #endif
  951. #ifdef CONFIG_STACKTRACE
  952. # define STACK_FLAGS \
  953. C(STACKTRACE, "stacktrace"),
  954. #else
  955. # define STACK_FLAGS
  956. #endif
  957. /*
  958. * trace_iterator_flags is an enumeration that defines bit
  959. * positions into trace_flags that controls the output.
  960. *
  961. * NOTE: These bits must match the trace_options array in
  962. * trace.c (this macro guarantees it).
  963. */
  964. #define TRACE_FLAGS \
  965. C(PRINT_PARENT, "print-parent"), \
  966. C(SYM_OFFSET, "sym-offset"), \
  967. C(SYM_ADDR, "sym-addr"), \
  968. C(VERBOSE, "verbose"), \
  969. C(RAW, "raw"), \
  970. C(HEX, "hex"), \
  971. C(BIN, "bin"), \
  972. C(BLOCK, "block"), \
  973. C(PRINTK, "trace_printk"), \
  974. C(ANNOTATE, "annotate"), \
  975. C(USERSTACKTRACE, "userstacktrace"), \
  976. C(SYM_USEROBJ, "sym-userobj"), \
  977. C(PRINTK_MSGONLY, "printk-msg-only"), \
  978. C(CONTEXT_INFO, "context-info"), /* Print pid/cpu/time */ \
  979. C(LATENCY_FMT, "latency-format"), \
  980. C(RECORD_CMD, "record-cmd"), \
  981. C(RECORD_TGID, "record-tgid"), \
  982. C(OVERWRITE, "overwrite"), \
  983. C(STOP_ON_FREE, "disable_on_free"), \
  984. C(IRQ_INFO, "irq-info"), \
  985. C(MARKERS, "markers"), \
  986. C(EVENT_FORK, "event-fork"), \
  987. FUNCTION_FLAGS \
  988. FGRAPH_FLAGS \
  989. STACK_FLAGS \
  990. BRANCH_FLAGS
  991. /*
  992. * By defining C, we can make TRACE_FLAGS a list of bit names
  993. * that will define the bits for the flag masks.
  994. */
  995. #undef C
  996. #define C(a, b) TRACE_ITER_##a##_BIT
  997. enum trace_iterator_bits {
  998. TRACE_FLAGS
  999. /* Make sure we don't go more than we have bits for */
  1000. TRACE_ITER_LAST_BIT
  1001. };
  1002. /*
  1003. * By redefining C, we can make TRACE_FLAGS a list of masks that
  1004. * use the bits as defined above.
  1005. */
  1006. #undef C
  1007. #define C(a, b) TRACE_ITER_##a = (1 << TRACE_ITER_##a##_BIT)
  1008. enum trace_iterator_flags { TRACE_FLAGS };
  1009. /*
  1010. * TRACE_ITER_SYM_MASK masks the options in trace_flags that
  1011. * control the output of kernel symbols.
  1012. */
  1013. #define TRACE_ITER_SYM_MASK \
  1014. (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR)
  1015. extern struct tracer nop_trace;
  1016. #ifdef CONFIG_BRANCH_TRACER
  1017. extern int enable_branch_tracing(struct trace_array *tr);
  1018. extern void disable_branch_tracing(void);
  1019. static inline int trace_branch_enable(struct trace_array *tr)
  1020. {
  1021. if (tr->trace_flags & TRACE_ITER_BRANCH)
  1022. return enable_branch_tracing(tr);
  1023. return 0;
  1024. }
  1025. static inline void trace_branch_disable(void)
  1026. {
  1027. /* due to races, always disable */
  1028. disable_branch_tracing();
  1029. }
  1030. #else
  1031. static inline int trace_branch_enable(struct trace_array *tr)
  1032. {
  1033. return 0;
  1034. }
  1035. static inline void trace_branch_disable(void)
  1036. {
  1037. }
  1038. #endif /* CONFIG_BRANCH_TRACER */
  1039. /* set ring buffers to default size if not already done so */
  1040. int tracing_update_buffers(void);
  1041. struct ftrace_event_field {
  1042. struct list_head link;
  1043. const char *name;
  1044. const char *type;
  1045. int filter_type;
  1046. int offset;
  1047. int size;
  1048. int is_signed;
  1049. };
  1050. struct prog_entry;
  1051. struct event_filter {
  1052. struct prog_entry __rcu *prog;
  1053. char *filter_string;
  1054. };
  1055. struct event_subsystem {
  1056. struct list_head list;
  1057. const char *name;
  1058. struct event_filter *filter;
  1059. int ref_count;
  1060. };
  1061. struct trace_subsystem_dir {
  1062. struct list_head list;
  1063. struct event_subsystem *subsystem;
  1064. struct trace_array *tr;
  1065. struct dentry *entry;
  1066. int ref_count;
  1067. int nr_events;
  1068. };
  1069. extern int call_filter_check_discard(struct trace_event_call *call, void *rec,
  1070. struct ring_buffer *buffer,
  1071. struct ring_buffer_event *event);
  1072. void trace_buffer_unlock_commit_regs(struct trace_array *tr,
  1073. struct ring_buffer *buffer,
  1074. struct ring_buffer_event *event,
  1075. unsigned long flags, int pc,
  1076. struct pt_regs *regs);
  1077. static inline void trace_buffer_unlock_commit(struct trace_array *tr,
  1078. struct ring_buffer *buffer,
  1079. struct ring_buffer_event *event,
  1080. unsigned long flags, int pc)
  1081. {
  1082. trace_buffer_unlock_commit_regs(tr, buffer, event, flags, pc, NULL);
  1083. }
  1084. DECLARE_PER_CPU(struct ring_buffer_event *, trace_buffered_event);
  1085. DECLARE_PER_CPU(int, trace_buffered_event_cnt);
  1086. void trace_buffered_event_disable(void);
  1087. void trace_buffered_event_enable(void);
  1088. static inline void
  1089. __trace_event_discard_commit(struct ring_buffer *buffer,
  1090. struct ring_buffer_event *event)
  1091. {
  1092. if (this_cpu_read(trace_buffered_event) == event) {
  1093. /* Simply release the temp buffer */
  1094. this_cpu_dec(trace_buffered_event_cnt);
  1095. return;
  1096. }
  1097. ring_buffer_discard_commit(buffer, event);
  1098. }
  1099. /*
  1100. * Helper function for event_trigger_unlock_commit{_regs}().
  1101. * If there are event triggers attached to this event that requires
  1102. * filtering against its fields, then they wil be called as the
  1103. * entry already holds the field information of the current event.
  1104. *
  1105. * It also checks if the event should be discarded or not.
  1106. * It is to be discarded if the event is soft disabled and the
  1107. * event was only recorded to process triggers, or if the event
  1108. * filter is active and this event did not match the filters.
  1109. *
  1110. * Returns true if the event is discarded, false otherwise.
  1111. */
  1112. static inline bool
  1113. __event_trigger_test_discard(struct trace_event_file *file,
  1114. struct ring_buffer *buffer,
  1115. struct ring_buffer_event *event,
  1116. void *entry,
  1117. enum event_trigger_type *tt)
  1118. {
  1119. unsigned long eflags = file->flags;
  1120. if (eflags & EVENT_FILE_FL_TRIGGER_COND)
  1121. *tt = event_triggers_call(file, entry, event);
  1122. if (test_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &file->flags) ||
  1123. (unlikely(file->flags & EVENT_FILE_FL_FILTERED) &&
  1124. !filter_match_preds(file->filter, entry))) {
  1125. __trace_event_discard_commit(buffer, event);
  1126. return true;
  1127. }
  1128. return false;
  1129. }
  1130. /**
  1131. * event_trigger_unlock_commit - handle triggers and finish event commit
  1132. * @file: The file pointer assoctiated to the event
  1133. * @buffer: The ring buffer that the event is being written to
  1134. * @event: The event meta data in the ring buffer
  1135. * @entry: The event itself
  1136. * @irq_flags: The state of the interrupts at the start of the event
  1137. * @pc: The state of the preempt count at the start of the event.
  1138. *
  1139. * This is a helper function to handle triggers that require data
  1140. * from the event itself. It also tests the event against filters and
  1141. * if the event is soft disabled and should be discarded.
  1142. */
  1143. static inline void
  1144. event_trigger_unlock_commit(struct trace_event_file *file,
  1145. struct ring_buffer *buffer,
  1146. struct ring_buffer_event *event,
  1147. void *entry, unsigned long irq_flags, int pc)
  1148. {
  1149. enum event_trigger_type tt = ETT_NONE;
  1150. if (!__event_trigger_test_discard(file, buffer, event, entry, &tt))
  1151. trace_buffer_unlock_commit(file->tr, buffer, event, irq_flags, pc);
  1152. if (tt)
  1153. event_triggers_post_call(file, tt, entry, event);
  1154. }
  1155. /**
  1156. * event_trigger_unlock_commit_regs - handle triggers and finish event commit
  1157. * @file: The file pointer assoctiated to the event
  1158. * @buffer: The ring buffer that the event is being written to
  1159. * @event: The event meta data in the ring buffer
  1160. * @entry: The event itself
  1161. * @irq_flags: The state of the interrupts at the start of the event
  1162. * @pc: The state of the preempt count at the start of the event.
  1163. *
  1164. * This is a helper function to handle triggers that require data
  1165. * from the event itself. It also tests the event against filters and
  1166. * if the event is soft disabled and should be discarded.
  1167. *
  1168. * Same as event_trigger_unlock_commit() but calls
  1169. * trace_buffer_unlock_commit_regs() instead of trace_buffer_unlock_commit().
  1170. */
  1171. static inline void
  1172. event_trigger_unlock_commit_regs(struct trace_event_file *file,
  1173. struct ring_buffer *buffer,
  1174. struct ring_buffer_event *event,
  1175. void *entry, unsigned long irq_flags, int pc,
  1176. struct pt_regs *regs)
  1177. {
  1178. enum event_trigger_type tt = ETT_NONE;
  1179. if (!__event_trigger_test_discard(file, buffer, event, entry, &tt))
  1180. trace_buffer_unlock_commit_regs(file->tr, buffer, event,
  1181. irq_flags, pc, regs);
  1182. if (tt)
  1183. event_triggers_post_call(file, tt, entry, event);
  1184. }
  1185. #define FILTER_PRED_INVALID ((unsigned short)-1)
  1186. #define FILTER_PRED_IS_RIGHT (1 << 15)
  1187. #define FILTER_PRED_FOLD (1 << 15)
  1188. /*
  1189. * The max preds is the size of unsigned short with
  1190. * two flags at the MSBs. One bit is used for both the IS_RIGHT
  1191. * and FOLD flags. The other is reserved.
  1192. *
  1193. * 2^14 preds is way more than enough.
  1194. */
  1195. #define MAX_FILTER_PRED 16384
  1196. struct filter_pred;
  1197. struct regex;
  1198. typedef int (*filter_pred_fn_t) (struct filter_pred *pred, void *event);
  1199. typedef int (*regex_match_func)(char *str, struct regex *r, int len);
  1200. enum regex_type {
  1201. MATCH_FULL = 0,
  1202. MATCH_FRONT_ONLY,
  1203. MATCH_MIDDLE_ONLY,
  1204. MATCH_END_ONLY,
  1205. MATCH_GLOB,
  1206. };
  1207. struct regex {
  1208. char pattern[MAX_FILTER_STR_VAL];
  1209. int len;
  1210. int field_len;
  1211. regex_match_func match;
  1212. };
  1213. struct filter_pred {
  1214. filter_pred_fn_t fn;
  1215. u64 val;
  1216. struct regex regex;
  1217. unsigned short *ops;
  1218. struct ftrace_event_field *field;
  1219. int offset;
  1220. int not;
  1221. int op;
  1222. };
  1223. static inline bool is_string_field(struct ftrace_event_field *field)
  1224. {
  1225. return field->filter_type == FILTER_DYN_STRING ||
  1226. field->filter_type == FILTER_STATIC_STRING ||
  1227. field->filter_type == FILTER_PTR_STRING ||
  1228. field->filter_type == FILTER_COMM;
  1229. }
  1230. static inline bool is_function_field(struct ftrace_event_field *field)
  1231. {
  1232. return field->filter_type == FILTER_TRACE_FN;
  1233. }
  1234. extern enum regex_type
  1235. filter_parse_regex(char *buff, int len, char **search, int *not);
  1236. extern void print_event_filter(struct trace_event_file *file,
  1237. struct trace_seq *s);
  1238. extern int apply_event_filter(struct trace_event_file *file,
  1239. char *filter_string);
  1240. extern int apply_subsystem_event_filter(struct trace_subsystem_dir *dir,
  1241. char *filter_string);
  1242. extern void print_subsystem_event_filter(struct event_subsystem *system,
  1243. struct trace_seq *s);
  1244. extern int filter_assign_type(const char *type);
  1245. extern int create_event_filter(struct trace_event_call *call,
  1246. char *filter_str, bool set_str,
  1247. struct event_filter **filterp);
  1248. extern void free_event_filter(struct event_filter *filter);
  1249. struct ftrace_event_field *
  1250. trace_find_event_field(struct trace_event_call *call, char *name);
  1251. extern void trace_event_enable_cmd_record(bool enable);
  1252. extern void trace_event_enable_tgid_record(bool enable);
  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. static inline void *event_file_data(struct file *filp)
  1259. {
  1260. return READ_ONCE(file_inode(filp)->i_private);
  1261. }
  1262. extern struct mutex event_mutex;
  1263. extern struct list_head ftrace_events;
  1264. extern const struct file_operations event_trigger_fops;
  1265. extern const struct file_operations event_hist_fops;
  1266. #ifdef CONFIG_HIST_TRIGGERS
  1267. extern int register_trigger_hist_cmd(void);
  1268. extern int register_trigger_hist_enable_disable_cmds(void);
  1269. #else
  1270. static inline int register_trigger_hist_cmd(void) { return 0; }
  1271. static inline int register_trigger_hist_enable_disable_cmds(void) { return 0; }
  1272. #endif
  1273. extern int register_trigger_cmds(void);
  1274. extern void clear_event_triggers(struct trace_array *tr);
  1275. struct event_trigger_data {
  1276. unsigned long count;
  1277. int ref;
  1278. struct event_trigger_ops *ops;
  1279. struct event_command *cmd_ops;
  1280. struct event_filter __rcu *filter;
  1281. char *filter_str;
  1282. void *private_data;
  1283. bool paused;
  1284. bool paused_tmp;
  1285. struct list_head list;
  1286. char *name;
  1287. struct list_head named_list;
  1288. struct event_trigger_data *named_data;
  1289. };
  1290. /* Avoid typos */
  1291. #define ENABLE_EVENT_STR "enable_event"
  1292. #define DISABLE_EVENT_STR "disable_event"
  1293. #define ENABLE_HIST_STR "enable_hist"
  1294. #define DISABLE_HIST_STR "disable_hist"
  1295. struct enable_trigger_data {
  1296. struct trace_event_file *file;
  1297. bool enable;
  1298. bool hist;
  1299. };
  1300. extern int event_enable_trigger_print(struct seq_file *m,
  1301. struct event_trigger_ops *ops,
  1302. struct event_trigger_data *data);
  1303. extern void event_enable_trigger_free(struct event_trigger_ops *ops,
  1304. struct event_trigger_data *data);
  1305. extern int event_enable_trigger_func(struct event_command *cmd_ops,
  1306. struct trace_event_file *file,
  1307. char *glob, char *cmd, char *param);
  1308. extern int event_enable_register_trigger(char *glob,
  1309. struct event_trigger_ops *ops,
  1310. struct event_trigger_data *data,
  1311. struct trace_event_file *file);
  1312. extern void event_enable_unregister_trigger(char *glob,
  1313. struct event_trigger_ops *ops,
  1314. struct event_trigger_data *test,
  1315. struct trace_event_file *file);
  1316. extern void trigger_data_free(struct event_trigger_data *data);
  1317. extern int event_trigger_init(struct event_trigger_ops *ops,
  1318. struct event_trigger_data *data);
  1319. extern int trace_event_trigger_enable_disable(struct trace_event_file *file,
  1320. int trigger_enable);
  1321. extern void update_cond_flag(struct trace_event_file *file);
  1322. extern void unregister_trigger(char *glob, struct event_trigger_ops *ops,
  1323. struct event_trigger_data *test,
  1324. struct trace_event_file *file);
  1325. extern int set_trigger_filter(char *filter_str,
  1326. struct event_trigger_data *trigger_data,
  1327. struct trace_event_file *file);
  1328. extern struct event_trigger_data *find_named_trigger(const char *name);
  1329. extern bool is_named_trigger(struct event_trigger_data *test);
  1330. extern int save_named_trigger(const char *name,
  1331. struct event_trigger_data *data);
  1332. extern void del_named_trigger(struct event_trigger_data *data);
  1333. extern void pause_named_trigger(struct event_trigger_data *data);
  1334. extern void unpause_named_trigger(struct event_trigger_data *data);
  1335. extern void set_named_trigger_data(struct event_trigger_data *data,
  1336. struct event_trigger_data *named_data);
  1337. extern struct event_trigger_data *
  1338. get_named_trigger_data(struct event_trigger_data *data);
  1339. extern int register_event_command(struct event_command *cmd);
  1340. extern int unregister_event_command(struct event_command *cmd);
  1341. extern int register_trigger_hist_enable_disable_cmds(void);
  1342. /**
  1343. * struct event_trigger_ops - callbacks for trace event triggers
  1344. *
  1345. * The methods in this structure provide per-event trigger hooks for
  1346. * various trigger operations.
  1347. *
  1348. * All the methods below, except for @init() and @free(), must be
  1349. * implemented.
  1350. *
  1351. * @func: The trigger 'probe' function called when the triggering
  1352. * event occurs. The data passed into this callback is the data
  1353. * that was supplied to the event_command @reg() function that
  1354. * registered the trigger (see struct event_command) along with
  1355. * the trace record, rec.
  1356. *
  1357. * @init: An optional initialization function called for the trigger
  1358. * when the trigger is registered (via the event_command reg()
  1359. * function). This can be used to perform per-trigger
  1360. * initialization such as incrementing a per-trigger reference
  1361. * count, for instance. This is usually implemented by the
  1362. * generic utility function @event_trigger_init() (see
  1363. * trace_event_triggers.c).
  1364. *
  1365. * @free: An optional de-initialization function called for the
  1366. * trigger when the trigger is unregistered (via the
  1367. * event_command @reg() function). This can be used to perform
  1368. * per-trigger de-initialization such as decrementing a
  1369. * per-trigger reference count and freeing corresponding trigger
  1370. * data, for instance. This is usually implemented by the
  1371. * generic utility function @event_trigger_free() (see
  1372. * trace_event_triggers.c).
  1373. *
  1374. * @print: The callback function invoked to have the trigger print
  1375. * itself. This is usually implemented by a wrapper function
  1376. * that calls the generic utility function @event_trigger_print()
  1377. * (see trace_event_triggers.c).
  1378. */
  1379. struct event_trigger_ops {
  1380. void (*func)(struct event_trigger_data *data,
  1381. void *rec,
  1382. struct ring_buffer_event *rbe);
  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. #define MAX_EVENT_NAME_LEN 64
  1541. extern int trace_run_command(const char *buf, int (*createfn)(int, char**));
  1542. extern ssize_t trace_parse_run_command(struct file *file,
  1543. const char __user *buffer, size_t count, loff_t *ppos,
  1544. int (*createfn)(int, char**));
  1545. /*
  1546. * Normal trace_printk() and friends allocates special buffers
  1547. * to do the manipulation, as well as saves the print formats
  1548. * into sections to display. But the trace infrastructure wants
  1549. * to use these without the added overhead at the price of being
  1550. * a bit slower (used mainly for warnings, where we don't care
  1551. * about performance). The internal_trace_puts() is for such
  1552. * a purpose.
  1553. */
  1554. #define internal_trace_puts(str) __trace_puts(_THIS_IP_, str, strlen(str))
  1555. #undef FTRACE_ENTRY
  1556. #define FTRACE_ENTRY(call, struct_name, id, tstruct, print, filter) \
  1557. extern struct trace_event_call \
  1558. __aligned(4) event_##call;
  1559. #undef FTRACE_ENTRY_DUP
  1560. #define FTRACE_ENTRY_DUP(call, struct_name, id, tstruct, print, filter) \
  1561. FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print), \
  1562. filter)
  1563. #undef FTRACE_ENTRY_PACKED
  1564. #define FTRACE_ENTRY_PACKED(call, struct_name, id, tstruct, print, filter) \
  1565. FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print), \
  1566. filter)
  1567. #include "trace_entries.h"
  1568. #if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_FUNCTION_TRACER)
  1569. int perf_ftrace_event_register(struct trace_event_call *call,
  1570. enum trace_reg type, void *data);
  1571. #else
  1572. #define perf_ftrace_event_register NULL
  1573. #endif
  1574. #ifdef CONFIG_FTRACE_SYSCALLS
  1575. void init_ftrace_syscalls(void);
  1576. const char *get_syscall_name(int syscall);
  1577. #else
  1578. static inline void init_ftrace_syscalls(void) { }
  1579. static inline const char *get_syscall_name(int syscall)
  1580. {
  1581. return NULL;
  1582. }
  1583. #endif
  1584. #ifdef CONFIG_EVENT_TRACING
  1585. void trace_event_init(void);
  1586. void trace_event_eval_update(struct trace_eval_map **map, int len);
  1587. #else
  1588. static inline void __init trace_event_init(void) { }
  1589. static inline void trace_event_eval_update(struct trace_eval_map **map, int len) { }
  1590. #endif
  1591. extern struct trace_iterator *tracepoint_print_iter;
  1592. #endif /* _LINUX_KERNEL_TRACE_H */