trace.h 56 KB

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