ftrace.h 6.9 KB

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