ftrace.h 6.3 KB

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