ftrace.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. #ifndef _LINUX_FTRACE_H
  2. #define _LINUX_FTRACE_H
  3. #ifdef CONFIG_FTRACE
  4. #include <linux/linkage.h>
  5. #include <linux/fs.h>
  6. #include <linux/init.h>
  7. #include <linux/types.h>
  8. #include <linux/kallsyms.h>
  9. extern int ftrace_enabled;
  10. extern int
  11. ftrace_enable_sysctl(struct ctl_table *table, int write,
  12. struct file *filp, void __user *buffer, size_t *lenp,
  13. loff_t *ppos);
  14. typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip);
  15. struct ftrace_ops {
  16. ftrace_func_t func;
  17. struct ftrace_ops *next;
  18. };
  19. /*
  20. * The ftrace_ops must be a static and should also
  21. * be read_mostly. These functions do modify read_mostly variables
  22. * so use them sparely. Never free an ftrace_op or modify the
  23. * next pointer after it has been registered. Even after unregistering
  24. * it, the next pointer may still be used internally.
  25. */
  26. int register_ftrace_function(struct ftrace_ops *ops);
  27. int unregister_ftrace_function(struct ftrace_ops *ops);
  28. void clear_ftrace_function(void);
  29. extern void ftrace_stub(unsigned long a0, unsigned long a1);
  30. #else /* !CONFIG_FTRACE */
  31. # define register_ftrace_function(ops) do { } while (0)
  32. # define unregister_ftrace_function(ops) do { } while (0)
  33. # define clear_ftrace_function(ops) do { } while (0)
  34. static inline void ftrace_kill_atomic(void) { }
  35. #endif /* CONFIG_FTRACE */
  36. #ifdef CONFIG_DYNAMIC_FTRACE
  37. # define FTRACE_HASHBITS 10
  38. # define FTRACE_HASHSIZE (1<<FTRACE_HASHBITS)
  39. enum {
  40. FTRACE_FL_FREE = (1 << 0),
  41. FTRACE_FL_FAILED = (1 << 1),
  42. FTRACE_FL_FILTER = (1 << 2),
  43. FTRACE_FL_ENABLED = (1 << 3),
  44. FTRACE_FL_NOTRACE = (1 << 4),
  45. FTRACE_FL_CONVERTED = (1 << 5),
  46. FTRACE_FL_FROZEN = (1 << 6),
  47. };
  48. struct dyn_ftrace {
  49. struct hlist_node node;
  50. unsigned long ip; /* address of mcount call-site */
  51. unsigned long flags;
  52. };
  53. int ftrace_force_update(void);
  54. void ftrace_set_filter(unsigned char *buf, int len, int reset);
  55. /* defined in arch */
  56. extern int ftrace_ip_converted(unsigned long ip);
  57. extern unsigned char *ftrace_nop_replace(void);
  58. extern unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr);
  59. extern int ftrace_dyn_arch_init(void *data);
  60. extern int ftrace_mcount_set(unsigned long *data);
  61. extern int ftrace_modify_code(unsigned long ip, unsigned char *old_code,
  62. unsigned char *new_code);
  63. extern int ftrace_update_ftrace_func(ftrace_func_t func);
  64. extern void ftrace_caller(void);
  65. extern void ftrace_call(void);
  66. extern void mcount_call(void);
  67. extern int skip_trace(unsigned long ip);
  68. extern void ftrace_release(void *start, unsigned long size);
  69. extern void ftrace_disable_daemon(void);
  70. extern void ftrace_enable_daemon(void);
  71. #else
  72. # define skip_trace(ip) ({ 0; })
  73. # define ftrace_force_update() ({ 0; })
  74. # define ftrace_set_filter(buf, len, reset) do { } while (0)
  75. # define ftrace_disable_daemon() do { } while (0)
  76. # define ftrace_enable_daemon() do { } while (0)
  77. static inline void ftrace_release(void *start, unsigned long size) { }
  78. #endif /* CONFIG_DYNAMIC_FTRACE */
  79. /* totally disable ftrace - can not re-enable after this */
  80. void ftrace_kill(void);
  81. void ftrace_kill_atomic(void);
  82. static inline void tracer_disable(void)
  83. {
  84. #ifdef CONFIG_FTRACE
  85. ftrace_enabled = 0;
  86. #endif
  87. }
  88. /*
  89. * Ftrace disable/restore without lock. Some synchronization mechanism
  90. * must be used to prevent ftrace_enabled to be changed between
  91. * disable/restore.
  92. */
  93. static inline int __ftrace_enabled_save(void)
  94. {
  95. #ifdef CONFIG_FTRACE
  96. int saved_ftrace_enabled = ftrace_enabled;
  97. ftrace_enabled = 0;
  98. return saved_ftrace_enabled;
  99. #else
  100. return 0;
  101. #endif
  102. }
  103. static inline void __ftrace_enabled_restore(int enabled)
  104. {
  105. #ifdef CONFIG_FTRACE
  106. ftrace_enabled = enabled;
  107. #endif
  108. }
  109. #ifdef CONFIG_FRAME_POINTER
  110. /* TODO: need to fix this for ARM */
  111. # define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
  112. # define CALLER_ADDR1 ((unsigned long)__builtin_return_address(1))
  113. # define CALLER_ADDR2 ((unsigned long)__builtin_return_address(2))
  114. # define CALLER_ADDR3 ((unsigned long)__builtin_return_address(3))
  115. # define CALLER_ADDR4 ((unsigned long)__builtin_return_address(4))
  116. # define CALLER_ADDR5 ((unsigned long)__builtin_return_address(5))
  117. # define CALLER_ADDR6 ((unsigned long)__builtin_return_address(6))
  118. #else
  119. # define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
  120. # define CALLER_ADDR1 0UL
  121. # define CALLER_ADDR2 0UL
  122. # define CALLER_ADDR3 0UL
  123. # define CALLER_ADDR4 0UL
  124. # define CALLER_ADDR5 0UL
  125. # define CALLER_ADDR6 0UL
  126. #endif
  127. #ifdef CONFIG_IRQSOFF_TRACER
  128. extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
  129. extern void time_hardirqs_off(unsigned long a0, unsigned long a1);
  130. #else
  131. # define time_hardirqs_on(a0, a1) do { } while (0)
  132. # define time_hardirqs_off(a0, a1) do { } while (0)
  133. #endif
  134. #ifdef CONFIG_PREEMPT_TRACER
  135. extern void trace_preempt_on(unsigned long a0, unsigned long a1);
  136. extern void trace_preempt_off(unsigned long a0, unsigned long a1);
  137. #else
  138. # define trace_preempt_on(a0, a1) do { } while (0)
  139. # define trace_preempt_off(a0, a1) do { } while (0)
  140. #endif
  141. #ifdef CONFIG_TRACING
  142. extern void
  143. ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3);
  144. /**
  145. * ftrace_printk - printf formatting in the ftrace buffer
  146. * @fmt: the printf format for printing
  147. *
  148. * Note: __ftrace_printk is an internal function for ftrace_printk and
  149. * the @ip is passed in via the ftrace_printk macro.
  150. *
  151. * This function allows a kernel developer to debug fast path sections
  152. * that printk is not appropriate for. By scattering in various
  153. * printk like tracing in the code, a developer can quickly see
  154. * where problems are occurring.
  155. *
  156. * This is intended as a debugging tool for the developer only.
  157. * Please refrain from leaving ftrace_printks scattered around in
  158. * your code.
  159. */
  160. # define ftrace_printk(fmt...) __ftrace_printk(_THIS_IP_, fmt)
  161. extern int
  162. __ftrace_printk(unsigned long ip, const char *fmt, ...)
  163. __attribute__ ((format (printf, 2, 3)));
  164. extern void ftrace_dump(void);
  165. #else
  166. static inline void
  167. ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) { }
  168. static inline int
  169. ftrace_printk(const char *fmt, ...) __attribute__ ((format (printf, 1, 0)));
  170. static inline int
  171. ftrace_printk(const char *fmt, ...)
  172. {
  173. return 0;
  174. }
  175. static inline void ftrace_dump(void) { }
  176. #endif
  177. #ifdef CONFIG_FTRACE_MCOUNT_RECORD
  178. extern void ftrace_init(void);
  179. extern void ftrace_init_module(unsigned long *start, unsigned long *end);
  180. #else
  181. static inline void ftrace_init(void) { }
  182. static inline void
  183. ftrace_init_module(unsigned long *start, unsigned long *end) { }
  184. #endif
  185. struct boot_trace {
  186. pid_t caller;
  187. char func[KSYM_NAME_LEN];
  188. int result;
  189. unsigned long long duration;
  190. ktime_t calltime;
  191. ktime_t rettime;
  192. };
  193. #ifdef CONFIG_BOOT_TRACER
  194. extern void trace_boot(struct boot_trace *it, initcall_t fn);
  195. extern void start_boot_trace(void);
  196. #else
  197. static inline void trace_boot(struct boot_trace *it, initcall_t fn) { }
  198. static inline void start_boot_trace(void) { }
  199. #endif
  200. #endif /* _LINUX_FTRACE_H */