ftrace.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. #endif /* CONFIG_FTRACE */
  32. #ifdef CONFIG_DYNAMIC_FTRACE
  33. # define FTRACE_HASHBITS 10
  34. # define FTRACE_HASHSIZE (1<<FTRACE_HASHBITS)
  35. enum {
  36. FTRACE_FL_FREE = (1 << 0),
  37. FTRACE_FL_FAILED = (1 << 1),
  38. FTRACE_FL_FILTER = (1 << 2),
  39. FTRACE_FL_ENABLED = (1 << 3),
  40. FTRACE_FL_NOTRACE = (1 << 4),
  41. FTRACE_FL_CONVERTED = (1 << 5),
  42. FTRACE_FL_FROZEN = (1 << 6),
  43. };
  44. struct dyn_ftrace {
  45. struct hlist_node node;
  46. unsigned long ip; /* address of mcount call-site */
  47. unsigned long flags;
  48. };
  49. int ftrace_force_update(void);
  50. void ftrace_set_filter(unsigned char *buf, int len, int reset);
  51. /* defined in arch */
  52. extern int ftrace_ip_converted(unsigned long ip);
  53. extern unsigned char *ftrace_nop_replace(void);
  54. extern unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr);
  55. extern int ftrace_dyn_arch_init(void *data);
  56. extern int ftrace_mcount_set(unsigned long *data);
  57. extern int ftrace_modify_code(unsigned long ip, unsigned char *old_code,
  58. unsigned char *new_code);
  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. extern int skip_trace(unsigned long ip);
  64. void ftrace_disable_daemon(void);
  65. void ftrace_enable_daemon(void);
  66. #else
  67. # define skip_trace(ip) ({ 0; })
  68. # define ftrace_force_update() ({ 0; })
  69. # define ftrace_set_filter(buf, len, reset) do { } while (0)
  70. # define ftrace_disable_daemon() do { } while (0)
  71. # define ftrace_enable_daemon() do { } while (0)
  72. #endif /* CONFIG_DYNAMIC_FTRACE */
  73. /* totally disable ftrace - can not re-enable after this */
  74. void ftrace_kill(void);
  75. void ftrace_kill_atomic(void);
  76. static inline void tracer_disable(void)
  77. {
  78. #ifdef CONFIG_FTRACE
  79. ftrace_enabled = 0;
  80. #endif
  81. }
  82. /* Ftrace disable/restore without lock. Some synchronization mechanism
  83. * must be used to prevent ftrace_enabled to be changed between
  84. * disable/restore. */
  85. static inline int __ftrace_enabled_save(void)
  86. {
  87. #ifdef CONFIG_FTRACE
  88. int saved_ftrace_enabled = ftrace_enabled;
  89. ftrace_enabled = 0;
  90. return saved_ftrace_enabled;
  91. #else
  92. return 0;
  93. #endif
  94. }
  95. static inline void __ftrace_enabled_restore(int enabled)
  96. {
  97. #ifdef CONFIG_FTRACE
  98. ftrace_enabled = enabled;
  99. #endif
  100. }
  101. #ifdef CONFIG_FRAME_POINTER
  102. /* TODO: need to fix this for ARM */
  103. # define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
  104. # define CALLER_ADDR1 ((unsigned long)__builtin_return_address(1))
  105. # define CALLER_ADDR2 ((unsigned long)__builtin_return_address(2))
  106. # define CALLER_ADDR3 ((unsigned long)__builtin_return_address(3))
  107. # define CALLER_ADDR4 ((unsigned long)__builtin_return_address(4))
  108. # define CALLER_ADDR5 ((unsigned long)__builtin_return_address(5))
  109. # define CALLER_ADDR6 ((unsigned long)__builtin_return_address(6))
  110. #else
  111. # define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
  112. # define CALLER_ADDR1 0UL
  113. # define CALLER_ADDR2 0UL
  114. # define CALLER_ADDR3 0UL
  115. # define CALLER_ADDR4 0UL
  116. # define CALLER_ADDR5 0UL
  117. # define CALLER_ADDR6 0UL
  118. #endif
  119. #ifdef CONFIG_IRQSOFF_TRACER
  120. extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
  121. extern void time_hardirqs_off(unsigned long a0, unsigned long a1);
  122. #else
  123. # define time_hardirqs_on(a0, a1) do { } while (0)
  124. # define time_hardirqs_off(a0, a1) do { } while (0)
  125. #endif
  126. #ifdef CONFIG_PREEMPT_TRACER
  127. extern void trace_preempt_on(unsigned long a0, unsigned long a1);
  128. extern void trace_preempt_off(unsigned long a0, unsigned long a1);
  129. #else
  130. # define trace_preempt_on(a0, a1) do { } while (0)
  131. # define trace_preempt_off(a0, a1) do { } while (0)
  132. #endif
  133. #ifdef CONFIG_TRACING
  134. extern void
  135. ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3);
  136. /**
  137. * ftrace_printk - printf formatting in the ftrace buffer
  138. * @fmt: the printf format for printing
  139. *
  140. * Note: __ftrace_printk is an internal function for ftrace_printk and
  141. * the @ip is passed in via the ftrace_printk macro.
  142. *
  143. * This function allows a kernel developer to debug fast path sections
  144. * that printk is not appropriate for. By scattering in various
  145. * printk like tracing in the code, a developer can quickly see
  146. * where problems are occurring.
  147. *
  148. * This is intended as a debugging tool for the developer only.
  149. * Please refrain from leaving ftrace_printks scattered around in
  150. * your code.
  151. */
  152. # define ftrace_printk(fmt...) __ftrace_printk(_THIS_IP_, fmt)
  153. extern int
  154. __ftrace_printk(unsigned long ip, const char *fmt, ...)
  155. __attribute__ ((format (printf, 2, 3)));
  156. #else
  157. static inline void
  158. ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) { }
  159. static inline int
  160. ftrace_printk(const char *fmt, ...) __attribute__ ((format (printf, 1, 0)))
  161. {
  162. return 0;
  163. }
  164. #endif
  165. #ifdef CONFIG_FTRACE_MCOUNT_RECORD
  166. extern void ftrace_init(void);
  167. extern void ftrace_init_module(unsigned long *start, unsigned long *end);
  168. extern void ftrace_release(void *start, unsigned long size);
  169. #else
  170. static inline void ftrace_init(void) { }
  171. static inline void
  172. ftrace_init_module(unsigned long *start, unsigned long *end) { }
  173. static inline void ftrace_release(void *start, unsigned long size) { }
  174. #endif
  175. #endif /* _LINUX_FTRACE_H */