trace.h 60 KB

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