trace.h 60 KB

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