ftrace.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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_FUNCTION_TRACER
  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_FUNCTION_TRACER */
  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(void) { }
  36. #endif /* CONFIG_FUNCTION_TRACER */
  37. #ifdef CONFIG_DYNAMIC_FTRACE
  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 list_head list;
  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_update_ftrace_func(ftrace_func_t func);
  60. extern void ftrace_caller(void);
  61. extern void ftrace_call(void);
  62. extern void mcount_call(void);
  63. /* May be defined in arch */
  64. extern int ftrace_arch_read_dyn_info(char *buf, int size);
  65. /**
  66. * ftrace_modify_code - modify code segment
  67. * @ip: the address of the code segment
  68. * @old_code: the contents of what is expected to be there
  69. * @new_code: the code to patch in
  70. *
  71. * This is a very sensitive operation and great care needs
  72. * to be taken by the arch. The operation should carefully
  73. * read the location, check to see if what is read is indeed
  74. * what we expect it to be, and then on success of the compare,
  75. * it should write to the location.
  76. *
  77. * Return must be:
  78. * 0 on success
  79. * -EFAULT on error reading the location
  80. * -EINVAL on a failed compare of the contents
  81. * -EPERM on error writing to the location
  82. * Any other value will be considered a failure.
  83. */
  84. extern int ftrace_modify_code(unsigned long ip, unsigned char *old_code,
  85. unsigned char *new_code);
  86. extern int skip_trace(unsigned long ip);
  87. extern void ftrace_release(void *start, unsigned long size);
  88. extern void ftrace_disable_daemon(void);
  89. extern void ftrace_enable_daemon(void);
  90. #else
  91. # define skip_trace(ip) ({ 0; })
  92. # define ftrace_force_update() ({ 0; })
  93. # define ftrace_set_filter(buf, len, reset) do { } while (0)
  94. # define ftrace_disable_daemon() do { } while (0)
  95. # define ftrace_enable_daemon() do { } while (0)
  96. static inline void ftrace_release(void *start, unsigned long size) { }
  97. #endif /* CONFIG_DYNAMIC_FTRACE */
  98. /* totally disable ftrace - can not re-enable after this */
  99. void ftrace_kill(void);
  100. static inline void tracer_disable(void)
  101. {
  102. #ifdef CONFIG_FUNCTION_TRACER
  103. ftrace_enabled = 0;
  104. #endif
  105. }
  106. /*
  107. * Ftrace disable/restore without lock. Some synchronization mechanism
  108. * must be used to prevent ftrace_enabled to be changed between
  109. * disable/restore.
  110. */
  111. static inline int __ftrace_enabled_save(void)
  112. {
  113. #ifdef CONFIG_FUNCTION_TRACER
  114. int saved_ftrace_enabled = ftrace_enabled;
  115. ftrace_enabled = 0;
  116. return saved_ftrace_enabled;
  117. #else
  118. return 0;
  119. #endif
  120. }
  121. static inline void __ftrace_enabled_restore(int enabled)
  122. {
  123. #ifdef CONFIG_FUNCTION_TRACER
  124. ftrace_enabled = enabled;
  125. #endif
  126. }
  127. #ifdef CONFIG_FRAME_POINTER
  128. /* TODO: need to fix this for ARM */
  129. # define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
  130. # define CALLER_ADDR1 ((unsigned long)__builtin_return_address(1))
  131. # define CALLER_ADDR2 ((unsigned long)__builtin_return_address(2))
  132. # define CALLER_ADDR3 ((unsigned long)__builtin_return_address(3))
  133. # define CALLER_ADDR4 ((unsigned long)__builtin_return_address(4))
  134. # define CALLER_ADDR5 ((unsigned long)__builtin_return_address(5))
  135. # define CALLER_ADDR6 ((unsigned long)__builtin_return_address(6))
  136. #else
  137. # define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
  138. # define CALLER_ADDR1 0UL
  139. # define CALLER_ADDR2 0UL
  140. # define CALLER_ADDR3 0UL
  141. # define CALLER_ADDR4 0UL
  142. # define CALLER_ADDR5 0UL
  143. # define CALLER_ADDR6 0UL
  144. #endif
  145. #ifdef CONFIG_IRQSOFF_TRACER
  146. extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
  147. extern void time_hardirqs_off(unsigned long a0, unsigned long a1);
  148. #else
  149. # define time_hardirqs_on(a0, a1) do { } while (0)
  150. # define time_hardirqs_off(a0, a1) do { } while (0)
  151. #endif
  152. #ifdef CONFIG_PREEMPT_TRACER
  153. extern void trace_preempt_on(unsigned long a0, unsigned long a1);
  154. extern void trace_preempt_off(unsigned long a0, unsigned long a1);
  155. #else
  156. # define trace_preempt_on(a0, a1) do { } while (0)
  157. # define trace_preempt_off(a0, a1) do { } while (0)
  158. #endif
  159. #ifdef CONFIG_TRACING
  160. extern int ftrace_dump_on_oops;
  161. extern void
  162. ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3);
  163. /**
  164. * ftrace_printk - printf formatting in the ftrace buffer
  165. * @fmt: the printf format for printing
  166. *
  167. * Note: __ftrace_printk is an internal function for ftrace_printk and
  168. * the @ip is passed in via the ftrace_printk macro.
  169. *
  170. * This function allows a kernel developer to debug fast path sections
  171. * that printk is not appropriate for. By scattering in various
  172. * printk like tracing in the code, a developer can quickly see
  173. * where problems are occurring.
  174. *
  175. * This is intended as a debugging tool for the developer only.
  176. * Please refrain from leaving ftrace_printks scattered around in
  177. * your code.
  178. */
  179. # define ftrace_printk(fmt...) __ftrace_printk(_THIS_IP_, fmt)
  180. extern int
  181. __ftrace_printk(unsigned long ip, const char *fmt, ...)
  182. __attribute__ ((format (printf, 2, 3)));
  183. extern void ftrace_dump(void);
  184. #else
  185. static inline void
  186. ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) { }
  187. static inline int
  188. ftrace_printk(const char *fmt, ...) __attribute__ ((format (printf, 1, 0)));
  189. static inline int
  190. ftrace_printk(const char *fmt, ...)
  191. {
  192. return 0;
  193. }
  194. static inline void ftrace_dump(void) { }
  195. #endif
  196. #ifdef CONFIG_FTRACE_MCOUNT_RECORD
  197. extern void ftrace_init(void);
  198. extern void ftrace_init_module(unsigned long *start, unsigned long *end);
  199. #else
  200. static inline void ftrace_init(void) { }
  201. static inline void
  202. ftrace_init_module(unsigned long *start, unsigned long *end) { }
  203. #endif
  204. /*
  205. * Structure which defines the trace of an initcall.
  206. * You don't have to fill the func field since it is
  207. * only used internally by the tracer.
  208. */
  209. struct boot_trace {
  210. pid_t caller;
  211. char func[KSYM_NAME_LEN];
  212. int result;
  213. unsigned long long duration; /* usecs */
  214. ktime_t calltime;
  215. ktime_t rettime;
  216. };
  217. #ifdef CONFIG_BOOT_TRACER
  218. /* Append the trace on the ring-buffer */
  219. extern void trace_boot(struct boot_trace *it, initcall_t fn);
  220. /* Tells the tracer that smp_pre_initcall is finished.
  221. * So we can start the tracing
  222. */
  223. extern void start_boot_trace(void);
  224. /* Resume the tracing of other necessary events
  225. * such as sched switches
  226. */
  227. extern void enable_boot_trace(void);
  228. /* Suspend this tracing. Actually, only sched_switches tracing have
  229. * to be suspended. Initcalls doesn't need it.)
  230. */
  231. extern void disable_boot_trace(void);
  232. #else
  233. static inline void trace_boot(struct boot_trace *it, initcall_t fn) { }
  234. static inline void start_boot_trace(void) { }
  235. static inline void enable_boot_trace(void) { }
  236. static inline void disable_boot_trace(void) { }
  237. #endif
  238. #endif /* _LINUX_FTRACE_H */