trace.h 57 KB

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