ftrace.h 26 KB

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