ftrace.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. extern int function_trace_stop;
  21. /**
  22. * ftrace_stop - stop function tracer.
  23. *
  24. * A quick way to stop the function tracer. Note this an on off switch,
  25. * it is not something that is recursive like preempt_disable.
  26. * This does not disable the calling of mcount, it only stops the
  27. * calling of functions from mcount.
  28. */
  29. static inline void ftrace_stop(void)
  30. {
  31. function_trace_stop = 1;
  32. }
  33. /**
  34. * ftrace_start - start the function tracer.
  35. *
  36. * This function is the inverse of ftrace_stop. This does not enable
  37. * the function tracing if the function tracer is disabled. This only
  38. * sets the function tracer flag to continue calling the functions
  39. * from mcount.
  40. */
  41. static inline void ftrace_start(void)
  42. {
  43. function_trace_stop = 0;
  44. }
  45. /*
  46. * The ftrace_ops must be a static and should also
  47. * be read_mostly. These functions do modify read_mostly variables
  48. * so use them sparely. Never free an ftrace_op or modify the
  49. * next pointer after it has been registered. Even after unregistering
  50. * it, the next pointer may still be used internally.
  51. */
  52. int register_ftrace_function(struct ftrace_ops *ops);
  53. int unregister_ftrace_function(struct ftrace_ops *ops);
  54. void clear_ftrace_function(void);
  55. extern void ftrace_stub(unsigned long a0, unsigned long a1);
  56. #else /* !CONFIG_FUNCTION_TRACER */
  57. # define register_ftrace_function(ops) do { } while (0)
  58. # define unregister_ftrace_function(ops) do { } while (0)
  59. # define clear_ftrace_function(ops) do { } while (0)
  60. static inline void ftrace_kill(void) { }
  61. static inline void ftrace_stop(void) { }
  62. static inline void ftrace_start(void) { }
  63. #endif /* CONFIG_FUNCTION_TRACER */
  64. #ifdef CONFIG_DYNAMIC_FTRACE
  65. enum {
  66. FTRACE_FL_FREE = (1 << 0),
  67. FTRACE_FL_FAILED = (1 << 1),
  68. FTRACE_FL_FILTER = (1 << 2),
  69. FTRACE_FL_ENABLED = (1 << 3),
  70. FTRACE_FL_NOTRACE = (1 << 4),
  71. FTRACE_FL_CONVERTED = (1 << 5),
  72. FTRACE_FL_FROZEN = (1 << 6),
  73. };
  74. struct dyn_ftrace {
  75. struct list_head list;
  76. unsigned long ip; /* address of mcount call-site */
  77. unsigned long flags;
  78. };
  79. int ftrace_force_update(void);
  80. void ftrace_set_filter(unsigned char *buf, int len, int reset);
  81. /* defined in arch */
  82. extern int ftrace_ip_converted(unsigned long ip);
  83. extern unsigned char *ftrace_nop_replace(void);
  84. extern unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr);
  85. extern int ftrace_dyn_arch_init(void *data);
  86. extern int ftrace_update_ftrace_func(ftrace_func_t func);
  87. extern void ftrace_caller(void);
  88. extern void ftrace_call(void);
  89. extern void mcount_call(void);
  90. /* May be defined in arch */
  91. extern int ftrace_arch_read_dyn_info(char *buf, int size);
  92. /**
  93. * ftrace_modify_code - modify code segment
  94. * @ip: the address of the code segment
  95. * @old_code: the contents of what is expected to be there
  96. * @new_code: the code to patch in
  97. *
  98. * This is a very sensitive operation and great care needs
  99. * to be taken by the arch. The operation should carefully
  100. * read the location, check to see if what is read is indeed
  101. * what we expect it to be, and then on success of the compare,
  102. * it should write to the location.
  103. *
  104. * Return must be:
  105. * 0 on success
  106. * -EFAULT on error reading the location
  107. * -EINVAL on a failed compare of the contents
  108. * -EPERM on error writing to the location
  109. * Any other value will be considered a failure.
  110. */
  111. extern int ftrace_modify_code(unsigned long ip, unsigned char *old_code,
  112. unsigned char *new_code);
  113. extern int skip_trace(unsigned long ip);
  114. extern void ftrace_release(void *start, unsigned long size);
  115. extern void ftrace_disable_daemon(void);
  116. extern void ftrace_enable_daemon(void);
  117. #else
  118. # define skip_trace(ip) ({ 0; })
  119. # define ftrace_force_update() ({ 0; })
  120. # define ftrace_set_filter(buf, len, reset) do { } while (0)
  121. # define ftrace_disable_daemon() do { } while (0)
  122. # define ftrace_enable_daemon() do { } while (0)
  123. static inline void ftrace_release(void *start, unsigned long size) { }
  124. #endif /* CONFIG_DYNAMIC_FTRACE */
  125. /* totally disable ftrace - can not re-enable after this */
  126. void ftrace_kill(void);
  127. static inline void tracer_disable(void)
  128. {
  129. #ifdef CONFIG_FUNCTION_TRACER
  130. ftrace_enabled = 0;
  131. #endif
  132. }
  133. /*
  134. * Ftrace disable/restore without lock. Some synchronization mechanism
  135. * must be used to prevent ftrace_enabled to be changed between
  136. * disable/restore.
  137. */
  138. static inline int __ftrace_enabled_save(void)
  139. {
  140. #ifdef CONFIG_FUNCTION_TRACER
  141. int saved_ftrace_enabled = ftrace_enabled;
  142. ftrace_enabled = 0;
  143. return saved_ftrace_enabled;
  144. #else
  145. return 0;
  146. #endif
  147. }
  148. static inline void __ftrace_enabled_restore(int enabled)
  149. {
  150. #ifdef CONFIG_FUNCTION_TRACER
  151. ftrace_enabled = enabled;
  152. #endif
  153. }
  154. #ifdef CONFIG_FRAME_POINTER
  155. /* TODO: need to fix this for ARM */
  156. # define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
  157. # define CALLER_ADDR1 ((unsigned long)__builtin_return_address(1))
  158. # define CALLER_ADDR2 ((unsigned long)__builtin_return_address(2))
  159. # define CALLER_ADDR3 ((unsigned long)__builtin_return_address(3))
  160. # define CALLER_ADDR4 ((unsigned long)__builtin_return_address(4))
  161. # define CALLER_ADDR5 ((unsigned long)__builtin_return_address(5))
  162. # define CALLER_ADDR6 ((unsigned long)__builtin_return_address(6))
  163. #else
  164. # define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
  165. # define CALLER_ADDR1 0UL
  166. # define CALLER_ADDR2 0UL
  167. # define CALLER_ADDR3 0UL
  168. # define CALLER_ADDR4 0UL
  169. # define CALLER_ADDR5 0UL
  170. # define CALLER_ADDR6 0UL
  171. #endif
  172. #ifdef CONFIG_IRQSOFF_TRACER
  173. extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
  174. extern void time_hardirqs_off(unsigned long a0, unsigned long a1);
  175. #else
  176. # define time_hardirqs_on(a0, a1) do { } while (0)
  177. # define time_hardirqs_off(a0, a1) do { } while (0)
  178. #endif
  179. #ifdef CONFIG_PREEMPT_TRACER
  180. extern void trace_preempt_on(unsigned long a0, unsigned long a1);
  181. extern void trace_preempt_off(unsigned long a0, unsigned long a1);
  182. #else
  183. # define trace_preempt_on(a0, a1) do { } while (0)
  184. # define trace_preempt_off(a0, a1) do { } while (0)
  185. #endif
  186. #ifdef CONFIG_TRACING
  187. extern int ftrace_dump_on_oops;
  188. extern void tracing_start(void);
  189. extern void tracing_stop(void);
  190. extern void
  191. ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3);
  192. /**
  193. * ftrace_printk - printf formatting in the ftrace buffer
  194. * @fmt: the printf format for printing
  195. *
  196. * Note: __ftrace_printk is an internal function for ftrace_printk and
  197. * the @ip is passed in via the ftrace_printk macro.
  198. *
  199. * This function allows a kernel developer to debug fast path sections
  200. * that printk is not appropriate for. By scattering in various
  201. * printk like tracing in the code, a developer can quickly see
  202. * where problems are occurring.
  203. *
  204. * This is intended as a debugging tool for the developer only.
  205. * Please refrain from leaving ftrace_printks scattered around in
  206. * your code.
  207. */
  208. # define ftrace_printk(fmt...) __ftrace_printk(_THIS_IP_, fmt)
  209. extern int
  210. __ftrace_printk(unsigned long ip, const char *fmt, ...)
  211. __attribute__ ((format (printf, 2, 3)));
  212. extern void ftrace_dump(void);
  213. #else
  214. static inline void
  215. ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) { }
  216. static inline int
  217. ftrace_printk(const char *fmt, ...) __attribute__ ((format (printf, 1, 0)));
  218. static inline void tracing_start(void) { }
  219. static inline void tracing_stop(void) { }
  220. static inline int
  221. ftrace_printk(const char *fmt, ...)
  222. {
  223. return 0;
  224. }
  225. static inline void ftrace_dump(void) { }
  226. #endif
  227. #ifdef CONFIG_FTRACE_MCOUNT_RECORD
  228. extern void ftrace_init(void);
  229. extern void ftrace_init_module(unsigned long *start, unsigned long *end);
  230. #else
  231. static inline void ftrace_init(void) { }
  232. static inline void
  233. ftrace_init_module(unsigned long *start, unsigned long *end) { }
  234. #endif
  235. /*
  236. * Structure which defines the trace of an initcall.
  237. * You don't have to fill the func field since it is
  238. * only used internally by the tracer.
  239. */
  240. struct boot_trace {
  241. pid_t caller;
  242. char func[KSYM_NAME_LEN];
  243. int result;
  244. unsigned long long duration; /* usecs */
  245. ktime_t calltime;
  246. ktime_t rettime;
  247. };
  248. #ifdef CONFIG_BOOT_TRACER
  249. /* Append the trace on the ring-buffer */
  250. extern void trace_boot(struct boot_trace *it, initcall_t fn);
  251. /* Tells the tracer that smp_pre_initcall is finished.
  252. * So we can start the tracing
  253. */
  254. extern void start_boot_trace(void);
  255. /* Resume the tracing of other necessary events
  256. * such as sched switches
  257. */
  258. extern void enable_boot_trace(void);
  259. /* Suspend this tracing. Actually, only sched_switches tracing have
  260. * to be suspended. Initcalls doesn't need it.)
  261. */
  262. extern void disable_boot_trace(void);
  263. #else
  264. static inline void trace_boot(struct boot_trace *it, initcall_t fn) { }
  265. static inline void start_boot_trace(void) { }
  266. static inline void enable_boot_trace(void) { }
  267. static inline void disable_boot_trace(void) { }
  268. #endif
  269. #endif /* _LINUX_FTRACE_H */