ftrace.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  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. */
  63. enum {
  64. FTRACE_OPS_FL_ENABLED = 1 << 0,
  65. FTRACE_OPS_FL_GLOBAL = 1 << 1,
  66. FTRACE_OPS_FL_DYNAMIC = 1 << 2,
  67. FTRACE_OPS_FL_CONTROL = 1 << 3,
  68. };
  69. struct ftrace_ops {
  70. ftrace_func_t func;
  71. struct ftrace_ops *next;
  72. unsigned long flags;
  73. int __percpu *disabled;
  74. #ifdef CONFIG_DYNAMIC_FTRACE
  75. struct ftrace_hash *notrace_hash;
  76. struct ftrace_hash *filter_hash;
  77. #endif
  78. };
  79. extern int function_trace_stop;
  80. /*
  81. * Type of the current tracing.
  82. */
  83. enum ftrace_tracing_type_t {
  84. FTRACE_TYPE_ENTER = 0, /* Hook the call of the function */
  85. FTRACE_TYPE_RETURN, /* Hook the return of the function */
  86. };
  87. /* Current tracing type, default is FTRACE_TYPE_ENTER */
  88. extern enum ftrace_tracing_type_t ftrace_tracing_type;
  89. /**
  90. * ftrace_stop - stop function tracer.
  91. *
  92. * A quick way to stop the function tracer. Note this an on off switch,
  93. * it is not something that is recursive like preempt_disable.
  94. * This does not disable the calling of mcount, it only stops the
  95. * calling of functions from mcount.
  96. */
  97. static inline void ftrace_stop(void)
  98. {
  99. function_trace_stop = 1;
  100. }
  101. /**
  102. * ftrace_start - start the function tracer.
  103. *
  104. * This function is the inverse of ftrace_stop. This does not enable
  105. * the function tracing if the function tracer is disabled. This only
  106. * sets the function tracer flag to continue calling the functions
  107. * from mcount.
  108. */
  109. static inline void ftrace_start(void)
  110. {
  111. function_trace_stop = 0;
  112. }
  113. /*
  114. * The ftrace_ops must be a static and should also
  115. * be read_mostly. These functions do modify read_mostly variables
  116. * so use them sparely. Never free an ftrace_op or modify the
  117. * next pointer after it has been registered. Even after unregistering
  118. * it, the next pointer may still be used internally.
  119. */
  120. int register_ftrace_function(struct ftrace_ops *ops);
  121. int unregister_ftrace_function(struct ftrace_ops *ops);
  122. void clear_ftrace_function(void);
  123. /**
  124. * ftrace_function_local_enable - enable controlled ftrace_ops on current cpu
  125. *
  126. * This function enables tracing on current cpu by decreasing
  127. * the per cpu control variable.
  128. * It must be called with preemption disabled and only on ftrace_ops
  129. * registered with FTRACE_OPS_FL_CONTROL. If called without preemption
  130. * disabled, this_cpu_ptr will complain when CONFIG_DEBUG_PREEMPT is enabled.
  131. */
  132. static inline void ftrace_function_local_enable(struct ftrace_ops *ops)
  133. {
  134. if (WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_CONTROL)))
  135. return;
  136. (*this_cpu_ptr(ops->disabled))--;
  137. }
  138. /**
  139. * ftrace_function_local_disable - enable controlled ftrace_ops on current cpu
  140. *
  141. * This function enables tracing on current cpu by decreasing
  142. * the per cpu control variable.
  143. * It must be called with preemption disabled and only on ftrace_ops
  144. * registered with FTRACE_OPS_FL_CONTROL. If called without preemption
  145. * disabled, this_cpu_ptr will complain when CONFIG_DEBUG_PREEMPT is enabled.
  146. */
  147. static inline void ftrace_function_local_disable(struct ftrace_ops *ops)
  148. {
  149. if (WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_CONTROL)))
  150. return;
  151. (*this_cpu_ptr(ops->disabled))++;
  152. }
  153. /**
  154. * ftrace_function_local_disabled - returns ftrace_ops disabled value
  155. * on current cpu
  156. *
  157. * This function returns value of ftrace_ops::disabled on current cpu.
  158. * It must be called with preemption disabled and only on ftrace_ops
  159. * registered with FTRACE_OPS_FL_CONTROL. If called without preemption
  160. * disabled, this_cpu_ptr will complain when CONFIG_DEBUG_PREEMPT is enabled.
  161. */
  162. static inline int ftrace_function_local_disabled(struct ftrace_ops *ops)
  163. {
  164. WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_CONTROL));
  165. return *this_cpu_ptr(ops->disabled);
  166. }
  167. extern void ftrace_stub(unsigned long a0, unsigned long a1,
  168. struct ftrace_ops *op, struct pt_regs *regs);
  169. #else /* !CONFIG_FUNCTION_TRACER */
  170. /*
  171. * (un)register_ftrace_function must be a macro since the ops parameter
  172. * must not be evaluated.
  173. */
  174. #define register_ftrace_function(ops) ({ 0; })
  175. #define unregister_ftrace_function(ops) ({ 0; })
  176. static inline void clear_ftrace_function(void) { }
  177. static inline void ftrace_kill(void) { }
  178. static inline void ftrace_stop(void) { }
  179. static inline void ftrace_start(void) { }
  180. #endif /* CONFIG_FUNCTION_TRACER */
  181. #ifdef CONFIG_STACK_TRACER
  182. extern int stack_tracer_enabled;
  183. int
  184. stack_trace_sysctl(struct ctl_table *table, int write,
  185. void __user *buffer, size_t *lenp,
  186. loff_t *ppos);
  187. #endif
  188. struct ftrace_func_command {
  189. struct list_head list;
  190. char *name;
  191. int (*func)(struct ftrace_hash *hash,
  192. char *func, char *cmd,
  193. char *params, int enable);
  194. };
  195. #ifdef CONFIG_DYNAMIC_FTRACE
  196. int ftrace_arch_code_modify_prepare(void);
  197. int ftrace_arch_code_modify_post_process(void);
  198. void ftrace_bug(int err, unsigned long ip);
  199. struct seq_file;
  200. struct ftrace_probe_ops {
  201. void (*func)(unsigned long ip,
  202. unsigned long parent_ip,
  203. void **data);
  204. int (*callback)(unsigned long ip, void **data);
  205. void (*free)(void **data);
  206. int (*print)(struct seq_file *m,
  207. unsigned long ip,
  208. struct ftrace_probe_ops *ops,
  209. void *data);
  210. };
  211. extern int
  212. register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
  213. void *data);
  214. extern void
  215. unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
  216. void *data);
  217. extern void
  218. unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops);
  219. extern void unregister_ftrace_function_probe_all(char *glob);
  220. extern int ftrace_text_reserved(void *start, void *end);
  221. enum {
  222. FTRACE_FL_ENABLED = (1 << 30),
  223. };
  224. #define FTRACE_FL_MASK (0x3UL << 30)
  225. #define FTRACE_REF_MAX ((1 << 30) - 1)
  226. struct dyn_ftrace {
  227. union {
  228. unsigned long ip; /* address of mcount call-site */
  229. struct dyn_ftrace *freelist;
  230. };
  231. unsigned long flags;
  232. struct dyn_arch_ftrace arch;
  233. };
  234. int ftrace_force_update(void);
  235. int ftrace_set_filter(struct ftrace_ops *ops, unsigned char *buf,
  236. int len, int reset);
  237. int ftrace_set_notrace(struct ftrace_ops *ops, unsigned char *buf,
  238. int len, int reset);
  239. void ftrace_set_global_filter(unsigned char *buf, int len, int reset);
  240. void ftrace_set_global_notrace(unsigned char *buf, int len, int reset);
  241. void ftrace_free_filter(struct ftrace_ops *ops);
  242. int register_ftrace_command(struct ftrace_func_command *cmd);
  243. int unregister_ftrace_command(struct ftrace_func_command *cmd);
  244. enum {
  245. FTRACE_UPDATE_CALLS = (1 << 0),
  246. FTRACE_DISABLE_CALLS = (1 << 1),
  247. FTRACE_UPDATE_TRACE_FUNC = (1 << 2),
  248. FTRACE_START_FUNC_RET = (1 << 3),
  249. FTRACE_STOP_FUNC_RET = (1 << 4),
  250. };
  251. enum {
  252. FTRACE_UPDATE_IGNORE,
  253. FTRACE_UPDATE_MAKE_CALL,
  254. FTRACE_UPDATE_MAKE_NOP,
  255. };
  256. enum {
  257. FTRACE_ITER_FILTER = (1 << 0),
  258. FTRACE_ITER_NOTRACE = (1 << 1),
  259. FTRACE_ITER_PRINTALL = (1 << 2),
  260. FTRACE_ITER_DO_HASH = (1 << 3),
  261. FTRACE_ITER_HASH = (1 << 4),
  262. FTRACE_ITER_ENABLED = (1 << 5),
  263. };
  264. void arch_ftrace_update_code(int command);
  265. struct ftrace_rec_iter;
  266. struct ftrace_rec_iter *ftrace_rec_iter_start(void);
  267. struct ftrace_rec_iter *ftrace_rec_iter_next(struct ftrace_rec_iter *iter);
  268. struct dyn_ftrace *ftrace_rec_iter_record(struct ftrace_rec_iter *iter);
  269. #define for_ftrace_rec_iter(iter) \
  270. for (iter = ftrace_rec_iter_start(); \
  271. iter; \
  272. iter = ftrace_rec_iter_next(iter))
  273. int ftrace_update_record(struct dyn_ftrace *rec, int enable);
  274. int ftrace_test_record(struct dyn_ftrace *rec, int enable);
  275. void ftrace_run_stop_machine(int command);
  276. unsigned long ftrace_location(unsigned long ip);
  277. extern ftrace_func_t ftrace_trace_function;
  278. int ftrace_regex_open(struct ftrace_ops *ops, int flag,
  279. struct inode *inode, struct file *file);
  280. ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
  281. size_t cnt, loff_t *ppos);
  282. ssize_t ftrace_notrace_write(struct file *file, const char __user *ubuf,
  283. size_t cnt, loff_t *ppos);
  284. loff_t ftrace_regex_lseek(struct file *file, loff_t offset, int origin);
  285. int ftrace_regex_release(struct inode *inode, struct file *file);
  286. void __init
  287. ftrace_set_early_filter(struct ftrace_ops *ops, char *buf, int enable);
  288. /* defined in arch */
  289. extern int ftrace_ip_converted(unsigned long ip);
  290. extern int ftrace_dyn_arch_init(void *data);
  291. extern void ftrace_replace_code(int enable);
  292. extern int ftrace_update_ftrace_func(ftrace_func_t func);
  293. extern void ftrace_caller(void);
  294. extern void ftrace_call(void);
  295. extern void mcount_call(void);
  296. void ftrace_modify_all_code(int command);
  297. #ifndef FTRACE_ADDR
  298. #define FTRACE_ADDR ((unsigned long)ftrace_caller)
  299. #endif
  300. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  301. extern void ftrace_graph_caller(void);
  302. extern int ftrace_enable_ftrace_graph_caller(void);
  303. extern int ftrace_disable_ftrace_graph_caller(void);
  304. #else
  305. static inline int ftrace_enable_ftrace_graph_caller(void) { return 0; }
  306. static inline int ftrace_disable_ftrace_graph_caller(void) { return 0; }
  307. #endif
  308. /**
  309. * ftrace_make_nop - convert code into nop
  310. * @mod: module structure if called by module load initialization
  311. * @rec: the mcount call site record
  312. * @addr: the address that the call site should be calling
  313. *
  314. * This is a very sensitive operation and great care needs
  315. * to be taken by the arch. The operation should carefully
  316. * read the location, check to see if what is read is indeed
  317. * what we expect it to be, and then on success of the compare,
  318. * it should write to the location.
  319. *
  320. * The code segment at @rec->ip should be a caller to @addr
  321. *
  322. * Return must be:
  323. * 0 on success
  324. * -EFAULT on error reading the location
  325. * -EINVAL on a failed compare of the contents
  326. * -EPERM on error writing to the location
  327. * Any other value will be considered a failure.
  328. */
  329. extern int ftrace_make_nop(struct module *mod,
  330. struct dyn_ftrace *rec, unsigned long addr);
  331. /**
  332. * ftrace_make_call - convert a nop call site into a call to addr
  333. * @rec: the mcount call site record
  334. * @addr: the address that the call site should call
  335. *
  336. * This is a very sensitive operation and great care needs
  337. * to be taken by the arch. The operation should carefully
  338. * read the location, check to see if what is read is indeed
  339. * what we expect it to be, and then on success of the compare,
  340. * it should write to the location.
  341. *
  342. * The code segment at @rec->ip should be a nop
  343. *
  344. * Return must be:
  345. * 0 on success
  346. * -EFAULT on error reading the location
  347. * -EINVAL on a failed compare of the contents
  348. * -EPERM on error writing to the location
  349. * Any other value will be considered a failure.
  350. */
  351. extern int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr);
  352. /* May be defined in arch */
  353. extern int ftrace_arch_read_dyn_info(char *buf, int size);
  354. extern int skip_trace(unsigned long ip);
  355. extern void ftrace_disable_daemon(void);
  356. extern void ftrace_enable_daemon(void);
  357. #else
  358. static inline int skip_trace(unsigned long ip) { return 0; }
  359. static inline int ftrace_force_update(void) { return 0; }
  360. static inline void ftrace_disable_daemon(void) { }
  361. static inline void ftrace_enable_daemon(void) { }
  362. static inline void ftrace_release_mod(struct module *mod) {}
  363. static inline int register_ftrace_command(struct ftrace_func_command *cmd)
  364. {
  365. return -EINVAL;
  366. }
  367. static inline int unregister_ftrace_command(char *cmd_name)
  368. {
  369. return -EINVAL;
  370. }
  371. static inline int ftrace_text_reserved(void *start, void *end)
  372. {
  373. return 0;
  374. }
  375. /*
  376. * Again users of functions that have ftrace_ops may not
  377. * have them defined when ftrace is not enabled, but these
  378. * functions may still be called. Use a macro instead of inline.
  379. */
  380. #define ftrace_regex_open(ops, flag, inod, file) ({ -ENODEV; })
  381. #define ftrace_set_early_filter(ops, buf, enable) do { } while (0)
  382. #define ftrace_set_filter(ops, buf, len, reset) ({ -ENODEV; })
  383. #define ftrace_set_notrace(ops, buf, len, reset) ({ -ENODEV; })
  384. #define ftrace_free_filter(ops) do { } while (0)
  385. static inline ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
  386. size_t cnt, loff_t *ppos) { return -ENODEV; }
  387. static inline ssize_t ftrace_notrace_write(struct file *file, const char __user *ubuf,
  388. size_t cnt, loff_t *ppos) { return -ENODEV; }
  389. static inline loff_t ftrace_regex_lseek(struct file *file, loff_t offset, int origin)
  390. {
  391. return -ENODEV;
  392. }
  393. static inline int
  394. ftrace_regex_release(struct inode *inode, struct file *file) { return -ENODEV; }
  395. #endif /* CONFIG_DYNAMIC_FTRACE */
  396. /* totally disable ftrace - can not re-enable after this */
  397. void ftrace_kill(void);
  398. static inline void tracer_disable(void)
  399. {
  400. #ifdef CONFIG_FUNCTION_TRACER
  401. ftrace_enabled = 0;
  402. #endif
  403. }
  404. /*
  405. * Ftrace disable/restore without lock. Some synchronization mechanism
  406. * must be used to prevent ftrace_enabled to be changed between
  407. * disable/restore.
  408. */
  409. static inline int __ftrace_enabled_save(void)
  410. {
  411. #ifdef CONFIG_FUNCTION_TRACER
  412. int saved_ftrace_enabled = ftrace_enabled;
  413. ftrace_enabled = 0;
  414. return saved_ftrace_enabled;
  415. #else
  416. return 0;
  417. #endif
  418. }
  419. static inline void __ftrace_enabled_restore(int enabled)
  420. {
  421. #ifdef CONFIG_FUNCTION_TRACER
  422. ftrace_enabled = enabled;
  423. #endif
  424. }
  425. #ifndef HAVE_ARCH_CALLER_ADDR
  426. # ifdef CONFIG_FRAME_POINTER
  427. # define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
  428. # define CALLER_ADDR1 ((unsigned long)__builtin_return_address(1))
  429. # define CALLER_ADDR2 ((unsigned long)__builtin_return_address(2))
  430. # define CALLER_ADDR3 ((unsigned long)__builtin_return_address(3))
  431. # define CALLER_ADDR4 ((unsigned long)__builtin_return_address(4))
  432. # define CALLER_ADDR5 ((unsigned long)__builtin_return_address(5))
  433. # define CALLER_ADDR6 ((unsigned long)__builtin_return_address(6))
  434. # else
  435. # define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
  436. # define CALLER_ADDR1 0UL
  437. # define CALLER_ADDR2 0UL
  438. # define CALLER_ADDR3 0UL
  439. # define CALLER_ADDR4 0UL
  440. # define CALLER_ADDR5 0UL
  441. # define CALLER_ADDR6 0UL
  442. # endif
  443. #endif /* ifndef HAVE_ARCH_CALLER_ADDR */
  444. #ifdef CONFIG_IRQSOFF_TRACER
  445. extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
  446. extern void time_hardirqs_off(unsigned long a0, unsigned long a1);
  447. #else
  448. static inline void time_hardirqs_on(unsigned long a0, unsigned long a1) { }
  449. static inline void time_hardirqs_off(unsigned long a0, unsigned long a1) { }
  450. #endif
  451. #ifdef CONFIG_PREEMPT_TRACER
  452. extern void trace_preempt_on(unsigned long a0, unsigned long a1);
  453. extern void trace_preempt_off(unsigned long a0, unsigned long a1);
  454. #else
  455. /*
  456. * Use defines instead of static inlines because some arches will make code out
  457. * of the CALLER_ADDR, when we really want these to be a real nop.
  458. */
  459. # define trace_preempt_on(a0, a1) do { } while (0)
  460. # define trace_preempt_off(a0, a1) do { } while (0)
  461. #endif
  462. #ifdef CONFIG_FTRACE_MCOUNT_RECORD
  463. extern void ftrace_init(void);
  464. #else
  465. static inline void ftrace_init(void) { }
  466. #endif
  467. /*
  468. * Structure that defines an entry function trace.
  469. */
  470. struct ftrace_graph_ent {
  471. unsigned long func; /* Current function */
  472. int depth;
  473. };
  474. /*
  475. * Structure that defines a return function trace.
  476. */
  477. struct ftrace_graph_ret {
  478. unsigned long func; /* Current function */
  479. unsigned long long calltime;
  480. unsigned long long rettime;
  481. /* Number of functions that overran the depth limit for current task */
  482. unsigned long overrun;
  483. int depth;
  484. };
  485. /* Type of the callback handlers for tracing function graph*/
  486. typedef void (*trace_func_graph_ret_t)(struct ftrace_graph_ret *); /* return */
  487. typedef int (*trace_func_graph_ent_t)(struct ftrace_graph_ent *); /* entry */
  488. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  489. /* for init task */
  490. #define INIT_FTRACE_GRAPH .ret_stack = NULL,
  491. /*
  492. * Stack of return addresses for functions
  493. * of a thread.
  494. * Used in struct thread_info
  495. */
  496. struct ftrace_ret_stack {
  497. unsigned long ret;
  498. unsigned long func;
  499. unsigned long long calltime;
  500. unsigned long long subtime;
  501. unsigned long fp;
  502. };
  503. /*
  504. * Primary handler of a function return.
  505. * It relays on ftrace_return_to_handler.
  506. * Defined in entry_32/64.S
  507. */
  508. extern void return_to_handler(void);
  509. extern int
  510. ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth,
  511. unsigned long frame_pointer);
  512. /*
  513. * Sometimes we don't want to trace a function with the function
  514. * graph tracer but we want them to keep traced by the usual function
  515. * tracer if the function graph tracer is not configured.
  516. */
  517. #define __notrace_funcgraph notrace
  518. /*
  519. * We want to which function is an entrypoint of a hardirq.
  520. * That will help us to put a signal on output.
  521. */
  522. #define __irq_entry __attribute__((__section__(".irqentry.text")))
  523. /* Limits of hardirq entrypoints */
  524. extern char __irqentry_text_start[];
  525. extern char __irqentry_text_end[];
  526. #define FTRACE_RETFUNC_DEPTH 50
  527. #define FTRACE_RETSTACK_ALLOC_SIZE 32
  528. extern int register_ftrace_graph(trace_func_graph_ret_t retfunc,
  529. trace_func_graph_ent_t entryfunc);
  530. extern void ftrace_graph_stop(void);
  531. /* The current handlers in use */
  532. extern trace_func_graph_ret_t ftrace_graph_return;
  533. extern trace_func_graph_ent_t ftrace_graph_entry;
  534. extern void unregister_ftrace_graph(void);
  535. extern void ftrace_graph_init_task(struct task_struct *t);
  536. extern void ftrace_graph_exit_task(struct task_struct *t);
  537. extern void ftrace_graph_init_idle_task(struct task_struct *t, int cpu);
  538. static inline int task_curr_ret_stack(struct task_struct *t)
  539. {
  540. return t->curr_ret_stack;
  541. }
  542. static inline void pause_graph_tracing(void)
  543. {
  544. atomic_inc(&current->tracing_graph_pause);
  545. }
  546. static inline void unpause_graph_tracing(void)
  547. {
  548. atomic_dec(&current->tracing_graph_pause);
  549. }
  550. #else /* !CONFIG_FUNCTION_GRAPH_TRACER */
  551. #define __notrace_funcgraph
  552. #define __irq_entry
  553. #define INIT_FTRACE_GRAPH
  554. static inline void ftrace_graph_init_task(struct task_struct *t) { }
  555. static inline void ftrace_graph_exit_task(struct task_struct *t) { }
  556. static inline void ftrace_graph_init_idle_task(struct task_struct *t, int cpu) { }
  557. static inline int register_ftrace_graph(trace_func_graph_ret_t retfunc,
  558. trace_func_graph_ent_t entryfunc)
  559. {
  560. return -1;
  561. }
  562. static inline void unregister_ftrace_graph(void) { }
  563. static inline int task_curr_ret_stack(struct task_struct *tsk)
  564. {
  565. return -1;
  566. }
  567. static inline void pause_graph_tracing(void) { }
  568. static inline void unpause_graph_tracing(void) { }
  569. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  570. #ifdef CONFIG_TRACING
  571. /* flags for current->trace */
  572. enum {
  573. TSK_TRACE_FL_TRACE_BIT = 0,
  574. TSK_TRACE_FL_GRAPH_BIT = 1,
  575. };
  576. enum {
  577. TSK_TRACE_FL_TRACE = 1 << TSK_TRACE_FL_TRACE_BIT,
  578. TSK_TRACE_FL_GRAPH = 1 << TSK_TRACE_FL_GRAPH_BIT,
  579. };
  580. static inline void set_tsk_trace_trace(struct task_struct *tsk)
  581. {
  582. set_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
  583. }
  584. static inline void clear_tsk_trace_trace(struct task_struct *tsk)
  585. {
  586. clear_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
  587. }
  588. static inline int test_tsk_trace_trace(struct task_struct *tsk)
  589. {
  590. return tsk->trace & TSK_TRACE_FL_TRACE;
  591. }
  592. static inline void set_tsk_trace_graph(struct task_struct *tsk)
  593. {
  594. set_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
  595. }
  596. static inline void clear_tsk_trace_graph(struct task_struct *tsk)
  597. {
  598. clear_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
  599. }
  600. static inline int test_tsk_trace_graph(struct task_struct *tsk)
  601. {
  602. return tsk->trace & TSK_TRACE_FL_GRAPH;
  603. }
  604. enum ftrace_dump_mode;
  605. extern enum ftrace_dump_mode ftrace_dump_on_oops;
  606. #ifdef CONFIG_PREEMPT
  607. #define INIT_TRACE_RECURSION .trace_recursion = 0,
  608. #endif
  609. #endif /* CONFIG_TRACING */
  610. #ifndef INIT_TRACE_RECURSION
  611. #define INIT_TRACE_RECURSION
  612. #endif
  613. #ifdef CONFIG_FTRACE_SYSCALLS
  614. unsigned long arch_syscall_addr(int nr);
  615. #endif /* CONFIG_FTRACE_SYSCALLS */
  616. #endif /* _LINUX_FTRACE_H */