trace.h 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192
  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. __printf(2, 0)
  711. int trace_vbprintk(unsigned long ip, const char *fmt, va_list args);
  712. __printf(2, 0)
  713. int trace_vprintk(unsigned long ip, const char *fmt, va_list args);
  714. __printf(3, 0)
  715. int trace_array_vprintk(struct trace_array *tr,
  716. unsigned long ip, const char *fmt, va_list args);
  717. __printf(3, 4)
  718. int trace_array_printk_buf(struct trace_buffer *buffer,
  719. unsigned long ip, const char *fmt, ...);
  720. void trace_printk_seq(struct trace_seq *s);
  721. enum print_line_t print_trace_line(struct trace_iterator *iter);
  722. extern char trace_find_mark(unsigned long long duration);
  723. struct ftrace_hash;
  724. struct ftrace_mod_load {
  725. struct list_head list;
  726. char *func;
  727. char *module;
  728. int enable;
  729. };
  730. enum {
  731. FTRACE_HASH_FL_MOD = (1 << 0),
  732. };
  733. struct ftrace_hash {
  734. unsigned long size_bits;
  735. struct hlist_head *buckets;
  736. unsigned long count;
  737. unsigned long flags;
  738. struct rcu_head rcu;
  739. };
  740. struct ftrace_func_entry *
  741. ftrace_lookup_ip(struct ftrace_hash *hash, unsigned long ip);
  742. static __always_inline bool ftrace_hash_empty(struct ftrace_hash *hash)
  743. {
  744. return !hash || !(hash->count || (hash->flags & FTRACE_HASH_FL_MOD));
  745. }
  746. /* Standard output formatting function used for function return traces */
  747. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  748. /* Flag options */
  749. #define TRACE_GRAPH_PRINT_OVERRUN 0x1
  750. #define TRACE_GRAPH_PRINT_CPU 0x2
  751. #define TRACE_GRAPH_PRINT_OVERHEAD 0x4
  752. #define TRACE_GRAPH_PRINT_PROC 0x8
  753. #define TRACE_GRAPH_PRINT_DURATION 0x10
  754. #define TRACE_GRAPH_PRINT_ABS_TIME 0x20
  755. #define TRACE_GRAPH_PRINT_REL_TIME 0x40
  756. #define TRACE_GRAPH_PRINT_IRQS 0x80
  757. #define TRACE_GRAPH_PRINT_TAIL 0x100
  758. #define TRACE_GRAPH_SLEEP_TIME 0x200
  759. #define TRACE_GRAPH_GRAPH_TIME 0x400
  760. #define TRACE_GRAPH_PRINT_RETVAL 0x800
  761. #define TRACE_GRAPH_PRINT_RETVAL_HEX 0x1000
  762. #define TRACE_GRAPH_PRINT_FILL_SHIFT 28
  763. #define TRACE_GRAPH_PRINT_FILL_MASK (0x3 << TRACE_GRAPH_PRINT_FILL_SHIFT)
  764. extern void ftrace_graph_sleep_time_control(bool enable);
  765. #ifdef CONFIG_FUNCTION_PROFILER
  766. extern void ftrace_graph_graph_time_control(bool enable);
  767. #else
  768. static inline void ftrace_graph_graph_time_control(bool enable) { }
  769. #endif
  770. extern enum print_line_t
  771. print_graph_function_flags(struct trace_iterator *iter, u32 flags);
  772. extern void print_graph_headers_flags(struct seq_file *s, u32 flags);
  773. extern void
  774. trace_print_graph_duration(unsigned long long duration, struct trace_seq *s);
  775. extern void graph_trace_open(struct trace_iterator *iter);
  776. extern void graph_trace_close(struct trace_iterator *iter);
  777. extern int __trace_graph_entry(struct trace_array *tr,
  778. struct ftrace_graph_ent *trace,
  779. unsigned int trace_ctx);
  780. extern void __trace_graph_return(struct trace_array *tr,
  781. struct ftrace_graph_ret *trace,
  782. unsigned int trace_ctx);
  783. extern void init_array_fgraph_ops(struct trace_array *tr, struct ftrace_ops *ops);
  784. extern int allocate_fgraph_ops(struct trace_array *tr, struct ftrace_ops *ops);
  785. extern void free_fgraph_ops(struct trace_array *tr);
  786. enum {
  787. TRACE_GRAPH_FL = 1,
  788. /*
  789. * In the very unlikely case that an interrupt came in
  790. * at a start of graph tracing, and we want to trace
  791. * the function in that interrupt, the depth can be greater
  792. * than zero, because of the preempted start of a previous
  793. * trace. In an even more unlikely case, depth could be 2
  794. * if a softirq interrupted the start of graph tracing,
  795. * followed by an interrupt preempting a start of graph
  796. * tracing in the softirq, and depth can even be 3
  797. * if an NMI came in at the start of an interrupt function
  798. * that preempted a softirq start of a function that
  799. * preempted normal context!!!! Luckily, it can't be
  800. * greater than 3, so the next two bits are a mask
  801. * of what the depth is when we set TRACE_GRAPH_FL
  802. */
  803. TRACE_GRAPH_DEPTH_START_BIT,
  804. TRACE_GRAPH_DEPTH_END_BIT,
  805. /*
  806. * To implement set_graph_notrace, if this bit is set, we ignore
  807. * function graph tracing of called functions, until the return
  808. * function is called to clear it.
  809. */
  810. TRACE_GRAPH_NOTRACE_BIT,
  811. };
  812. #define TRACE_GRAPH_NOTRACE (1 << TRACE_GRAPH_NOTRACE_BIT)
  813. static inline unsigned long ftrace_graph_depth(unsigned long *task_var)
  814. {
  815. return (*task_var >> TRACE_GRAPH_DEPTH_START_BIT) & 3;
  816. }
  817. static inline void ftrace_graph_set_depth(unsigned long *task_var, int depth)
  818. {
  819. *task_var &= ~(3 << TRACE_GRAPH_DEPTH_START_BIT);
  820. *task_var |= (depth & 3) << TRACE_GRAPH_DEPTH_START_BIT;
  821. }
  822. #ifdef CONFIG_DYNAMIC_FTRACE
  823. extern struct ftrace_hash __rcu *ftrace_graph_hash;
  824. extern struct ftrace_hash __rcu *ftrace_graph_notrace_hash;
  825. static inline int
  826. ftrace_graph_addr(unsigned long *task_var, struct ftrace_graph_ent *trace)
  827. {
  828. unsigned long addr = trace->func;
  829. int ret = 0;
  830. struct ftrace_hash *hash;
  831. preempt_disable_notrace();
  832. /*
  833. * Have to open code "rcu_dereference_sched()" because the
  834. * function graph tracer can be called when RCU is not
  835. * "watching".
  836. * Protected with schedule_on_each_cpu(ftrace_sync)
  837. */
  838. hash = rcu_dereference_protected(ftrace_graph_hash, !preemptible());
  839. if (ftrace_hash_empty(hash)) {
  840. ret = 1;
  841. goto out;
  842. }
  843. if (ftrace_lookup_ip(hash, addr)) {
  844. /*
  845. * This needs to be cleared on the return functions
  846. * when the depth is zero.
  847. */
  848. *task_var |= TRACE_GRAPH_FL;
  849. ftrace_graph_set_depth(task_var, trace->depth);
  850. /*
  851. * If no irqs are to be traced, but a set_graph_function
  852. * is set, and called by an interrupt handler, we still
  853. * want to trace it.
  854. */
  855. if (in_hardirq())
  856. trace_recursion_set(TRACE_IRQ_BIT);
  857. else
  858. trace_recursion_clear(TRACE_IRQ_BIT);
  859. ret = 1;
  860. }
  861. out:
  862. preempt_enable_notrace();
  863. return ret;
  864. }
  865. static inline void
  866. ftrace_graph_addr_finish(struct fgraph_ops *gops, struct ftrace_graph_ret *trace)
  867. {
  868. unsigned long *task_var = fgraph_get_task_var(gops);
  869. if ((*task_var & TRACE_GRAPH_FL) &&
  870. trace->depth == ftrace_graph_depth(task_var))
  871. *task_var &= ~TRACE_GRAPH_FL;
  872. }
  873. static inline int ftrace_graph_notrace_addr(unsigned long addr)
  874. {
  875. int ret = 0;
  876. struct ftrace_hash *notrace_hash;
  877. preempt_disable_notrace();
  878. /*
  879. * Have to open code "rcu_dereference_sched()" because the
  880. * function graph tracer can be called when RCU is not
  881. * "watching".
  882. * Protected with schedule_on_each_cpu(ftrace_sync)
  883. */
  884. notrace_hash = rcu_dereference_protected(ftrace_graph_notrace_hash,
  885. !preemptible());
  886. if (ftrace_lookup_ip(notrace_hash, addr))
  887. ret = 1;
  888. preempt_enable_notrace();
  889. return ret;
  890. }
  891. #else
  892. static inline int ftrace_graph_addr(unsigned long *task_var, struct ftrace_graph_ent *trace)
  893. {
  894. return 1;
  895. }
  896. static inline int ftrace_graph_notrace_addr(unsigned long addr)
  897. {
  898. return 0;
  899. }
  900. static inline void ftrace_graph_addr_finish(struct fgraph_ops *gops, struct ftrace_graph_ret *trace)
  901. { }
  902. #endif /* CONFIG_DYNAMIC_FTRACE */
  903. extern unsigned int fgraph_max_depth;
  904. static inline bool
  905. ftrace_graph_ignore_func(struct fgraph_ops *gops, struct ftrace_graph_ent *trace)
  906. {
  907. unsigned long *task_var = fgraph_get_task_var(gops);
  908. /* trace it when it is-nested-in or is a function enabled. */
  909. return !((*task_var & TRACE_GRAPH_FL) ||
  910. ftrace_graph_addr(task_var, trace)) ||
  911. (trace->depth < 0) ||
  912. (fgraph_max_depth && trace->depth >= fgraph_max_depth);
  913. }
  914. void fgraph_init_ops(struct ftrace_ops *dst_ops,
  915. struct ftrace_ops *src_ops);
  916. #else /* CONFIG_FUNCTION_GRAPH_TRACER */
  917. static inline enum print_line_t
  918. print_graph_function_flags(struct trace_iterator *iter, u32 flags)
  919. {
  920. return TRACE_TYPE_UNHANDLED;
  921. }
  922. static inline void free_fgraph_ops(struct trace_array *tr) { }
  923. /* ftrace_ops may not be defined */
  924. #define init_array_fgraph_ops(tr, ops) do { } while (0)
  925. #define allocate_fgraph_ops(tr, ops) ({ 0; })
  926. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  927. extern struct list_head ftrace_pids;
  928. #ifdef CONFIG_FUNCTION_TRACER
  929. #define FTRACE_PID_IGNORE -1
  930. #define FTRACE_PID_TRACE -2
  931. struct ftrace_func_command {
  932. struct list_head list;
  933. char *name;
  934. int (*func)(struct trace_array *tr,
  935. struct ftrace_hash *hash,
  936. char *func, char *cmd,
  937. char *params, int enable);
  938. };
  939. extern bool ftrace_filter_param __initdata;
  940. static inline int ftrace_trace_task(struct trace_array *tr)
  941. {
  942. return this_cpu_read(tr->array_buffer.data->ftrace_ignore_pid) !=
  943. FTRACE_PID_IGNORE;
  944. }
  945. extern int ftrace_is_dead(void);
  946. int ftrace_create_function_files(struct trace_array *tr,
  947. struct dentry *parent);
  948. void ftrace_destroy_function_files(struct trace_array *tr);
  949. int ftrace_allocate_ftrace_ops(struct trace_array *tr);
  950. void ftrace_free_ftrace_ops(struct trace_array *tr);
  951. void ftrace_init_global_array_ops(struct trace_array *tr);
  952. void ftrace_init_array_ops(struct trace_array *tr, ftrace_func_t func);
  953. void ftrace_reset_array_ops(struct trace_array *tr);
  954. void ftrace_init_tracefs(struct trace_array *tr, struct dentry *d_tracer);
  955. void ftrace_init_tracefs_toplevel(struct trace_array *tr,
  956. struct dentry *d_tracer);
  957. void ftrace_clear_pids(struct trace_array *tr);
  958. int init_function_trace(void);
  959. void ftrace_pid_follow_fork(struct trace_array *tr, bool enable);
  960. #else
  961. static inline int ftrace_trace_task(struct trace_array *tr)
  962. {
  963. return 1;
  964. }
  965. static inline int ftrace_is_dead(void) { return 0; }
  966. static inline int
  967. ftrace_create_function_files(struct trace_array *tr,
  968. struct dentry *parent)
  969. {
  970. return 0;
  971. }
  972. static inline int ftrace_allocate_ftrace_ops(struct trace_array *tr)
  973. {
  974. return 0;
  975. }
  976. static inline void ftrace_free_ftrace_ops(struct trace_array *tr) { }
  977. static inline void ftrace_destroy_function_files(struct trace_array *tr) { }
  978. static inline __init void
  979. ftrace_init_global_array_ops(struct trace_array *tr) { }
  980. static inline void ftrace_reset_array_ops(struct trace_array *tr) { }
  981. static inline void ftrace_init_tracefs(struct trace_array *tr, struct dentry *d) { }
  982. static inline void ftrace_init_tracefs_toplevel(struct trace_array *tr, struct dentry *d) { }
  983. static inline void ftrace_clear_pids(struct trace_array *tr) { }
  984. static inline int init_function_trace(void) { return 0; }
  985. static inline void ftrace_pid_follow_fork(struct trace_array *tr, bool enable) { }
  986. /* ftace_func_t type is not defined, use macro instead of static inline */
  987. #define ftrace_init_array_ops(tr, func) do { } while (0)
  988. #endif /* CONFIG_FUNCTION_TRACER */
  989. #if defined(CONFIG_FUNCTION_TRACER) && defined(CONFIG_DYNAMIC_FTRACE)
  990. struct ftrace_probe_ops {
  991. void (*func)(unsigned long ip,
  992. unsigned long parent_ip,
  993. struct trace_array *tr,
  994. struct ftrace_probe_ops *ops,
  995. void *data);
  996. int (*init)(struct ftrace_probe_ops *ops,
  997. struct trace_array *tr,
  998. unsigned long ip, void *init_data,
  999. void **data);
  1000. void (*free)(struct ftrace_probe_ops *ops,
  1001. struct trace_array *tr,
  1002. unsigned long ip, void *data);
  1003. int (*print)(struct seq_file *m,
  1004. unsigned long ip,
  1005. struct ftrace_probe_ops *ops,
  1006. void *data);
  1007. };
  1008. struct ftrace_func_mapper;
  1009. typedef int (*ftrace_mapper_func)(void *data);
  1010. struct ftrace_func_mapper *allocate_ftrace_func_mapper(void);
  1011. void **ftrace_func_mapper_find_ip(struct ftrace_func_mapper *mapper,
  1012. unsigned long ip);
  1013. int ftrace_func_mapper_add_ip(struct ftrace_func_mapper *mapper,
  1014. unsigned long ip, void *data);
  1015. void *ftrace_func_mapper_remove_ip(struct ftrace_func_mapper *mapper,
  1016. unsigned long ip);
  1017. void free_ftrace_func_mapper(struct ftrace_func_mapper *mapper,
  1018. ftrace_mapper_func free_func);
  1019. extern int
  1020. register_ftrace_function_probe(char *glob, struct trace_array *tr,
  1021. struct ftrace_probe_ops *ops, void *data);
  1022. extern int
  1023. unregister_ftrace_function_probe_func(char *glob, struct trace_array *tr,
  1024. struct ftrace_probe_ops *ops);
  1025. extern void clear_ftrace_function_probes(struct trace_array *tr);
  1026. int register_ftrace_command(struct ftrace_func_command *cmd);
  1027. int unregister_ftrace_command(struct ftrace_func_command *cmd);
  1028. void ftrace_create_filter_files(struct ftrace_ops *ops,
  1029. struct dentry *parent);
  1030. void ftrace_destroy_filter_files(struct ftrace_ops *ops);
  1031. extern int ftrace_set_filter(struct ftrace_ops *ops, unsigned char *buf,
  1032. int len, int reset);
  1033. extern int ftrace_set_notrace(struct ftrace_ops *ops, unsigned char *buf,
  1034. int len, int reset);
  1035. #else
  1036. struct ftrace_func_command;
  1037. static inline __init int register_ftrace_command(struct ftrace_func_command *cmd)
  1038. {
  1039. return -EINVAL;
  1040. }
  1041. static inline __init int unregister_ftrace_command(char *cmd_name)
  1042. {
  1043. return -EINVAL;
  1044. }
  1045. static inline void clear_ftrace_function_probes(struct trace_array *tr)
  1046. {
  1047. }
  1048. /*
  1049. * The ops parameter passed in is usually undefined.
  1050. * This must be a macro.
  1051. */
  1052. #define ftrace_create_filter_files(ops, parent) do { } while (0)
  1053. #define ftrace_destroy_filter_files(ops) do { } while (0)
  1054. #endif /* CONFIG_FUNCTION_TRACER && CONFIG_DYNAMIC_FTRACE */
  1055. bool ftrace_event_is_function(struct trace_event_call *call);
  1056. /*
  1057. * struct trace_parser - servers for reading the user input separated by spaces
  1058. * @cont: set if the input is not complete - no final space char was found
  1059. * @buffer: holds the parsed user input
  1060. * @idx: user input length
  1061. * @size: buffer size
  1062. */
  1063. struct trace_parser {
  1064. bool cont;
  1065. bool fail;
  1066. char *buffer;
  1067. unsigned idx;
  1068. unsigned size;
  1069. };
  1070. static inline bool trace_parser_loaded(struct trace_parser *parser)
  1071. {
  1072. return !parser->fail && parser->idx != 0;
  1073. }
  1074. static inline bool trace_parser_cont(struct trace_parser *parser)
  1075. {
  1076. return parser->cont;
  1077. }
  1078. static inline void trace_parser_clear(struct trace_parser *parser)
  1079. {
  1080. parser->cont = false;
  1081. parser->idx = 0;
  1082. }
  1083. static inline void trace_parser_fail(struct trace_parser *parser)
  1084. {
  1085. parser->fail = true;
  1086. }
  1087. extern int trace_parser_get_init(struct trace_parser *parser, int size);
  1088. extern void trace_parser_put(struct trace_parser *parser);
  1089. extern int trace_get_user(struct trace_parser *parser, const char __user *ubuf,
  1090. size_t cnt, loff_t *ppos);
  1091. /*
  1092. * Only create function graph options if function graph is configured.
  1093. */
  1094. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  1095. # define FGRAPH_FLAGS \
  1096. C(DISPLAY_GRAPH, "display-graph"),
  1097. #else
  1098. # define FGRAPH_FLAGS
  1099. #endif
  1100. #ifdef CONFIG_BRANCH_TRACER
  1101. # define BRANCH_FLAGS \
  1102. C(BRANCH, "branch"),
  1103. #else
  1104. # define BRANCH_FLAGS
  1105. #endif
  1106. #ifdef CONFIG_FUNCTION_TRACER
  1107. # define FUNCTION_FLAGS \
  1108. C(FUNCTION, "function-trace"), \
  1109. C(FUNC_FORK, "function-fork"),
  1110. # define FUNCTION_DEFAULT_FLAGS TRACE_ITER_FUNCTION
  1111. #else
  1112. # define FUNCTION_FLAGS
  1113. # define FUNCTION_DEFAULT_FLAGS 0UL
  1114. # define TRACE_ITER_FUNC_FORK 0UL
  1115. #endif
  1116. #ifdef CONFIG_STACKTRACE
  1117. # define STACK_FLAGS \
  1118. C(STACKTRACE, "stacktrace"),
  1119. #else
  1120. # define STACK_FLAGS
  1121. #endif
  1122. /*
  1123. * trace_iterator_flags is an enumeration that defines bit
  1124. * positions into trace_flags that controls the output.
  1125. *
  1126. * NOTE: These bits must match the trace_options array in
  1127. * trace.c (this macro guarantees it).
  1128. */
  1129. #define TRACE_FLAGS \
  1130. C(PRINT_PARENT, "print-parent"), \
  1131. C(SYM_OFFSET, "sym-offset"), \
  1132. C(SYM_ADDR, "sym-addr"), \
  1133. C(VERBOSE, "verbose"), \
  1134. C(RAW, "raw"), \
  1135. C(HEX, "hex"), \
  1136. C(BIN, "bin"), \
  1137. C(BLOCK, "block"), \
  1138. C(FIELDS, "fields"), \
  1139. C(PRINTK, "trace_printk"), \
  1140. C(ANNOTATE, "annotate"), \
  1141. C(USERSTACKTRACE, "userstacktrace"), \
  1142. C(SYM_USEROBJ, "sym-userobj"), \
  1143. C(PRINTK_MSGONLY, "printk-msg-only"), \
  1144. C(CONTEXT_INFO, "context-info"), /* Print pid/cpu/time */ \
  1145. C(LATENCY_FMT, "latency-format"), \
  1146. C(RECORD_CMD, "record-cmd"), \
  1147. C(RECORD_TGID, "record-tgid"), \
  1148. C(OVERWRITE, "overwrite"), \
  1149. C(STOP_ON_FREE, "disable_on_free"), \
  1150. C(IRQ_INFO, "irq-info"), \
  1151. C(MARKERS, "markers"), \
  1152. C(EVENT_FORK, "event-fork"), \
  1153. C(TRACE_PRINTK, "trace_printk_dest"), \
  1154. C(PAUSE_ON_TRACE, "pause-on-trace"), \
  1155. C(HASH_PTR, "hash-ptr"), /* Print hashed pointer */ \
  1156. FUNCTION_FLAGS \
  1157. FGRAPH_FLAGS \
  1158. STACK_FLAGS \
  1159. BRANCH_FLAGS
  1160. /*
  1161. * By defining C, we can make TRACE_FLAGS a list of bit names
  1162. * that will define the bits for the flag masks.
  1163. */
  1164. #undef C
  1165. #define C(a, b) TRACE_ITER_##a##_BIT
  1166. enum trace_iterator_bits {
  1167. TRACE_FLAGS
  1168. /* Make sure we don't go more than we have bits for */
  1169. TRACE_ITER_LAST_BIT
  1170. };
  1171. /*
  1172. * By redefining C, we can make TRACE_FLAGS a list of masks that
  1173. * use the bits as defined above.
  1174. */
  1175. #undef C
  1176. #define C(a, b) TRACE_ITER_##a = (1 << TRACE_ITER_##a##_BIT)
  1177. enum trace_iterator_flags { TRACE_FLAGS };
  1178. /*
  1179. * TRACE_ITER_SYM_MASK masks the options in trace_flags that
  1180. * control the output of kernel symbols.
  1181. */
  1182. #define TRACE_ITER_SYM_MASK \
  1183. (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR)
  1184. extern struct tracer nop_trace;
  1185. #ifdef CONFIG_BRANCH_TRACER
  1186. extern int enable_branch_tracing(struct trace_array *tr);
  1187. extern void disable_branch_tracing(void);
  1188. static inline int trace_branch_enable(struct trace_array *tr)
  1189. {
  1190. if (tr->trace_flags & TRACE_ITER_BRANCH)
  1191. return enable_branch_tracing(tr);
  1192. return 0;
  1193. }
  1194. static inline void trace_branch_disable(void)
  1195. {
  1196. /* due to races, always disable */
  1197. disable_branch_tracing();
  1198. }
  1199. #else
  1200. static inline int trace_branch_enable(struct trace_array *tr)
  1201. {
  1202. return 0;
  1203. }
  1204. static inline void trace_branch_disable(void)
  1205. {
  1206. }
  1207. #endif /* CONFIG_BRANCH_TRACER */
  1208. /* set ring buffers to default size if not already done so */
  1209. int tracing_update_buffers(struct trace_array *tr);
  1210. union trace_synth_field {
  1211. u8 as_u8;
  1212. u16 as_u16;
  1213. u32 as_u32;
  1214. u64 as_u64;
  1215. struct trace_dynamic_info as_dynamic;
  1216. };
  1217. struct ftrace_event_field {
  1218. struct list_head link;
  1219. const char *name;
  1220. const char *type;
  1221. int filter_type;
  1222. int offset;
  1223. int size;
  1224. unsigned int is_signed:1;
  1225. unsigned int needs_test:1;
  1226. int len;
  1227. };
  1228. struct prog_entry;
  1229. struct event_filter {
  1230. struct prog_entry __rcu *prog;
  1231. char *filter_string;
  1232. };
  1233. struct event_subsystem {
  1234. struct list_head list;
  1235. const char *name;
  1236. struct event_filter *filter;
  1237. int ref_count;
  1238. };
  1239. struct trace_subsystem_dir {
  1240. struct list_head list;
  1241. struct event_subsystem *subsystem;
  1242. struct trace_array *tr;
  1243. struct eventfs_inode *ei;
  1244. int ref_count;
  1245. int nr_events;
  1246. };
  1247. extern int call_filter_check_discard(struct trace_event_call *call, void *rec,
  1248. struct trace_buffer *buffer,
  1249. struct ring_buffer_event *event);
  1250. void trace_buffer_unlock_commit_regs(struct trace_array *tr,
  1251. struct trace_buffer *buffer,
  1252. struct ring_buffer_event *event,
  1253. unsigned int trcace_ctx,
  1254. struct pt_regs *regs);
  1255. static inline void trace_buffer_unlock_commit(struct trace_array *tr,
  1256. struct trace_buffer *buffer,
  1257. struct ring_buffer_event *event,
  1258. unsigned int trace_ctx)
  1259. {
  1260. trace_buffer_unlock_commit_regs(tr, buffer, event, trace_ctx, NULL);
  1261. }
  1262. DECLARE_PER_CPU(bool, trace_taskinfo_save);
  1263. int trace_save_cmdline(struct task_struct *tsk);
  1264. int trace_create_savedcmd(void);
  1265. int trace_alloc_tgid_map(void);
  1266. void trace_free_saved_cmdlines_buffer(void);
  1267. extern const struct file_operations tracing_saved_cmdlines_fops;
  1268. extern const struct file_operations tracing_saved_tgids_fops;
  1269. extern const struct file_operations tracing_saved_cmdlines_size_fops;
  1270. DECLARE_PER_CPU(struct ring_buffer_event *, trace_buffered_event);
  1271. DECLARE_PER_CPU(int, trace_buffered_event_cnt);
  1272. void trace_buffered_event_disable(void);
  1273. void trace_buffered_event_enable(void);
  1274. void early_enable_events(struct trace_array *tr, char *buf, bool disable_first);
  1275. static inline void
  1276. __trace_event_discard_commit(struct trace_buffer *buffer,
  1277. struct ring_buffer_event *event)
  1278. {
  1279. if (this_cpu_read(trace_buffered_event) == event) {
  1280. /* Simply release the temp buffer and enable preemption */
  1281. this_cpu_dec(trace_buffered_event_cnt);
  1282. preempt_enable_notrace();
  1283. return;
  1284. }
  1285. /* ring_buffer_discard_commit() enables preemption */
  1286. ring_buffer_discard_commit(buffer, event);
  1287. }
  1288. /*
  1289. * Helper function for event_trigger_unlock_commit{_regs}().
  1290. * If there are event triggers attached to this event that requires
  1291. * filtering against its fields, then they will be called as the
  1292. * entry already holds the field information of the current event.
  1293. *
  1294. * It also checks if the event should be discarded or not.
  1295. * It is to be discarded if the event is soft disabled and the
  1296. * event was only recorded to process triggers, or if the event
  1297. * filter is active and this event did not match the filters.
  1298. *
  1299. * Returns true if the event is discarded, false otherwise.
  1300. */
  1301. static inline bool
  1302. __event_trigger_test_discard(struct trace_event_file *file,
  1303. struct trace_buffer *buffer,
  1304. struct ring_buffer_event *event,
  1305. void *entry,
  1306. enum event_trigger_type *tt)
  1307. {
  1308. unsigned long eflags = file->flags;
  1309. if (eflags & EVENT_FILE_FL_TRIGGER_COND)
  1310. *tt = event_triggers_call(file, buffer, entry, event);
  1311. if (likely(!(file->flags & (EVENT_FILE_FL_SOFT_DISABLED |
  1312. EVENT_FILE_FL_FILTERED |
  1313. EVENT_FILE_FL_PID_FILTER))))
  1314. return false;
  1315. if (file->flags & EVENT_FILE_FL_SOFT_DISABLED)
  1316. goto discard;
  1317. if (file->flags & EVENT_FILE_FL_FILTERED &&
  1318. !filter_match_preds(file->filter, entry))
  1319. goto discard;
  1320. if ((file->flags & EVENT_FILE_FL_PID_FILTER) &&
  1321. trace_event_ignore_this_pid(file))
  1322. goto discard;
  1323. return false;
  1324. discard:
  1325. __trace_event_discard_commit(buffer, event);
  1326. return true;
  1327. }
  1328. /**
  1329. * event_trigger_unlock_commit - handle triggers and finish event commit
  1330. * @file: The file pointer associated with the event
  1331. * @buffer: The ring buffer that the event is being written to
  1332. * @event: The event meta data in the ring buffer
  1333. * @entry: The event itself
  1334. * @trace_ctx: The tracing context flags.
  1335. *
  1336. * This is a helper function to handle triggers that require data
  1337. * from the event itself. It also tests the event against filters and
  1338. * if the event is soft disabled and should be discarded.
  1339. */
  1340. static inline void
  1341. event_trigger_unlock_commit(struct trace_event_file *file,
  1342. struct trace_buffer *buffer,
  1343. struct ring_buffer_event *event,
  1344. void *entry, unsigned int trace_ctx)
  1345. {
  1346. enum event_trigger_type tt = ETT_NONE;
  1347. if (!__event_trigger_test_discard(file, buffer, event, entry, &tt))
  1348. trace_buffer_unlock_commit(file->tr, buffer, event, trace_ctx);
  1349. if (tt)
  1350. event_triggers_post_call(file, tt);
  1351. }
  1352. #define FILTER_PRED_INVALID ((unsigned short)-1)
  1353. #define FILTER_PRED_IS_RIGHT (1 << 15)
  1354. #define FILTER_PRED_FOLD (1 << 15)
  1355. /*
  1356. * The max preds is the size of unsigned short with
  1357. * two flags at the MSBs. One bit is used for both the IS_RIGHT
  1358. * and FOLD flags. The other is reserved.
  1359. *
  1360. * 2^14 preds is way more than enough.
  1361. */
  1362. #define MAX_FILTER_PRED 16384
  1363. struct filter_pred;
  1364. struct regex;
  1365. typedef int (*regex_match_func)(char *str, struct regex *r, int len);
  1366. enum regex_type {
  1367. MATCH_FULL = 0,
  1368. MATCH_FRONT_ONLY,
  1369. MATCH_MIDDLE_ONLY,
  1370. MATCH_END_ONLY,
  1371. MATCH_GLOB,
  1372. MATCH_INDEX,
  1373. };
  1374. struct regex {
  1375. char pattern[MAX_FILTER_STR_VAL];
  1376. int len;
  1377. int field_len;
  1378. regex_match_func match;
  1379. };
  1380. static inline bool is_string_field(struct ftrace_event_field *field)
  1381. {
  1382. return field->filter_type == FILTER_DYN_STRING ||
  1383. field->filter_type == FILTER_RDYN_STRING ||
  1384. field->filter_type == FILTER_STATIC_STRING ||
  1385. field->filter_type == FILTER_PTR_STRING ||
  1386. field->filter_type == FILTER_COMM;
  1387. }
  1388. static inline bool is_function_field(struct ftrace_event_field *field)
  1389. {
  1390. return field->filter_type == FILTER_TRACE_FN;
  1391. }
  1392. extern enum regex_type
  1393. filter_parse_regex(char *buff, int len, char **search, int *not);
  1394. extern void print_event_filter(struct trace_event_file *file,
  1395. struct trace_seq *s);
  1396. extern int apply_event_filter(struct trace_event_file *file,
  1397. char *filter_string);
  1398. extern int apply_subsystem_event_filter(struct trace_subsystem_dir *dir,
  1399. char *filter_string);
  1400. extern void print_subsystem_event_filter(struct event_subsystem *system,
  1401. struct trace_seq *s);
  1402. extern int filter_assign_type(const char *type);
  1403. extern int create_event_filter(struct trace_array *tr,
  1404. struct trace_event_call *call,
  1405. char *filter_str, bool set_str,
  1406. struct event_filter **filterp);
  1407. extern void free_event_filter(struct event_filter *filter);
  1408. struct ftrace_event_field *
  1409. trace_find_event_field(struct trace_event_call *call, char *name);
  1410. extern void trace_event_enable_cmd_record(bool enable);
  1411. extern void trace_event_enable_tgid_record(bool enable);
  1412. extern int event_trace_init(void);
  1413. extern int init_events(void);
  1414. extern int event_trace_add_tracer(struct dentry *parent, struct trace_array *tr);
  1415. extern int event_trace_del_tracer(struct trace_array *tr);
  1416. extern void __trace_early_add_events(struct trace_array *tr);
  1417. extern struct trace_event_file *__find_event_file(struct trace_array *tr,
  1418. const char *system,
  1419. const char *event);
  1420. extern struct trace_event_file *find_event_file(struct trace_array *tr,
  1421. const char *system,
  1422. const char *event);
  1423. static inline void *event_file_data(struct file *filp)
  1424. {
  1425. return READ_ONCE(file_inode(filp)->i_private);
  1426. }
  1427. extern struct mutex event_mutex;
  1428. extern struct list_head ftrace_events;
  1429. /*
  1430. * When the trace_event_file is the filp->i_private pointer,
  1431. * it must be taken under the event_mutex lock, and then checked
  1432. * if the EVENT_FILE_FL_FREED flag is set. If it is, then the
  1433. * data pointed to by the trace_event_file can not be trusted.
  1434. *
  1435. * Use the event_file_file() to access the trace_event_file from
  1436. * the filp the first time under the event_mutex and check for
  1437. * NULL. If it is needed to be retrieved again and the event_mutex
  1438. * is still held, then the event_file_data() can be used and it
  1439. * is guaranteed to be valid.
  1440. */
  1441. static inline struct trace_event_file *event_file_file(struct file *filp)
  1442. {
  1443. struct trace_event_file *file;
  1444. lockdep_assert_held(&event_mutex);
  1445. file = READ_ONCE(file_inode(filp)->i_private);
  1446. if (!file || file->flags & EVENT_FILE_FL_FREED)
  1447. return NULL;
  1448. return file;
  1449. }
  1450. extern const struct file_operations event_trigger_fops;
  1451. extern const struct file_operations event_hist_fops;
  1452. extern const struct file_operations event_hist_debug_fops;
  1453. extern const struct file_operations event_inject_fops;
  1454. #ifdef CONFIG_HIST_TRIGGERS
  1455. extern int register_trigger_hist_cmd(void);
  1456. extern int register_trigger_hist_enable_disable_cmds(void);
  1457. #else
  1458. static inline int register_trigger_hist_cmd(void) { return 0; }
  1459. static inline int register_trigger_hist_enable_disable_cmds(void) { return 0; }
  1460. #endif
  1461. extern int register_trigger_cmds(void);
  1462. extern void clear_event_triggers(struct trace_array *tr);
  1463. enum {
  1464. EVENT_TRIGGER_FL_PROBE = BIT(0),
  1465. };
  1466. struct event_trigger_data {
  1467. unsigned long count;
  1468. int ref;
  1469. int flags;
  1470. struct event_trigger_ops *ops;
  1471. struct event_command *cmd_ops;
  1472. struct event_filter __rcu *filter;
  1473. char *filter_str;
  1474. void *private_data;
  1475. bool paused;
  1476. bool paused_tmp;
  1477. struct list_head list;
  1478. char *name;
  1479. struct list_head named_list;
  1480. struct event_trigger_data *named_data;
  1481. };
  1482. /* Avoid typos */
  1483. #define ENABLE_EVENT_STR "enable_event"
  1484. #define DISABLE_EVENT_STR "disable_event"
  1485. #define ENABLE_HIST_STR "enable_hist"
  1486. #define DISABLE_HIST_STR "disable_hist"
  1487. struct enable_trigger_data {
  1488. struct trace_event_file *file;
  1489. bool enable;
  1490. bool hist;
  1491. };
  1492. extern int event_enable_trigger_print(struct seq_file *m,
  1493. struct event_trigger_data *data);
  1494. extern void event_enable_trigger_free(struct event_trigger_data *data);
  1495. extern int event_enable_trigger_parse(struct event_command *cmd_ops,
  1496. struct trace_event_file *file,
  1497. char *glob, char *cmd,
  1498. char *param_and_filter);
  1499. extern int event_enable_register_trigger(char *glob,
  1500. struct event_trigger_data *data,
  1501. struct trace_event_file *file);
  1502. extern void event_enable_unregister_trigger(char *glob,
  1503. struct event_trigger_data *test,
  1504. struct trace_event_file *file);
  1505. extern struct event_trigger_data *
  1506. trigger_data_alloc(struct event_command *cmd_ops, char *cmd, char *param,
  1507. void *private_data);
  1508. extern void trigger_data_free(struct event_trigger_data *data);
  1509. extern int event_trigger_init(struct event_trigger_data *data);
  1510. extern int trace_event_trigger_enable_disable(struct trace_event_file *file,
  1511. int trigger_enable);
  1512. extern void update_cond_flag(struct trace_event_file *file);
  1513. extern int set_trigger_filter(char *filter_str,
  1514. struct event_trigger_data *trigger_data,
  1515. struct trace_event_file *file);
  1516. extern struct event_trigger_data *find_named_trigger(const char *name);
  1517. extern bool is_named_trigger(struct event_trigger_data *test);
  1518. extern int save_named_trigger(const char *name,
  1519. struct event_trigger_data *data);
  1520. extern void del_named_trigger(struct event_trigger_data *data);
  1521. extern void pause_named_trigger(struct event_trigger_data *data);
  1522. extern void unpause_named_trigger(struct event_trigger_data *data);
  1523. extern void set_named_trigger_data(struct event_trigger_data *data,
  1524. struct event_trigger_data *named_data);
  1525. extern struct event_trigger_data *
  1526. get_named_trigger_data(struct event_trigger_data *data);
  1527. extern int register_event_command(struct event_command *cmd);
  1528. extern int unregister_event_command(struct event_command *cmd);
  1529. extern int register_trigger_hist_enable_disable_cmds(void);
  1530. extern bool event_trigger_check_remove(const char *glob);
  1531. extern bool event_trigger_empty_param(const char *param);
  1532. extern int event_trigger_separate_filter(char *param_and_filter, char **param,
  1533. char **filter, bool param_required);
  1534. extern int event_trigger_parse_num(char *trigger,
  1535. struct event_trigger_data *trigger_data);
  1536. extern int event_trigger_set_filter(struct event_command *cmd_ops,
  1537. struct trace_event_file *file,
  1538. char *param,
  1539. struct event_trigger_data *trigger_data);
  1540. extern void event_trigger_reset_filter(struct event_command *cmd_ops,
  1541. struct event_trigger_data *trigger_data);
  1542. extern int event_trigger_register(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_trigger_unregister(struct event_command *cmd_ops,
  1547. struct trace_event_file *file,
  1548. char *glob,
  1549. struct event_trigger_data *trigger_data);
  1550. extern void event_file_get(struct trace_event_file *file);
  1551. extern void event_file_put(struct trace_event_file *file);
  1552. /**
  1553. * struct event_trigger_ops - callbacks for trace event triggers
  1554. *
  1555. * The methods in this structure provide per-event trigger hooks for
  1556. * various trigger operations.
  1557. *
  1558. * The @init and @free methods are used during trigger setup and
  1559. * teardown, typically called from an event_command's @parse()
  1560. * function implementation.
  1561. *
  1562. * The @print method is used to print the trigger spec.
  1563. *
  1564. * The @trigger method is the function that actually implements the
  1565. * trigger and is called in the context of the triggering event
  1566. * whenever that event occurs.
  1567. *
  1568. * All the methods below, except for @init() and @free(), must be
  1569. * implemented.
  1570. *
  1571. * @trigger: The trigger 'probe' function called when the triggering
  1572. * event occurs. The data passed into this callback is the data
  1573. * that was supplied to the event_command @reg() function that
  1574. * registered the trigger (see struct event_command) along with
  1575. * the trace record, rec.
  1576. *
  1577. * @init: An optional initialization function called for the trigger
  1578. * when the trigger is registered (via the event_command reg()
  1579. * function). This can be used to perform per-trigger
  1580. * initialization such as incrementing a per-trigger reference
  1581. * count, for instance. This is usually implemented by the
  1582. * generic utility function @event_trigger_init() (see
  1583. * trace_event_triggers.c).
  1584. *
  1585. * @free: An optional de-initialization function called for the
  1586. * trigger when the trigger is unregistered (via the
  1587. * event_command @reg() function). This can be used to perform
  1588. * per-trigger de-initialization such as decrementing a
  1589. * per-trigger reference count and freeing corresponding trigger
  1590. * data, for instance. This is usually implemented by the
  1591. * generic utility function @event_trigger_free() (see
  1592. * trace_event_triggers.c).
  1593. *
  1594. * @print: The callback function invoked to have the trigger print
  1595. * itself. This is usually implemented by a wrapper function
  1596. * that calls the generic utility function @event_trigger_print()
  1597. * (see trace_event_triggers.c).
  1598. */
  1599. struct event_trigger_ops {
  1600. void (*trigger)(struct event_trigger_data *data,
  1601. struct trace_buffer *buffer,
  1602. void *rec,
  1603. struct ring_buffer_event *rbe);
  1604. int (*init)(struct event_trigger_data *data);
  1605. void (*free)(struct event_trigger_data *data);
  1606. int (*print)(struct seq_file *m,
  1607. struct event_trigger_data *data);
  1608. };
  1609. /**
  1610. * struct event_command - callbacks and data members for event commands
  1611. *
  1612. * Event commands are invoked by users by writing the command name
  1613. * into the 'trigger' file associated with a trace event. The
  1614. * parameters associated with a specific invocation of an event
  1615. * command are used to create an event trigger instance, which is
  1616. * added to the list of trigger instances associated with that trace
  1617. * event. When the event is hit, the set of triggers associated with
  1618. * that event is invoked.
  1619. *
  1620. * The data members in this structure provide per-event command data
  1621. * for various event commands.
  1622. *
  1623. * All the data members below, except for @post_trigger, must be set
  1624. * for each event command.
  1625. *
  1626. * @name: The unique name that identifies the event command. This is
  1627. * the name used when setting triggers via trigger files.
  1628. *
  1629. * @trigger_type: A unique id that identifies the event command
  1630. * 'type'. This value has two purposes, the first to ensure that
  1631. * only one trigger of the same type can be set at a given time
  1632. * for a particular event e.g. it doesn't make sense to have both
  1633. * a traceon and traceoff trigger attached to a single event at
  1634. * the same time, so traceon and traceoff have the same type
  1635. * though they have different names. The @trigger_type value is
  1636. * also used as a bit value for deferring the actual trigger
  1637. * action until after the current event is finished. Some
  1638. * commands need to do this if they themselves log to the trace
  1639. * buffer (see the @post_trigger() member below). @trigger_type
  1640. * values are defined by adding new values to the trigger_type
  1641. * enum in include/linux/trace_events.h.
  1642. *
  1643. * @flags: See the enum event_command_flags below.
  1644. *
  1645. * All the methods below, except for @set_filter() and @unreg_all(),
  1646. * must be implemented.
  1647. *
  1648. * @parse: The callback function responsible for parsing and
  1649. * registering the trigger written to the 'trigger' file by the
  1650. * user. It allocates the trigger instance and registers it with
  1651. * the appropriate trace event. It makes use of the other
  1652. * event_command callback functions to orchestrate this, and is
  1653. * usually implemented by the generic utility function
  1654. * @event_trigger_callback() (see trace_event_triggers.c).
  1655. *
  1656. * @reg: Adds the trigger to the list of triggers associated with the
  1657. * event, and enables the event trigger itself, after
  1658. * initializing it (via the event_trigger_ops @init() function).
  1659. * This is also where commands can use the @trigger_type value to
  1660. * make the decision as to whether or not multiple instances of
  1661. * the trigger should be allowed. This is usually implemented by
  1662. * the generic utility function @register_trigger() (see
  1663. * trace_event_triggers.c).
  1664. *
  1665. * @unreg: Removes the trigger from the list of triggers associated
  1666. * with the event, and disables the event trigger itself, after
  1667. * initializing it (via the event_trigger_ops @free() function).
  1668. * This is usually implemented by the generic utility function
  1669. * @unregister_trigger() (see trace_event_triggers.c).
  1670. *
  1671. * @unreg_all: An optional function called to remove all the triggers
  1672. * from the list of triggers associated with the event. Called
  1673. * when a trigger file is opened in truncate mode.
  1674. *
  1675. * @set_filter: An optional function called to parse and set a filter
  1676. * for the trigger. If no @set_filter() method is set for the
  1677. * event command, filters set by the user for the command will be
  1678. * ignored. This is usually implemented by the generic utility
  1679. * function @set_trigger_filter() (see trace_event_triggers.c).
  1680. *
  1681. * @get_trigger_ops: The callback function invoked to retrieve the
  1682. * event_trigger_ops implementation associated with the command.
  1683. * This callback function allows a single event_command to
  1684. * support multiple trigger implementations via different sets of
  1685. * event_trigger_ops, depending on the value of the @param
  1686. * string.
  1687. */
  1688. struct event_command {
  1689. struct list_head list;
  1690. char *name;
  1691. enum event_trigger_type trigger_type;
  1692. int flags;
  1693. int (*parse)(struct event_command *cmd_ops,
  1694. struct trace_event_file *file,
  1695. char *glob, char *cmd,
  1696. char *param_and_filter);
  1697. int (*reg)(char *glob,
  1698. struct event_trigger_data *data,
  1699. struct trace_event_file *file);
  1700. void (*unreg)(char *glob,
  1701. struct event_trigger_data *data,
  1702. struct trace_event_file *file);
  1703. void (*unreg_all)(struct trace_event_file *file);
  1704. int (*set_filter)(char *filter_str,
  1705. struct event_trigger_data *data,
  1706. struct trace_event_file *file);
  1707. struct event_trigger_ops *(*get_trigger_ops)(char *cmd, char *param);
  1708. };
  1709. /**
  1710. * enum event_command_flags - flags for struct event_command
  1711. *
  1712. * @POST_TRIGGER: A flag that says whether or not this command needs
  1713. * to have its action delayed until after the current event has
  1714. * been closed. Some triggers need to avoid being invoked while
  1715. * an event is currently in the process of being logged, since
  1716. * the trigger may itself log data into the trace buffer. Thus
  1717. * we make sure the current event is committed before invoking
  1718. * those triggers. To do that, the trigger invocation is split
  1719. * in two - the first part checks the filter using the current
  1720. * trace record; if a command has the @post_trigger flag set, it
  1721. * sets a bit for itself in the return value, otherwise it
  1722. * directly invokes the trigger. Once all commands have been
  1723. * either invoked or set their return flag, the current record is
  1724. * either committed or discarded. At that point, if any commands
  1725. * have deferred their triggers, those commands are finally
  1726. * invoked following the close of the current event. In other
  1727. * words, if the event_trigger_ops @func() probe implementation
  1728. * itself logs to the trace buffer, this flag should be set,
  1729. * otherwise it can be left unspecified.
  1730. *
  1731. * @NEEDS_REC: A flag that says whether or not this command needs
  1732. * access to the trace record in order to perform its function,
  1733. * regardless of whether or not it has a filter associated with
  1734. * it (filters make a trigger require access to the trace record
  1735. * but are not always present).
  1736. */
  1737. enum event_command_flags {
  1738. EVENT_CMD_FL_POST_TRIGGER = 1,
  1739. EVENT_CMD_FL_NEEDS_REC = 2,
  1740. };
  1741. static inline bool event_command_post_trigger(struct event_command *cmd_ops)
  1742. {
  1743. return cmd_ops->flags & EVENT_CMD_FL_POST_TRIGGER;
  1744. }
  1745. static inline bool event_command_needs_rec(struct event_command *cmd_ops)
  1746. {
  1747. return cmd_ops->flags & EVENT_CMD_FL_NEEDS_REC;
  1748. }
  1749. extern int trace_event_enable_disable(struct trace_event_file *file,
  1750. int enable, int soft_disable);
  1751. extern int tracing_alloc_snapshot(void);
  1752. extern void tracing_snapshot_cond(struct trace_array *tr, void *cond_data);
  1753. extern int tracing_snapshot_cond_enable(struct trace_array *tr, void *cond_data, cond_update_fn_t update);
  1754. extern int tracing_snapshot_cond_disable(struct trace_array *tr);
  1755. extern void *tracing_cond_snapshot_data(struct trace_array *tr);
  1756. extern const char *__start___trace_bprintk_fmt[];
  1757. extern const char *__stop___trace_bprintk_fmt[];
  1758. extern const char *__start___tracepoint_str[];
  1759. extern const char *__stop___tracepoint_str[];
  1760. void trace_printk_control(bool enabled);
  1761. void trace_printk_start_comm(void);
  1762. int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
  1763. int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
  1764. /* Used from boot time tracer */
  1765. extern int trace_set_options(struct trace_array *tr, char *option);
  1766. extern int tracing_set_tracer(struct trace_array *tr, const char *buf);
  1767. extern ssize_t tracing_resize_ring_buffer(struct trace_array *tr,
  1768. unsigned long size, int cpu_id);
  1769. extern int tracing_set_cpumask(struct trace_array *tr,
  1770. cpumask_var_t tracing_cpumask_new);
  1771. #define MAX_EVENT_NAME_LEN 64
  1772. extern ssize_t trace_parse_run_command(struct file *file,
  1773. const char __user *buffer, size_t count, loff_t *ppos,
  1774. int (*createfn)(const char *));
  1775. extern unsigned int err_pos(char *cmd, const char *str);
  1776. extern void tracing_log_err(struct trace_array *tr,
  1777. const char *loc, const char *cmd,
  1778. const char **errs, u8 type, u16 pos);
  1779. /*
  1780. * Normal trace_printk() and friends allocates special buffers
  1781. * to do the manipulation, as well as saves the print formats
  1782. * into sections to display. But the trace infrastructure wants
  1783. * to use these without the added overhead at the price of being
  1784. * a bit slower (used mainly for warnings, where we don't care
  1785. * about performance). The internal_trace_puts() is for such
  1786. * a purpose.
  1787. */
  1788. #define internal_trace_puts(str) __trace_puts(_THIS_IP_, str, strlen(str))
  1789. #undef FTRACE_ENTRY
  1790. #define FTRACE_ENTRY(call, struct_name, id, tstruct, print) \
  1791. extern struct trace_event_call \
  1792. __aligned(4) event_##call;
  1793. #undef FTRACE_ENTRY_DUP
  1794. #define FTRACE_ENTRY_DUP(call, struct_name, id, tstruct, print) \
  1795. FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print))
  1796. #undef FTRACE_ENTRY_PACKED
  1797. #define FTRACE_ENTRY_PACKED(call, struct_name, id, tstruct, print) \
  1798. FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print))
  1799. #include "trace_entries.h"
  1800. #if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_FUNCTION_TRACER)
  1801. int perf_ftrace_event_register(struct trace_event_call *call,
  1802. enum trace_reg type, void *data);
  1803. #else
  1804. #define perf_ftrace_event_register NULL
  1805. #endif
  1806. #ifdef CONFIG_FTRACE_SYSCALLS
  1807. void init_ftrace_syscalls(void);
  1808. const char *get_syscall_name(int syscall);
  1809. #else
  1810. static inline void init_ftrace_syscalls(void) { }
  1811. static inline const char *get_syscall_name(int syscall)
  1812. {
  1813. return NULL;
  1814. }
  1815. #endif
  1816. #ifdef CONFIG_EVENT_TRACING
  1817. void trace_event_init(void);
  1818. void trace_event_eval_update(struct trace_eval_map **map, int len);
  1819. /* Used from boot time tracer */
  1820. extern int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set);
  1821. extern int trigger_process_regex(struct trace_event_file *file, char *buff);
  1822. #else
  1823. static inline void __init trace_event_init(void) { }
  1824. static inline void trace_event_eval_update(struct trace_eval_map **map, int len) { }
  1825. #endif
  1826. #ifdef CONFIG_TRACER_SNAPSHOT
  1827. void tracing_snapshot_instance(struct trace_array *tr);
  1828. int tracing_alloc_snapshot_instance(struct trace_array *tr);
  1829. int tracing_arm_snapshot(struct trace_array *tr);
  1830. void tracing_disarm_snapshot(struct trace_array *tr);
  1831. #else
  1832. static inline void tracing_snapshot_instance(struct trace_array *tr) { }
  1833. static inline int tracing_alloc_snapshot_instance(struct trace_array *tr)
  1834. {
  1835. return 0;
  1836. }
  1837. static inline int tracing_arm_snapshot(struct trace_array *tr) { return 0; }
  1838. static inline void tracing_disarm_snapshot(struct trace_array *tr) { }
  1839. #endif
  1840. #ifdef CONFIG_PREEMPT_TRACER
  1841. void tracer_preempt_on(unsigned long a0, unsigned long a1);
  1842. void tracer_preempt_off(unsigned long a0, unsigned long a1);
  1843. #else
  1844. static inline void tracer_preempt_on(unsigned long a0, unsigned long a1) { }
  1845. static inline void tracer_preempt_off(unsigned long a0, unsigned long a1) { }
  1846. #endif
  1847. #ifdef CONFIG_IRQSOFF_TRACER
  1848. void tracer_hardirqs_on(unsigned long a0, unsigned long a1);
  1849. void tracer_hardirqs_off(unsigned long a0, unsigned long a1);
  1850. #else
  1851. static inline void tracer_hardirqs_on(unsigned long a0, unsigned long a1) { }
  1852. static inline void tracer_hardirqs_off(unsigned long a0, unsigned long a1) { }
  1853. #endif
  1854. /*
  1855. * Reset the state of the trace_iterator so that it can read consumed data.
  1856. * Normally, the trace_iterator is used for reading the data when it is not
  1857. * consumed, and must retain state.
  1858. */
  1859. static __always_inline void trace_iterator_reset(struct trace_iterator *iter)
  1860. {
  1861. memset_startat(iter, 0, seq);
  1862. iter->pos = -1;
  1863. }
  1864. /* Check the name is good for event/group/fields */
  1865. static inline bool __is_good_name(const char *name, bool hash_ok)
  1866. {
  1867. if (!isalpha(*name) && *name != '_' && (!hash_ok || *name != '-'))
  1868. return false;
  1869. while (*++name != '\0') {
  1870. if (!isalpha(*name) && !isdigit(*name) && *name != '_' &&
  1871. (!hash_ok || *name != '-'))
  1872. return false;
  1873. }
  1874. return true;
  1875. }
  1876. /* Check the name is good for event/group/fields */
  1877. static inline bool is_good_name(const char *name)
  1878. {
  1879. return __is_good_name(name, false);
  1880. }
  1881. /* Check the name is good for system */
  1882. static inline bool is_good_system_name(const char *name)
  1883. {
  1884. return __is_good_name(name, true);
  1885. }
  1886. /* Convert certain expected symbols into '_' when generating event names */
  1887. static inline void sanitize_event_name(char *name)
  1888. {
  1889. while (*name++ != '\0')
  1890. if (*name == ':' || *name == '.' || *name == '*')
  1891. *name = '_';
  1892. }
  1893. /*
  1894. * This is a generic way to read and write a u64 value from a file in tracefs.
  1895. *
  1896. * The value is stored on the variable pointed by *val. The value needs
  1897. * to be at least *min and at most *max. The write is protected by an
  1898. * existing *lock.
  1899. */
  1900. struct trace_min_max_param {
  1901. struct mutex *lock;
  1902. u64 *val;
  1903. u64 *min;
  1904. u64 *max;
  1905. };
  1906. #define U64_STR_SIZE 24 /* 20 digits max */
  1907. extern const struct file_operations trace_min_max_fops;
  1908. #ifdef CONFIG_RV
  1909. extern int rv_init_interface(void);
  1910. #else
  1911. static inline int rv_init_interface(void)
  1912. {
  1913. return 0;
  1914. }
  1915. #endif
  1916. /*
  1917. * This is used only to distinguish
  1918. * function address from trampoline code.
  1919. * So this value has no meaning.
  1920. */
  1921. #define FTRACE_TRAMPOLINE_MARKER ((unsigned long) INT_MAX)
  1922. #endif /* _LINUX_KERNEL_TRACE_H */