ftrace.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  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. * (ARCH_SUPPORTS_FTRACE_SAVE_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. */
  81. enum {
  82. FTRACE_OPS_FL_ENABLED = 1 << 0,
  83. FTRACE_OPS_FL_GLOBAL = 1 << 1,
  84. FTRACE_OPS_FL_DYNAMIC = 1 << 2,
  85. FTRACE_OPS_FL_CONTROL = 1 << 3,
  86. FTRACE_OPS_FL_SAVE_REGS = 1 << 4,
  87. FTRACE_OPS_FL_SAVE_REGS_IF_SUPPORTED = 1 << 5,
  88. FTRACE_OPS_FL_RECURSION_SAFE = 1 << 6,
  89. };
  90. struct ftrace_ops {
  91. ftrace_func_t func;
  92. struct ftrace_ops *next;
  93. unsigned long flags;
  94. int __percpu *disabled;
  95. #ifdef CONFIG_DYNAMIC_FTRACE
  96. struct ftrace_hash *notrace_hash;
  97. struct ftrace_hash *filter_hash;
  98. #endif
  99. };
  100. extern int function_trace_stop;
  101. /*
  102. * Type of the current tracing.
  103. */
  104. enum ftrace_tracing_type_t {
  105. FTRACE_TYPE_ENTER = 0, /* Hook the call of the function */
  106. FTRACE_TYPE_RETURN, /* Hook the return of the function */
  107. };
  108. /* Current tracing type, default is FTRACE_TYPE_ENTER */
  109. extern enum ftrace_tracing_type_t ftrace_tracing_type;
  110. /**
  111. * ftrace_stop - stop function tracer.
  112. *
  113. * A quick way to stop the function tracer. Note this an on off switch,
  114. * it is not something that is recursive like preempt_disable.
  115. * This does not disable the calling of mcount, it only stops the
  116. * calling of functions from mcount.
  117. */
  118. static inline void ftrace_stop(void)
  119. {
  120. function_trace_stop = 1;
  121. }
  122. /**
  123. * ftrace_start - start the function tracer.
  124. *
  125. * This function is the inverse of ftrace_stop. This does not enable
  126. * the function tracing if the function tracer is disabled. This only
  127. * sets the function tracer flag to continue calling the functions
  128. * from mcount.
  129. */
  130. static inline void ftrace_start(void)
  131. {
  132. function_trace_stop = 0;
  133. }
  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. static inline void ftrace_stop(void) { }
  204. static inline void ftrace_start(void) { }
  205. #endif /* CONFIG_FUNCTION_TRACER */
  206. #ifdef CONFIG_STACK_TRACER
  207. extern int stack_tracer_enabled;
  208. int
  209. stack_trace_sysctl(struct ctl_table *table, int write,
  210. void __user *buffer, size_t *lenp,
  211. loff_t *ppos);
  212. #endif
  213. struct ftrace_func_command {
  214. struct list_head list;
  215. char *name;
  216. int (*func)(struct ftrace_hash *hash,
  217. char *func, char *cmd,
  218. char *params, int enable);
  219. };
  220. #ifdef CONFIG_DYNAMIC_FTRACE
  221. int ftrace_arch_code_modify_prepare(void);
  222. int ftrace_arch_code_modify_post_process(void);
  223. void ftrace_bug(int err, unsigned long ip);
  224. struct seq_file;
  225. struct ftrace_probe_ops {
  226. void (*func)(unsigned long ip,
  227. unsigned long parent_ip,
  228. void **data);
  229. int (*callback)(unsigned long ip, void **data);
  230. void (*free)(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(void *start, 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 << 29),
  266. FTRACE_FL_REGS = (1UL << 30),
  267. FTRACE_FL_REGS_EN = (1UL << 31)
  268. };
  269. #define FTRACE_FL_MASK (0x7UL << 29)
  270. #define FTRACE_REF_MAX ((1UL << 29) - 1)
  271. struct dyn_ftrace {
  272. union {
  273. unsigned long ip; /* address of mcount call-site */
  274. struct dyn_ftrace *freelist;
  275. };
  276. unsigned long flags;
  277. struct dyn_arch_ftrace arch;
  278. };
  279. int ftrace_force_update(void);
  280. int ftrace_set_filter_ip(struct ftrace_ops *ops, unsigned long ip,
  281. int remove, int reset);
  282. int ftrace_set_filter(struct ftrace_ops *ops, unsigned char *buf,
  283. int len, int reset);
  284. int ftrace_set_notrace(struct ftrace_ops *ops, unsigned char *buf,
  285. int len, int reset);
  286. void ftrace_set_global_filter(unsigned char *buf, int len, int reset);
  287. void ftrace_set_global_notrace(unsigned char *buf, int len, int reset);
  288. void ftrace_free_filter(struct ftrace_ops *ops);
  289. int register_ftrace_command(struct ftrace_func_command *cmd);
  290. int unregister_ftrace_command(struct ftrace_func_command *cmd);
  291. enum {
  292. FTRACE_UPDATE_CALLS = (1 << 0),
  293. FTRACE_DISABLE_CALLS = (1 << 1),
  294. FTRACE_UPDATE_TRACE_FUNC = (1 << 2),
  295. FTRACE_START_FUNC_RET = (1 << 3),
  296. FTRACE_STOP_FUNC_RET = (1 << 4),
  297. };
  298. /*
  299. * The FTRACE_UPDATE_* enum is used to pass information back
  300. * from the ftrace_update_record() and ftrace_test_record()
  301. * functions. These are called by the code update routines
  302. * to find out what is to be done for a given function.
  303. *
  304. * IGNORE - The function is already what we want it to be
  305. * MAKE_CALL - Start tracing the function
  306. * MODIFY_CALL - Stop saving regs for the function
  307. * MODIFY_CALL_REGS - Start saving regs for the function
  308. * MAKE_NOP - Stop tracing the function
  309. */
  310. enum {
  311. FTRACE_UPDATE_IGNORE,
  312. FTRACE_UPDATE_MAKE_CALL,
  313. FTRACE_UPDATE_MODIFY_CALL,
  314. FTRACE_UPDATE_MODIFY_CALL_REGS,
  315. FTRACE_UPDATE_MAKE_NOP,
  316. };
  317. enum {
  318. FTRACE_ITER_FILTER = (1 << 0),
  319. FTRACE_ITER_NOTRACE = (1 << 1),
  320. FTRACE_ITER_PRINTALL = (1 << 2),
  321. FTRACE_ITER_DO_HASH = (1 << 3),
  322. FTRACE_ITER_HASH = (1 << 4),
  323. FTRACE_ITER_ENABLED = (1 << 5),
  324. };
  325. void arch_ftrace_update_code(int command);
  326. struct ftrace_rec_iter;
  327. struct ftrace_rec_iter *ftrace_rec_iter_start(void);
  328. struct ftrace_rec_iter *ftrace_rec_iter_next(struct ftrace_rec_iter *iter);
  329. struct dyn_ftrace *ftrace_rec_iter_record(struct ftrace_rec_iter *iter);
  330. #define for_ftrace_rec_iter(iter) \
  331. for (iter = ftrace_rec_iter_start(); \
  332. iter; \
  333. iter = ftrace_rec_iter_next(iter))
  334. int ftrace_update_record(struct dyn_ftrace *rec, int enable);
  335. int ftrace_test_record(struct dyn_ftrace *rec, int enable);
  336. void ftrace_run_stop_machine(int command);
  337. unsigned long ftrace_location(unsigned long ip);
  338. extern ftrace_func_t ftrace_trace_function;
  339. int ftrace_regex_open(struct ftrace_ops *ops, int flag,
  340. struct inode *inode, struct file *file);
  341. ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
  342. size_t cnt, loff_t *ppos);
  343. ssize_t ftrace_notrace_write(struct file *file, const char __user *ubuf,
  344. size_t cnt, loff_t *ppos);
  345. loff_t ftrace_regex_lseek(struct file *file, loff_t offset, int origin);
  346. int ftrace_regex_release(struct inode *inode, struct file *file);
  347. void __init
  348. ftrace_set_early_filter(struct ftrace_ops *ops, char *buf, int enable);
  349. /* defined in arch */
  350. extern int ftrace_ip_converted(unsigned long ip);
  351. extern int ftrace_dyn_arch_init(void *data);
  352. extern void ftrace_replace_code(int enable);
  353. extern int ftrace_update_ftrace_func(ftrace_func_t func);
  354. extern void ftrace_caller(void);
  355. extern void ftrace_regs_caller(void);
  356. extern void ftrace_call(void);
  357. extern void ftrace_regs_call(void);
  358. extern void mcount_call(void);
  359. void ftrace_modify_all_code(int command);
  360. #ifndef FTRACE_ADDR
  361. #define FTRACE_ADDR ((unsigned long)ftrace_caller)
  362. #endif
  363. #ifndef FTRACE_REGS_ADDR
  364. #ifdef ARCH_SUPPORTS_FTRACE_SAVE_REGS
  365. # define FTRACE_REGS_ADDR ((unsigned long)ftrace_regs_caller)
  366. #else
  367. # define FTRACE_REGS_ADDR FTRACE_ADDR
  368. #endif
  369. #endif
  370. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  371. extern void ftrace_graph_caller(void);
  372. extern int ftrace_enable_ftrace_graph_caller(void);
  373. extern int ftrace_disable_ftrace_graph_caller(void);
  374. #else
  375. static inline int ftrace_enable_ftrace_graph_caller(void) { return 0; }
  376. static inline int ftrace_disable_ftrace_graph_caller(void) { return 0; }
  377. #endif
  378. /**
  379. * ftrace_make_nop - convert code into nop
  380. * @mod: module structure if called by module load initialization
  381. * @rec: the mcount call site record
  382. * @addr: the address that the call site should be calling
  383. *
  384. * This is a very sensitive operation and great care needs
  385. * to be taken by the arch. The operation should carefully
  386. * read the location, check to see if what is read is indeed
  387. * what we expect it to be, and then on success of the compare,
  388. * it should write to the location.
  389. *
  390. * The code segment at @rec->ip should be a caller to @addr
  391. *
  392. * Return must be:
  393. * 0 on success
  394. * -EFAULT on error reading the location
  395. * -EINVAL on a failed compare of the contents
  396. * -EPERM on error writing to the location
  397. * Any other value will be considered a failure.
  398. */
  399. extern int ftrace_make_nop(struct module *mod,
  400. struct dyn_ftrace *rec, unsigned long addr);
  401. /**
  402. * ftrace_make_call - convert a nop call site into a call to addr
  403. * @rec: the mcount call site record
  404. * @addr: the address that the call site should call
  405. *
  406. * This is a very sensitive operation and great care needs
  407. * to be taken by the arch. The operation should carefully
  408. * read the location, check to see if what is read is indeed
  409. * what we expect it to be, and then on success of the compare,
  410. * it should write to the location.
  411. *
  412. * The code segment at @rec->ip should be a nop
  413. *
  414. * Return must be:
  415. * 0 on success
  416. * -EFAULT on error reading the location
  417. * -EINVAL on a failed compare of the contents
  418. * -EPERM on error writing to the location
  419. * Any other value will be considered a failure.
  420. */
  421. extern int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr);
  422. #ifdef ARCH_SUPPORTS_FTRACE_SAVE_REGS
  423. /**
  424. * ftrace_modify_call - convert from one addr to another (no nop)
  425. * @rec: the mcount call site record
  426. * @old_addr: the address expected to be currently called to
  427. * @addr: the address to change to
  428. *
  429. * This is a very sensitive operation and great care needs
  430. * to be taken by the arch. The operation should carefully
  431. * read the location, check to see if what is read is indeed
  432. * what we expect it to be, and then on success of the compare,
  433. * it should write to the location.
  434. *
  435. * The code segment at @rec->ip should be a caller to @old_addr
  436. *
  437. * Return must be:
  438. * 0 on success
  439. * -EFAULT on error reading the location
  440. * -EINVAL on a failed compare of the contents
  441. * -EPERM on error writing to the location
  442. * Any other value will be considered a failure.
  443. */
  444. extern int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
  445. unsigned long addr);
  446. #else
  447. /* Should never be called */
  448. static inline int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
  449. unsigned long addr)
  450. {
  451. return -EINVAL;
  452. }
  453. #endif
  454. /* May be defined in arch */
  455. extern int ftrace_arch_read_dyn_info(char *buf, int size);
  456. extern int skip_trace(unsigned long ip);
  457. extern void ftrace_disable_daemon(void);
  458. extern void ftrace_enable_daemon(void);
  459. #else /* CONFIG_DYNAMIC_FTRACE */
  460. static inline int skip_trace(unsigned long ip) { return 0; }
  461. static inline int ftrace_force_update(void) { return 0; }
  462. static inline void ftrace_disable_daemon(void) { }
  463. static inline void ftrace_enable_daemon(void) { }
  464. static inline void ftrace_release_mod(struct module *mod) {}
  465. static inline int register_ftrace_command(struct ftrace_func_command *cmd)
  466. {
  467. return -EINVAL;
  468. }
  469. static inline int unregister_ftrace_command(char *cmd_name)
  470. {
  471. return -EINVAL;
  472. }
  473. static inline int ftrace_text_reserved(void *start, void *end)
  474. {
  475. return 0;
  476. }
  477. static inline unsigned long ftrace_location(unsigned long ip)
  478. {
  479. return 0;
  480. }
  481. /*
  482. * Again users of functions that have ftrace_ops may not
  483. * have them defined when ftrace is not enabled, but these
  484. * functions may still be called. Use a macro instead of inline.
  485. */
  486. #define ftrace_regex_open(ops, flag, inod, file) ({ -ENODEV; })
  487. #define ftrace_set_early_filter(ops, buf, enable) do { } while (0)
  488. #define ftrace_set_filter_ip(ops, ip, remove, reset) ({ -ENODEV; })
  489. #define ftrace_set_filter(ops, buf, len, reset) ({ -ENODEV; })
  490. #define ftrace_set_notrace(ops, buf, len, reset) ({ -ENODEV; })
  491. #define ftrace_free_filter(ops) do { } while (0)
  492. static inline ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
  493. size_t cnt, loff_t *ppos) { return -ENODEV; }
  494. static inline ssize_t ftrace_notrace_write(struct file *file, const char __user *ubuf,
  495. size_t cnt, loff_t *ppos) { return -ENODEV; }
  496. static inline loff_t ftrace_regex_lseek(struct file *file, loff_t offset, int origin)
  497. {
  498. return -ENODEV;
  499. }
  500. static inline int
  501. ftrace_regex_release(struct inode *inode, struct file *file) { return -ENODEV; }
  502. #endif /* CONFIG_DYNAMIC_FTRACE */
  503. /* totally disable ftrace - can not re-enable after this */
  504. void ftrace_kill(void);
  505. static inline void tracer_disable(void)
  506. {
  507. #ifdef CONFIG_FUNCTION_TRACER
  508. ftrace_enabled = 0;
  509. #endif
  510. }
  511. /*
  512. * Ftrace disable/restore without lock. Some synchronization mechanism
  513. * must be used to prevent ftrace_enabled to be changed between
  514. * disable/restore.
  515. */
  516. static inline int __ftrace_enabled_save(void)
  517. {
  518. #ifdef CONFIG_FUNCTION_TRACER
  519. int saved_ftrace_enabled = ftrace_enabled;
  520. ftrace_enabled = 0;
  521. return saved_ftrace_enabled;
  522. #else
  523. return 0;
  524. #endif
  525. }
  526. static inline void __ftrace_enabled_restore(int enabled)
  527. {
  528. #ifdef CONFIG_FUNCTION_TRACER
  529. ftrace_enabled = enabled;
  530. #endif
  531. }
  532. #ifndef HAVE_ARCH_CALLER_ADDR
  533. # ifdef CONFIG_FRAME_POINTER
  534. # define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
  535. # define CALLER_ADDR1 ((unsigned long)__builtin_return_address(1))
  536. # define CALLER_ADDR2 ((unsigned long)__builtin_return_address(2))
  537. # define CALLER_ADDR3 ((unsigned long)__builtin_return_address(3))
  538. # define CALLER_ADDR4 ((unsigned long)__builtin_return_address(4))
  539. # define CALLER_ADDR5 ((unsigned long)__builtin_return_address(5))
  540. # define CALLER_ADDR6 ((unsigned long)__builtin_return_address(6))
  541. # else
  542. # define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
  543. # define CALLER_ADDR1 0UL
  544. # define CALLER_ADDR2 0UL
  545. # define CALLER_ADDR3 0UL
  546. # define CALLER_ADDR4 0UL
  547. # define CALLER_ADDR5 0UL
  548. # define CALLER_ADDR6 0UL
  549. # endif
  550. #endif /* ifndef HAVE_ARCH_CALLER_ADDR */
  551. #ifdef CONFIG_IRQSOFF_TRACER
  552. extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
  553. extern void time_hardirqs_off(unsigned long a0, unsigned long a1);
  554. #else
  555. static inline void time_hardirqs_on(unsigned long a0, unsigned long a1) { }
  556. static inline void time_hardirqs_off(unsigned long a0, unsigned long a1) { }
  557. #endif
  558. #ifdef CONFIG_PREEMPT_TRACER
  559. extern void trace_preempt_on(unsigned long a0, unsigned long a1);
  560. extern void trace_preempt_off(unsigned long a0, unsigned long a1);
  561. #else
  562. /*
  563. * Use defines instead of static inlines because some arches will make code out
  564. * of the CALLER_ADDR, when we really want these to be a real nop.
  565. */
  566. # define trace_preempt_on(a0, a1) do { } while (0)
  567. # define trace_preempt_off(a0, a1) do { } while (0)
  568. #endif
  569. #ifdef CONFIG_FTRACE_MCOUNT_RECORD
  570. extern void ftrace_init(void);
  571. #else
  572. static inline void ftrace_init(void) { }
  573. #endif
  574. /*
  575. * Structure that defines an entry function trace.
  576. */
  577. struct ftrace_graph_ent {
  578. unsigned long func; /* Current function */
  579. int depth;
  580. };
  581. /*
  582. * Structure that defines a return function trace.
  583. */
  584. struct ftrace_graph_ret {
  585. unsigned long func; /* Current function */
  586. unsigned long long calltime;
  587. unsigned long long rettime;
  588. /* Number of functions that overran the depth limit for current task */
  589. unsigned long overrun;
  590. int depth;
  591. };
  592. /* Type of the callback handlers for tracing function graph*/
  593. typedef void (*trace_func_graph_ret_t)(struct ftrace_graph_ret *); /* return */
  594. typedef int (*trace_func_graph_ent_t)(struct ftrace_graph_ent *); /* entry */
  595. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  596. /* for init task */
  597. #define INIT_FTRACE_GRAPH .ret_stack = NULL,
  598. /*
  599. * Stack of return addresses for functions
  600. * of a thread.
  601. * Used in struct thread_info
  602. */
  603. struct ftrace_ret_stack {
  604. unsigned long ret;
  605. unsigned long func;
  606. unsigned long long calltime;
  607. unsigned long long subtime;
  608. unsigned long fp;
  609. };
  610. /*
  611. * Primary handler of a function return.
  612. * It relays on ftrace_return_to_handler.
  613. * Defined in entry_32/64.S
  614. */
  615. extern void return_to_handler(void);
  616. extern int
  617. ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth,
  618. unsigned long frame_pointer);
  619. /*
  620. * Sometimes we don't want to trace a function with the function
  621. * graph tracer but we want them to keep traced by the usual function
  622. * tracer if the function graph tracer is not configured.
  623. */
  624. #define __notrace_funcgraph notrace
  625. /*
  626. * We want to which function is an entrypoint of a hardirq.
  627. * That will help us to put a signal on output.
  628. */
  629. #define __irq_entry __attribute__((__section__(".irqentry.text")))
  630. /* Limits of hardirq entrypoints */
  631. extern char __irqentry_text_start[];
  632. extern char __irqentry_text_end[];
  633. #define FTRACE_RETFUNC_DEPTH 50
  634. #define FTRACE_RETSTACK_ALLOC_SIZE 32
  635. extern int register_ftrace_graph(trace_func_graph_ret_t retfunc,
  636. trace_func_graph_ent_t entryfunc);
  637. extern void ftrace_graph_stop(void);
  638. /* The current handlers in use */
  639. extern trace_func_graph_ret_t ftrace_graph_return;
  640. extern trace_func_graph_ent_t ftrace_graph_entry;
  641. extern void unregister_ftrace_graph(void);
  642. extern void ftrace_graph_init_task(struct task_struct *t);
  643. extern void ftrace_graph_exit_task(struct task_struct *t);
  644. extern void ftrace_graph_init_idle_task(struct task_struct *t, int cpu);
  645. static inline int task_curr_ret_stack(struct task_struct *t)
  646. {
  647. return t->curr_ret_stack;
  648. }
  649. static inline void pause_graph_tracing(void)
  650. {
  651. atomic_inc(&current->tracing_graph_pause);
  652. }
  653. static inline void unpause_graph_tracing(void)
  654. {
  655. atomic_dec(&current->tracing_graph_pause);
  656. }
  657. #else /* !CONFIG_FUNCTION_GRAPH_TRACER */
  658. #define __notrace_funcgraph
  659. #define __irq_entry
  660. #define INIT_FTRACE_GRAPH
  661. static inline void ftrace_graph_init_task(struct task_struct *t) { }
  662. static inline void ftrace_graph_exit_task(struct task_struct *t) { }
  663. static inline void ftrace_graph_init_idle_task(struct task_struct *t, int cpu) { }
  664. static inline int register_ftrace_graph(trace_func_graph_ret_t retfunc,
  665. trace_func_graph_ent_t entryfunc)
  666. {
  667. return -1;
  668. }
  669. static inline void unregister_ftrace_graph(void) { }
  670. static inline int task_curr_ret_stack(struct task_struct *tsk)
  671. {
  672. return -1;
  673. }
  674. static inline void pause_graph_tracing(void) { }
  675. static inline void unpause_graph_tracing(void) { }
  676. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  677. #ifdef CONFIG_TRACING
  678. /* flags for current->trace */
  679. enum {
  680. TSK_TRACE_FL_TRACE_BIT = 0,
  681. TSK_TRACE_FL_GRAPH_BIT = 1,
  682. };
  683. enum {
  684. TSK_TRACE_FL_TRACE = 1 << TSK_TRACE_FL_TRACE_BIT,
  685. TSK_TRACE_FL_GRAPH = 1 << TSK_TRACE_FL_GRAPH_BIT,
  686. };
  687. static inline void set_tsk_trace_trace(struct task_struct *tsk)
  688. {
  689. set_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
  690. }
  691. static inline void clear_tsk_trace_trace(struct task_struct *tsk)
  692. {
  693. clear_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
  694. }
  695. static inline int test_tsk_trace_trace(struct task_struct *tsk)
  696. {
  697. return tsk->trace & TSK_TRACE_FL_TRACE;
  698. }
  699. static inline void set_tsk_trace_graph(struct task_struct *tsk)
  700. {
  701. set_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
  702. }
  703. static inline void clear_tsk_trace_graph(struct task_struct *tsk)
  704. {
  705. clear_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
  706. }
  707. static inline int test_tsk_trace_graph(struct task_struct *tsk)
  708. {
  709. return tsk->trace & TSK_TRACE_FL_GRAPH;
  710. }
  711. enum ftrace_dump_mode;
  712. extern enum ftrace_dump_mode ftrace_dump_on_oops;
  713. #ifdef CONFIG_PREEMPT
  714. #define INIT_TRACE_RECURSION .trace_recursion = 0,
  715. #endif
  716. #endif /* CONFIG_TRACING */
  717. #ifndef INIT_TRACE_RECURSION
  718. #define INIT_TRACE_RECURSION
  719. #endif
  720. #ifdef CONFIG_FTRACE_SYSCALLS
  721. unsigned long arch_syscall_addr(int nr);
  722. #endif /* CONFIG_FTRACE_SYSCALLS */
  723. #endif /* _LINUX_FTRACE_H */