trace.h 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186
  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/trace.h>
  13. #include <linux/hw_breakpoint.h>
  14. #include <linux/trace_seq.h>
  15. #include <linux/trace_events.h>
  16. #include <linux/compiler.h>
  17. #include <linux/glob.h>
  18. #include <linux/irq_work.h>
  19. #include <linux/workqueue.h>
  20. #include <linux/ctype.h>
  21. #include <linux/once_lite.h>
  22. #include "pid_list.h"
  23. #ifdef CONFIG_FTRACE_SYSCALLS
  24. #include <asm/unistd.h> /* For NR_syscalls */
  25. #include <asm/syscall.h> /* some archs define it here */
  26. #endif
  27. #define TRACE_MODE_WRITE 0640
  28. #define TRACE_MODE_READ 0440
  29. enum trace_type {
  30. __TRACE_FIRST_TYPE = 0,
  31. TRACE_FN,
  32. TRACE_CTX,
  33. TRACE_WAKE,
  34. TRACE_STACK,
  35. TRACE_PRINT,
  36. TRACE_BPRINT,
  37. TRACE_MMIO_RW,
  38. TRACE_MMIO_MAP,
  39. TRACE_BRANCH,
  40. TRACE_GRAPH_RET,
  41. TRACE_GRAPH_ENT,
  42. TRACE_USER_STACK,
  43. TRACE_BLK,
  44. TRACE_BPUTS,
  45. TRACE_HWLAT,
  46. TRACE_OSNOISE,
  47. TRACE_TIMERLAT,
  48. TRACE_RAW_DATA,
  49. TRACE_FUNC_REPEATS,
  50. __TRACE_LAST_TYPE,
  51. };
  52. #undef __field
  53. #define __field(type, item) type item;
  54. #undef __field_fn
  55. #define __field_fn(type, item) type item;
  56. #undef __field_struct
  57. #define __field_struct(type, item) __field(type, item)
  58. #undef __field_desc
  59. #define __field_desc(type, container, item)
  60. #undef __field_packed
  61. #define __field_packed(type, container, item)
  62. #undef __array
  63. #define __array(type, item, size) type item[size];
  64. /*
  65. * For backward compatibility, older user space expects to see the
  66. * kernel_stack event with a fixed size caller field. But today the fix
  67. * size is ignored by the kernel, and the real structure is dynamic.
  68. * Expose to user space: "unsigned long caller[8];" but the real structure
  69. * will be "unsigned long caller[] __counted_by(size)"
  70. */
  71. #undef __stack_array
  72. #define __stack_array(type, item, size, field) type item[] __counted_by(field);
  73. #undef __array_desc
  74. #define __array_desc(type, container, item, size)
  75. #undef __dynamic_array
  76. #define __dynamic_array(type, item) type item[];
  77. #undef __rel_dynamic_array
  78. #define __rel_dynamic_array(type, item) type item[];
  79. #undef F_STRUCT
  80. #define F_STRUCT(args...) args
  81. #undef FTRACE_ENTRY
  82. #define FTRACE_ENTRY(name, struct_name, id, tstruct, print) \
  83. struct struct_name { \
  84. struct trace_entry ent; \
  85. tstruct \
  86. }
  87. #undef FTRACE_ENTRY_DUP
  88. #define FTRACE_ENTRY_DUP(name, name_struct, id, tstruct, printk)
  89. #undef FTRACE_ENTRY_REG
  90. #define FTRACE_ENTRY_REG(name, struct_name, id, tstruct, print, regfn) \
  91. FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print))
  92. #undef FTRACE_ENTRY_PACKED
  93. #define FTRACE_ENTRY_PACKED(name, struct_name, id, tstruct, print) \
  94. FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print)) __packed
  95. #include "trace_entries.h"
  96. /* Use this for memory failure errors */
  97. #define MEM_FAIL(condition, fmt, ...) \
  98. DO_ONCE_LITE_IF(condition, pr_err, "ERROR: " fmt, ##__VA_ARGS__)
  99. #define FAULT_STRING "(fault)"
  100. #define HIST_STACKTRACE_DEPTH 16
  101. #define HIST_STACKTRACE_SIZE (HIST_STACKTRACE_DEPTH * sizeof(unsigned long))
  102. #define HIST_STACKTRACE_SKIP 5
  103. /*
  104. * syscalls are special, and need special handling, this is why
  105. * they are not included in trace_entries.h
  106. */
  107. struct syscall_trace_enter {
  108. struct trace_entry ent;
  109. int nr;
  110. unsigned long args[];
  111. };
  112. struct syscall_trace_exit {
  113. struct trace_entry ent;
  114. int nr;
  115. long ret;
  116. };
  117. struct kprobe_trace_entry_head {
  118. struct trace_entry ent;
  119. unsigned long ip;
  120. };
  121. struct eprobe_trace_entry_head {
  122. struct trace_entry ent;
  123. };
  124. struct kretprobe_trace_entry_head {
  125. struct trace_entry ent;
  126. unsigned long func;
  127. unsigned long ret_ip;
  128. };
  129. struct fentry_trace_entry_head {
  130. struct trace_entry ent;
  131. unsigned long ip;
  132. };
  133. struct fexit_trace_entry_head {
  134. struct trace_entry ent;
  135. unsigned long func;
  136. unsigned long ret_ip;
  137. };
  138. #define TRACE_BUF_SIZE 1024
  139. struct trace_array;
  140. /*
  141. * The CPU trace array - it consists of thousands of trace entries
  142. * plus some other descriptor data: (for example which task started
  143. * the trace, etc.)
  144. */
  145. struct trace_array_cpu {
  146. atomic_t disabled;
  147. void *buffer_page; /* ring buffer spare */
  148. unsigned long entries;
  149. unsigned long saved_latency;
  150. unsigned long critical_start;
  151. unsigned long critical_end;
  152. unsigned long critical_sequence;
  153. unsigned long nice;
  154. unsigned long policy;
  155. unsigned long rt_priority;
  156. unsigned long skipped_entries;
  157. u64 preempt_timestamp;
  158. pid_t pid;
  159. kuid_t uid;
  160. char comm[TASK_COMM_LEN];
  161. #ifdef CONFIG_FUNCTION_TRACER
  162. int ftrace_ignore_pid;
  163. #endif
  164. bool ignore_pid;
  165. };
  166. struct tracer;
  167. struct trace_option_dentry;
  168. struct array_buffer {
  169. struct trace_array *tr;
  170. struct trace_buffer *buffer;
  171. struct trace_array_cpu __percpu *data;
  172. u64 time_start;
  173. int cpu;
  174. };
  175. #define TRACE_FLAGS_MAX_SIZE 32
  176. struct trace_options {
  177. struct tracer *tracer;
  178. struct trace_option_dentry *topts;
  179. };
  180. struct trace_pid_list *trace_pid_list_alloc(void);
  181. void trace_pid_list_free(struct trace_pid_list *pid_list);
  182. bool trace_pid_list_is_set(struct trace_pid_list *pid_list, unsigned int pid);
  183. int trace_pid_list_set(struct trace_pid_list *pid_list, unsigned int pid);
  184. int trace_pid_list_clear(struct trace_pid_list *pid_list, unsigned int pid);
  185. int trace_pid_list_first(struct trace_pid_list *pid_list, unsigned int *pid);
  186. int trace_pid_list_next(struct trace_pid_list *pid_list, unsigned int pid,
  187. unsigned int *next);
  188. enum {
  189. TRACE_PIDS = BIT(0),
  190. TRACE_NO_PIDS = BIT(1),
  191. };
  192. static inline bool pid_type_enabled(int type, struct trace_pid_list *pid_list,
  193. struct trace_pid_list *no_pid_list)
  194. {
  195. /* Return true if the pid list in type has pids */
  196. return ((type & TRACE_PIDS) && pid_list) ||
  197. ((type & TRACE_NO_PIDS) && no_pid_list);
  198. }
  199. static inline bool still_need_pid_events(int type, struct trace_pid_list *pid_list,
  200. struct trace_pid_list *no_pid_list)
  201. {
  202. /*
  203. * Turning off what is in @type, return true if the "other"
  204. * pid list, still has pids in it.
  205. */
  206. return (!(type & TRACE_PIDS) && pid_list) ||
  207. (!(type & TRACE_NO_PIDS) && no_pid_list);
  208. }
  209. typedef bool (*cond_update_fn_t)(struct trace_array *tr, void *cond_data);
  210. /**
  211. * struct cond_snapshot - conditional snapshot data and callback
  212. *
  213. * The cond_snapshot structure encapsulates a callback function and
  214. * data associated with the snapshot for a given tracing instance.
  215. *
  216. * When a snapshot is taken conditionally, by invoking
  217. * tracing_snapshot_cond(tr, cond_data), the cond_data passed in is
  218. * passed in turn to the cond_snapshot.update() function. That data
  219. * can be compared by the update() implementation with the cond_data
  220. * contained within the struct cond_snapshot instance associated with
  221. * the trace_array. Because the tr->max_lock is held throughout the
  222. * update() call, the update() function can directly retrieve the
  223. * cond_snapshot and cond_data associated with the per-instance
  224. * snapshot associated with the trace_array.
  225. *
  226. * The cond_snapshot.update() implementation can save data to be
  227. * associated with the snapshot if it decides to, and returns 'true'
  228. * in that case, or it returns 'false' if the conditional snapshot
  229. * shouldn't be taken.
  230. *
  231. * The cond_snapshot instance is created and associated with the
  232. * user-defined cond_data by tracing_cond_snapshot_enable().
  233. * Likewise, the cond_snapshot instance is destroyed and is no longer
  234. * associated with the trace instance by
  235. * tracing_cond_snapshot_disable().
  236. *
  237. * The method below is required.
  238. *
  239. * @update: When a conditional snapshot is invoked, the update()
  240. * callback function is invoked with the tr->max_lock held. The
  241. * update() implementation signals whether or not to actually
  242. * take the snapshot, by returning 'true' if so, 'false' if no
  243. * snapshot should be taken. Because the max_lock is held for
  244. * the duration of update(), the implementation is safe to
  245. * directly retrieved and save any implementation data it needs
  246. * to in association with the snapshot.
  247. */
  248. struct cond_snapshot {
  249. void *cond_data;
  250. cond_update_fn_t update;
  251. };
  252. /*
  253. * struct trace_func_repeats - used to keep track of the consecutive
  254. * (on the same CPU) calls of a single function.
  255. */
  256. struct trace_func_repeats {
  257. unsigned long ip;
  258. unsigned long parent_ip;
  259. unsigned long count;
  260. u64 ts_last_call;
  261. };
  262. /*
  263. * The trace array - an array of per-CPU trace arrays. This is the
  264. * highest level data structure that individual tracers deal with.
  265. * They have on/off state as well:
  266. */
  267. struct trace_array {
  268. struct list_head list;
  269. char *name;
  270. struct array_buffer array_buffer;
  271. #ifdef CONFIG_TRACER_MAX_TRACE
  272. /*
  273. * The max_buffer is used to snapshot the trace when a maximum
  274. * latency is reached, or when the user initiates a snapshot.
  275. * Some tracers will use this to store a maximum trace while
  276. * it continues examining live traces.
  277. *
  278. * The buffers for the max_buffer are set up the same as the array_buffer
  279. * When a snapshot is taken, the buffer of the max_buffer is swapped
  280. * with the buffer of the array_buffer and the buffers are reset for
  281. * the array_buffer so the tracing can continue.
  282. */
  283. struct array_buffer max_buffer;
  284. bool allocated_snapshot;
  285. spinlock_t snapshot_trigger_lock;
  286. unsigned int snapshot;
  287. unsigned long max_latency;
  288. #ifdef CONFIG_FSNOTIFY
  289. struct dentry *d_max_latency;
  290. struct work_struct fsnotify_work;
  291. struct irq_work fsnotify_irqwork;
  292. #endif
  293. #endif
  294. /* The below is for memory mapped ring buffer */
  295. unsigned int mapped;
  296. unsigned long range_addr_start;
  297. unsigned long range_addr_size;
  298. long text_delta;
  299. long data_delta;
  300. struct trace_pid_list __rcu *filtered_pids;
  301. struct trace_pid_list __rcu *filtered_no_pids;
  302. /*
  303. * max_lock is used to protect the swapping of buffers
  304. * when taking a max snapshot. The buffers themselves are
  305. * protected by per_cpu spinlocks. But the action of the swap
  306. * needs its own lock.
  307. *
  308. * This is defined as a arch_spinlock_t in order to help
  309. * with performance when lockdep debugging is enabled.
  310. *
  311. * It is also used in other places outside the update_max_tr
  312. * so it needs to be defined outside of the
  313. * CONFIG_TRACER_MAX_TRACE.
  314. */
  315. arch_spinlock_t max_lock;
  316. int buffer_disabled;
  317. #ifdef CONFIG_FTRACE_SYSCALLS
  318. int sys_refcount_enter;
  319. int sys_refcount_exit;
  320. struct trace_event_file __rcu *enter_syscall_files[NR_syscalls];
  321. struct trace_event_file __rcu *exit_syscall_files[NR_syscalls];
  322. #endif
  323. int stop_count;
  324. int clock_id;
  325. int nr_topts;
  326. bool clear_trace;
  327. int buffer_percent;
  328. unsigned int n_err_log_entries;
  329. struct tracer *current_trace;
  330. unsigned int trace_flags;
  331. unsigned char trace_flags_index[TRACE_FLAGS_MAX_SIZE];
  332. unsigned int flags;
  333. raw_spinlock_t start_lock;
  334. const char *system_names;
  335. struct list_head err_log;
  336. struct dentry *dir;
  337. struct dentry *options;
  338. struct dentry *percpu_dir;
  339. struct eventfs_inode *event_dir;
  340. struct trace_options *topts;
  341. struct list_head systems;
  342. struct list_head events;
  343. struct trace_event_file *trace_marker_file;
  344. cpumask_var_t tracing_cpumask; /* only trace on set CPUs */
  345. /* one per_cpu trace_pipe can be opened by only one user */
  346. cpumask_var_t pipe_cpumask;
  347. int ref;
  348. int trace_ref;
  349. #ifdef CONFIG_FUNCTION_TRACER
  350. struct ftrace_ops *ops;
  351. struct trace_pid_list __rcu *function_pids;
  352. struct trace_pid_list __rcu *function_no_pids;
  353. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  354. struct fgraph_ops *gops;
  355. #endif
  356. #ifdef CONFIG_DYNAMIC_FTRACE
  357. /* All of these are protected by the ftrace_lock */
  358. struct list_head func_probes;
  359. struct list_head mod_trace;
  360. struct list_head mod_notrace;
  361. #endif
  362. /* function tracing enabled */
  363. int function_enabled;
  364. #endif
  365. int no_filter_buffering_ref;
  366. struct list_head hist_vars;
  367. #ifdef CONFIG_TRACER_SNAPSHOT
  368. struct cond_snapshot *cond_snapshot;
  369. #endif
  370. struct trace_func_repeats __percpu *last_func_repeats;
  371. /*
  372. * On boot up, the ring buffer is set to the minimum size, so that
  373. * we do not waste memory on systems that are not using tracing.
  374. */
  375. bool ring_buffer_expanded;
  376. };
  377. enum {
  378. TRACE_ARRAY_FL_GLOBAL = BIT(0),
  379. TRACE_ARRAY_FL_BOOT = BIT(1),
  380. };
  381. extern struct list_head ftrace_trace_arrays;
  382. extern struct mutex trace_types_lock;
  383. extern int trace_array_get(struct trace_array *tr);
  384. extern int tracing_check_open_get_tr(struct trace_array *tr);
  385. extern struct trace_array *trace_array_find(const char *instance);
  386. extern struct trace_array *trace_array_find_get(const char *instance);
  387. extern u64 tracing_event_time_stamp(struct trace_buffer *buffer, struct ring_buffer_event *rbe);
  388. extern int tracing_set_filter_buffering(struct trace_array *tr, bool set);
  389. extern int tracing_set_clock(struct trace_array *tr, const char *clockstr);
  390. extern bool trace_clock_in_ns(struct trace_array *tr);
  391. /*
  392. * The global tracer (top) should be the first trace array added,
  393. * but we check the flag anyway.
  394. */
  395. static inline struct trace_array *top_trace_array(void)
  396. {
  397. struct trace_array *tr;
  398. if (list_empty(&ftrace_trace_arrays))
  399. return NULL;
  400. tr = list_entry(ftrace_trace_arrays.prev,
  401. typeof(*tr), list);
  402. WARN_ON(!(tr->flags & TRACE_ARRAY_FL_GLOBAL));
  403. return tr;
  404. }
  405. #define FTRACE_CMP_TYPE(var, type) \
  406. __builtin_types_compatible_p(typeof(var), type *)
  407. #undef IF_ASSIGN
  408. #define IF_ASSIGN(var, entry, etype, id) \
  409. if (FTRACE_CMP_TYPE(var, etype)) { \
  410. var = (typeof(var))(entry); \
  411. WARN_ON(id != 0 && (entry)->type != id); \
  412. break; \
  413. }
  414. /* Will cause compile errors if type is not found. */
  415. extern void __ftrace_bad_type(void);
  416. /*
  417. * The trace_assign_type is a verifier that the entry type is
  418. * the same as the type being assigned. To add new types simply
  419. * add a line with the following format:
  420. *
  421. * IF_ASSIGN(var, ent, type, id);
  422. *
  423. * Where "type" is the trace type that includes the trace_entry
  424. * as the "ent" item. And "id" is the trace identifier that is
  425. * used in the trace_type enum.
  426. *
  427. * If the type can have more than one id, then use zero.
  428. */
  429. #define trace_assign_type(var, ent) \
  430. do { \
  431. IF_ASSIGN(var, ent, struct ftrace_entry, TRACE_FN); \
  432. IF_ASSIGN(var, ent, struct ctx_switch_entry, 0); \
  433. IF_ASSIGN(var, ent, struct stack_entry, TRACE_STACK); \
  434. IF_ASSIGN(var, ent, struct userstack_entry, TRACE_USER_STACK);\
  435. IF_ASSIGN(var, ent, struct print_entry, TRACE_PRINT); \
  436. IF_ASSIGN(var, ent, struct bprint_entry, TRACE_BPRINT); \
  437. IF_ASSIGN(var, ent, struct bputs_entry, TRACE_BPUTS); \
  438. IF_ASSIGN(var, ent, struct hwlat_entry, TRACE_HWLAT); \
  439. IF_ASSIGN(var, ent, struct osnoise_entry, TRACE_OSNOISE);\
  440. IF_ASSIGN(var, ent, struct timerlat_entry, TRACE_TIMERLAT);\
  441. IF_ASSIGN(var, ent, struct raw_data_entry, TRACE_RAW_DATA);\
  442. IF_ASSIGN(var, ent, struct trace_mmiotrace_rw, \
  443. TRACE_MMIO_RW); \
  444. IF_ASSIGN(var, ent, struct trace_mmiotrace_map, \
  445. TRACE_MMIO_MAP); \
  446. IF_ASSIGN(var, ent, struct trace_branch, TRACE_BRANCH); \
  447. IF_ASSIGN(var, ent, struct ftrace_graph_ent_entry, \
  448. TRACE_GRAPH_ENT); \
  449. IF_ASSIGN(var, ent, struct ftrace_graph_ret_entry, \
  450. TRACE_GRAPH_RET); \
  451. IF_ASSIGN(var, ent, struct func_repeats_entry, \
  452. TRACE_FUNC_REPEATS); \
  453. __ftrace_bad_type(); \
  454. } while (0)
  455. /*
  456. * An option specific to a tracer. This is a boolean value.
  457. * The bit is the bit index that sets its value on the
  458. * flags value in struct tracer_flags.
  459. */
  460. struct tracer_opt {
  461. const char *name; /* Will appear on the trace_options file */
  462. u32 bit; /* Mask assigned in val field in tracer_flags */
  463. };
  464. /*
  465. * The set of specific options for a tracer. Your tracer
  466. * have to set the initial value of the flags val.
  467. */
  468. struct tracer_flags {
  469. u32 val;
  470. struct tracer_opt *opts;
  471. struct tracer *trace;
  472. };
  473. /* Makes more easy to define a tracer opt */
  474. #define TRACER_OPT(s, b) .name = #s, .bit = b
  475. struct trace_option_dentry {
  476. struct tracer_opt *opt;
  477. struct tracer_flags *flags;
  478. struct trace_array *tr;
  479. struct dentry *entry;
  480. };
  481. /**
  482. * struct tracer - a specific tracer and its callbacks to interact with tracefs
  483. * @name: the name chosen to select it on the available_tracers file
  484. * @init: called when one switches to this tracer (echo name > current_tracer)
  485. * @reset: called when one switches to another tracer
  486. * @start: called when tracing is unpaused (echo 1 > tracing_on)
  487. * @stop: called when tracing is paused (echo 0 > tracing_on)
  488. * @update_thresh: called when tracing_thresh is updated
  489. * @open: called when the trace file is opened
  490. * @pipe_open: called when the trace_pipe file is opened
  491. * @close: called when the trace file is released
  492. * @pipe_close: called when the trace_pipe file is released
  493. * @read: override the default read callback on trace_pipe
  494. * @splice_read: override the default splice_read callback on trace_pipe
  495. * @selftest: selftest to run on boot (see trace_selftest.c)
  496. * @print_headers: override the first lines that describe your columns
  497. * @print_line: callback that prints a trace
  498. * @set_flag: signals one of your private flags changed (trace_options file)
  499. * @flags: your private flags
  500. */
  501. struct tracer {
  502. const char *name;
  503. int (*init)(struct trace_array *tr);
  504. void (*reset)(struct trace_array *tr);
  505. void (*start)(struct trace_array *tr);
  506. void (*stop)(struct trace_array *tr);
  507. int (*update_thresh)(struct trace_array *tr);
  508. void (*open)(struct trace_iterator *iter);
  509. void (*pipe_open)(struct trace_iterator *iter);
  510. void (*close)(struct trace_iterator *iter);
  511. void (*pipe_close)(struct trace_iterator *iter);
  512. ssize_t (*read)(struct trace_iterator *iter,
  513. struct file *filp, char __user *ubuf,
  514. size_t cnt, loff_t *ppos);
  515. ssize_t (*splice_read)(struct trace_iterator *iter,
  516. struct file *filp,
  517. loff_t *ppos,
  518. struct pipe_inode_info *pipe,
  519. size_t len,
  520. unsigned int flags);
  521. #ifdef CONFIG_FTRACE_STARTUP_TEST
  522. int (*selftest)(struct tracer *trace,
  523. struct trace_array *tr);
  524. #endif
  525. void (*print_header)(struct seq_file *m);
  526. enum print_line_t (*print_line)(struct trace_iterator *iter);
  527. /* If you handled the flag setting, return 0 */
  528. int (*set_flag)(struct trace_array *tr,
  529. u32 old_flags, u32 bit, int set);
  530. /* Return 0 if OK with change, else return non-zero */
  531. int (*flag_changed)(struct trace_array *tr,
  532. u32 mask, int set);
  533. struct tracer *next;
  534. struct tracer_flags *flags;
  535. int enabled;
  536. bool print_max;
  537. bool allow_instances;
  538. #ifdef CONFIG_TRACER_MAX_TRACE
  539. bool use_max_tr;
  540. #endif
  541. /* True if tracer cannot be enabled in kernel param */
  542. bool noboot;
  543. };
  544. static inline struct ring_buffer_iter *
  545. trace_buffer_iter(struct trace_iterator *iter, int cpu)
  546. {
  547. return iter->buffer_iter ? iter->buffer_iter[cpu] : NULL;
  548. }
  549. int tracer_init(struct tracer *t, struct trace_array *tr);
  550. int tracing_is_enabled(void);
  551. void tracing_reset_online_cpus(struct array_buffer *buf);
  552. void tracing_reset_all_online_cpus(void);
  553. void tracing_reset_all_online_cpus_unlocked(void);
  554. int tracing_open_generic(struct inode *inode, struct file *filp);
  555. int tracing_open_generic_tr(struct inode *inode, struct file *filp);
  556. int tracing_release_generic_tr(struct inode *inode, struct file *file);
  557. int tracing_open_file_tr(struct inode *inode, struct file *filp);
  558. int tracing_release_file_tr(struct inode *inode, struct file *filp);
  559. int tracing_single_release_file_tr(struct inode *inode, struct file *filp);
  560. bool tracing_is_disabled(void);
  561. bool tracer_tracing_is_on(struct trace_array *tr);
  562. void tracer_tracing_on(struct trace_array *tr);
  563. void tracer_tracing_off(struct trace_array *tr);
  564. struct dentry *trace_create_file(const char *name,
  565. umode_t mode,
  566. struct dentry *parent,
  567. void *data,
  568. const struct file_operations *fops);
  569. int tracing_init_dentry(void);
  570. struct ring_buffer_event;
  571. struct ring_buffer_event *
  572. trace_buffer_lock_reserve(struct trace_buffer *buffer,
  573. int type,
  574. unsigned long len,
  575. unsigned int trace_ctx);
  576. int ring_buffer_meta_seq_init(struct file *file, struct trace_buffer *buffer, int cpu);
  577. struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
  578. struct trace_array_cpu *data);
  579. struct trace_entry *trace_find_next_entry(struct trace_iterator *iter,
  580. int *ent_cpu, u64 *ent_ts);
  581. void trace_buffer_unlock_commit_nostack(struct trace_buffer *buffer,
  582. struct ring_buffer_event *event);
  583. bool trace_is_tracepoint_string(const char *str);
  584. const char *trace_event_format(struct trace_iterator *iter, const char *fmt);
  585. char *trace_iter_expand_format(struct trace_iterator *iter);
  586. bool ignore_event(struct trace_iterator *iter);
  587. int trace_empty(struct trace_iterator *iter);
  588. void *trace_find_next_entry_inc(struct trace_iterator *iter);
  589. void trace_init_global_iter(struct trace_iterator *iter);
  590. void tracing_iter_reset(struct trace_iterator *iter, int cpu);
  591. unsigned long trace_total_entries_cpu(struct trace_array *tr, int cpu);
  592. unsigned long trace_total_entries(struct trace_array *tr);
  593. void trace_function(struct trace_array *tr,
  594. unsigned long ip,
  595. unsigned long parent_ip,
  596. unsigned int trace_ctx);
  597. void trace_graph_function(struct trace_array *tr,
  598. unsigned long ip,
  599. unsigned long parent_ip,
  600. unsigned int trace_ctx);
  601. void trace_latency_header(struct seq_file *m);
  602. void trace_default_header(struct seq_file *m);
  603. void print_trace_header(struct seq_file *m, struct trace_iterator *iter);
  604. void trace_graph_return(struct ftrace_graph_ret *trace, struct fgraph_ops *gops);
  605. int trace_graph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops *gops);
  606. void tracing_start_cmdline_record(void);
  607. void tracing_stop_cmdline_record(void);
  608. void tracing_start_tgid_record(void);
  609. void tracing_stop_tgid_record(void);
  610. int register_tracer(struct tracer *type);
  611. int is_tracing_stopped(void);
  612. loff_t tracing_lseek(struct file *file, loff_t offset, int whence);
  613. extern cpumask_var_t __read_mostly tracing_buffer_mask;
  614. #define for_each_tracing_cpu(cpu) \
  615. for_each_cpu(cpu, tracing_buffer_mask)
  616. extern unsigned long nsecs_to_usecs(unsigned long nsecs);
  617. extern unsigned long tracing_thresh;
  618. /* PID filtering */
  619. extern int pid_max;
  620. bool trace_find_filtered_pid(struct trace_pid_list *filtered_pids,
  621. pid_t search_pid);
  622. bool trace_ignore_this_task(struct trace_pid_list *filtered_pids,
  623. struct trace_pid_list *filtered_no_pids,
  624. struct task_struct *task);
  625. void trace_filter_add_remove_task(struct trace_pid_list *pid_list,
  626. struct task_struct *self,
  627. struct task_struct *task);
  628. void *trace_pid_next(struct trace_pid_list *pid_list, void *v, loff_t *pos);
  629. void *trace_pid_start(struct trace_pid_list *pid_list, loff_t *pos);
  630. int trace_pid_show(struct seq_file *m, void *v);
  631. int trace_pid_write(struct trace_pid_list *filtered_pids,
  632. struct trace_pid_list **new_pid_list,
  633. const char __user *ubuf, size_t cnt);
  634. #ifdef CONFIG_TRACER_MAX_TRACE
  635. void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu,
  636. void *cond_data);
  637. void update_max_tr_single(struct trace_array *tr,
  638. struct task_struct *tsk, int cpu);
  639. #ifdef CONFIG_FSNOTIFY
  640. #define LATENCY_FS_NOTIFY
  641. #endif
  642. #endif /* CONFIG_TRACER_MAX_TRACE */
  643. #ifdef LATENCY_FS_NOTIFY
  644. void latency_fsnotify(struct trace_array *tr);
  645. #else
  646. static inline void latency_fsnotify(struct trace_array *tr) { }
  647. #endif
  648. #ifdef CONFIG_STACKTRACE
  649. void __trace_stack(struct trace_array *tr, unsigned int trace_ctx, int skip);
  650. #else
  651. static inline void __trace_stack(struct trace_array *tr, unsigned int trace_ctx,
  652. int skip)
  653. {
  654. }
  655. #endif /* CONFIG_STACKTRACE */
  656. void trace_last_func_repeats(struct trace_array *tr,
  657. struct trace_func_repeats *last_info,
  658. unsigned int trace_ctx);
  659. extern u64 ftrace_now(int cpu);
  660. extern void trace_find_cmdline(int pid, char comm[]);
  661. extern int trace_find_tgid(int pid);
  662. extern void trace_event_follow_fork(struct trace_array *tr, bool enable);
  663. #ifdef CONFIG_DYNAMIC_FTRACE
  664. extern unsigned long ftrace_update_tot_cnt;
  665. extern unsigned long ftrace_number_of_pages;
  666. extern unsigned long ftrace_number_of_groups;
  667. void ftrace_init_trace_array(struct trace_array *tr);
  668. #else
  669. static inline void ftrace_init_trace_array(struct trace_array *tr) { }
  670. #endif
  671. #define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
  672. extern int DYN_FTRACE_TEST_NAME(void);
  673. #define DYN_FTRACE_TEST_NAME2 trace_selftest_dynamic_test_func2
  674. extern int DYN_FTRACE_TEST_NAME2(void);
  675. extern void trace_set_ring_buffer_expanded(struct trace_array *tr);
  676. extern bool tracing_selftest_disabled;
  677. #ifdef CONFIG_FTRACE_STARTUP_TEST
  678. extern void __init disable_tracing_selftest(const char *reason);
  679. extern int trace_selftest_startup_function(struct tracer *trace,
  680. struct trace_array *tr);
  681. extern int trace_selftest_startup_function_graph(struct tracer *trace,
  682. struct trace_array *tr);
  683. extern int trace_selftest_startup_irqsoff(struct tracer *trace,
  684. struct trace_array *tr);
  685. extern int trace_selftest_startup_preemptoff(struct tracer *trace,
  686. struct trace_array *tr);
  687. extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
  688. struct trace_array *tr);
  689. extern int trace_selftest_startup_wakeup(struct tracer *trace,
  690. struct trace_array *tr);
  691. extern int trace_selftest_startup_nop(struct tracer *trace,
  692. struct trace_array *tr);
  693. extern int trace_selftest_startup_branch(struct tracer *trace,
  694. struct trace_array *tr);
  695. /*
  696. * Tracer data references selftest functions that only occur
  697. * on boot up. These can be __init functions. Thus, when selftests
  698. * are enabled, then the tracers need to reference __init functions.
  699. */
  700. #define __tracer_data __refdata
  701. #else
  702. static inline void __init disable_tracing_selftest(const char *reason)
  703. {
  704. }
  705. /* Tracers are seldom changed. Optimize when selftests are disabled. */
  706. #define __tracer_data __read_mostly
  707. #endif /* CONFIG_FTRACE_STARTUP_TEST */
  708. extern void *head_page(struct trace_array_cpu *data);
  709. extern unsigned long long ns2usecs(u64 nsec);
  710. extern int
  711. trace_vbprintk(unsigned long ip, const char *fmt, va_list args);
  712. extern int
  713. trace_vprintk(unsigned long ip, const char *fmt, va_list args);
  714. extern int
  715. trace_array_vprintk(struct trace_array *tr,
  716. unsigned long ip, const char *fmt, va_list args);
  717. int trace_array_printk_buf(struct trace_buffer *buffer,
  718. unsigned long ip, const char *fmt, ...);
  719. void trace_printk_seq(struct trace_seq *s);
  720. enum print_line_t print_trace_line(struct trace_iterator *iter);
  721. extern char trace_find_mark(unsigned long long duration);
  722. struct ftrace_hash;
  723. struct ftrace_mod_load {
  724. struct list_head list;
  725. char *func;
  726. char *module;
  727. int enable;
  728. };
  729. enum {
  730. FTRACE_HASH_FL_MOD = (1 << 0),
  731. };
  732. struct ftrace_hash {
  733. unsigned long size_bits;
  734. struct hlist_head *buckets;
  735. unsigned long count;
  736. unsigned long flags;
  737. struct rcu_head rcu;
  738. };
  739. struct ftrace_func_entry *
  740. ftrace_lookup_ip(struct ftrace_hash *hash, unsigned long ip);
  741. static __always_inline bool ftrace_hash_empty(struct ftrace_hash *hash)
  742. {
  743. return !hash || !(hash->count || (hash->flags & FTRACE_HASH_FL_MOD));
  744. }
  745. /* Standard output formatting function used for function return traces */
  746. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  747. /* Flag options */
  748. #define TRACE_GRAPH_PRINT_OVERRUN 0x1
  749. #define TRACE_GRAPH_PRINT_CPU 0x2
  750. #define TRACE_GRAPH_PRINT_OVERHEAD 0x4
  751. #define TRACE_GRAPH_PRINT_PROC 0x8
  752. #define TRACE_GRAPH_PRINT_DURATION 0x10
  753. #define TRACE_GRAPH_PRINT_ABS_TIME 0x20
  754. #define TRACE_GRAPH_PRINT_REL_TIME 0x40
  755. #define TRACE_GRAPH_PRINT_IRQS 0x80
  756. #define TRACE_GRAPH_PRINT_TAIL 0x100
  757. #define TRACE_GRAPH_SLEEP_TIME 0x200
  758. #define TRACE_GRAPH_GRAPH_TIME 0x400
  759. #define TRACE_GRAPH_PRINT_RETVAL 0x800
  760. #define TRACE_GRAPH_PRINT_RETVAL_HEX 0x1000
  761. #define TRACE_GRAPH_PRINT_FILL_SHIFT 28
  762. #define TRACE_GRAPH_PRINT_FILL_MASK (0x3 << TRACE_GRAPH_PRINT_FILL_SHIFT)
  763. extern void ftrace_graph_sleep_time_control(bool enable);
  764. #ifdef CONFIG_FUNCTION_PROFILER
  765. extern void ftrace_graph_graph_time_control(bool enable);
  766. #else
  767. static inline void ftrace_graph_graph_time_control(bool enable) { }
  768. #endif
  769. extern enum print_line_t
  770. print_graph_function_flags(struct trace_iterator *iter, u32 flags);
  771. extern void print_graph_headers_flags(struct seq_file *s, u32 flags);
  772. extern void
  773. trace_print_graph_duration(unsigned long long duration, struct trace_seq *s);
  774. extern void graph_trace_open(struct trace_iterator *iter);
  775. extern void graph_trace_close(struct trace_iterator *iter);
  776. extern int __trace_graph_entry(struct trace_array *tr,
  777. struct ftrace_graph_ent *trace,
  778. unsigned int trace_ctx);
  779. extern void __trace_graph_return(struct trace_array *tr,
  780. struct ftrace_graph_ret *trace,
  781. unsigned int trace_ctx);
  782. extern void init_array_fgraph_ops(struct trace_array *tr, struct ftrace_ops *ops);
  783. extern int allocate_fgraph_ops(struct trace_array *tr, struct ftrace_ops *ops);
  784. extern void free_fgraph_ops(struct trace_array *tr);
  785. enum {
  786. TRACE_GRAPH_FL = 1,
  787. /*
  788. * In the very unlikely case that an interrupt came in
  789. * at a start of graph tracing, and we want to trace
  790. * the function in that interrupt, the depth can be greater
  791. * than zero, because of the preempted start of a previous
  792. * trace. In an even more unlikely case, depth could be 2
  793. * if a softirq interrupted the start of graph tracing,
  794. * followed by an interrupt preempting a start of graph
  795. * tracing in the softirq, and depth can even be 3
  796. * if an NMI came in at the start of an interrupt function
  797. * that preempted a softirq start of a function that
  798. * preempted normal context!!!! Luckily, it can't be
  799. * greater than 3, so the next two bits are a mask
  800. * of what the depth is when we set TRACE_GRAPH_FL
  801. */
  802. TRACE_GRAPH_DEPTH_START_BIT,
  803. TRACE_GRAPH_DEPTH_END_BIT,
  804. /*
  805. * To implement set_graph_notrace, if this bit is set, we ignore
  806. * function graph tracing of called functions, until the return
  807. * function is called to clear it.
  808. */
  809. TRACE_GRAPH_NOTRACE_BIT,
  810. };
  811. #define TRACE_GRAPH_NOTRACE (1 << TRACE_GRAPH_NOTRACE_BIT)
  812. static inline unsigned long ftrace_graph_depth(unsigned long *task_var)
  813. {
  814. return (*task_var >> TRACE_GRAPH_DEPTH_START_BIT) & 3;
  815. }
  816. static inline void ftrace_graph_set_depth(unsigned long *task_var, int depth)
  817. {
  818. *task_var &= ~(3 << TRACE_GRAPH_DEPTH_START_BIT);
  819. *task_var |= (depth & 3) << TRACE_GRAPH_DEPTH_START_BIT;
  820. }
  821. #ifdef CONFIG_DYNAMIC_FTRACE
  822. extern struct ftrace_hash __rcu *ftrace_graph_hash;
  823. extern struct ftrace_hash __rcu *ftrace_graph_notrace_hash;
  824. static inline int
  825. ftrace_graph_addr(unsigned long *task_var, struct ftrace_graph_ent *trace)
  826. {
  827. unsigned long addr = trace->func;
  828. int ret = 0;
  829. struct ftrace_hash *hash;
  830. preempt_disable_notrace();
  831. /*
  832. * Have to open code "rcu_dereference_sched()" because the
  833. * function graph tracer can be called when RCU is not
  834. * "watching".
  835. * Protected with schedule_on_each_cpu(ftrace_sync)
  836. */
  837. hash = rcu_dereference_protected(ftrace_graph_hash, !preemptible());
  838. if (ftrace_hash_empty(hash)) {
  839. ret = 1;
  840. goto out;
  841. }
  842. if (ftrace_lookup_ip(hash, addr)) {
  843. /*
  844. * This needs to be cleared on the return functions
  845. * when the depth is zero.
  846. */
  847. *task_var |= TRACE_GRAPH_FL;
  848. ftrace_graph_set_depth(task_var, trace->depth);
  849. /*
  850. * If no irqs are to be traced, but a set_graph_function
  851. * is set, and called by an interrupt handler, we still
  852. * want to trace it.
  853. */
  854. if (in_hardirq())
  855. trace_recursion_set(TRACE_IRQ_BIT);
  856. else
  857. trace_recursion_clear(TRACE_IRQ_BIT);
  858. ret = 1;
  859. }
  860. out:
  861. preempt_enable_notrace();
  862. return ret;
  863. }
  864. static inline void
  865. ftrace_graph_addr_finish(struct fgraph_ops *gops, struct ftrace_graph_ret *trace)
  866. {
  867. unsigned long *task_var = fgraph_get_task_var(gops);
  868. if ((*task_var & TRACE_GRAPH_FL) &&
  869. trace->depth == ftrace_graph_depth(task_var))
  870. *task_var &= ~TRACE_GRAPH_FL;
  871. }
  872. static inline int ftrace_graph_notrace_addr(unsigned long addr)
  873. {
  874. int ret = 0;
  875. struct ftrace_hash *notrace_hash;
  876. preempt_disable_notrace();
  877. /*
  878. * Have to open code "rcu_dereference_sched()" because the
  879. * function graph tracer can be called when RCU is not
  880. * "watching".
  881. * Protected with schedule_on_each_cpu(ftrace_sync)
  882. */
  883. notrace_hash = rcu_dereference_protected(ftrace_graph_notrace_hash,
  884. !preemptible());
  885. if (ftrace_lookup_ip(notrace_hash, addr))
  886. ret = 1;
  887. preempt_enable_notrace();
  888. return ret;
  889. }
  890. #else
  891. static inline int ftrace_graph_addr(unsigned long *task_var, struct ftrace_graph_ent *trace)
  892. {
  893. return 1;
  894. }
  895. static inline int ftrace_graph_notrace_addr(unsigned long addr)
  896. {
  897. return 0;
  898. }
  899. static inline void ftrace_graph_addr_finish(struct fgraph_ops *gops, struct ftrace_graph_ret *trace)
  900. { }
  901. #endif /* CONFIG_DYNAMIC_FTRACE */
  902. extern unsigned int fgraph_max_depth;
  903. static inline bool
  904. ftrace_graph_ignore_func(struct fgraph_ops *gops, struct ftrace_graph_ent *trace)
  905. {
  906. unsigned long *task_var = fgraph_get_task_var(gops);
  907. /* trace it when it is-nested-in or is a function enabled. */
  908. return !((*task_var & TRACE_GRAPH_FL) ||
  909. ftrace_graph_addr(task_var, trace)) ||
  910. (trace->depth < 0) ||
  911. (fgraph_max_depth && trace->depth >= fgraph_max_depth);
  912. }
  913. void fgraph_init_ops(struct ftrace_ops *dst_ops,
  914. struct ftrace_ops *src_ops);
  915. #else /* CONFIG_FUNCTION_GRAPH_TRACER */
  916. static inline enum print_line_t
  917. print_graph_function_flags(struct trace_iterator *iter, u32 flags)
  918. {
  919. return TRACE_TYPE_UNHANDLED;
  920. }
  921. static inline void free_fgraph_ops(struct trace_array *tr) { }
  922. /* ftrace_ops may not be defined */
  923. #define init_array_fgraph_ops(tr, ops) do { } while (0)
  924. #define allocate_fgraph_ops(tr, ops) ({ 0; })
  925. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  926. extern struct list_head ftrace_pids;
  927. #ifdef CONFIG_FUNCTION_TRACER
  928. #define FTRACE_PID_IGNORE -1
  929. #define FTRACE_PID_TRACE -2
  930. struct ftrace_func_command {
  931. struct list_head list;
  932. char *name;
  933. int (*func)(struct trace_array *tr,
  934. struct ftrace_hash *hash,
  935. char *func, char *cmd,
  936. char *params, int enable);
  937. };
  938. extern bool ftrace_filter_param __initdata;
  939. static inline int ftrace_trace_task(struct trace_array *tr)
  940. {
  941. return this_cpu_read(tr->array_buffer.data->ftrace_ignore_pid) !=
  942. FTRACE_PID_IGNORE;
  943. }
  944. extern int ftrace_is_dead(void);
  945. int ftrace_create_function_files(struct trace_array *tr,
  946. struct dentry *parent);
  947. void ftrace_destroy_function_files(struct trace_array *tr);
  948. int ftrace_allocate_ftrace_ops(struct trace_array *tr);
  949. void ftrace_free_ftrace_ops(struct trace_array *tr);
  950. void ftrace_init_global_array_ops(struct trace_array *tr);
  951. void ftrace_init_array_ops(struct trace_array *tr, ftrace_func_t func);
  952. void ftrace_reset_array_ops(struct trace_array *tr);
  953. void ftrace_init_tracefs(struct trace_array *tr, struct dentry *d_tracer);
  954. void ftrace_init_tracefs_toplevel(struct trace_array *tr,
  955. struct dentry *d_tracer);
  956. void ftrace_clear_pids(struct trace_array *tr);
  957. int init_function_trace(void);
  958. void ftrace_pid_follow_fork(struct trace_array *tr, bool enable);
  959. #else
  960. static inline int ftrace_trace_task(struct trace_array *tr)
  961. {
  962. return 1;
  963. }
  964. static inline int ftrace_is_dead(void) { return 0; }
  965. static inline int
  966. ftrace_create_function_files(struct trace_array *tr,
  967. struct dentry *parent)
  968. {
  969. return 0;
  970. }
  971. static inline int ftrace_allocate_ftrace_ops(struct trace_array *tr)
  972. {
  973. return 0;
  974. }
  975. static inline void ftrace_free_ftrace_ops(struct trace_array *tr) { }
  976. static inline void ftrace_destroy_function_files(struct trace_array *tr) { }
  977. static inline __init void
  978. ftrace_init_global_array_ops(struct trace_array *tr) { }
  979. static inline void ftrace_reset_array_ops(struct trace_array *tr) { }
  980. static inline void ftrace_init_tracefs(struct trace_array *tr, struct dentry *d) { }
  981. static inline void ftrace_init_tracefs_toplevel(struct trace_array *tr, struct dentry *d) { }
  982. static inline void ftrace_clear_pids(struct trace_array *tr) { }
  983. static inline int init_function_trace(void) { return 0; }
  984. static inline void ftrace_pid_follow_fork(struct trace_array *tr, bool enable) { }
  985. /* ftace_func_t type is not defined, use macro instead of static inline */
  986. #define ftrace_init_array_ops(tr, func) do { } while (0)
  987. #endif /* CONFIG_FUNCTION_TRACER */
  988. #if defined(CONFIG_FUNCTION_TRACER) && defined(CONFIG_DYNAMIC_FTRACE)
  989. struct ftrace_probe_ops {
  990. void (*func)(unsigned long ip,
  991. unsigned long parent_ip,
  992. struct trace_array *tr,
  993. struct ftrace_probe_ops *ops,
  994. void *data);
  995. int (*init)(struct ftrace_probe_ops *ops,
  996. struct trace_array *tr,
  997. unsigned long ip, void *init_data,
  998. void **data);
  999. void (*free)(struct ftrace_probe_ops *ops,
  1000. struct trace_array *tr,
  1001. unsigned long ip, void *data);
  1002. int (*print)(struct seq_file *m,
  1003. unsigned long ip,
  1004. struct ftrace_probe_ops *ops,
  1005. void *data);
  1006. };
  1007. struct ftrace_func_mapper;
  1008. typedef int (*ftrace_mapper_func)(void *data);
  1009. struct ftrace_func_mapper *allocate_ftrace_func_mapper(void);
  1010. void **ftrace_func_mapper_find_ip(struct ftrace_func_mapper *mapper,
  1011. unsigned long ip);
  1012. int ftrace_func_mapper_add_ip(struct ftrace_func_mapper *mapper,
  1013. unsigned long ip, void *data);
  1014. void *ftrace_func_mapper_remove_ip(struct ftrace_func_mapper *mapper,
  1015. unsigned long ip);
  1016. void free_ftrace_func_mapper(struct ftrace_func_mapper *mapper,
  1017. ftrace_mapper_func free_func);
  1018. extern int
  1019. register_ftrace_function_probe(char *glob, struct trace_array *tr,
  1020. struct ftrace_probe_ops *ops, void *data);
  1021. extern int
  1022. unregister_ftrace_function_probe_func(char *glob, struct trace_array *tr,
  1023. struct ftrace_probe_ops *ops);
  1024. extern void clear_ftrace_function_probes(struct trace_array *tr);
  1025. int register_ftrace_command(struct ftrace_func_command *cmd);
  1026. int unregister_ftrace_command(struct ftrace_func_command *cmd);
  1027. void ftrace_create_filter_files(struct ftrace_ops *ops,
  1028. struct dentry *parent);
  1029. void ftrace_destroy_filter_files(struct ftrace_ops *ops);
  1030. extern int ftrace_set_filter(struct ftrace_ops *ops, unsigned char *buf,
  1031. int len, int reset);
  1032. extern int ftrace_set_notrace(struct ftrace_ops *ops, unsigned char *buf,
  1033. int len, int reset);
  1034. #else
  1035. struct ftrace_func_command;
  1036. static inline __init int register_ftrace_command(struct ftrace_func_command *cmd)
  1037. {
  1038. return -EINVAL;
  1039. }
  1040. static inline __init int unregister_ftrace_command(char *cmd_name)
  1041. {
  1042. return -EINVAL;
  1043. }
  1044. static inline void clear_ftrace_function_probes(struct trace_array *tr)
  1045. {
  1046. }
  1047. /*
  1048. * The ops parameter passed in is usually undefined.
  1049. * This must be a macro.
  1050. */
  1051. #define ftrace_create_filter_files(ops, parent) do { } while (0)
  1052. #define ftrace_destroy_filter_files(ops) do { } while (0)
  1053. #endif /* CONFIG_FUNCTION_TRACER && CONFIG_DYNAMIC_FTRACE */
  1054. bool ftrace_event_is_function(struct trace_event_call *call);
  1055. /*
  1056. * struct trace_parser - servers for reading the user input separated by spaces
  1057. * @cont: set if the input is not complete - no final space char was found
  1058. * @buffer: holds the parsed user input
  1059. * @idx: user input length
  1060. * @size: buffer size
  1061. */
  1062. struct trace_parser {
  1063. bool cont;
  1064. char *buffer;
  1065. unsigned idx;
  1066. unsigned size;
  1067. };
  1068. static inline bool trace_parser_loaded(struct trace_parser *parser)
  1069. {
  1070. return (parser->idx != 0);
  1071. }
  1072. static inline bool trace_parser_cont(struct trace_parser *parser)
  1073. {
  1074. return parser->cont;
  1075. }
  1076. static inline void trace_parser_clear(struct trace_parser *parser)
  1077. {
  1078. parser->cont = false;
  1079. parser->idx = 0;
  1080. }
  1081. extern int trace_parser_get_init(struct trace_parser *parser, int size);
  1082. extern void trace_parser_put(struct trace_parser *parser);
  1083. extern int trace_get_user(struct trace_parser *parser, const char __user *ubuf,
  1084. size_t cnt, loff_t *ppos);
  1085. /*
  1086. * Only create function graph options if function graph is configured.
  1087. */
  1088. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  1089. # define FGRAPH_FLAGS \
  1090. C(DISPLAY_GRAPH, "display-graph"),
  1091. #else
  1092. # define FGRAPH_FLAGS
  1093. #endif
  1094. #ifdef CONFIG_BRANCH_TRACER
  1095. # define BRANCH_FLAGS \
  1096. C(BRANCH, "branch"),
  1097. #else
  1098. # define BRANCH_FLAGS
  1099. #endif
  1100. #ifdef CONFIG_FUNCTION_TRACER
  1101. # define FUNCTION_FLAGS \
  1102. C(FUNCTION, "function-trace"), \
  1103. C(FUNC_FORK, "function-fork"),
  1104. # define FUNCTION_DEFAULT_FLAGS TRACE_ITER_FUNCTION
  1105. #else
  1106. # define FUNCTION_FLAGS
  1107. # define FUNCTION_DEFAULT_FLAGS 0UL
  1108. # define TRACE_ITER_FUNC_FORK 0UL
  1109. #endif
  1110. #ifdef CONFIG_STACKTRACE
  1111. # define STACK_FLAGS \
  1112. C(STACKTRACE, "stacktrace"),
  1113. #else
  1114. # define STACK_FLAGS
  1115. #endif
  1116. /*
  1117. * trace_iterator_flags is an enumeration that defines bit
  1118. * positions into trace_flags that controls the output.
  1119. *
  1120. * NOTE: These bits must match the trace_options array in
  1121. * trace.c (this macro guarantees it).
  1122. */
  1123. #define TRACE_FLAGS \
  1124. C(PRINT_PARENT, "print-parent"), \
  1125. C(SYM_OFFSET, "sym-offset"), \
  1126. C(SYM_ADDR, "sym-addr"), \
  1127. C(VERBOSE, "verbose"), \
  1128. C(RAW, "raw"), \
  1129. C(HEX, "hex"), \
  1130. C(BIN, "bin"), \
  1131. C(BLOCK, "block"), \
  1132. C(FIELDS, "fields"), \
  1133. C(PRINTK, "trace_printk"), \
  1134. C(ANNOTATE, "annotate"), \
  1135. C(USERSTACKTRACE, "userstacktrace"), \
  1136. C(SYM_USEROBJ, "sym-userobj"), \
  1137. C(PRINTK_MSGONLY, "printk-msg-only"), \
  1138. C(CONTEXT_INFO, "context-info"), /* Print pid/cpu/time */ \
  1139. C(LATENCY_FMT, "latency-format"), \
  1140. C(RECORD_CMD, "record-cmd"), \
  1141. C(RECORD_TGID, "record-tgid"), \
  1142. C(OVERWRITE, "overwrite"), \
  1143. C(STOP_ON_FREE, "disable_on_free"), \
  1144. C(IRQ_INFO, "irq-info"), \
  1145. C(MARKERS, "markers"), \
  1146. C(EVENT_FORK, "event-fork"), \
  1147. C(TRACE_PRINTK, "trace_printk_dest"), \
  1148. C(PAUSE_ON_TRACE, "pause-on-trace"), \
  1149. C(HASH_PTR, "hash-ptr"), /* Print hashed pointer */ \
  1150. FUNCTION_FLAGS \
  1151. FGRAPH_FLAGS \
  1152. STACK_FLAGS \
  1153. BRANCH_FLAGS
  1154. /*
  1155. * By defining C, we can make TRACE_FLAGS a list of bit names
  1156. * that will define the bits for the flag masks.
  1157. */
  1158. #undef C
  1159. #define C(a, b) TRACE_ITER_##a##_BIT
  1160. enum trace_iterator_bits {
  1161. TRACE_FLAGS
  1162. /* Make sure we don't go more than we have bits for */
  1163. TRACE_ITER_LAST_BIT
  1164. };
  1165. /*
  1166. * By redefining C, we can make TRACE_FLAGS a list of masks that
  1167. * use the bits as defined above.
  1168. */
  1169. #undef C
  1170. #define C(a, b) TRACE_ITER_##a = (1 << TRACE_ITER_##a##_BIT)
  1171. enum trace_iterator_flags { TRACE_FLAGS };
  1172. /*
  1173. * TRACE_ITER_SYM_MASK masks the options in trace_flags that
  1174. * control the output of kernel symbols.
  1175. */
  1176. #define TRACE_ITER_SYM_MASK \
  1177. (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR)
  1178. extern struct tracer nop_trace;
  1179. #ifdef CONFIG_BRANCH_TRACER
  1180. extern int enable_branch_tracing(struct trace_array *tr);
  1181. extern void disable_branch_tracing(void);
  1182. static inline int trace_branch_enable(struct trace_array *tr)
  1183. {
  1184. if (tr->trace_flags & TRACE_ITER_BRANCH)
  1185. return enable_branch_tracing(tr);
  1186. return 0;
  1187. }
  1188. static inline void trace_branch_disable(void)
  1189. {
  1190. /* due to races, always disable */
  1191. disable_branch_tracing();
  1192. }
  1193. #else
  1194. static inline int trace_branch_enable(struct trace_array *tr)
  1195. {
  1196. return 0;
  1197. }
  1198. static inline void trace_branch_disable(void)
  1199. {
  1200. }
  1201. #endif /* CONFIG_BRANCH_TRACER */
  1202. /* set ring buffers to default size if not already done so */
  1203. int tracing_update_buffers(struct trace_array *tr);
  1204. union trace_synth_field {
  1205. u8 as_u8;
  1206. u16 as_u16;
  1207. u32 as_u32;
  1208. u64 as_u64;
  1209. struct trace_dynamic_info as_dynamic;
  1210. };
  1211. struct ftrace_event_field {
  1212. struct list_head link;
  1213. const char *name;
  1214. const char *type;
  1215. int filter_type;
  1216. int offset;
  1217. int size;
  1218. unsigned int is_signed:1;
  1219. unsigned int needs_test:1;
  1220. int len;
  1221. };
  1222. struct prog_entry;
  1223. struct event_filter {
  1224. struct prog_entry __rcu *prog;
  1225. char *filter_string;
  1226. };
  1227. struct event_subsystem {
  1228. struct list_head list;
  1229. const char *name;
  1230. struct event_filter *filter;
  1231. int ref_count;
  1232. };
  1233. struct trace_subsystem_dir {
  1234. struct list_head list;
  1235. struct event_subsystem *subsystem;
  1236. struct trace_array *tr;
  1237. struct eventfs_inode *ei;
  1238. int ref_count;
  1239. int nr_events;
  1240. };
  1241. extern int call_filter_check_discard(struct trace_event_call *call, void *rec,
  1242. struct trace_buffer *buffer,
  1243. struct ring_buffer_event *event);
  1244. void trace_buffer_unlock_commit_regs(struct trace_array *tr,
  1245. struct trace_buffer *buffer,
  1246. struct ring_buffer_event *event,
  1247. unsigned int trcace_ctx,
  1248. struct pt_regs *regs);
  1249. static inline void trace_buffer_unlock_commit(struct trace_array *tr,
  1250. struct trace_buffer *buffer,
  1251. struct ring_buffer_event *event,
  1252. unsigned int trace_ctx)
  1253. {
  1254. trace_buffer_unlock_commit_regs(tr, buffer, event, trace_ctx, NULL);
  1255. }
  1256. DECLARE_PER_CPU(bool, trace_taskinfo_save);
  1257. int trace_save_cmdline(struct task_struct *tsk);
  1258. int trace_create_savedcmd(void);
  1259. int trace_alloc_tgid_map(void);
  1260. void trace_free_saved_cmdlines_buffer(void);
  1261. extern const struct file_operations tracing_saved_cmdlines_fops;
  1262. extern const struct file_operations tracing_saved_tgids_fops;
  1263. extern const struct file_operations tracing_saved_cmdlines_size_fops;
  1264. DECLARE_PER_CPU(struct ring_buffer_event *, trace_buffered_event);
  1265. DECLARE_PER_CPU(int, trace_buffered_event_cnt);
  1266. void trace_buffered_event_disable(void);
  1267. void trace_buffered_event_enable(void);
  1268. void early_enable_events(struct trace_array *tr, char *buf, bool disable_first);
  1269. static inline void
  1270. __trace_event_discard_commit(struct trace_buffer *buffer,
  1271. struct ring_buffer_event *event)
  1272. {
  1273. if (this_cpu_read(trace_buffered_event) == event) {
  1274. /* Simply release the temp buffer and enable preemption */
  1275. this_cpu_dec(trace_buffered_event_cnt);
  1276. preempt_enable_notrace();
  1277. return;
  1278. }
  1279. /* ring_buffer_discard_commit() enables preemption */
  1280. ring_buffer_discard_commit(buffer, event);
  1281. }
  1282. /*
  1283. * Helper function for event_trigger_unlock_commit{_regs}().
  1284. * If there are event triggers attached to this event that requires
  1285. * filtering against its fields, then they will be called as the
  1286. * entry already holds the field information of the current event.
  1287. *
  1288. * It also checks if the event should be discarded or not.
  1289. * It is to be discarded if the event is soft disabled and the
  1290. * event was only recorded to process triggers, or if the event
  1291. * filter is active and this event did not match the filters.
  1292. *
  1293. * Returns true if the event is discarded, false otherwise.
  1294. */
  1295. static inline bool
  1296. __event_trigger_test_discard(struct trace_event_file *file,
  1297. struct trace_buffer *buffer,
  1298. struct ring_buffer_event *event,
  1299. void *entry,
  1300. enum event_trigger_type *tt)
  1301. {
  1302. unsigned long eflags = file->flags;
  1303. if (eflags & EVENT_FILE_FL_TRIGGER_COND)
  1304. *tt = event_triggers_call(file, buffer, entry, event);
  1305. if (likely(!(file->flags & (EVENT_FILE_FL_SOFT_DISABLED |
  1306. EVENT_FILE_FL_FILTERED |
  1307. EVENT_FILE_FL_PID_FILTER))))
  1308. return false;
  1309. if (file->flags & EVENT_FILE_FL_SOFT_DISABLED)
  1310. goto discard;
  1311. if (file->flags & EVENT_FILE_FL_FILTERED &&
  1312. !filter_match_preds(file->filter, entry))
  1313. goto discard;
  1314. if ((file->flags & EVENT_FILE_FL_PID_FILTER) &&
  1315. trace_event_ignore_this_pid(file))
  1316. goto discard;
  1317. return false;
  1318. discard:
  1319. __trace_event_discard_commit(buffer, event);
  1320. return true;
  1321. }
  1322. /**
  1323. * event_trigger_unlock_commit - handle triggers and finish event commit
  1324. * @file: The file pointer associated with the event
  1325. * @buffer: The ring buffer that the event is being written to
  1326. * @event: The event meta data in the ring buffer
  1327. * @entry: The event itself
  1328. * @trace_ctx: The tracing context flags.
  1329. *
  1330. * This is a helper function to handle triggers that require data
  1331. * from the event itself. It also tests the event against filters and
  1332. * if the event is soft disabled and should be discarded.
  1333. */
  1334. static inline void
  1335. event_trigger_unlock_commit(struct trace_event_file *file,
  1336. struct trace_buffer *buffer,
  1337. struct ring_buffer_event *event,
  1338. void *entry, unsigned int trace_ctx)
  1339. {
  1340. enum event_trigger_type tt = ETT_NONE;
  1341. if (!__event_trigger_test_discard(file, buffer, event, entry, &tt))
  1342. trace_buffer_unlock_commit(file->tr, buffer, event, trace_ctx);
  1343. if (tt)
  1344. event_triggers_post_call(file, tt);
  1345. }
  1346. #define FILTER_PRED_INVALID ((unsigned short)-1)
  1347. #define FILTER_PRED_IS_RIGHT (1 << 15)
  1348. #define FILTER_PRED_FOLD (1 << 15)
  1349. /*
  1350. * The max preds is the size of unsigned short with
  1351. * two flags at the MSBs. One bit is used for both the IS_RIGHT
  1352. * and FOLD flags. The other is reserved.
  1353. *
  1354. * 2^14 preds is way more than enough.
  1355. */
  1356. #define MAX_FILTER_PRED 16384
  1357. struct filter_pred;
  1358. struct regex;
  1359. typedef int (*regex_match_func)(char *str, struct regex *r, int len);
  1360. enum regex_type {
  1361. MATCH_FULL = 0,
  1362. MATCH_FRONT_ONLY,
  1363. MATCH_MIDDLE_ONLY,
  1364. MATCH_END_ONLY,
  1365. MATCH_GLOB,
  1366. MATCH_INDEX,
  1367. };
  1368. struct regex {
  1369. char pattern[MAX_FILTER_STR_VAL];
  1370. int len;
  1371. int field_len;
  1372. regex_match_func match;
  1373. };
  1374. static inline bool is_string_field(struct ftrace_event_field *field)
  1375. {
  1376. return field->filter_type == FILTER_DYN_STRING ||
  1377. field->filter_type == FILTER_RDYN_STRING ||
  1378. field->filter_type == FILTER_STATIC_STRING ||
  1379. field->filter_type == FILTER_PTR_STRING ||
  1380. field->filter_type == FILTER_COMM;
  1381. }
  1382. static inline bool is_function_field(struct ftrace_event_field *field)
  1383. {
  1384. return field->filter_type == FILTER_TRACE_FN;
  1385. }
  1386. extern enum regex_type
  1387. filter_parse_regex(char *buff, int len, char **search, int *not);
  1388. extern void print_event_filter(struct trace_event_file *file,
  1389. struct trace_seq *s);
  1390. extern int apply_event_filter(struct trace_event_file *file,
  1391. char *filter_string);
  1392. extern int apply_subsystem_event_filter(struct trace_subsystem_dir *dir,
  1393. char *filter_string);
  1394. extern void print_subsystem_event_filter(struct event_subsystem *system,
  1395. struct trace_seq *s);
  1396. extern int filter_assign_type(const char *type);
  1397. extern int create_event_filter(struct trace_array *tr,
  1398. struct trace_event_call *call,
  1399. char *filter_str, bool set_str,
  1400. struct event_filter **filterp);
  1401. extern void free_event_filter(struct event_filter *filter);
  1402. struct ftrace_event_field *
  1403. trace_find_event_field(struct trace_event_call *call, char *name);
  1404. extern void trace_event_enable_cmd_record(bool enable);
  1405. extern void trace_event_enable_tgid_record(bool enable);
  1406. extern int event_trace_init(void);
  1407. extern int init_events(void);
  1408. extern int event_trace_add_tracer(struct dentry *parent, struct trace_array *tr);
  1409. extern int event_trace_del_tracer(struct trace_array *tr);
  1410. extern void __trace_early_add_events(struct trace_array *tr);
  1411. extern struct trace_event_file *__find_event_file(struct trace_array *tr,
  1412. const char *system,
  1413. const char *event);
  1414. extern struct trace_event_file *find_event_file(struct trace_array *tr,
  1415. const char *system,
  1416. const char *event);
  1417. static inline void *event_file_data(struct file *filp)
  1418. {
  1419. return READ_ONCE(file_inode(filp)->i_private);
  1420. }
  1421. extern struct mutex event_mutex;
  1422. extern struct list_head ftrace_events;
  1423. /*
  1424. * When the trace_event_file is the filp->i_private pointer,
  1425. * it must be taken under the event_mutex lock, and then checked
  1426. * if the EVENT_FILE_FL_FREED flag is set. If it is, then the
  1427. * data pointed to by the trace_event_file can not be trusted.
  1428. *
  1429. * Use the event_file_file() to access the trace_event_file from
  1430. * the filp the first time under the event_mutex and check for
  1431. * NULL. If it is needed to be retrieved again and the event_mutex
  1432. * is still held, then the event_file_data() can be used and it
  1433. * is guaranteed to be valid.
  1434. */
  1435. static inline struct trace_event_file *event_file_file(struct file *filp)
  1436. {
  1437. struct trace_event_file *file;
  1438. lockdep_assert_held(&event_mutex);
  1439. file = READ_ONCE(file_inode(filp)->i_private);
  1440. if (!file || file->flags & EVENT_FILE_FL_FREED)
  1441. return NULL;
  1442. return file;
  1443. }
  1444. extern const struct file_operations event_trigger_fops;
  1445. extern const struct file_operations event_hist_fops;
  1446. extern const struct file_operations event_hist_debug_fops;
  1447. extern const struct file_operations event_inject_fops;
  1448. #ifdef CONFIG_HIST_TRIGGERS
  1449. extern int register_trigger_hist_cmd(void);
  1450. extern int register_trigger_hist_enable_disable_cmds(void);
  1451. #else
  1452. static inline int register_trigger_hist_cmd(void) { return 0; }
  1453. static inline int register_trigger_hist_enable_disable_cmds(void) { return 0; }
  1454. #endif
  1455. extern int register_trigger_cmds(void);
  1456. extern void clear_event_triggers(struct trace_array *tr);
  1457. enum {
  1458. EVENT_TRIGGER_FL_PROBE = BIT(0),
  1459. };
  1460. struct event_trigger_data {
  1461. unsigned long count;
  1462. int ref;
  1463. int flags;
  1464. struct event_trigger_ops *ops;
  1465. struct event_command *cmd_ops;
  1466. struct event_filter __rcu *filter;
  1467. char *filter_str;
  1468. void *private_data;
  1469. bool paused;
  1470. bool paused_tmp;
  1471. struct list_head list;
  1472. char *name;
  1473. struct list_head named_list;
  1474. struct event_trigger_data *named_data;
  1475. };
  1476. /* Avoid typos */
  1477. #define ENABLE_EVENT_STR "enable_event"
  1478. #define DISABLE_EVENT_STR "disable_event"
  1479. #define ENABLE_HIST_STR "enable_hist"
  1480. #define DISABLE_HIST_STR "disable_hist"
  1481. struct enable_trigger_data {
  1482. struct trace_event_file *file;
  1483. bool enable;
  1484. bool hist;
  1485. };
  1486. extern int event_enable_trigger_print(struct seq_file *m,
  1487. struct event_trigger_data *data);
  1488. extern void event_enable_trigger_free(struct event_trigger_data *data);
  1489. extern int event_enable_trigger_parse(struct event_command *cmd_ops,
  1490. struct trace_event_file *file,
  1491. char *glob, char *cmd,
  1492. char *param_and_filter);
  1493. extern int event_enable_register_trigger(char *glob,
  1494. struct event_trigger_data *data,
  1495. struct trace_event_file *file);
  1496. extern void event_enable_unregister_trigger(char *glob,
  1497. struct event_trigger_data *test,
  1498. struct trace_event_file *file);
  1499. extern void trigger_data_free(struct event_trigger_data *data);
  1500. extern int event_trigger_init(struct event_trigger_data *data);
  1501. extern int trace_event_trigger_enable_disable(struct trace_event_file *file,
  1502. int trigger_enable);
  1503. extern void update_cond_flag(struct trace_event_file *file);
  1504. extern int set_trigger_filter(char *filter_str,
  1505. struct event_trigger_data *trigger_data,
  1506. struct trace_event_file *file);
  1507. extern struct event_trigger_data *find_named_trigger(const char *name);
  1508. extern bool is_named_trigger(struct event_trigger_data *test);
  1509. extern int save_named_trigger(const char *name,
  1510. struct event_trigger_data *data);
  1511. extern void del_named_trigger(struct event_trigger_data *data);
  1512. extern void pause_named_trigger(struct event_trigger_data *data);
  1513. extern void unpause_named_trigger(struct event_trigger_data *data);
  1514. extern void set_named_trigger_data(struct event_trigger_data *data,
  1515. struct event_trigger_data *named_data);
  1516. extern struct event_trigger_data *
  1517. get_named_trigger_data(struct event_trigger_data *data);
  1518. extern int register_event_command(struct event_command *cmd);
  1519. extern int unregister_event_command(struct event_command *cmd);
  1520. extern int register_trigger_hist_enable_disable_cmds(void);
  1521. extern bool event_trigger_check_remove(const char *glob);
  1522. extern bool event_trigger_empty_param(const char *param);
  1523. extern int event_trigger_separate_filter(char *param_and_filter, char **param,
  1524. char **filter, bool param_required);
  1525. extern struct event_trigger_data *
  1526. event_trigger_alloc(struct event_command *cmd_ops,
  1527. char *cmd,
  1528. char *param,
  1529. void *private_data);
  1530. extern int event_trigger_parse_num(char *trigger,
  1531. struct event_trigger_data *trigger_data);
  1532. extern int event_trigger_set_filter(struct event_command *cmd_ops,
  1533. struct trace_event_file *file,
  1534. char *param,
  1535. struct event_trigger_data *trigger_data);
  1536. extern void event_trigger_reset_filter(struct event_command *cmd_ops,
  1537. struct event_trigger_data *trigger_data);
  1538. extern int event_trigger_register(struct event_command *cmd_ops,
  1539. struct trace_event_file *file,
  1540. char *glob,
  1541. struct event_trigger_data *trigger_data);
  1542. extern void event_trigger_unregister(struct event_command *cmd_ops,
  1543. struct trace_event_file *file,
  1544. char *glob,
  1545. struct event_trigger_data *trigger_data);
  1546. extern void event_file_get(struct trace_event_file *file);
  1547. extern void event_file_put(struct trace_event_file *file);
  1548. /**
  1549. * struct event_trigger_ops - callbacks for trace event triggers
  1550. *
  1551. * The methods in this structure provide per-event trigger hooks for
  1552. * various trigger operations.
  1553. *
  1554. * The @init and @free methods are used during trigger setup and
  1555. * teardown, typically called from an event_command's @parse()
  1556. * function implementation.
  1557. *
  1558. * The @print method is used to print the trigger spec.
  1559. *
  1560. * The @trigger method is the function that actually implements the
  1561. * trigger and is called in the context of the triggering event
  1562. * whenever that event occurs.
  1563. *
  1564. * All the methods below, except for @init() and @free(), must be
  1565. * implemented.
  1566. *
  1567. * @trigger: The trigger 'probe' function called when the triggering
  1568. * event occurs. The data passed into this callback is the data
  1569. * that was supplied to the event_command @reg() function that
  1570. * registered the trigger (see struct event_command) along with
  1571. * the trace record, rec.
  1572. *
  1573. * @init: An optional initialization function called for the trigger
  1574. * when the trigger is registered (via the event_command reg()
  1575. * function). This can be used to perform per-trigger
  1576. * initialization such as incrementing a per-trigger reference
  1577. * count, for instance. This is usually implemented by the
  1578. * generic utility function @event_trigger_init() (see
  1579. * trace_event_triggers.c).
  1580. *
  1581. * @free: An optional de-initialization function called for the
  1582. * trigger when the trigger is unregistered (via the
  1583. * event_command @reg() function). This can be used to perform
  1584. * per-trigger de-initialization such as decrementing a
  1585. * per-trigger reference count and freeing corresponding trigger
  1586. * data, for instance. This is usually implemented by the
  1587. * generic utility function @event_trigger_free() (see
  1588. * trace_event_triggers.c).
  1589. *
  1590. * @print: The callback function invoked to have the trigger print
  1591. * itself. This is usually implemented by a wrapper function
  1592. * that calls the generic utility function @event_trigger_print()
  1593. * (see trace_event_triggers.c).
  1594. */
  1595. struct event_trigger_ops {
  1596. void (*trigger)(struct event_trigger_data *data,
  1597. struct trace_buffer *buffer,
  1598. void *rec,
  1599. struct ring_buffer_event *rbe);
  1600. int (*init)(struct event_trigger_data *data);
  1601. void (*free)(struct event_trigger_data *data);
  1602. int (*print)(struct seq_file *m,
  1603. struct event_trigger_data *data);
  1604. };
  1605. /**
  1606. * struct event_command - callbacks and data members for event commands
  1607. *
  1608. * Event commands are invoked by users by writing the command name
  1609. * into the 'trigger' file associated with a trace event. The
  1610. * parameters associated with a specific invocation of an event
  1611. * command are used to create an event trigger instance, which is
  1612. * added to the list of trigger instances associated with that trace
  1613. * event. When the event is hit, the set of triggers associated with
  1614. * that event is invoked.
  1615. *
  1616. * The data members in this structure provide per-event command data
  1617. * for various event commands.
  1618. *
  1619. * All the data members below, except for @post_trigger, must be set
  1620. * for each event command.
  1621. *
  1622. * @name: The unique name that identifies the event command. This is
  1623. * the name used when setting triggers via trigger files.
  1624. *
  1625. * @trigger_type: A unique id that identifies the event command
  1626. * 'type'. This value has two purposes, the first to ensure that
  1627. * only one trigger of the same type can be set at a given time
  1628. * for a particular event e.g. it doesn't make sense to have both
  1629. * a traceon and traceoff trigger attached to a single event at
  1630. * the same time, so traceon and traceoff have the same type
  1631. * though they have different names. The @trigger_type value is
  1632. * also used as a bit value for deferring the actual trigger
  1633. * action until after the current event is finished. Some
  1634. * commands need to do this if they themselves log to the trace
  1635. * buffer (see the @post_trigger() member below). @trigger_type
  1636. * values are defined by adding new values to the trigger_type
  1637. * enum in include/linux/trace_events.h.
  1638. *
  1639. * @flags: See the enum event_command_flags below.
  1640. *
  1641. * All the methods below, except for @set_filter() and @unreg_all(),
  1642. * must be implemented.
  1643. *
  1644. * @parse: The callback function responsible for parsing and
  1645. * registering the trigger written to the 'trigger' file by the
  1646. * user. It allocates the trigger instance and registers it with
  1647. * the appropriate trace event. It makes use of the other
  1648. * event_command callback functions to orchestrate this, and is
  1649. * usually implemented by the generic utility function
  1650. * @event_trigger_callback() (see trace_event_triggers.c).
  1651. *
  1652. * @reg: Adds the trigger to the list of triggers associated with the
  1653. * event, and enables the event trigger itself, after
  1654. * initializing it (via the event_trigger_ops @init() function).
  1655. * This is also where commands can use the @trigger_type value to
  1656. * make the decision as to whether or not multiple instances of
  1657. * the trigger should be allowed. This is usually implemented by
  1658. * the generic utility function @register_trigger() (see
  1659. * trace_event_triggers.c).
  1660. *
  1661. * @unreg: Removes the trigger from the list of triggers associated
  1662. * with the event, and disables the event trigger itself, after
  1663. * initializing it (via the event_trigger_ops @free() function).
  1664. * This is usually implemented by the generic utility function
  1665. * @unregister_trigger() (see trace_event_triggers.c).
  1666. *
  1667. * @unreg_all: An optional function called to remove all the triggers
  1668. * from the list of triggers associated with the event. Called
  1669. * when a trigger file is opened in truncate mode.
  1670. *
  1671. * @set_filter: An optional function called to parse and set a filter
  1672. * for the trigger. If no @set_filter() method is set for the
  1673. * event command, filters set by the user for the command will be
  1674. * ignored. This is usually implemented by the generic utility
  1675. * function @set_trigger_filter() (see trace_event_triggers.c).
  1676. *
  1677. * @get_trigger_ops: The callback function invoked to retrieve the
  1678. * event_trigger_ops implementation associated with the command.
  1679. * This callback function allows a single event_command to
  1680. * support multiple trigger implementations via different sets of
  1681. * event_trigger_ops, depending on the value of the @param
  1682. * string.
  1683. */
  1684. struct event_command {
  1685. struct list_head list;
  1686. char *name;
  1687. enum event_trigger_type trigger_type;
  1688. int flags;
  1689. int (*parse)(struct event_command *cmd_ops,
  1690. struct trace_event_file *file,
  1691. char *glob, char *cmd,
  1692. char *param_and_filter);
  1693. int (*reg)(char *glob,
  1694. struct event_trigger_data *data,
  1695. struct trace_event_file *file);
  1696. void (*unreg)(char *glob,
  1697. struct event_trigger_data *data,
  1698. struct trace_event_file *file);
  1699. void (*unreg_all)(struct trace_event_file *file);
  1700. int (*set_filter)(char *filter_str,
  1701. struct event_trigger_data *data,
  1702. struct trace_event_file *file);
  1703. struct event_trigger_ops *(*get_trigger_ops)(char *cmd, char *param);
  1704. };
  1705. /**
  1706. * enum event_command_flags - flags for struct event_command
  1707. *
  1708. * @POST_TRIGGER: A flag that says whether or not this command needs
  1709. * to have its action delayed until after the current event has
  1710. * been closed. Some triggers need to avoid being invoked while
  1711. * an event is currently in the process of being logged, since
  1712. * the trigger may itself log data into the trace buffer. Thus
  1713. * we make sure the current event is committed before invoking
  1714. * those triggers. To do that, the trigger invocation is split
  1715. * in two - the first part checks the filter using the current
  1716. * trace record; if a command has the @post_trigger flag set, it
  1717. * sets a bit for itself in the return value, otherwise it
  1718. * directly invokes the trigger. Once all commands have been
  1719. * either invoked or set their return flag, the current record is
  1720. * either committed or discarded. At that point, if any commands
  1721. * have deferred their triggers, those commands are finally
  1722. * invoked following the close of the current event. In other
  1723. * words, if the event_trigger_ops @func() probe implementation
  1724. * itself logs to the trace buffer, this flag should be set,
  1725. * otherwise it can be left unspecified.
  1726. *
  1727. * @NEEDS_REC: A flag that says whether or not this command needs
  1728. * access to the trace record in order to perform its function,
  1729. * regardless of whether or not it has a filter associated with
  1730. * it (filters make a trigger require access to the trace record
  1731. * but are not always present).
  1732. */
  1733. enum event_command_flags {
  1734. EVENT_CMD_FL_POST_TRIGGER = 1,
  1735. EVENT_CMD_FL_NEEDS_REC = 2,
  1736. };
  1737. static inline bool event_command_post_trigger(struct event_command *cmd_ops)
  1738. {
  1739. return cmd_ops->flags & EVENT_CMD_FL_POST_TRIGGER;
  1740. }
  1741. static inline bool event_command_needs_rec(struct event_command *cmd_ops)
  1742. {
  1743. return cmd_ops->flags & EVENT_CMD_FL_NEEDS_REC;
  1744. }
  1745. extern int trace_event_enable_disable(struct trace_event_file *file,
  1746. int enable, int soft_disable);
  1747. extern int tracing_alloc_snapshot(void);
  1748. extern void tracing_snapshot_cond(struct trace_array *tr, void *cond_data);
  1749. extern int tracing_snapshot_cond_enable(struct trace_array *tr, void *cond_data, cond_update_fn_t update);
  1750. extern int tracing_snapshot_cond_disable(struct trace_array *tr);
  1751. extern void *tracing_cond_snapshot_data(struct trace_array *tr);
  1752. extern const char *__start___trace_bprintk_fmt[];
  1753. extern const char *__stop___trace_bprintk_fmt[];
  1754. extern const char *__start___tracepoint_str[];
  1755. extern const char *__stop___tracepoint_str[];
  1756. void trace_printk_control(bool enabled);
  1757. void trace_printk_start_comm(void);
  1758. int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
  1759. int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
  1760. /* Used from boot time tracer */
  1761. extern int trace_set_options(struct trace_array *tr, char *option);
  1762. extern int tracing_set_tracer(struct trace_array *tr, const char *buf);
  1763. extern ssize_t tracing_resize_ring_buffer(struct trace_array *tr,
  1764. unsigned long size, int cpu_id);
  1765. extern int tracing_set_cpumask(struct trace_array *tr,
  1766. cpumask_var_t tracing_cpumask_new);
  1767. #define MAX_EVENT_NAME_LEN 64
  1768. extern ssize_t trace_parse_run_command(struct file *file,
  1769. const char __user *buffer, size_t count, loff_t *ppos,
  1770. int (*createfn)(const char *));
  1771. extern unsigned int err_pos(char *cmd, const char *str);
  1772. extern void tracing_log_err(struct trace_array *tr,
  1773. const char *loc, const char *cmd,
  1774. const char **errs, u8 type, u16 pos);
  1775. /*
  1776. * Normal trace_printk() and friends allocates special buffers
  1777. * to do the manipulation, as well as saves the print formats
  1778. * into sections to display. But the trace infrastructure wants
  1779. * to use these without the added overhead at the price of being
  1780. * a bit slower (used mainly for warnings, where we don't care
  1781. * about performance). The internal_trace_puts() is for such
  1782. * a purpose.
  1783. */
  1784. #define internal_trace_puts(str) __trace_puts(_THIS_IP_, str, strlen(str))
  1785. #undef FTRACE_ENTRY
  1786. #define FTRACE_ENTRY(call, struct_name, id, tstruct, print) \
  1787. extern struct trace_event_call \
  1788. __aligned(4) event_##call;
  1789. #undef FTRACE_ENTRY_DUP
  1790. #define FTRACE_ENTRY_DUP(call, struct_name, id, tstruct, print) \
  1791. FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print))
  1792. #undef FTRACE_ENTRY_PACKED
  1793. #define FTRACE_ENTRY_PACKED(call, struct_name, id, tstruct, print) \
  1794. FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print))
  1795. #include "trace_entries.h"
  1796. #if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_FUNCTION_TRACER)
  1797. int perf_ftrace_event_register(struct trace_event_call *call,
  1798. enum trace_reg type, void *data);
  1799. #else
  1800. #define perf_ftrace_event_register NULL
  1801. #endif
  1802. #ifdef CONFIG_FTRACE_SYSCALLS
  1803. void init_ftrace_syscalls(void);
  1804. const char *get_syscall_name(int syscall);
  1805. #else
  1806. static inline void init_ftrace_syscalls(void) { }
  1807. static inline const char *get_syscall_name(int syscall)
  1808. {
  1809. return NULL;
  1810. }
  1811. #endif
  1812. #ifdef CONFIG_EVENT_TRACING
  1813. void trace_event_init(void);
  1814. void trace_event_eval_update(struct trace_eval_map **map, int len);
  1815. /* Used from boot time tracer */
  1816. extern int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set);
  1817. extern int trigger_process_regex(struct trace_event_file *file, char *buff);
  1818. #else
  1819. static inline void __init trace_event_init(void) { }
  1820. static inline void trace_event_eval_update(struct trace_eval_map **map, int len) { }
  1821. #endif
  1822. #ifdef CONFIG_TRACER_SNAPSHOT
  1823. void tracing_snapshot_instance(struct trace_array *tr);
  1824. int tracing_alloc_snapshot_instance(struct trace_array *tr);
  1825. int tracing_arm_snapshot(struct trace_array *tr);
  1826. void tracing_disarm_snapshot(struct trace_array *tr);
  1827. #else
  1828. static inline void tracing_snapshot_instance(struct trace_array *tr) { }
  1829. static inline int tracing_alloc_snapshot_instance(struct trace_array *tr)
  1830. {
  1831. return 0;
  1832. }
  1833. static inline int tracing_arm_snapshot(struct trace_array *tr) { return 0; }
  1834. static inline void tracing_disarm_snapshot(struct trace_array *tr) { }
  1835. #endif
  1836. #ifdef CONFIG_PREEMPT_TRACER
  1837. void tracer_preempt_on(unsigned long a0, unsigned long a1);
  1838. void tracer_preempt_off(unsigned long a0, unsigned long a1);
  1839. #else
  1840. static inline void tracer_preempt_on(unsigned long a0, unsigned long a1) { }
  1841. static inline void tracer_preempt_off(unsigned long a0, unsigned long a1) { }
  1842. #endif
  1843. #ifdef CONFIG_IRQSOFF_TRACER
  1844. void tracer_hardirqs_on(unsigned long a0, unsigned long a1);
  1845. void tracer_hardirqs_off(unsigned long a0, unsigned long a1);
  1846. #else
  1847. static inline void tracer_hardirqs_on(unsigned long a0, unsigned long a1) { }
  1848. static inline void tracer_hardirqs_off(unsigned long a0, unsigned long a1) { }
  1849. #endif
  1850. /*
  1851. * Reset the state of the trace_iterator so that it can read consumed data.
  1852. * Normally, the trace_iterator is used for reading the data when it is not
  1853. * consumed, and must retain state.
  1854. */
  1855. static __always_inline void trace_iterator_reset(struct trace_iterator *iter)
  1856. {
  1857. memset_startat(iter, 0, seq);
  1858. iter->pos = -1;
  1859. }
  1860. /* Check the name is good for event/group/fields */
  1861. static inline bool __is_good_name(const char *name, bool hash_ok)
  1862. {
  1863. if (!isalpha(*name) && *name != '_' && (!hash_ok || *name != '-'))
  1864. return false;
  1865. while (*++name != '\0') {
  1866. if (!isalpha(*name) && !isdigit(*name) && *name != '_' &&
  1867. (!hash_ok || *name != '-'))
  1868. return false;
  1869. }
  1870. return true;
  1871. }
  1872. /* Check the name is good for event/group/fields */
  1873. static inline bool is_good_name(const char *name)
  1874. {
  1875. return __is_good_name(name, false);
  1876. }
  1877. /* Check the name is good for system */
  1878. static inline bool is_good_system_name(const char *name)
  1879. {
  1880. return __is_good_name(name, true);
  1881. }
  1882. /* Convert certain expected symbols into '_' when generating event names */
  1883. static inline void sanitize_event_name(char *name)
  1884. {
  1885. while (*name++ != '\0')
  1886. if (*name == ':' || *name == '.')
  1887. *name = '_';
  1888. }
  1889. /*
  1890. * This is a generic way to read and write a u64 value from a file in tracefs.
  1891. *
  1892. * The value is stored on the variable pointed by *val. The value needs
  1893. * to be at least *min and at most *max. The write is protected by an
  1894. * existing *lock.
  1895. */
  1896. struct trace_min_max_param {
  1897. struct mutex *lock;
  1898. u64 *val;
  1899. u64 *min;
  1900. u64 *max;
  1901. };
  1902. #define U64_STR_SIZE 24 /* 20 digits max */
  1903. extern const struct file_operations trace_min_max_fops;
  1904. #ifdef CONFIG_RV
  1905. extern int rv_init_interface(void);
  1906. #else
  1907. static inline int rv_init_interface(void)
  1908. {
  1909. return 0;
  1910. }
  1911. #endif
  1912. /*
  1913. * This is used only to distinguish
  1914. * function address from trampoline code.
  1915. * So this value has no meaning.
  1916. */
  1917. #define FTRACE_TRAMPOLINE_MARKER ((unsigned long) INT_MAX)
  1918. #endif /* _LINUX_KERNEL_TRACE_H */