trace.h 56 KB

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