ftrace.h 6.7 KB

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