trace.h 64 KB

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