ftrace.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  1. /*
  2. * Ftrace header. For implementation details beyond the random comments
  3. * scattered below, see: Documentation/trace/ftrace-design.txt
  4. */
  5. #ifndef _LINUX_FTRACE_H
  6. #define _LINUX_FTRACE_H
  7. #include <linux/trace_clock.h>
  8. #include <linux/kallsyms.h>
  9. #include <linux/linkage.h>
  10. #include <linux/bitops.h>
  11. #include <linux/ptrace.h>
  12. #include <linux/ktime.h>
  13. #include <linux/sched.h>
  14. #include <linux/types.h>
  15. #include <linux/init.h>
  16. #include <linux/fs.h>
  17. #include <asm/ftrace.h>
  18. /*
  19. * If the arch supports passing the variable contents of
  20. * function_trace_op as the third parameter back from the
  21. * mcount call, then the arch should define this as 1.
  22. */
  23. #ifndef ARCH_SUPPORTS_FTRACE_OPS
  24. #define ARCH_SUPPORTS_FTRACE_OPS 0
  25. #endif
  26. /*
  27. * If the arch's mcount caller does not support all of ftrace's
  28. * features, then it must call an indirect function that
  29. * does. Or at least does enough to prevent any unwelcomed side effects.
  30. */
  31. #if !ARCH_SUPPORTS_FTRACE_OPS
  32. # define FTRACE_FORCE_LIST_FUNC 1
  33. #else
  34. # define FTRACE_FORCE_LIST_FUNC 0
  35. #endif
  36. struct module;
  37. struct ftrace_hash;
  38. #ifdef CONFIG_FUNCTION_TRACER
  39. extern int ftrace_enabled;
  40. extern int
  41. ftrace_enable_sysctl(struct ctl_table *table, int write,
  42. void __user *buffer, size_t *lenp,
  43. loff_t *ppos);
  44. struct ftrace_ops;
  45. typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip,
  46. struct ftrace_ops *op, struct pt_regs *regs);
  47. /*
  48. * FTRACE_OPS_FL_* bits denote the state of ftrace_ops struct and are
  49. * set in the flags member.
  50. *
  51. * ENABLED - set/unset when ftrace_ops is registered/unregistered
  52. * DYNAMIC - set when ftrace_ops is registered to denote dynamically
  53. * allocated ftrace_ops which need special care
  54. * CONTROL - set manualy by ftrace_ops user to denote the ftrace_ops
  55. * could be controled by following calls:
  56. * ftrace_function_local_enable
  57. * ftrace_function_local_disable
  58. * SAVE_REGS - The ftrace_ops wants regs saved at each function called
  59. * and passed to the callback. If this flag is set, but the
  60. * architecture does not support passing regs
  61. * (CONFIG_DYNAMIC_FTRACE_WITH_REGS is not defined), then the
  62. * ftrace_ops will fail to register, unless the next flag
  63. * is set.
  64. * SAVE_REGS_IF_SUPPORTED - This is the same as SAVE_REGS, but if the
  65. * handler can handle an arch that does not save regs
  66. * (the handler tests if regs == NULL), then it can set
  67. * this flag instead. It will not fail registering the ftrace_ops
  68. * but, the regs field will be NULL if the arch does not support
  69. * passing regs to the handler.
  70. * Note, if this flag is set, the SAVE_REGS flag will automatically
  71. * get set upon registering the ftrace_ops, if the arch supports it.
  72. * RECURSION_SAFE - The ftrace_ops can set this to tell the ftrace infrastructure
  73. * that the call back has its own recursion protection. If it does
  74. * not set this, then the ftrace infrastructure will add recursion
  75. * protection for the caller.
  76. * STUB - The ftrace_ops is just a place holder.
  77. * INITIALIZED - The ftrace_ops has already been initialized (first use time
  78. * register_ftrace_function() is called, it will initialized the ops)
  79. * DELETED - The ops are being deleted, do not let them be registered again.
  80. */
  81. enum {
  82. FTRACE_OPS_FL_ENABLED = 1 << 0,
  83. FTRACE_OPS_FL_DYNAMIC = 1 << 1,
  84. FTRACE_OPS_FL_CONTROL = 1 << 2,
  85. FTRACE_OPS_FL_SAVE_REGS = 1 << 3,
  86. FTRACE_OPS_FL_SAVE_REGS_IF_SUPPORTED = 1 << 4,
  87. FTRACE_OPS_FL_RECURSION_SAFE = 1 << 5,
  88. FTRACE_OPS_FL_STUB = 1 << 6,
  89. FTRACE_OPS_FL_INITIALIZED = 1 << 7,
  90. FTRACE_OPS_FL_DELETED = 1 << 8,
  91. };
  92. #ifdef CONFIG_DYNAMIC_FTRACE
  93. /* The hash used to know what functions callbacks trace */
  94. struct ftrace_ops_hash {
  95. struct ftrace_hash *notrace_hash;
  96. struct ftrace_hash *filter_hash;
  97. struct mutex regex_lock;
  98. };
  99. #endif
  100. /*
  101. * Note, ftrace_ops can be referenced outside of RCU protection.
  102. * (Although, for perf, the control ops prevent that). If ftrace_ops is
  103. * allocated and not part of kernel core data, the unregistering of it will
  104. * perform a scheduling on all CPUs to make sure that there are no more users.
  105. * Depending on the load of the system that may take a bit of time.
  106. *
  107. * Any private data added must also take care not to be freed and if private
  108. * data is added to a ftrace_ops that is in core code, the user of the
  109. * ftrace_ops must perform a schedule_on_each_cpu() before freeing it.
  110. */
  111. struct ftrace_ops {
  112. ftrace_func_t func;
  113. struct ftrace_ops *next;
  114. unsigned long flags;
  115. void *private;
  116. int __percpu *disabled;
  117. #ifdef CONFIG_DYNAMIC_FTRACE
  118. int nr_trampolines;
  119. struct ftrace_ops_hash local_hash;
  120. struct ftrace_ops_hash *func_hash;
  121. struct ftrace_hash *tramp_hash;
  122. unsigned long trampoline;
  123. #endif
  124. };
  125. /*
  126. * Type of the current tracing.
  127. */
  128. enum ftrace_tracing_type_t {
  129. FTRACE_TYPE_ENTER = 0, /* Hook the call of the function */
  130. FTRACE_TYPE_RETURN, /* Hook the return of the function */
  131. };
  132. /* Current tracing type, default is FTRACE_TYPE_ENTER */
  133. extern enum ftrace_tracing_type_t ftrace_tracing_type;
  134. /*
  135. * The ftrace_ops must be a static and should also
  136. * be read_mostly. These functions do modify read_mostly variables
  137. * so use them sparely. Never free an ftrace_op or modify the
  138. * next pointer after it has been registered. Even after unregistering
  139. * it, the next pointer may still be used internally.
  140. */
  141. int register_ftrace_function(struct ftrace_ops *ops);
  142. int unregister_ftrace_function(struct ftrace_ops *ops);
  143. void clear_ftrace_function(void);
  144. /**
  145. * ftrace_function_local_enable - enable controlled ftrace_ops on current cpu
  146. *
  147. * This function enables tracing on current cpu by decreasing
  148. * the per cpu control variable.
  149. * It must be called with preemption disabled and only on ftrace_ops
  150. * registered with FTRACE_OPS_FL_CONTROL. If called without preemption
  151. * disabled, this_cpu_ptr will complain when CONFIG_DEBUG_PREEMPT is enabled.
  152. */
  153. static inline void ftrace_function_local_enable(struct ftrace_ops *ops)
  154. {
  155. if (WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_CONTROL)))
  156. return;
  157. (*this_cpu_ptr(ops->disabled))--;
  158. }
  159. /**
  160. * ftrace_function_local_disable - enable controlled ftrace_ops on current cpu
  161. *
  162. * This function enables tracing on current cpu by decreasing
  163. * the per cpu control variable.
  164. * It must be called with preemption disabled and only on ftrace_ops
  165. * registered with FTRACE_OPS_FL_CONTROL. If called without preemption
  166. * disabled, this_cpu_ptr will complain when CONFIG_DEBUG_PREEMPT is enabled.
  167. */
  168. static inline void ftrace_function_local_disable(struct ftrace_ops *ops)
  169. {
  170. if (WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_CONTROL)))
  171. return;
  172. (*this_cpu_ptr(ops->disabled))++;
  173. }
  174. /**
  175. * ftrace_function_local_disabled - returns ftrace_ops disabled value
  176. * on current cpu
  177. *
  178. * This function returns value of ftrace_ops::disabled on current cpu.
  179. * It must be called with preemption disabled and only on ftrace_ops
  180. * registered with FTRACE_OPS_FL_CONTROL. If called without preemption
  181. * disabled, this_cpu_ptr will complain when CONFIG_DEBUG_PREEMPT is enabled.
  182. */
  183. static inline int ftrace_function_local_disabled(struct ftrace_ops *ops)
  184. {
  185. WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_CONTROL));
  186. return *this_cpu_ptr(ops->disabled);
  187. }
  188. extern void ftrace_stub(unsigned long a0, unsigned long a1,
  189. struct ftrace_ops *op, struct pt_regs *regs);
  190. #else /* !CONFIG_FUNCTION_TRACER */
  191. /*
  192. * (un)register_ftrace_function must be a macro since the ops parameter
  193. * must not be evaluated.
  194. */
  195. #define register_ftrace_function(ops) ({ 0; })
  196. #define unregister_ftrace_function(ops) ({ 0; })
  197. static inline int ftrace_nr_registered_ops(void)
  198. {
  199. return 0;
  200. }
  201. static inline void clear_ftrace_function(void) { }
  202. static inline void ftrace_kill(void) { }
  203. #endif /* CONFIG_FUNCTION_TRACER */
  204. #ifdef CONFIG_STACK_TRACER
  205. extern int stack_tracer_enabled;
  206. int
  207. stack_trace_sysctl(struct ctl_table *table, int write,
  208. void __user *buffer, size_t *lenp,
  209. loff_t *ppos);
  210. #endif
  211. struct ftrace_func_command {
  212. struct list_head list;
  213. char *name;
  214. int (*func)(struct ftrace_hash *hash,
  215. char *func, char *cmd,
  216. char *params, int enable);
  217. };
  218. #ifdef CONFIG_DYNAMIC_FTRACE
  219. int ftrace_arch_code_modify_prepare(void);
  220. int ftrace_arch_code_modify_post_process(void);
  221. void ftrace_bug(int err, unsigned long ip);
  222. struct seq_file;
  223. struct ftrace_probe_ops {
  224. void (*func)(unsigned long ip,
  225. unsigned long parent_ip,
  226. void **data);
  227. int (*init)(struct ftrace_probe_ops *ops,
  228. unsigned long ip, void **data);
  229. void (*free)(struct ftrace_probe_ops *ops,
  230. unsigned long ip, void **data);
  231. int (*print)(struct seq_file *m,
  232. unsigned long ip,
  233. struct ftrace_probe_ops *ops,
  234. void *data);
  235. };
  236. extern int
  237. register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
  238. void *data);
  239. extern void
  240. unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
  241. void *data);
  242. extern void
  243. unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops);
  244. extern void unregister_ftrace_function_probe_all(char *glob);
  245. extern int ftrace_text_reserved(const void *start, const void *end);
  246. extern int ftrace_nr_registered_ops(void);
  247. /*
  248. * The dyn_ftrace record's flags field is split into two parts.
  249. * the first part which is '0-FTRACE_REF_MAX' is a counter of
  250. * the number of callbacks that have registered the function that
  251. * the dyn_ftrace descriptor represents.
  252. *
  253. * The second part is a mask:
  254. * ENABLED - the function is being traced
  255. * REGS - the record wants the function to save regs
  256. * REGS_EN - the function is set up to save regs.
  257. *
  258. * When a new ftrace_ops is registered and wants a function to save
  259. * pt_regs, the rec->flag REGS is set. When the function has been
  260. * set up to save regs, the REG_EN flag is set. Once a function
  261. * starts saving regs it will do so until all ftrace_ops are removed
  262. * from tracing that function.
  263. */
  264. enum {
  265. FTRACE_FL_ENABLED = (1UL << 31),
  266. FTRACE_FL_REGS = (1UL << 30),
  267. FTRACE_FL_REGS_EN = (1UL << 29),
  268. FTRACE_FL_TRAMP = (1UL << 28),
  269. FTRACE_FL_TRAMP_EN = (1UL << 27),
  270. };
  271. #define FTRACE_REF_MAX_SHIFT 27
  272. #define FTRACE_FL_BITS 5
  273. #define FTRACE_FL_MASKED_BITS ((1UL << FTRACE_FL_BITS) - 1)
  274. #define FTRACE_FL_MASK (FTRACE_FL_MASKED_BITS << FTRACE_REF_MAX_SHIFT)
  275. #define FTRACE_REF_MAX ((1UL << FTRACE_REF_MAX_SHIFT) - 1)
  276. #define ftrace_rec_count(rec) ((rec)->flags & ~FTRACE_FL_MASK)
  277. struct dyn_ftrace {
  278. unsigned long ip; /* address of mcount call-site */
  279. unsigned long flags;
  280. struct dyn_arch_ftrace arch;
  281. };
  282. int ftrace_force_update(void);
  283. int ftrace_set_filter_ip(struct ftrace_ops *ops, unsigned long ip,
  284. int remove, int reset);
  285. int ftrace_set_filter(struct ftrace_ops *ops, unsigned char *buf,
  286. int len, int reset);
  287. int ftrace_set_notrace(struct ftrace_ops *ops, unsigned char *buf,
  288. int len, int reset);
  289. void ftrace_set_global_filter(unsigned char *buf, int len, int reset);
  290. void ftrace_set_global_notrace(unsigned char *buf, int len, int reset);
  291. void ftrace_free_filter(struct ftrace_ops *ops);
  292. int register_ftrace_command(struct ftrace_func_command *cmd);
  293. int unregister_ftrace_command(struct ftrace_func_command *cmd);
  294. enum {
  295. FTRACE_UPDATE_CALLS = (1 << 0),
  296. FTRACE_DISABLE_CALLS = (1 << 1),
  297. FTRACE_UPDATE_TRACE_FUNC = (1 << 2),
  298. FTRACE_START_FUNC_RET = (1 << 3),
  299. FTRACE_STOP_FUNC_RET = (1 << 4),
  300. };
  301. /*
  302. * The FTRACE_UPDATE_* enum is used to pass information back
  303. * from the ftrace_update_record() and ftrace_test_record()
  304. * functions. These are called by the code update routines
  305. * to find out what is to be done for a given function.
  306. *
  307. * IGNORE - The function is already what we want it to be
  308. * MAKE_CALL - Start tracing the function
  309. * MODIFY_CALL - Stop saving regs for the function
  310. * MAKE_NOP - Stop tracing the function
  311. */
  312. enum {
  313. FTRACE_UPDATE_IGNORE,
  314. FTRACE_UPDATE_MAKE_CALL,
  315. FTRACE_UPDATE_MODIFY_CALL,
  316. FTRACE_UPDATE_MAKE_NOP,
  317. };
  318. enum {
  319. FTRACE_ITER_FILTER = (1 << 0),
  320. FTRACE_ITER_NOTRACE = (1 << 1),
  321. FTRACE_ITER_PRINTALL = (1 << 2),
  322. FTRACE_ITER_DO_HASH = (1 << 3),
  323. FTRACE_ITER_HASH = (1 << 4),
  324. FTRACE_ITER_ENABLED = (1 << 5),
  325. };
  326. void arch_ftrace_update_code(int command);
  327. struct ftrace_rec_iter;
  328. struct ftrace_rec_iter *ftrace_rec_iter_start(void);
  329. struct ftrace_rec_iter *ftrace_rec_iter_next(struct ftrace_rec_iter *iter);
  330. struct dyn_ftrace *ftrace_rec_iter_record(struct ftrace_rec_iter *iter);
  331. #define for_ftrace_rec_iter(iter) \
  332. for (iter = ftrace_rec_iter_start(); \
  333. iter; \
  334. iter = ftrace_rec_iter_next(iter))
  335. int ftrace_update_record(struct dyn_ftrace *rec, int enable);
  336. int ftrace_test_record(struct dyn_ftrace *rec, int enable);
  337. void ftrace_run_stop_machine(int command);
  338. unsigned long ftrace_location(unsigned long ip);
  339. unsigned long ftrace_get_addr_new(struct dyn_ftrace *rec);
  340. unsigned long ftrace_get_addr_curr(struct dyn_ftrace *rec);
  341. extern ftrace_func_t ftrace_trace_function;
  342. int ftrace_regex_open(struct ftrace_ops *ops, int flag,
  343. struct inode *inode, struct file *file);
  344. ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
  345. size_t cnt, loff_t *ppos);
  346. ssize_t ftrace_notrace_write(struct file *file, const char __user *ubuf,
  347. size_t cnt, loff_t *ppos);
  348. int ftrace_regex_release(struct inode *inode, struct file *file);
  349. void __init
  350. ftrace_set_early_filter(struct ftrace_ops *ops, char *buf, int enable);
  351. /* defined in arch */
  352. extern int ftrace_ip_converted(unsigned long ip);
  353. extern int ftrace_dyn_arch_init(void);
  354. extern void ftrace_replace_code(int enable);
  355. extern int ftrace_update_ftrace_func(ftrace_func_t func);
  356. extern void ftrace_caller(void);
  357. extern void ftrace_regs_caller(void);
  358. extern void ftrace_call(void);
  359. extern void ftrace_regs_call(void);
  360. extern void mcount_call(void);
  361. void ftrace_modify_all_code(int command);
  362. #ifndef FTRACE_ADDR
  363. #define FTRACE_ADDR ((unsigned long)ftrace_caller)
  364. #endif
  365. #ifndef FTRACE_GRAPH_ADDR
  366. #define FTRACE_GRAPH_ADDR ((unsigned long)ftrace_graph_caller)
  367. #endif
  368. #ifndef FTRACE_REGS_ADDR
  369. #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
  370. # define FTRACE_REGS_ADDR ((unsigned long)ftrace_regs_caller)
  371. #else
  372. # define FTRACE_REGS_ADDR FTRACE_ADDR
  373. #endif
  374. #endif
  375. /*
  376. * If an arch would like functions that are only traced
  377. * by the function graph tracer to jump directly to its own
  378. * trampoline, then they can define FTRACE_GRAPH_TRAMP_ADDR
  379. * to be that address to jump to.
  380. */
  381. #ifndef FTRACE_GRAPH_TRAMP_ADDR
  382. #define FTRACE_GRAPH_TRAMP_ADDR ((unsigned long) 0)
  383. #endif
  384. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  385. extern void ftrace_graph_caller(void);
  386. extern int ftrace_enable_ftrace_graph_caller(void);
  387. extern int ftrace_disable_ftrace_graph_caller(void);
  388. #else
  389. static inline int ftrace_enable_ftrace_graph_caller(void) { return 0; }
  390. static inline int ftrace_disable_ftrace_graph_caller(void) { return 0; }
  391. #endif
  392. /**
  393. * ftrace_make_nop - convert code into nop
  394. * @mod: module structure if called by module load initialization
  395. * @rec: the mcount call site record
  396. * @addr: the address that the call site should be calling
  397. *
  398. * This is a very sensitive operation and great care needs
  399. * to be taken by the arch. The operation should carefully
  400. * read the location, check to see if what is read is indeed
  401. * what we expect it to be, and then on success of the compare,
  402. * it should write to the location.
  403. *
  404. * The code segment at @rec->ip should be a caller to @addr
  405. *
  406. * Return must be:
  407. * 0 on success
  408. * -EFAULT on error reading the location
  409. * -EINVAL on a failed compare of the contents
  410. * -EPERM on error writing to the location
  411. * Any other value will be considered a failure.
  412. */
  413. extern int ftrace_make_nop(struct module *mod,
  414. struct dyn_ftrace *rec, unsigned long addr);
  415. /**
  416. * ftrace_make_call - convert a nop call site into a call to addr
  417. * @rec: the mcount call site record
  418. * @addr: the address that the call site should call
  419. *
  420. * This is a very sensitive operation and great care needs
  421. * to be taken by the arch. The operation should carefully
  422. * read the location, check to see if what is read is indeed
  423. * what we expect it to be, and then on success of the compare,
  424. * it should write to the location.
  425. *
  426. * The code segment at @rec->ip should be a nop
  427. *
  428. * Return must be:
  429. * 0 on success
  430. * -EFAULT on error reading the location
  431. * -EINVAL on a failed compare of the contents
  432. * -EPERM on error writing to the location
  433. * Any other value will be considered a failure.
  434. */
  435. extern int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr);
  436. #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
  437. /**
  438. * ftrace_modify_call - convert from one addr to another (no nop)
  439. * @rec: the mcount call site record
  440. * @old_addr: the address expected to be currently called to
  441. * @addr: the address to change to
  442. *
  443. * This is a very sensitive operation and great care needs
  444. * to be taken by the arch. The operation should carefully
  445. * read the location, check to see if what is read is indeed
  446. * what we expect it to be, and then on success of the compare,
  447. * it should write to the location.
  448. *
  449. * The code segment at @rec->ip should be a caller to @old_addr
  450. *
  451. * Return must be:
  452. * 0 on success
  453. * -EFAULT on error reading the location
  454. * -EINVAL on a failed compare of the contents
  455. * -EPERM on error writing to the location
  456. * Any other value will be considered a failure.
  457. */
  458. extern int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
  459. unsigned long addr);
  460. #else
  461. /* Should never be called */
  462. static inline int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
  463. unsigned long addr)
  464. {
  465. return -EINVAL;
  466. }
  467. #endif
  468. /* May be defined in arch */
  469. extern int ftrace_arch_read_dyn_info(char *buf, int size);
  470. extern int skip_trace(unsigned long ip);
  471. extern void ftrace_module_init(struct module *mod);
  472. extern void ftrace_disable_daemon(void);
  473. extern void ftrace_enable_daemon(void);
  474. #else /* CONFIG_DYNAMIC_FTRACE */
  475. static inline int skip_trace(unsigned long ip) { return 0; }
  476. static inline int ftrace_force_update(void) { return 0; }
  477. static inline void ftrace_disable_daemon(void) { }
  478. static inline void ftrace_enable_daemon(void) { }
  479. static inline void ftrace_release_mod(struct module *mod) {}
  480. static inline void ftrace_module_init(struct module *mod) {}
  481. static inline __init int register_ftrace_command(struct ftrace_func_command *cmd)
  482. {
  483. return -EINVAL;
  484. }
  485. static inline __init int unregister_ftrace_command(char *cmd_name)
  486. {
  487. return -EINVAL;
  488. }
  489. static inline int ftrace_text_reserved(const void *start, const void *end)
  490. {
  491. return 0;
  492. }
  493. static inline unsigned long ftrace_location(unsigned long ip)
  494. {
  495. return 0;
  496. }
  497. /*
  498. * Again users of functions that have ftrace_ops may not
  499. * have them defined when ftrace is not enabled, but these
  500. * functions may still be called. Use a macro instead of inline.
  501. */
  502. #define ftrace_regex_open(ops, flag, inod, file) ({ -ENODEV; })
  503. #define ftrace_set_early_filter(ops, buf, enable) do { } while (0)
  504. #define ftrace_set_filter_ip(ops, ip, remove, reset) ({ -ENODEV; })
  505. #define ftrace_set_filter(ops, buf, len, reset) ({ -ENODEV; })
  506. #define ftrace_set_notrace(ops, buf, len, reset) ({ -ENODEV; })
  507. #define ftrace_free_filter(ops) do { } while (0)
  508. static inline ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
  509. size_t cnt, loff_t *ppos) { return -ENODEV; }
  510. static inline ssize_t ftrace_notrace_write(struct file *file, const char __user *ubuf,
  511. size_t cnt, loff_t *ppos) { return -ENODEV; }
  512. static inline int
  513. ftrace_regex_release(struct inode *inode, struct file *file) { return -ENODEV; }
  514. #endif /* CONFIG_DYNAMIC_FTRACE */
  515. /* totally disable ftrace - can not re-enable after this */
  516. void ftrace_kill(void);
  517. static inline void tracer_disable(void)
  518. {
  519. #ifdef CONFIG_FUNCTION_TRACER
  520. ftrace_enabled = 0;
  521. #endif
  522. }
  523. /*
  524. * Ftrace disable/restore without lock. Some synchronization mechanism
  525. * must be used to prevent ftrace_enabled to be changed between
  526. * disable/restore.
  527. */
  528. static inline int __ftrace_enabled_save(void)
  529. {
  530. #ifdef CONFIG_FUNCTION_TRACER
  531. int saved_ftrace_enabled = ftrace_enabled;
  532. ftrace_enabled = 0;
  533. return saved_ftrace_enabled;
  534. #else
  535. return 0;
  536. #endif
  537. }
  538. static inline void __ftrace_enabled_restore(int enabled)
  539. {
  540. #ifdef CONFIG_FUNCTION_TRACER
  541. ftrace_enabled = enabled;
  542. #endif
  543. }
  544. /* All archs should have this, but we define it for consistency */
  545. #ifndef ftrace_return_address0
  546. # define ftrace_return_address0 __builtin_return_address(0)
  547. #endif
  548. /* Archs may use other ways for ADDR1 and beyond */
  549. #ifndef ftrace_return_address
  550. # ifdef CONFIG_FRAME_POINTER
  551. # define ftrace_return_address(n) __builtin_return_address(n)
  552. # else
  553. # define ftrace_return_address(n) 0UL
  554. # endif
  555. #endif
  556. #define CALLER_ADDR0 ((unsigned long)ftrace_return_address0)
  557. #define CALLER_ADDR1 ((unsigned long)ftrace_return_address(1))
  558. #define CALLER_ADDR2 ((unsigned long)ftrace_return_address(2))
  559. #define CALLER_ADDR3 ((unsigned long)ftrace_return_address(3))
  560. #define CALLER_ADDR4 ((unsigned long)ftrace_return_address(4))
  561. #define CALLER_ADDR5 ((unsigned long)ftrace_return_address(5))
  562. #define CALLER_ADDR6 ((unsigned long)ftrace_return_address(6))
  563. #ifdef CONFIG_IRQSOFF_TRACER
  564. extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
  565. extern void time_hardirqs_off(unsigned long a0, unsigned long a1);
  566. #else
  567. static inline void time_hardirqs_on(unsigned long a0, unsigned long a1) { }
  568. static inline void time_hardirqs_off(unsigned long a0, unsigned long a1) { }
  569. #endif
  570. #ifdef CONFIG_PREEMPT_TRACER
  571. extern void trace_preempt_on(unsigned long a0, unsigned long a1);
  572. extern void trace_preempt_off(unsigned long a0, unsigned long a1);
  573. #else
  574. /*
  575. * Use defines instead of static inlines because some arches will make code out
  576. * of the CALLER_ADDR, when we really want these to be a real nop.
  577. */
  578. # define trace_preempt_on(a0, a1) do { } while (0)
  579. # define trace_preempt_off(a0, a1) do { } while (0)
  580. #endif
  581. #ifdef CONFIG_FTRACE_MCOUNT_RECORD
  582. extern void ftrace_init(void);
  583. #else
  584. static inline void ftrace_init(void) { }
  585. #endif
  586. /*
  587. * Structure that defines an entry function trace.
  588. */
  589. struct ftrace_graph_ent {
  590. unsigned long func; /* Current function */
  591. int depth;
  592. };
  593. /*
  594. * Structure that defines a return function trace.
  595. */
  596. struct ftrace_graph_ret {
  597. unsigned long func; /* Current function */
  598. unsigned long long calltime;
  599. unsigned long long rettime;
  600. /* Number of functions that overran the depth limit for current task */
  601. unsigned long overrun;
  602. int depth;
  603. };
  604. /* Type of the callback handlers for tracing function graph*/
  605. typedef void (*trace_func_graph_ret_t)(struct ftrace_graph_ret *); /* return */
  606. typedef int (*trace_func_graph_ent_t)(struct ftrace_graph_ent *); /* entry */
  607. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  608. /* for init task */
  609. #define INIT_FTRACE_GRAPH .ret_stack = NULL,
  610. /*
  611. * Stack of return addresses for functions
  612. * of a thread.
  613. * Used in struct thread_info
  614. */
  615. struct ftrace_ret_stack {
  616. unsigned long ret;
  617. unsigned long func;
  618. unsigned long long calltime;
  619. unsigned long long subtime;
  620. unsigned long fp;
  621. };
  622. /*
  623. * Primary handler of a function return.
  624. * It relays on ftrace_return_to_handler.
  625. * Defined in entry_32/64.S
  626. */
  627. extern void return_to_handler(void);
  628. extern int
  629. ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth,
  630. unsigned long frame_pointer);
  631. /*
  632. * Sometimes we don't want to trace a function with the function
  633. * graph tracer but we want them to keep traced by the usual function
  634. * tracer if the function graph tracer is not configured.
  635. */
  636. #define __notrace_funcgraph notrace
  637. /*
  638. * We want to which function is an entrypoint of a hardirq.
  639. * That will help us to put a signal on output.
  640. */
  641. #define __irq_entry __attribute__((__section__(".irqentry.text")))
  642. /* Limits of hardirq entrypoints */
  643. extern char __irqentry_text_start[];
  644. extern char __irqentry_text_end[];
  645. #define FTRACE_NOTRACE_DEPTH 65536
  646. #define FTRACE_RETFUNC_DEPTH 50
  647. #define FTRACE_RETSTACK_ALLOC_SIZE 32
  648. extern int register_ftrace_graph(trace_func_graph_ret_t retfunc,
  649. trace_func_graph_ent_t entryfunc);
  650. extern bool ftrace_graph_is_dead(void);
  651. extern void ftrace_graph_stop(void);
  652. /* The current handlers in use */
  653. extern trace_func_graph_ret_t ftrace_graph_return;
  654. extern trace_func_graph_ent_t ftrace_graph_entry;
  655. extern void unregister_ftrace_graph(void);
  656. extern void ftrace_graph_init_task(struct task_struct *t);
  657. extern void ftrace_graph_exit_task(struct task_struct *t);
  658. extern void ftrace_graph_init_idle_task(struct task_struct *t, int cpu);
  659. static inline int task_curr_ret_stack(struct task_struct *t)
  660. {
  661. return t->curr_ret_stack;
  662. }
  663. static inline void pause_graph_tracing(void)
  664. {
  665. atomic_inc(&current->tracing_graph_pause);
  666. }
  667. static inline void unpause_graph_tracing(void)
  668. {
  669. atomic_dec(&current->tracing_graph_pause);
  670. }
  671. #else /* !CONFIG_FUNCTION_GRAPH_TRACER */
  672. #define __notrace_funcgraph
  673. #define __irq_entry
  674. #define INIT_FTRACE_GRAPH
  675. static inline void ftrace_graph_init_task(struct task_struct *t) { }
  676. static inline void ftrace_graph_exit_task(struct task_struct *t) { }
  677. static inline void ftrace_graph_init_idle_task(struct task_struct *t, int cpu) { }
  678. static inline int register_ftrace_graph(trace_func_graph_ret_t retfunc,
  679. trace_func_graph_ent_t entryfunc)
  680. {
  681. return -1;
  682. }
  683. static inline void unregister_ftrace_graph(void) { }
  684. static inline int task_curr_ret_stack(struct task_struct *tsk)
  685. {
  686. return -1;
  687. }
  688. static inline void pause_graph_tracing(void) { }
  689. static inline void unpause_graph_tracing(void) { }
  690. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  691. #ifdef CONFIG_TRACING
  692. /* flags for current->trace */
  693. enum {
  694. TSK_TRACE_FL_TRACE_BIT = 0,
  695. TSK_TRACE_FL_GRAPH_BIT = 1,
  696. };
  697. enum {
  698. TSK_TRACE_FL_TRACE = 1 << TSK_TRACE_FL_TRACE_BIT,
  699. TSK_TRACE_FL_GRAPH = 1 << TSK_TRACE_FL_GRAPH_BIT,
  700. };
  701. static inline void set_tsk_trace_trace(struct task_struct *tsk)
  702. {
  703. set_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
  704. }
  705. static inline void clear_tsk_trace_trace(struct task_struct *tsk)
  706. {
  707. clear_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
  708. }
  709. static inline int test_tsk_trace_trace(struct task_struct *tsk)
  710. {
  711. return tsk->trace & TSK_TRACE_FL_TRACE;
  712. }
  713. static inline void set_tsk_trace_graph(struct task_struct *tsk)
  714. {
  715. set_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
  716. }
  717. static inline void clear_tsk_trace_graph(struct task_struct *tsk)
  718. {
  719. clear_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
  720. }
  721. static inline int test_tsk_trace_graph(struct task_struct *tsk)
  722. {
  723. return tsk->trace & TSK_TRACE_FL_GRAPH;
  724. }
  725. enum ftrace_dump_mode;
  726. extern enum ftrace_dump_mode ftrace_dump_on_oops;
  727. extern void disable_trace_on_warning(void);
  728. extern int __disable_trace_on_warning;
  729. #ifdef CONFIG_PREEMPT
  730. #define INIT_TRACE_RECURSION .trace_recursion = 0,
  731. #endif
  732. #else /* CONFIG_TRACING */
  733. static inline void disable_trace_on_warning(void) { }
  734. #endif /* CONFIG_TRACING */
  735. #ifndef INIT_TRACE_RECURSION
  736. #define INIT_TRACE_RECURSION
  737. #endif
  738. #ifdef CONFIG_FTRACE_SYSCALLS
  739. unsigned long arch_syscall_addr(int nr);
  740. #endif /* CONFIG_FTRACE_SYSCALLS */
  741. #endif /* _LINUX_FTRACE_H */