trace.h 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847
  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. return iter->buffer_iter ? iter->buffer_iter[cpu] : NULL;
  508. }
  509. int tracer_init(struct tracer *t, struct trace_array *tr);
  510. int tracing_is_enabled(void);
  511. void tracing_reset(struct trace_buffer *buf, int cpu);
  512. void tracing_reset_online_cpus(struct trace_buffer *buf);
  513. void tracing_reset_current(int cpu);
  514. void tracing_reset_all_online_cpus(void);
  515. int tracing_open_generic(struct inode *inode, struct file *filp);
  516. bool tracing_is_disabled(void);
  517. bool tracer_tracing_is_on(struct trace_array *tr);
  518. void tracer_tracing_on(struct trace_array *tr);
  519. void tracer_tracing_off(struct trace_array *tr);
  520. struct dentry *trace_create_file(const char *name,
  521. umode_t mode,
  522. struct dentry *parent,
  523. void *data,
  524. const struct file_operations *fops);
  525. struct dentry *tracing_init_dentry(void);
  526. struct ring_buffer_event;
  527. struct ring_buffer_event *
  528. trace_buffer_lock_reserve(struct ring_buffer *buffer,
  529. int type,
  530. unsigned long len,
  531. unsigned long flags,
  532. int pc);
  533. struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
  534. struct trace_array_cpu *data);
  535. struct trace_entry *trace_find_next_entry(struct trace_iterator *iter,
  536. int *ent_cpu, u64 *ent_ts);
  537. void trace_buffer_unlock_commit_nostack(struct ring_buffer *buffer,
  538. struct ring_buffer_event *event);
  539. int trace_empty(struct trace_iterator *iter);
  540. void *trace_find_next_entry_inc(struct trace_iterator *iter);
  541. void trace_init_global_iter(struct trace_iterator *iter);
  542. void tracing_iter_reset(struct trace_iterator *iter, int cpu);
  543. void trace_function(struct trace_array *tr,
  544. unsigned long ip,
  545. unsigned long parent_ip,
  546. unsigned long flags, int pc);
  547. void trace_graph_function(struct trace_array *tr,
  548. unsigned long ip,
  549. unsigned long parent_ip,
  550. unsigned long flags, int pc);
  551. void trace_latency_header(struct seq_file *m);
  552. void trace_default_header(struct seq_file *m);
  553. void print_trace_header(struct seq_file *m, struct trace_iterator *iter);
  554. int trace_empty(struct trace_iterator *iter);
  555. void trace_graph_return(struct ftrace_graph_ret *trace);
  556. int trace_graph_entry(struct ftrace_graph_ent *trace);
  557. void set_graph_array(struct trace_array *tr);
  558. void tracing_start_cmdline_record(void);
  559. void tracing_stop_cmdline_record(void);
  560. void tracing_start_tgid_record(void);
  561. void tracing_stop_tgid_record(void);
  562. int register_tracer(struct tracer *type);
  563. int is_tracing_stopped(void);
  564. loff_t tracing_lseek(struct file *file, loff_t offset, int whence);
  565. extern cpumask_var_t __read_mostly tracing_buffer_mask;
  566. #define for_each_tracing_cpu(cpu) \
  567. for_each_cpu(cpu, tracing_buffer_mask)
  568. extern unsigned long nsecs_to_usecs(unsigned long nsecs);
  569. extern unsigned long tracing_thresh;
  570. /* PID filtering */
  571. extern int pid_max;
  572. bool trace_find_filtered_pid(struct trace_pid_list *filtered_pids,
  573. pid_t search_pid);
  574. bool trace_ignore_this_task(struct trace_pid_list *filtered_pids,
  575. struct task_struct *task);
  576. void trace_filter_add_remove_task(struct trace_pid_list *pid_list,
  577. struct task_struct *self,
  578. struct task_struct *task);
  579. void *trace_pid_next(struct trace_pid_list *pid_list, void *v, loff_t *pos);
  580. void *trace_pid_start(struct trace_pid_list *pid_list, loff_t *pos);
  581. int trace_pid_show(struct seq_file *m, void *v);
  582. void trace_free_pid_list(struct trace_pid_list *pid_list);
  583. int trace_pid_write(struct trace_pid_list *filtered_pids,
  584. struct trace_pid_list **new_pid_list,
  585. const char __user *ubuf, size_t cnt);
  586. #ifdef CONFIG_TRACER_MAX_TRACE
  587. void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
  588. void update_max_tr_single(struct trace_array *tr,
  589. struct task_struct *tsk, int cpu);
  590. #endif /* CONFIG_TRACER_MAX_TRACE */
  591. #ifdef CONFIG_STACKTRACE
  592. void ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags,
  593. int pc);
  594. void __trace_stack(struct trace_array *tr, unsigned long flags, int skip,
  595. int pc);
  596. #else
  597. static inline void ftrace_trace_userstack(struct ring_buffer *buffer,
  598. unsigned long flags, int pc)
  599. {
  600. }
  601. static inline void __trace_stack(struct trace_array *tr, unsigned long flags,
  602. int skip, int pc)
  603. {
  604. }
  605. #endif /* CONFIG_STACKTRACE */
  606. extern u64 ftrace_now(int cpu);
  607. extern void trace_find_cmdline(int pid, char comm[]);
  608. extern int trace_find_tgid(int pid);
  609. extern void trace_event_follow_fork(struct trace_array *tr, bool enable);
  610. #ifdef CONFIG_DYNAMIC_FTRACE
  611. extern unsigned long ftrace_update_tot_cnt;
  612. void ftrace_init_trace_array(struct trace_array *tr);
  613. #else
  614. static inline void ftrace_init_trace_array(struct trace_array *tr) { }
  615. #endif
  616. #define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
  617. extern int DYN_FTRACE_TEST_NAME(void);
  618. #define DYN_FTRACE_TEST_NAME2 trace_selftest_dynamic_test_func2
  619. extern int DYN_FTRACE_TEST_NAME2(void);
  620. extern bool ring_buffer_expanded;
  621. extern bool tracing_selftest_disabled;
  622. #ifdef CONFIG_FTRACE_STARTUP_TEST
  623. extern int trace_selftest_startup_function(struct tracer *trace,
  624. struct trace_array *tr);
  625. extern int trace_selftest_startup_function_graph(struct tracer *trace,
  626. struct trace_array *tr);
  627. extern int trace_selftest_startup_irqsoff(struct tracer *trace,
  628. struct trace_array *tr);
  629. extern int trace_selftest_startup_preemptoff(struct tracer *trace,
  630. struct trace_array *tr);
  631. extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
  632. struct trace_array *tr);
  633. extern int trace_selftest_startup_wakeup(struct tracer *trace,
  634. struct trace_array *tr);
  635. extern int trace_selftest_startup_nop(struct tracer *trace,
  636. struct trace_array *tr);
  637. extern int trace_selftest_startup_branch(struct tracer *trace,
  638. struct trace_array *tr);
  639. /*
  640. * Tracer data references selftest functions that only occur
  641. * on boot up. These can be __init functions. Thus, when selftests
  642. * are enabled, then the tracers need to reference __init functions.
  643. */
  644. #define __tracer_data __refdata
  645. #else
  646. /* Tracers are seldom changed. Optimize when selftests are disabled. */
  647. #define __tracer_data __read_mostly
  648. #endif /* CONFIG_FTRACE_STARTUP_TEST */
  649. extern void *head_page(struct trace_array_cpu *data);
  650. extern unsigned long long ns2usecs(u64 nsec);
  651. extern int
  652. trace_vbprintk(unsigned long ip, const char *fmt, va_list args);
  653. extern int
  654. trace_vprintk(unsigned long ip, const char *fmt, va_list args);
  655. extern int
  656. trace_array_vprintk(struct trace_array *tr,
  657. unsigned long ip, const char *fmt, va_list args);
  658. int trace_array_printk(struct trace_array *tr,
  659. unsigned long ip, const char *fmt, ...);
  660. int trace_array_printk_buf(struct ring_buffer *buffer,
  661. unsigned long ip, const char *fmt, ...);
  662. void trace_printk_seq(struct trace_seq *s);
  663. enum print_line_t print_trace_line(struct trace_iterator *iter);
  664. extern char trace_find_mark(unsigned long long duration);
  665. struct ftrace_hash;
  666. struct ftrace_mod_load {
  667. struct list_head list;
  668. char *func;
  669. char *module;
  670. int enable;
  671. };
  672. enum {
  673. FTRACE_HASH_FL_MOD = (1 << 0),
  674. };
  675. struct ftrace_hash {
  676. unsigned long size_bits;
  677. struct hlist_head *buckets;
  678. unsigned long count;
  679. unsigned long flags;
  680. struct rcu_head rcu;
  681. };
  682. struct ftrace_func_entry *
  683. ftrace_lookup_ip(struct ftrace_hash *hash, unsigned long ip);
  684. static __always_inline bool ftrace_hash_empty(struct ftrace_hash *hash)
  685. {
  686. return !hash || !(hash->count || (hash->flags & FTRACE_HASH_FL_MOD));
  687. }
  688. /* Standard output formatting function used for function return traces */
  689. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  690. /* Flag options */
  691. #define TRACE_GRAPH_PRINT_OVERRUN 0x1
  692. #define TRACE_GRAPH_PRINT_CPU 0x2
  693. #define TRACE_GRAPH_PRINT_OVERHEAD 0x4
  694. #define TRACE_GRAPH_PRINT_PROC 0x8
  695. #define TRACE_GRAPH_PRINT_DURATION 0x10
  696. #define TRACE_GRAPH_PRINT_ABS_TIME 0x20
  697. #define TRACE_GRAPH_PRINT_IRQS 0x40
  698. #define TRACE_GRAPH_PRINT_TAIL 0x80
  699. #define TRACE_GRAPH_SLEEP_TIME 0x100
  700. #define TRACE_GRAPH_GRAPH_TIME 0x200
  701. #define TRACE_GRAPH_PRINT_FILL_SHIFT 28
  702. #define TRACE_GRAPH_PRINT_FILL_MASK (0x3 << TRACE_GRAPH_PRINT_FILL_SHIFT)
  703. extern void ftrace_graph_sleep_time_control(bool enable);
  704. extern void ftrace_graph_graph_time_control(bool enable);
  705. extern enum print_line_t
  706. print_graph_function_flags(struct trace_iterator *iter, u32 flags);
  707. extern void print_graph_headers_flags(struct seq_file *s, u32 flags);
  708. extern void
  709. trace_print_graph_duration(unsigned long long duration, struct trace_seq *s);
  710. extern void graph_trace_open(struct trace_iterator *iter);
  711. extern void graph_trace_close(struct trace_iterator *iter);
  712. extern int __trace_graph_entry(struct trace_array *tr,
  713. struct ftrace_graph_ent *trace,
  714. unsigned long flags, int pc);
  715. extern void __trace_graph_return(struct trace_array *tr,
  716. struct ftrace_graph_ret *trace,
  717. unsigned long flags, int pc);
  718. #ifdef CONFIG_DYNAMIC_FTRACE
  719. extern struct ftrace_hash *ftrace_graph_hash;
  720. extern struct ftrace_hash *ftrace_graph_notrace_hash;
  721. static inline int ftrace_graph_addr(unsigned long addr)
  722. {
  723. int ret = 0;
  724. preempt_disable_notrace();
  725. if (ftrace_hash_empty(ftrace_graph_hash)) {
  726. ret = 1;
  727. goto out;
  728. }
  729. if (ftrace_lookup_ip(ftrace_graph_hash, addr)) {
  730. /*
  731. * If no irqs are to be traced, but a set_graph_function
  732. * is set, and called by an interrupt handler, we still
  733. * want to trace it.
  734. */
  735. if (in_irq())
  736. trace_recursion_set(TRACE_IRQ_BIT);
  737. else
  738. trace_recursion_clear(TRACE_IRQ_BIT);
  739. ret = 1;
  740. }
  741. out:
  742. preempt_enable_notrace();
  743. return ret;
  744. }
  745. static inline int ftrace_graph_notrace_addr(unsigned long addr)
  746. {
  747. int ret = 0;
  748. preempt_disable_notrace();
  749. if (ftrace_lookup_ip(ftrace_graph_notrace_hash, addr))
  750. ret = 1;
  751. preempt_enable_notrace();
  752. return ret;
  753. }
  754. #else
  755. static inline int ftrace_graph_addr(unsigned long addr)
  756. {
  757. return 1;
  758. }
  759. static inline int ftrace_graph_notrace_addr(unsigned long addr)
  760. {
  761. return 0;
  762. }
  763. #endif /* CONFIG_DYNAMIC_FTRACE */
  764. extern unsigned int fgraph_max_depth;
  765. static inline bool ftrace_graph_ignore_func(struct ftrace_graph_ent *trace)
  766. {
  767. /* trace it when it is-nested-in or is a function enabled. */
  768. return !(trace->depth || ftrace_graph_addr(trace->func)) ||
  769. (trace->depth < 0) ||
  770. (fgraph_max_depth && trace->depth >= fgraph_max_depth);
  771. }
  772. #else /* CONFIG_FUNCTION_GRAPH_TRACER */
  773. static inline enum print_line_t
  774. print_graph_function_flags(struct trace_iterator *iter, u32 flags)
  775. {
  776. return TRACE_TYPE_UNHANDLED;
  777. }
  778. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  779. extern struct list_head ftrace_pids;
  780. #ifdef CONFIG_FUNCTION_TRACER
  781. struct ftrace_func_command {
  782. struct list_head list;
  783. char *name;
  784. int (*func)(struct trace_array *tr,
  785. struct ftrace_hash *hash,
  786. char *func, char *cmd,
  787. char *params, int enable);
  788. };
  789. extern bool ftrace_filter_param __initdata;
  790. static inline int ftrace_trace_task(struct trace_array *tr)
  791. {
  792. return !this_cpu_read(tr->trace_buffer.data->ftrace_ignore_pid);
  793. }
  794. extern int ftrace_is_dead(void);
  795. int ftrace_create_function_files(struct trace_array *tr,
  796. struct dentry *parent);
  797. void ftrace_destroy_function_files(struct trace_array *tr);
  798. void ftrace_init_global_array_ops(struct trace_array *tr);
  799. void ftrace_init_array_ops(struct trace_array *tr, ftrace_func_t func);
  800. void ftrace_reset_array_ops(struct trace_array *tr);
  801. void ftrace_init_tracefs(struct trace_array *tr, struct dentry *d_tracer);
  802. void ftrace_init_tracefs_toplevel(struct trace_array *tr,
  803. struct dentry *d_tracer);
  804. void ftrace_clear_pids(struct trace_array *tr);
  805. int init_function_trace(void);
  806. void ftrace_pid_follow_fork(struct trace_array *tr, bool enable);
  807. #else
  808. static inline int ftrace_trace_task(struct trace_array *tr)
  809. {
  810. return 1;
  811. }
  812. static inline int ftrace_is_dead(void) { return 0; }
  813. static inline int
  814. ftrace_create_function_files(struct trace_array *tr,
  815. struct dentry *parent)
  816. {
  817. return 0;
  818. }
  819. static inline void ftrace_destroy_function_files(struct trace_array *tr) { }
  820. static inline __init void
  821. ftrace_init_global_array_ops(struct trace_array *tr) { }
  822. static inline void ftrace_reset_array_ops(struct trace_array *tr) { }
  823. static inline void ftrace_init_tracefs(struct trace_array *tr, struct dentry *d) { }
  824. static inline void ftrace_init_tracefs_toplevel(struct trace_array *tr, struct dentry *d) { }
  825. static inline void ftrace_clear_pids(struct trace_array *tr) { }
  826. static inline int init_function_trace(void) { return 0; }
  827. static inline void ftrace_pid_follow_fork(struct trace_array *tr, bool enable) { }
  828. /* ftace_func_t type is not defined, use macro instead of static inline */
  829. #define ftrace_init_array_ops(tr, func) do { } while (0)
  830. #endif /* CONFIG_FUNCTION_TRACER */
  831. #if defined(CONFIG_FUNCTION_TRACER) && defined(CONFIG_DYNAMIC_FTRACE)
  832. struct ftrace_probe_ops {
  833. void (*func)(unsigned long ip,
  834. unsigned long parent_ip,
  835. struct trace_array *tr,
  836. struct ftrace_probe_ops *ops,
  837. void *data);
  838. int (*init)(struct ftrace_probe_ops *ops,
  839. struct trace_array *tr,
  840. unsigned long ip, void *init_data,
  841. void **data);
  842. void (*free)(struct ftrace_probe_ops *ops,
  843. struct trace_array *tr,
  844. unsigned long ip, void *data);
  845. int (*print)(struct seq_file *m,
  846. unsigned long ip,
  847. struct ftrace_probe_ops *ops,
  848. void *data);
  849. };
  850. struct ftrace_func_mapper;
  851. typedef int (*ftrace_mapper_func)(void *data);
  852. struct ftrace_func_mapper *allocate_ftrace_func_mapper(void);
  853. void **ftrace_func_mapper_find_ip(struct ftrace_func_mapper *mapper,
  854. unsigned long ip);
  855. int ftrace_func_mapper_add_ip(struct ftrace_func_mapper *mapper,
  856. unsigned long ip, void *data);
  857. void *ftrace_func_mapper_remove_ip(struct ftrace_func_mapper *mapper,
  858. unsigned long ip);
  859. void free_ftrace_func_mapper(struct ftrace_func_mapper *mapper,
  860. ftrace_mapper_func free_func);
  861. extern int
  862. register_ftrace_function_probe(char *glob, struct trace_array *tr,
  863. struct ftrace_probe_ops *ops, void *data);
  864. extern int
  865. unregister_ftrace_function_probe_func(char *glob, struct trace_array *tr,
  866. struct ftrace_probe_ops *ops);
  867. extern void clear_ftrace_function_probes(struct trace_array *tr);
  868. int register_ftrace_command(struct ftrace_func_command *cmd);
  869. int unregister_ftrace_command(struct ftrace_func_command *cmd);
  870. void ftrace_create_filter_files(struct ftrace_ops *ops,
  871. struct dentry *parent);
  872. void ftrace_destroy_filter_files(struct ftrace_ops *ops);
  873. #else
  874. struct ftrace_func_command;
  875. static inline __init int register_ftrace_command(struct ftrace_func_command *cmd)
  876. {
  877. return -EINVAL;
  878. }
  879. static inline __init int unregister_ftrace_command(char *cmd_name)
  880. {
  881. return -EINVAL;
  882. }
  883. static inline void clear_ftrace_function_probes(struct trace_array *tr)
  884. {
  885. }
  886. /*
  887. * The ops parameter passed in is usually undefined.
  888. * This must be a macro.
  889. */
  890. #define ftrace_create_filter_files(ops, parent) do { } while (0)
  891. #define ftrace_destroy_filter_files(ops) do { } while (0)
  892. #endif /* CONFIG_FUNCTION_TRACER && CONFIG_DYNAMIC_FTRACE */
  893. bool ftrace_event_is_function(struct trace_event_call *call);
  894. /*
  895. * struct trace_parser - servers for reading the user input separated by spaces
  896. * @cont: set if the input is not complete - no final space char was found
  897. * @buffer: holds the parsed user input
  898. * @idx: user input length
  899. * @size: buffer size
  900. */
  901. struct trace_parser {
  902. bool cont;
  903. char *buffer;
  904. unsigned idx;
  905. unsigned size;
  906. };
  907. static inline bool trace_parser_loaded(struct trace_parser *parser)
  908. {
  909. return (parser->idx != 0);
  910. }
  911. static inline bool trace_parser_cont(struct trace_parser *parser)
  912. {
  913. return parser->cont;
  914. }
  915. static inline void trace_parser_clear(struct trace_parser *parser)
  916. {
  917. parser->cont = false;
  918. parser->idx = 0;
  919. }
  920. extern int trace_parser_get_init(struct trace_parser *parser, int size);
  921. extern void trace_parser_put(struct trace_parser *parser);
  922. extern int trace_get_user(struct trace_parser *parser, const char __user *ubuf,
  923. size_t cnt, loff_t *ppos);
  924. /*
  925. * Only create function graph options if function graph is configured.
  926. */
  927. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  928. # define FGRAPH_FLAGS \
  929. C(DISPLAY_GRAPH, "display-graph"),
  930. #else
  931. # define FGRAPH_FLAGS
  932. #endif
  933. #ifdef CONFIG_BRANCH_TRACER
  934. # define BRANCH_FLAGS \
  935. C(BRANCH, "branch"),
  936. #else
  937. # define BRANCH_FLAGS
  938. #endif
  939. #ifdef CONFIG_FUNCTION_TRACER
  940. # define FUNCTION_FLAGS \
  941. C(FUNCTION, "function-trace"), \
  942. C(FUNC_FORK, "function-fork"),
  943. # define FUNCTION_DEFAULT_FLAGS TRACE_ITER_FUNCTION
  944. #else
  945. # define FUNCTION_FLAGS
  946. # define FUNCTION_DEFAULT_FLAGS 0UL
  947. # define TRACE_ITER_FUNC_FORK 0UL
  948. #endif
  949. #ifdef CONFIG_STACKTRACE
  950. # define STACK_FLAGS \
  951. C(STACKTRACE, "stacktrace"),
  952. #else
  953. # define STACK_FLAGS
  954. #endif
  955. /*
  956. * trace_iterator_flags is an enumeration that defines bit
  957. * positions into trace_flags that controls the output.
  958. *
  959. * NOTE: These bits must match the trace_options array in
  960. * trace.c (this macro guarantees it).
  961. */
  962. #define TRACE_FLAGS \
  963. C(PRINT_PARENT, "print-parent"), \
  964. C(SYM_OFFSET, "sym-offset"), \
  965. C(SYM_ADDR, "sym-addr"), \
  966. C(VERBOSE, "verbose"), \
  967. C(RAW, "raw"), \
  968. C(HEX, "hex"), \
  969. C(BIN, "bin"), \
  970. C(BLOCK, "block"), \
  971. C(PRINTK, "trace_printk"), \
  972. C(ANNOTATE, "annotate"), \
  973. C(USERSTACKTRACE, "userstacktrace"), \
  974. C(SYM_USEROBJ, "sym-userobj"), \
  975. C(PRINTK_MSGONLY, "printk-msg-only"), \
  976. C(CONTEXT_INFO, "context-info"), /* Print pid/cpu/time */ \
  977. C(LATENCY_FMT, "latency-format"), \
  978. C(RECORD_CMD, "record-cmd"), \
  979. C(RECORD_TGID, "record-tgid"), \
  980. C(OVERWRITE, "overwrite"), \
  981. C(STOP_ON_FREE, "disable_on_free"), \
  982. C(IRQ_INFO, "irq-info"), \
  983. C(MARKERS, "markers"), \
  984. C(EVENT_FORK, "event-fork"), \
  985. FUNCTION_FLAGS \
  986. FGRAPH_FLAGS \
  987. STACK_FLAGS \
  988. BRANCH_FLAGS
  989. /*
  990. * By defining C, we can make TRACE_FLAGS a list of bit names
  991. * that will define the bits for the flag masks.
  992. */
  993. #undef C
  994. #define C(a, b) TRACE_ITER_##a##_BIT
  995. enum trace_iterator_bits {
  996. TRACE_FLAGS
  997. /* Make sure we don't go more than we have bits for */
  998. TRACE_ITER_LAST_BIT
  999. };
  1000. /*
  1001. * By redefining C, we can make TRACE_FLAGS a list of masks that
  1002. * use the bits as defined above.
  1003. */
  1004. #undef C
  1005. #define C(a, b) TRACE_ITER_##a = (1 << TRACE_ITER_##a##_BIT)
  1006. enum trace_iterator_flags { TRACE_FLAGS };
  1007. /*
  1008. * TRACE_ITER_SYM_MASK masks the options in trace_flags that
  1009. * control the output of kernel symbols.
  1010. */
  1011. #define TRACE_ITER_SYM_MASK \
  1012. (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR)
  1013. extern struct tracer nop_trace;
  1014. #ifdef CONFIG_BRANCH_TRACER
  1015. extern int enable_branch_tracing(struct trace_array *tr);
  1016. extern void disable_branch_tracing(void);
  1017. static inline int trace_branch_enable(struct trace_array *tr)
  1018. {
  1019. if (tr->trace_flags & TRACE_ITER_BRANCH)
  1020. return enable_branch_tracing(tr);
  1021. return 0;
  1022. }
  1023. static inline void trace_branch_disable(void)
  1024. {
  1025. /* due to races, always disable */
  1026. disable_branch_tracing();
  1027. }
  1028. #else
  1029. static inline int trace_branch_enable(struct trace_array *tr)
  1030. {
  1031. return 0;
  1032. }
  1033. static inline void trace_branch_disable(void)
  1034. {
  1035. }
  1036. #endif /* CONFIG_BRANCH_TRACER */
  1037. /* set ring buffers to default size if not already done so */
  1038. int tracing_update_buffers(void);
  1039. struct ftrace_event_field {
  1040. struct list_head link;
  1041. const char *name;
  1042. const char *type;
  1043. int filter_type;
  1044. int offset;
  1045. int size;
  1046. int is_signed;
  1047. };
  1048. struct prog_entry;
  1049. struct event_filter {
  1050. struct prog_entry __rcu *prog;
  1051. char *filter_string;
  1052. };
  1053. struct event_subsystem {
  1054. struct list_head list;
  1055. const char *name;
  1056. struct event_filter *filter;
  1057. int ref_count;
  1058. };
  1059. struct trace_subsystem_dir {
  1060. struct list_head list;
  1061. struct event_subsystem *subsystem;
  1062. struct trace_array *tr;
  1063. struct dentry *entry;
  1064. int ref_count;
  1065. int nr_events;
  1066. };
  1067. extern int call_filter_check_discard(struct trace_event_call *call, void *rec,
  1068. struct ring_buffer *buffer,
  1069. struct ring_buffer_event *event);
  1070. void trace_buffer_unlock_commit_regs(struct trace_array *tr,
  1071. struct ring_buffer *buffer,
  1072. struct ring_buffer_event *event,
  1073. unsigned long flags, int pc,
  1074. struct pt_regs *regs);
  1075. static inline void trace_buffer_unlock_commit(struct trace_array *tr,
  1076. struct ring_buffer *buffer,
  1077. struct ring_buffer_event *event,
  1078. unsigned long flags, int pc)
  1079. {
  1080. trace_buffer_unlock_commit_regs(tr, buffer, event, flags, pc, NULL);
  1081. }
  1082. DECLARE_PER_CPU(struct ring_buffer_event *, trace_buffered_event);
  1083. DECLARE_PER_CPU(int, trace_buffered_event_cnt);
  1084. void trace_buffered_event_disable(void);
  1085. void trace_buffered_event_enable(void);
  1086. static inline void
  1087. __trace_event_discard_commit(struct ring_buffer *buffer,
  1088. struct ring_buffer_event *event)
  1089. {
  1090. if (this_cpu_read(trace_buffered_event) == event) {
  1091. /* Simply release the temp buffer */
  1092. this_cpu_dec(trace_buffered_event_cnt);
  1093. return;
  1094. }
  1095. ring_buffer_discard_commit(buffer, event);
  1096. }
  1097. /*
  1098. * Helper function for event_trigger_unlock_commit{_regs}().
  1099. * If there are event triggers attached to this event that requires
  1100. * filtering against its fields, then they wil be called as the
  1101. * entry already holds the field information of the current event.
  1102. *
  1103. * It also checks if the event should be discarded or not.
  1104. * It is to be discarded if the event is soft disabled and the
  1105. * event was only recorded to process triggers, or if the event
  1106. * filter is active and this event did not match the filters.
  1107. *
  1108. * Returns true if the event is discarded, false otherwise.
  1109. */
  1110. static inline bool
  1111. __event_trigger_test_discard(struct trace_event_file *file,
  1112. struct ring_buffer *buffer,
  1113. struct ring_buffer_event *event,
  1114. void *entry,
  1115. enum event_trigger_type *tt)
  1116. {
  1117. unsigned long eflags = file->flags;
  1118. if (eflags & EVENT_FILE_FL_TRIGGER_COND)
  1119. *tt = event_triggers_call(file, entry, event);
  1120. if (test_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &file->flags) ||
  1121. (unlikely(file->flags & EVENT_FILE_FL_FILTERED) &&
  1122. !filter_match_preds(file->filter, entry))) {
  1123. __trace_event_discard_commit(buffer, event);
  1124. return true;
  1125. }
  1126. return false;
  1127. }
  1128. /**
  1129. * event_trigger_unlock_commit - handle triggers and finish event commit
  1130. * @file: The file pointer assoctiated to the event
  1131. * @buffer: The ring buffer that the event is being written to
  1132. * @event: The event meta data in the ring buffer
  1133. * @entry: The event itself
  1134. * @irq_flags: The state of the interrupts at the start of the event
  1135. * @pc: The state of the preempt count at the start of the event.
  1136. *
  1137. * This is a helper function to handle triggers that require data
  1138. * from the event itself. It also tests the event against filters and
  1139. * if the event is soft disabled and should be discarded.
  1140. */
  1141. static inline void
  1142. event_trigger_unlock_commit(struct trace_event_file *file,
  1143. struct ring_buffer *buffer,
  1144. struct ring_buffer_event *event,
  1145. void *entry, unsigned long irq_flags, int pc)
  1146. {
  1147. enum event_trigger_type tt = ETT_NONE;
  1148. if (!__event_trigger_test_discard(file, buffer, event, entry, &tt))
  1149. trace_buffer_unlock_commit(file->tr, buffer, event, irq_flags, pc);
  1150. if (tt)
  1151. event_triggers_post_call(file, tt);
  1152. }
  1153. /**
  1154. * event_trigger_unlock_commit_regs - handle triggers and finish event commit
  1155. * @file: The file pointer assoctiated to the event
  1156. * @buffer: The ring buffer that the event is being written to
  1157. * @event: The event meta data in the ring buffer
  1158. * @entry: The event itself
  1159. * @irq_flags: The state of the interrupts at the start of the event
  1160. * @pc: The state of the preempt count at the start of the event.
  1161. *
  1162. * This is a helper function to handle triggers that require data
  1163. * from the event itself. It also tests the event against filters and
  1164. * if the event is soft disabled and should be discarded.
  1165. *
  1166. * Same as event_trigger_unlock_commit() but calls
  1167. * trace_buffer_unlock_commit_regs() instead of trace_buffer_unlock_commit().
  1168. */
  1169. static inline void
  1170. event_trigger_unlock_commit_regs(struct trace_event_file *file,
  1171. struct ring_buffer *buffer,
  1172. struct ring_buffer_event *event,
  1173. void *entry, unsigned long irq_flags, int pc,
  1174. struct pt_regs *regs)
  1175. {
  1176. enum event_trigger_type tt = ETT_NONE;
  1177. if (!__event_trigger_test_discard(file, buffer, event, entry, &tt))
  1178. trace_buffer_unlock_commit_regs(file->tr, buffer, event,
  1179. irq_flags, pc, regs);
  1180. if (tt)
  1181. event_triggers_post_call(file, tt);
  1182. }
  1183. #define FILTER_PRED_INVALID ((unsigned short)-1)
  1184. #define FILTER_PRED_IS_RIGHT (1 << 15)
  1185. #define FILTER_PRED_FOLD (1 << 15)
  1186. /*
  1187. * The max preds is the size of unsigned short with
  1188. * two flags at the MSBs. One bit is used for both the IS_RIGHT
  1189. * and FOLD flags. The other is reserved.
  1190. *
  1191. * 2^14 preds is way more than enough.
  1192. */
  1193. #define MAX_FILTER_PRED 16384
  1194. struct filter_pred;
  1195. struct regex;
  1196. typedef int (*filter_pred_fn_t) (struct filter_pred *pred, void *event);
  1197. typedef int (*regex_match_func)(char *str, struct regex *r, int len);
  1198. enum regex_type {
  1199. MATCH_FULL = 0,
  1200. MATCH_FRONT_ONLY,
  1201. MATCH_MIDDLE_ONLY,
  1202. MATCH_END_ONLY,
  1203. MATCH_GLOB,
  1204. };
  1205. struct regex {
  1206. char pattern[MAX_FILTER_STR_VAL];
  1207. int len;
  1208. int field_len;
  1209. regex_match_func match;
  1210. };
  1211. struct filter_pred {
  1212. filter_pred_fn_t fn;
  1213. u64 val;
  1214. struct regex regex;
  1215. unsigned short *ops;
  1216. struct ftrace_event_field *field;
  1217. int offset;
  1218. int not;
  1219. int op;
  1220. };
  1221. static inline bool is_string_field(struct ftrace_event_field *field)
  1222. {
  1223. return field->filter_type == FILTER_DYN_STRING ||
  1224. field->filter_type == FILTER_STATIC_STRING ||
  1225. field->filter_type == FILTER_PTR_STRING ||
  1226. field->filter_type == FILTER_COMM;
  1227. }
  1228. static inline bool is_function_field(struct ftrace_event_field *field)
  1229. {
  1230. return field->filter_type == FILTER_TRACE_FN;
  1231. }
  1232. extern enum regex_type
  1233. filter_parse_regex(char *buff, int len, char **search, int *not);
  1234. extern void print_event_filter(struct trace_event_file *file,
  1235. struct trace_seq *s);
  1236. extern int apply_event_filter(struct trace_event_file *file,
  1237. char *filter_string);
  1238. extern int apply_subsystem_event_filter(struct trace_subsystem_dir *dir,
  1239. char *filter_string);
  1240. extern void print_subsystem_event_filter(struct event_subsystem *system,
  1241. struct trace_seq *s);
  1242. extern int filter_assign_type(const char *type);
  1243. extern int create_event_filter(struct trace_event_call *call,
  1244. char *filter_str, bool set_str,
  1245. struct event_filter **filterp);
  1246. extern void free_event_filter(struct event_filter *filter);
  1247. struct ftrace_event_field *
  1248. trace_find_event_field(struct trace_event_call *call, char *name);
  1249. extern void trace_event_enable_cmd_record(bool enable);
  1250. extern void trace_event_enable_tgid_record(bool enable);
  1251. extern int event_trace_init(void);
  1252. extern int event_trace_add_tracer(struct dentry *parent, struct trace_array *tr);
  1253. extern int event_trace_del_tracer(struct trace_array *tr);
  1254. extern struct trace_event_file *__find_event_file(struct trace_array *tr,
  1255. const char *system,
  1256. const char *event);
  1257. extern struct trace_event_file *find_event_file(struct trace_array *tr,
  1258. const char *system,
  1259. const char *event);
  1260. static inline void *event_file_data(struct file *filp)
  1261. {
  1262. return READ_ONCE(file_inode(filp)->i_private);
  1263. }
  1264. extern struct mutex event_mutex;
  1265. extern struct list_head ftrace_events;
  1266. extern const struct file_operations event_trigger_fops;
  1267. extern const struct file_operations event_hist_fops;
  1268. #ifdef CONFIG_HIST_TRIGGERS
  1269. extern int register_trigger_hist_cmd(void);
  1270. extern int register_trigger_hist_enable_disable_cmds(void);
  1271. #else
  1272. static inline int register_trigger_hist_cmd(void) { return 0; }
  1273. static inline int register_trigger_hist_enable_disable_cmds(void) { return 0; }
  1274. #endif
  1275. extern int register_trigger_cmds(void);
  1276. extern void clear_event_triggers(struct trace_array *tr);
  1277. struct event_trigger_data {
  1278. unsigned long count;
  1279. int ref;
  1280. struct event_trigger_ops *ops;
  1281. struct event_command *cmd_ops;
  1282. struct event_filter __rcu *filter;
  1283. char *filter_str;
  1284. void *private_data;
  1285. bool paused;
  1286. bool paused_tmp;
  1287. struct list_head list;
  1288. char *name;
  1289. struct list_head named_list;
  1290. struct event_trigger_data *named_data;
  1291. };
  1292. /* Avoid typos */
  1293. #define ENABLE_EVENT_STR "enable_event"
  1294. #define DISABLE_EVENT_STR "disable_event"
  1295. #define ENABLE_HIST_STR "enable_hist"
  1296. #define DISABLE_HIST_STR "disable_hist"
  1297. struct enable_trigger_data {
  1298. struct trace_event_file *file;
  1299. bool enable;
  1300. bool hist;
  1301. };
  1302. extern int event_enable_trigger_print(struct seq_file *m,
  1303. struct event_trigger_ops *ops,
  1304. struct event_trigger_data *data);
  1305. extern void event_enable_trigger_free(struct event_trigger_ops *ops,
  1306. struct event_trigger_data *data);
  1307. extern int event_enable_trigger_func(struct event_command *cmd_ops,
  1308. struct trace_event_file *file,
  1309. char *glob, char *cmd, char *param);
  1310. extern int event_enable_register_trigger(char *glob,
  1311. struct event_trigger_ops *ops,
  1312. struct event_trigger_data *data,
  1313. struct trace_event_file *file);
  1314. extern void event_enable_unregister_trigger(char *glob,
  1315. struct event_trigger_ops *ops,
  1316. struct event_trigger_data *test,
  1317. struct trace_event_file *file);
  1318. extern void trigger_data_free(struct event_trigger_data *data);
  1319. extern int event_trigger_init(struct event_trigger_ops *ops,
  1320. struct event_trigger_data *data);
  1321. extern int trace_event_trigger_enable_disable(struct trace_event_file *file,
  1322. int trigger_enable);
  1323. extern void update_cond_flag(struct trace_event_file *file);
  1324. extern int set_trigger_filter(char *filter_str,
  1325. struct event_trigger_data *trigger_data,
  1326. struct trace_event_file *file);
  1327. extern struct event_trigger_data *find_named_trigger(const char *name);
  1328. extern bool is_named_trigger(struct event_trigger_data *test);
  1329. extern int save_named_trigger(const char *name,
  1330. struct event_trigger_data *data);
  1331. extern void del_named_trigger(struct event_trigger_data *data);
  1332. extern void pause_named_trigger(struct event_trigger_data *data);
  1333. extern void unpause_named_trigger(struct event_trigger_data *data);
  1334. extern void set_named_trigger_data(struct event_trigger_data *data,
  1335. struct event_trigger_data *named_data);
  1336. extern struct event_trigger_data *
  1337. get_named_trigger_data(struct event_trigger_data *data);
  1338. extern int register_event_command(struct event_command *cmd);
  1339. extern int unregister_event_command(struct event_command *cmd);
  1340. extern int register_trigger_hist_enable_disable_cmds(void);
  1341. /**
  1342. * struct event_trigger_ops - callbacks for trace event triggers
  1343. *
  1344. * The methods in this structure provide per-event trigger hooks for
  1345. * various trigger operations.
  1346. *
  1347. * All the methods below, except for @init() and @free(), must be
  1348. * implemented.
  1349. *
  1350. * @func: The trigger 'probe' function called when the triggering
  1351. * event occurs. The data passed into this callback is the data
  1352. * that was supplied to the event_command @reg() function that
  1353. * registered the trigger (see struct event_command) along with
  1354. * the trace record, rec.
  1355. *
  1356. * @init: An optional initialization function called for the trigger
  1357. * when the trigger is registered (via the event_command reg()
  1358. * function). This can be used to perform per-trigger
  1359. * initialization such as incrementing a per-trigger reference
  1360. * count, for instance. This is usually implemented by the
  1361. * generic utility function @event_trigger_init() (see
  1362. * trace_event_triggers.c).
  1363. *
  1364. * @free: An optional de-initialization function called for the
  1365. * trigger when the trigger is unregistered (via the
  1366. * event_command @reg() function). This can be used to perform
  1367. * per-trigger de-initialization such as decrementing a
  1368. * per-trigger reference count and freeing corresponding trigger
  1369. * data, for instance. This is usually implemented by the
  1370. * generic utility function @event_trigger_free() (see
  1371. * trace_event_triggers.c).
  1372. *
  1373. * @print: The callback function invoked to have the trigger print
  1374. * itself. This is usually implemented by a wrapper function
  1375. * that calls the generic utility function @event_trigger_print()
  1376. * (see trace_event_triggers.c).
  1377. */
  1378. struct event_trigger_ops {
  1379. void (*func)(struct event_trigger_data *data,
  1380. void *rec,
  1381. struct ring_buffer_event *rbe);
  1382. int (*init)(struct event_trigger_ops *ops,
  1383. struct event_trigger_data *data);
  1384. void (*free)(struct event_trigger_ops *ops,
  1385. struct event_trigger_data *data);
  1386. int (*print)(struct seq_file *m,
  1387. struct event_trigger_ops *ops,
  1388. struct event_trigger_data *data);
  1389. };
  1390. /**
  1391. * struct event_command - callbacks and data members for event commands
  1392. *
  1393. * Event commands are invoked by users by writing the command name
  1394. * into the 'trigger' file associated with a trace event. The
  1395. * parameters associated with a specific invocation of an event
  1396. * command are used to create an event trigger instance, which is
  1397. * added to the list of trigger instances associated with that trace
  1398. * event. When the event is hit, the set of triggers associated with
  1399. * that event is invoked.
  1400. *
  1401. * The data members in this structure provide per-event command data
  1402. * for various event commands.
  1403. *
  1404. * All the data members below, except for @post_trigger, must be set
  1405. * for each event command.
  1406. *
  1407. * @name: The unique name that identifies the event command. This is
  1408. * the name used when setting triggers via trigger files.
  1409. *
  1410. * @trigger_type: A unique id that identifies the event command
  1411. * 'type'. This value has two purposes, the first to ensure that
  1412. * only one trigger of the same type can be set at a given time
  1413. * for a particular event e.g. it doesn't make sense to have both
  1414. * a traceon and traceoff trigger attached to a single event at
  1415. * the same time, so traceon and traceoff have the same type
  1416. * though they have different names. The @trigger_type value is
  1417. * also used as a bit value for deferring the actual trigger
  1418. * action until after the current event is finished. Some
  1419. * commands need to do this if they themselves log to the trace
  1420. * buffer (see the @post_trigger() member below). @trigger_type
  1421. * values are defined by adding new values to the trigger_type
  1422. * enum in include/linux/trace_events.h.
  1423. *
  1424. * @flags: See the enum event_command_flags below.
  1425. *
  1426. * All the methods below, except for @set_filter() and @unreg_all(),
  1427. * must be implemented.
  1428. *
  1429. * @func: The callback function responsible for parsing and
  1430. * registering the trigger written to the 'trigger' file by the
  1431. * user. It allocates the trigger instance and registers it with
  1432. * the appropriate trace event. It makes use of the other
  1433. * event_command callback functions to orchestrate this, and is
  1434. * usually implemented by the generic utility function
  1435. * @event_trigger_callback() (see trace_event_triggers.c).
  1436. *
  1437. * @reg: Adds the trigger to the list of triggers associated with the
  1438. * event, and enables the event trigger itself, after
  1439. * initializing it (via the event_trigger_ops @init() function).
  1440. * This is also where commands can use the @trigger_type value to
  1441. * make the decision as to whether or not multiple instances of
  1442. * the trigger should be allowed. This is usually implemented by
  1443. * the generic utility function @register_trigger() (see
  1444. * trace_event_triggers.c).
  1445. *
  1446. * @unreg: Removes the trigger from the list of triggers associated
  1447. * with the event, and disables the event trigger itself, after
  1448. * initializing it (via the event_trigger_ops @free() function).
  1449. * This is usually implemented by the generic utility function
  1450. * @unregister_trigger() (see trace_event_triggers.c).
  1451. *
  1452. * @unreg_all: An optional function called to remove all the triggers
  1453. * from the list of triggers associated with the event. Called
  1454. * when a trigger file is opened in truncate mode.
  1455. *
  1456. * @set_filter: An optional function called to parse and set a filter
  1457. * for the trigger. If no @set_filter() method is set for the
  1458. * event command, filters set by the user for the command will be
  1459. * ignored. This is usually implemented by the generic utility
  1460. * function @set_trigger_filter() (see trace_event_triggers.c).
  1461. *
  1462. * @get_trigger_ops: The callback function invoked to retrieve the
  1463. * event_trigger_ops implementation associated with the command.
  1464. */
  1465. struct event_command {
  1466. struct list_head list;
  1467. char *name;
  1468. enum event_trigger_type trigger_type;
  1469. int flags;
  1470. int (*func)(struct event_command *cmd_ops,
  1471. struct trace_event_file *file,
  1472. char *glob, char *cmd, char *params);
  1473. int (*reg)(char *glob,
  1474. struct event_trigger_ops *ops,
  1475. struct event_trigger_data *data,
  1476. struct trace_event_file *file);
  1477. void (*unreg)(char *glob,
  1478. struct event_trigger_ops *ops,
  1479. struct event_trigger_data *data,
  1480. struct trace_event_file *file);
  1481. void (*unreg_all)(struct trace_event_file *file);
  1482. int (*set_filter)(char *filter_str,
  1483. struct event_trigger_data *data,
  1484. struct trace_event_file *file);
  1485. struct event_trigger_ops *(*get_trigger_ops)(char *cmd, char *param);
  1486. };
  1487. /**
  1488. * enum event_command_flags - flags for struct event_command
  1489. *
  1490. * @POST_TRIGGER: A flag that says whether or not this command needs
  1491. * to have its action delayed until after the current event has
  1492. * been closed. Some triggers need to avoid being invoked while
  1493. * an event is currently in the process of being logged, since
  1494. * the trigger may itself log data into the trace buffer. Thus
  1495. * we make sure the current event is committed before invoking
  1496. * those triggers. To do that, the trigger invocation is split
  1497. * in two - the first part checks the filter using the current
  1498. * trace record; if a command has the @post_trigger flag set, it
  1499. * sets a bit for itself in the return value, otherwise it
  1500. * directly invokes the trigger. Once all commands have been
  1501. * either invoked or set their return flag, the current record is
  1502. * either committed or discarded. At that point, if any commands
  1503. * have deferred their triggers, those commands are finally
  1504. * invoked following the close of the current event. In other
  1505. * words, if the event_trigger_ops @func() probe implementation
  1506. * itself logs to the trace buffer, this flag should be set,
  1507. * otherwise it can be left unspecified.
  1508. *
  1509. * @NEEDS_REC: A flag that says whether or not this command needs
  1510. * access to the trace record in order to perform its function,
  1511. * regardless of whether or not it has a filter associated with
  1512. * it (filters make a trigger require access to the trace record
  1513. * but are not always present).
  1514. */
  1515. enum event_command_flags {
  1516. EVENT_CMD_FL_POST_TRIGGER = 1,
  1517. EVENT_CMD_FL_NEEDS_REC = 2,
  1518. };
  1519. static inline bool event_command_post_trigger(struct event_command *cmd_ops)
  1520. {
  1521. return cmd_ops->flags & EVENT_CMD_FL_POST_TRIGGER;
  1522. }
  1523. static inline bool event_command_needs_rec(struct event_command *cmd_ops)
  1524. {
  1525. return cmd_ops->flags & EVENT_CMD_FL_NEEDS_REC;
  1526. }
  1527. extern int trace_event_enable_disable(struct trace_event_file *file,
  1528. int enable, int soft_disable);
  1529. extern int tracing_alloc_snapshot(void);
  1530. extern const char *__start___trace_bprintk_fmt[];
  1531. extern const char *__stop___trace_bprintk_fmt[];
  1532. extern const char *__start___tracepoint_str[];
  1533. extern const char *__stop___tracepoint_str[];
  1534. void trace_printk_control(bool enabled);
  1535. void trace_printk_init_buffers(void);
  1536. void trace_printk_start_comm(void);
  1537. int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
  1538. int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
  1539. #define MAX_EVENT_NAME_LEN 64
  1540. extern int trace_run_command(const char *buf, int (*createfn)(int, char**));
  1541. extern ssize_t trace_parse_run_command(struct file *file,
  1542. const char __user *buffer, size_t count, loff_t *ppos,
  1543. int (*createfn)(int, char**));
  1544. /*
  1545. * Normal trace_printk() and friends allocates special buffers
  1546. * to do the manipulation, as well as saves the print formats
  1547. * into sections to display. But the trace infrastructure wants
  1548. * to use these without the added overhead at the price of being
  1549. * a bit slower (used mainly for warnings, where we don't care
  1550. * about performance). The internal_trace_puts() is for such
  1551. * a purpose.
  1552. */
  1553. #define internal_trace_puts(str) __trace_puts(_THIS_IP_, str, strlen(str))
  1554. #undef FTRACE_ENTRY
  1555. #define FTRACE_ENTRY(call, struct_name, id, tstruct, print, filter) \
  1556. extern struct trace_event_call \
  1557. __aligned(4) event_##call;
  1558. #undef FTRACE_ENTRY_DUP
  1559. #define FTRACE_ENTRY_DUP(call, struct_name, id, tstruct, print, filter) \
  1560. FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print), \
  1561. filter)
  1562. #undef FTRACE_ENTRY_PACKED
  1563. #define FTRACE_ENTRY_PACKED(call, struct_name, id, tstruct, print, filter) \
  1564. FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print), \
  1565. filter)
  1566. #include "trace_entries.h"
  1567. #if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_FUNCTION_TRACER)
  1568. int perf_ftrace_event_register(struct trace_event_call *call,
  1569. enum trace_reg type, void *data);
  1570. #else
  1571. #define perf_ftrace_event_register NULL
  1572. #endif
  1573. #ifdef CONFIG_FTRACE_SYSCALLS
  1574. void init_ftrace_syscalls(void);
  1575. const char *get_syscall_name(int syscall);
  1576. #else
  1577. static inline void init_ftrace_syscalls(void) { }
  1578. static inline const char *get_syscall_name(int syscall)
  1579. {
  1580. return NULL;
  1581. }
  1582. #endif
  1583. #ifdef CONFIG_EVENT_TRACING
  1584. void trace_event_init(void);
  1585. void trace_event_eval_update(struct trace_eval_map **map, int len);
  1586. #else
  1587. static inline void __init trace_event_init(void) { }
  1588. static inline void trace_event_eval_update(struct trace_eval_map **map, int len) { }
  1589. #endif
  1590. #ifdef CONFIG_TRACER_SNAPSHOT
  1591. void tracing_snapshot_instance(struct trace_array *tr);
  1592. int tracing_alloc_snapshot_instance(struct trace_array *tr);
  1593. #else
  1594. static inline void tracing_snapshot_instance(struct trace_array *tr) { }
  1595. static inline int tracing_alloc_snapshot_instance(struct trace_array *tr)
  1596. {
  1597. return 0;
  1598. }
  1599. #endif
  1600. #ifdef CONFIG_PREEMPT_TRACER
  1601. void tracer_preempt_on(unsigned long a0, unsigned long a1);
  1602. void tracer_preempt_off(unsigned long a0, unsigned long a1);
  1603. #else
  1604. static inline void tracer_preempt_on(unsigned long a0, unsigned long a1) { }
  1605. static inline void tracer_preempt_off(unsigned long a0, unsigned long a1) { }
  1606. #endif
  1607. #ifdef CONFIG_IRQSOFF_TRACER
  1608. void tracer_hardirqs_on(unsigned long a0, unsigned long a1);
  1609. void tracer_hardirqs_off(unsigned long a0, unsigned long a1);
  1610. #else
  1611. static inline void tracer_hardirqs_on(unsigned long a0, unsigned long a1) { }
  1612. static inline void tracer_hardirqs_off(unsigned long a0, unsigned long a1) { }
  1613. #endif
  1614. extern struct trace_iterator *tracepoint_print_iter;
  1615. #endif /* _LINUX_KERNEL_TRACE_H */