ftrace.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  1. /*
  2. * Ftrace header. For implementation details beyond the random comments
  3. * scattered below, see: Documentation/trace/ftrace-design.txt
  4. */
  5. #ifndef _LINUX_FTRACE_H
  6. #define _LINUX_FTRACE_H
  7. #include <linux/trace_clock.h>
  8. #include <linux/kallsyms.h>
  9. #include <linux/linkage.h>
  10. #include <linux/bitops.h>
  11. #include <linux/ptrace.h>
  12. #include <linux/ktime.h>
  13. #include <linux/sched.h>
  14. #include <linux/types.h>
  15. #include <linux/init.h>
  16. #include <linux/fs.h>
  17. #include <asm/ftrace.h>
  18. /*
  19. * If the arch supports passing the variable contents of
  20. * function_trace_op as the third parameter back from the
  21. * mcount call, then the arch should define this as 1.
  22. */
  23. #ifndef ARCH_SUPPORTS_FTRACE_OPS
  24. #define ARCH_SUPPORTS_FTRACE_OPS 0
  25. #endif
  26. /*
  27. * If the arch's mcount caller does not support all of ftrace's
  28. * features, then it must call an indirect function that
  29. * does. Or at least does enough to prevent any unwelcomed side effects.
  30. */
  31. #if !ARCH_SUPPORTS_FTRACE_OPS
  32. # define FTRACE_FORCE_LIST_FUNC 1
  33. #else
  34. # define FTRACE_FORCE_LIST_FUNC 0
  35. #endif
  36. struct module;
  37. struct ftrace_hash;
  38. #ifdef CONFIG_FUNCTION_TRACER
  39. extern int ftrace_enabled;
  40. extern int
  41. ftrace_enable_sysctl(struct ctl_table *table, int write,
  42. void __user *buffer, size_t *lenp,
  43. loff_t *ppos);
  44. struct ftrace_ops;
  45. typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip,
  46. struct ftrace_ops *op, struct pt_regs *regs);
  47. ftrace_func_t ftrace_ops_get_func(struct ftrace_ops *ops);
  48. /*
  49. * FTRACE_OPS_FL_* bits denote the state of ftrace_ops struct and are
  50. * set in the flags member.
  51. *
  52. * ENABLED - set/unset when ftrace_ops is registered/unregistered
  53. * DYNAMIC - set when ftrace_ops is registered to denote dynamically
  54. * allocated ftrace_ops which need special care
  55. * CONTROL - set manualy by ftrace_ops user to denote the ftrace_ops
  56. * could be controled by following calls:
  57. * ftrace_function_local_enable
  58. * ftrace_function_local_disable
  59. * SAVE_REGS - The ftrace_ops wants regs saved at each function called
  60. * and passed to the callback. If this flag is set, but the
  61. * architecture does not support passing regs
  62. * (CONFIG_DYNAMIC_FTRACE_WITH_REGS is not defined), then the
  63. * ftrace_ops will fail to register, unless the next flag
  64. * is set.
  65. * SAVE_REGS_IF_SUPPORTED - This is the same as SAVE_REGS, but if the
  66. * handler can handle an arch that does not save regs
  67. * (the handler tests if regs == NULL), then it can set
  68. * this flag instead. It will not fail registering the ftrace_ops
  69. * but, the regs field will be NULL if the arch does not support
  70. * passing regs to the handler.
  71. * Note, if this flag is set, the SAVE_REGS flag will automatically
  72. * get set upon registering the ftrace_ops, if the arch supports it.
  73. * RECURSION_SAFE - The ftrace_ops can set this to tell the ftrace infrastructure
  74. * that the call back has its own recursion protection. If it does
  75. * not set this, then the ftrace infrastructure will add recursion
  76. * protection for the caller.
  77. * STUB - The ftrace_ops is just a place holder.
  78. * INITIALIZED - The ftrace_ops has already been initialized (first use time
  79. * register_ftrace_function() is called, it will initialized the ops)
  80. * DELETED - The ops are being deleted, do not let them be registered again.
  81. * ADDING - The ops is in the process of being added.
  82. * REMOVING - The ops is in the process of being removed.
  83. * MODIFYING - The ops is in the process of changing its filter functions.
  84. */
  85. enum {
  86. FTRACE_OPS_FL_ENABLED = 1 << 0,
  87. FTRACE_OPS_FL_DYNAMIC = 1 << 1,
  88. FTRACE_OPS_FL_CONTROL = 1 << 2,
  89. FTRACE_OPS_FL_SAVE_REGS = 1 << 3,
  90. FTRACE_OPS_FL_SAVE_REGS_IF_SUPPORTED = 1 << 4,
  91. FTRACE_OPS_FL_RECURSION_SAFE = 1 << 5,
  92. FTRACE_OPS_FL_STUB = 1 << 6,
  93. FTRACE_OPS_FL_INITIALIZED = 1 << 7,
  94. FTRACE_OPS_FL_DELETED = 1 << 8,
  95. FTRACE_OPS_FL_ADDING = 1 << 9,
  96. FTRACE_OPS_FL_REMOVING = 1 << 10,
  97. FTRACE_OPS_FL_MODIFYING = 1 << 11,
  98. };
  99. #ifdef CONFIG_DYNAMIC_FTRACE
  100. /* The hash used to know what functions callbacks trace */
  101. struct ftrace_ops_hash {
  102. struct ftrace_hash *notrace_hash;
  103. struct ftrace_hash *filter_hash;
  104. struct mutex regex_lock;
  105. };
  106. #endif
  107. /*
  108. * Note, ftrace_ops can be referenced outside of RCU protection.
  109. * (Although, for perf, the control ops prevent that). If ftrace_ops is
  110. * allocated and not part of kernel core data, the unregistering of it will
  111. * perform a scheduling on all CPUs to make sure that there are no more users.
  112. * Depending on the load of the system that may take a bit of time.
  113. *
  114. * Any private data added must also take care not to be freed and if private
  115. * data is added to a ftrace_ops that is in core code, the user of the
  116. * ftrace_ops must perform a schedule_on_each_cpu() before freeing it.
  117. */
  118. struct ftrace_ops {
  119. ftrace_func_t func;
  120. struct ftrace_ops *next;
  121. unsigned long flags;
  122. void *private;
  123. int __percpu *disabled;
  124. #ifdef CONFIG_DYNAMIC_FTRACE
  125. int nr_trampolines;
  126. struct ftrace_ops_hash local_hash;
  127. struct ftrace_ops_hash *func_hash;
  128. struct ftrace_ops_hash old_hash;
  129. unsigned long trampoline;
  130. #endif
  131. };
  132. /*
  133. * Type of the current tracing.
  134. */
  135. enum ftrace_tracing_type_t {
  136. FTRACE_TYPE_ENTER = 0, /* Hook the call of the function */
  137. FTRACE_TYPE_RETURN, /* Hook the return of the function */
  138. };
  139. /* Current tracing type, default is FTRACE_TYPE_ENTER */
  140. extern enum ftrace_tracing_type_t ftrace_tracing_type;
  141. /*
  142. * The ftrace_ops must be a static and should also
  143. * be read_mostly. These functions do modify read_mostly variables
  144. * so use them sparely. Never free an ftrace_op or modify the
  145. * next pointer after it has been registered. Even after unregistering
  146. * it, the next pointer may still be used internally.
  147. */
  148. int register_ftrace_function(struct ftrace_ops *ops);
  149. int unregister_ftrace_function(struct ftrace_ops *ops);
  150. void clear_ftrace_function(void);
  151. /**
  152. * ftrace_function_local_enable - enable controlled ftrace_ops on current cpu
  153. *
  154. * This function enables tracing on current cpu by decreasing
  155. * the per cpu control variable.
  156. * It must be called with preemption disabled and only on ftrace_ops
  157. * registered with FTRACE_OPS_FL_CONTROL. If called without preemption
  158. * disabled, this_cpu_ptr will complain when CONFIG_DEBUG_PREEMPT is enabled.
  159. */
  160. static inline void ftrace_function_local_enable(struct ftrace_ops *ops)
  161. {
  162. if (WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_CONTROL)))
  163. return;
  164. (*this_cpu_ptr(ops->disabled))--;
  165. }
  166. /**
  167. * ftrace_function_local_disable - enable controlled ftrace_ops on current cpu
  168. *
  169. * This function enables tracing on current cpu by decreasing
  170. * the per cpu control variable.
  171. * It must be called with preemption disabled and only on ftrace_ops
  172. * registered with FTRACE_OPS_FL_CONTROL. If called without preemption
  173. * disabled, this_cpu_ptr will complain when CONFIG_DEBUG_PREEMPT is enabled.
  174. */
  175. static inline void ftrace_function_local_disable(struct ftrace_ops *ops)
  176. {
  177. if (WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_CONTROL)))
  178. return;
  179. (*this_cpu_ptr(ops->disabled))++;
  180. }
  181. /**
  182. * ftrace_function_local_disabled - returns ftrace_ops disabled value
  183. * on current cpu
  184. *
  185. * This function returns value of ftrace_ops::disabled on current cpu.
  186. * It must be called with preemption disabled and only on ftrace_ops
  187. * registered with FTRACE_OPS_FL_CONTROL. If called without preemption
  188. * disabled, this_cpu_ptr will complain when CONFIG_DEBUG_PREEMPT is enabled.
  189. */
  190. static inline int ftrace_function_local_disabled(struct ftrace_ops *ops)
  191. {
  192. WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_CONTROL));
  193. return *this_cpu_ptr(ops->disabled);
  194. }
  195. extern void ftrace_stub(unsigned long a0, unsigned long a1,
  196. struct ftrace_ops *op, struct pt_regs *regs);
  197. #else /* !CONFIG_FUNCTION_TRACER */
  198. /*
  199. * (un)register_ftrace_function must be a macro since the ops parameter
  200. * must not be evaluated.
  201. */
  202. #define register_ftrace_function(ops) ({ 0; })
  203. #define unregister_ftrace_function(ops) ({ 0; })
  204. static inline int ftrace_nr_registered_ops(void)
  205. {
  206. return 0;
  207. }
  208. static inline void clear_ftrace_function(void) { }
  209. static inline void ftrace_kill(void) { }
  210. #endif /* CONFIG_FUNCTION_TRACER */
  211. #ifdef CONFIG_STACK_TRACER
  212. extern int stack_tracer_enabled;
  213. int
  214. stack_trace_sysctl(struct ctl_table *table, int write,
  215. void __user *buffer, size_t *lenp,
  216. loff_t *ppos);
  217. #endif
  218. struct ftrace_func_command {
  219. struct list_head list;
  220. char *name;
  221. int (*func)(struct ftrace_hash *hash,
  222. char *func, char *cmd,
  223. char *params, int enable);
  224. };
  225. #ifdef CONFIG_DYNAMIC_FTRACE
  226. int ftrace_arch_code_modify_prepare(void);
  227. int ftrace_arch_code_modify_post_process(void);
  228. void ftrace_bug(int err, unsigned long ip);
  229. struct seq_file;
  230. struct ftrace_probe_ops {
  231. void (*func)(unsigned long ip,
  232. unsigned long parent_ip,
  233. void **data);
  234. int (*init)(struct ftrace_probe_ops *ops,
  235. unsigned long ip, void **data);
  236. void (*free)(struct ftrace_probe_ops *ops,
  237. unsigned long ip, void **data);
  238. int (*print)(struct seq_file *m,
  239. unsigned long ip,
  240. struct ftrace_probe_ops *ops,
  241. void *data);
  242. };
  243. extern int
  244. register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
  245. void *data);
  246. extern void
  247. unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
  248. void *data);
  249. extern void
  250. unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops);
  251. extern void unregister_ftrace_function_probe_all(char *glob);
  252. extern int ftrace_text_reserved(const void *start, const void *end);
  253. extern int ftrace_nr_registered_ops(void);
  254. /*
  255. * The dyn_ftrace record's flags field is split into two parts.
  256. * the first part which is '0-FTRACE_REF_MAX' is a counter of
  257. * the number of callbacks that have registered the function that
  258. * the dyn_ftrace descriptor represents.
  259. *
  260. * The second part is a mask:
  261. * ENABLED - the function is being traced
  262. * REGS - the record wants the function to save regs
  263. * REGS_EN - the function is set up to save regs.
  264. *
  265. * When a new ftrace_ops is registered and wants a function to save
  266. * pt_regs, the rec->flag REGS is set. When the function has been
  267. * set up to save regs, the REG_EN flag is set. Once a function
  268. * starts saving regs it will do so until all ftrace_ops are removed
  269. * from tracing that function.
  270. */
  271. enum {
  272. FTRACE_FL_ENABLED = (1UL << 31),
  273. FTRACE_FL_REGS = (1UL << 30),
  274. FTRACE_FL_REGS_EN = (1UL << 29),
  275. FTRACE_FL_TRAMP = (1UL << 28),
  276. FTRACE_FL_TRAMP_EN = (1UL << 27),
  277. };
  278. #define FTRACE_REF_MAX_SHIFT 27
  279. #define FTRACE_FL_BITS 5
  280. #define FTRACE_FL_MASKED_BITS ((1UL << FTRACE_FL_BITS) - 1)
  281. #define FTRACE_FL_MASK (FTRACE_FL_MASKED_BITS << FTRACE_REF_MAX_SHIFT)
  282. #define FTRACE_REF_MAX ((1UL << FTRACE_REF_MAX_SHIFT) - 1)
  283. #define ftrace_rec_count(rec) ((rec)->flags & ~FTRACE_FL_MASK)
  284. struct dyn_ftrace {
  285. unsigned long ip; /* address of mcount call-site */
  286. unsigned long flags;
  287. struct dyn_arch_ftrace arch;
  288. };
  289. int ftrace_force_update(void);
  290. int ftrace_set_filter_ip(struct ftrace_ops *ops, unsigned long ip,
  291. int remove, int reset);
  292. int ftrace_set_filter(struct ftrace_ops *ops, unsigned char *buf,
  293. int len, int reset);
  294. int ftrace_set_notrace(struct ftrace_ops *ops, unsigned char *buf,
  295. int len, int reset);
  296. void ftrace_set_global_filter(unsigned char *buf, int len, int reset);
  297. void ftrace_set_global_notrace(unsigned char *buf, int len, int reset);
  298. void ftrace_free_filter(struct ftrace_ops *ops);
  299. int register_ftrace_command(struct ftrace_func_command *cmd);
  300. int unregister_ftrace_command(struct ftrace_func_command *cmd);
  301. enum {
  302. FTRACE_UPDATE_CALLS = (1 << 0),
  303. FTRACE_DISABLE_CALLS = (1 << 1),
  304. FTRACE_UPDATE_TRACE_FUNC = (1 << 2),
  305. FTRACE_START_FUNC_RET = (1 << 3),
  306. FTRACE_STOP_FUNC_RET = (1 << 4),
  307. };
  308. /*
  309. * The FTRACE_UPDATE_* enum is used to pass information back
  310. * from the ftrace_update_record() and ftrace_test_record()
  311. * functions. These are called by the code update routines
  312. * to find out what is to be done for a given function.
  313. *
  314. * IGNORE - The function is already what we want it to be
  315. * MAKE_CALL - Start tracing the function
  316. * MODIFY_CALL - Stop saving regs for the function
  317. * MAKE_NOP - Stop tracing the function
  318. */
  319. enum {
  320. FTRACE_UPDATE_IGNORE,
  321. FTRACE_UPDATE_MAKE_CALL,
  322. FTRACE_UPDATE_MODIFY_CALL,
  323. FTRACE_UPDATE_MAKE_NOP,
  324. };
  325. enum {
  326. FTRACE_ITER_FILTER = (1 << 0),
  327. FTRACE_ITER_NOTRACE = (1 << 1),
  328. FTRACE_ITER_PRINTALL = (1 << 2),
  329. FTRACE_ITER_DO_HASH = (1 << 3),
  330. FTRACE_ITER_HASH = (1 << 4),
  331. FTRACE_ITER_ENABLED = (1 << 5),
  332. };
  333. void arch_ftrace_update_code(int command);
  334. struct ftrace_rec_iter;
  335. struct ftrace_rec_iter *ftrace_rec_iter_start(void);
  336. struct ftrace_rec_iter *ftrace_rec_iter_next(struct ftrace_rec_iter *iter);
  337. struct dyn_ftrace *ftrace_rec_iter_record(struct ftrace_rec_iter *iter);
  338. #define for_ftrace_rec_iter(iter) \
  339. for (iter = ftrace_rec_iter_start(); \
  340. iter; \
  341. iter = ftrace_rec_iter_next(iter))
  342. int ftrace_update_record(struct dyn_ftrace *rec, int enable);
  343. int ftrace_test_record(struct dyn_ftrace *rec, int enable);
  344. void ftrace_run_stop_machine(int command);
  345. unsigned long ftrace_location(unsigned long ip);
  346. unsigned long ftrace_get_addr_new(struct dyn_ftrace *rec);
  347. unsigned long ftrace_get_addr_curr(struct dyn_ftrace *rec);
  348. extern ftrace_func_t ftrace_trace_function;
  349. int ftrace_regex_open(struct ftrace_ops *ops, int flag,
  350. struct inode *inode, struct file *file);
  351. ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
  352. size_t cnt, loff_t *ppos);
  353. ssize_t ftrace_notrace_write(struct file *file, const char __user *ubuf,
  354. size_t cnt, loff_t *ppos);
  355. int ftrace_regex_release(struct inode *inode, struct file *file);
  356. void __init
  357. ftrace_set_early_filter(struct ftrace_ops *ops, char *buf, int enable);
  358. /* defined in arch */
  359. extern int ftrace_ip_converted(unsigned long ip);
  360. extern int ftrace_dyn_arch_init(void);
  361. extern void ftrace_replace_code(int enable);
  362. extern int ftrace_update_ftrace_func(ftrace_func_t func);
  363. extern void ftrace_caller(void);
  364. extern void ftrace_regs_caller(void);
  365. extern void ftrace_call(void);
  366. extern void ftrace_regs_call(void);
  367. extern void mcount_call(void);
  368. void ftrace_modify_all_code(int command);
  369. #ifndef FTRACE_ADDR
  370. #define FTRACE_ADDR ((unsigned long)ftrace_caller)
  371. #endif
  372. #ifndef FTRACE_GRAPH_ADDR
  373. #define FTRACE_GRAPH_ADDR ((unsigned long)ftrace_graph_caller)
  374. #endif
  375. #ifndef FTRACE_REGS_ADDR
  376. #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
  377. # define FTRACE_REGS_ADDR ((unsigned long)ftrace_regs_caller)
  378. #else
  379. # define FTRACE_REGS_ADDR FTRACE_ADDR
  380. #endif
  381. #endif
  382. /*
  383. * If an arch would like functions that are only traced
  384. * by the function graph tracer to jump directly to its own
  385. * trampoline, then they can define FTRACE_GRAPH_TRAMP_ADDR
  386. * to be that address to jump to.
  387. */
  388. #ifndef FTRACE_GRAPH_TRAMP_ADDR
  389. #define FTRACE_GRAPH_TRAMP_ADDR ((unsigned long) 0)
  390. #endif
  391. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  392. extern void ftrace_graph_caller(void);
  393. extern int ftrace_enable_ftrace_graph_caller(void);
  394. extern int ftrace_disable_ftrace_graph_caller(void);
  395. #else
  396. static inline int ftrace_enable_ftrace_graph_caller(void) { return 0; }
  397. static inline int ftrace_disable_ftrace_graph_caller(void) { return 0; }
  398. #endif
  399. /**
  400. * ftrace_make_nop - convert code into nop
  401. * @mod: module structure if called by module load initialization
  402. * @rec: the mcount call site record
  403. * @addr: the address that the call site should be calling
  404. *
  405. * This is a very sensitive operation and great care needs
  406. * to be taken by the arch. The operation should carefully
  407. * read the location, check to see if what is read is indeed
  408. * what we expect it to be, and then on success of the compare,
  409. * it should write to the location.
  410. *
  411. * The code segment at @rec->ip should be a caller to @addr
  412. *
  413. * Return must be:
  414. * 0 on success
  415. * -EFAULT on error reading the location
  416. * -EINVAL on a failed compare of the contents
  417. * -EPERM on error writing to the location
  418. * Any other value will be considered a failure.
  419. */
  420. extern int ftrace_make_nop(struct module *mod,
  421. struct dyn_ftrace *rec, unsigned long addr);
  422. /**
  423. * ftrace_make_call - convert a nop call site into a call to addr
  424. * @rec: the mcount call site record
  425. * @addr: the address that the call site should call
  426. *
  427. * This is a very sensitive operation and great care needs
  428. * to be taken by the arch. The operation should carefully
  429. * read the location, check to see if what is read is indeed
  430. * what we expect it to be, and then on success of the compare,
  431. * it should write to the location.
  432. *
  433. * The code segment at @rec->ip should be a nop
  434. *
  435. * Return must be:
  436. * 0 on success
  437. * -EFAULT on error reading the location
  438. * -EINVAL on a failed compare of the contents
  439. * -EPERM on error writing to the location
  440. * Any other value will be considered a failure.
  441. */
  442. extern int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr);
  443. #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
  444. /**
  445. * ftrace_modify_call - convert from one addr to another (no nop)
  446. * @rec: the mcount call site record
  447. * @old_addr: the address expected to be currently called to
  448. * @addr: the address to change to
  449. *
  450. * This is a very sensitive operation and great care needs
  451. * to be taken by the arch. The operation should carefully
  452. * read the location, check to see if what is read is indeed
  453. * what we expect it to be, and then on success of the compare,
  454. * it should write to the location.
  455. *
  456. * The code segment at @rec->ip should be a caller to @old_addr
  457. *
  458. * Return must be:
  459. * 0 on success
  460. * -EFAULT on error reading the location
  461. * -EINVAL on a failed compare of the contents
  462. * -EPERM on error writing to the location
  463. * Any other value will be considered a failure.
  464. */
  465. extern int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
  466. unsigned long addr);
  467. #else
  468. /* Should never be called */
  469. static inline int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
  470. unsigned long addr)
  471. {
  472. return -EINVAL;
  473. }
  474. #endif
  475. /* May be defined in arch */
  476. extern int ftrace_arch_read_dyn_info(char *buf, int size);
  477. extern int skip_trace(unsigned long ip);
  478. extern void ftrace_module_init(struct module *mod);
  479. extern void ftrace_disable_daemon(void);
  480. extern void ftrace_enable_daemon(void);
  481. #else /* CONFIG_DYNAMIC_FTRACE */
  482. static inline int skip_trace(unsigned long ip) { return 0; }
  483. static inline int ftrace_force_update(void) { return 0; }
  484. static inline void ftrace_disable_daemon(void) { }
  485. static inline void ftrace_enable_daemon(void) { }
  486. static inline void ftrace_release_mod(struct module *mod) {}
  487. static inline void ftrace_module_init(struct module *mod) {}
  488. static inline __init int register_ftrace_command(struct ftrace_func_command *cmd)
  489. {
  490. return -EINVAL;
  491. }
  492. static inline __init int unregister_ftrace_command(char *cmd_name)
  493. {
  494. return -EINVAL;
  495. }
  496. static inline int ftrace_text_reserved(const void *start, const void *end)
  497. {
  498. return 0;
  499. }
  500. static inline unsigned long ftrace_location(unsigned long ip)
  501. {
  502. return 0;
  503. }
  504. /*
  505. * Again users of functions that have ftrace_ops may not
  506. * have them defined when ftrace is not enabled, but these
  507. * functions may still be called. Use a macro instead of inline.
  508. */
  509. #define ftrace_regex_open(ops, flag, inod, file) ({ -ENODEV; })
  510. #define ftrace_set_early_filter(ops, buf, enable) do { } while (0)
  511. #define ftrace_set_filter_ip(ops, ip, remove, reset) ({ -ENODEV; })
  512. #define ftrace_set_filter(ops, buf, len, reset) ({ -ENODEV; })
  513. #define ftrace_set_notrace(ops, buf, len, reset) ({ -ENODEV; })
  514. #define ftrace_free_filter(ops) do { } while (0)
  515. static inline ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
  516. size_t cnt, loff_t *ppos) { return -ENODEV; }
  517. static inline ssize_t ftrace_notrace_write(struct file *file, const char __user *ubuf,
  518. size_t cnt, loff_t *ppos) { return -ENODEV; }
  519. static inline int
  520. ftrace_regex_release(struct inode *inode, struct file *file) { return -ENODEV; }
  521. #endif /* CONFIG_DYNAMIC_FTRACE */
  522. /* totally disable ftrace - can not re-enable after this */
  523. void ftrace_kill(void);
  524. static inline void tracer_disable(void)
  525. {
  526. #ifdef CONFIG_FUNCTION_TRACER
  527. ftrace_enabled = 0;
  528. #endif
  529. }
  530. /*
  531. * Ftrace disable/restore without lock. Some synchronization mechanism
  532. * must be used to prevent ftrace_enabled to be changed between
  533. * disable/restore.
  534. */
  535. static inline int __ftrace_enabled_save(void)
  536. {
  537. #ifdef CONFIG_FUNCTION_TRACER
  538. int saved_ftrace_enabled = ftrace_enabled;
  539. ftrace_enabled = 0;
  540. return saved_ftrace_enabled;
  541. #else
  542. return 0;
  543. #endif
  544. }
  545. static inline void __ftrace_enabled_restore(int enabled)
  546. {
  547. #ifdef CONFIG_FUNCTION_TRACER
  548. ftrace_enabled = enabled;
  549. #endif
  550. }
  551. /* All archs should have this, but we define it for consistency */
  552. #ifndef ftrace_return_address0
  553. # define ftrace_return_address0 __builtin_return_address(0)
  554. #endif
  555. /* Archs may use other ways for ADDR1 and beyond */
  556. #ifndef ftrace_return_address
  557. # ifdef CONFIG_FRAME_POINTER
  558. # define ftrace_return_address(n) __builtin_return_address(n)
  559. # else
  560. # define ftrace_return_address(n) 0UL
  561. # endif
  562. #endif
  563. #define CALLER_ADDR0 ((unsigned long)ftrace_return_address0)
  564. #define CALLER_ADDR1 ((unsigned long)ftrace_return_address(1))
  565. #define CALLER_ADDR2 ((unsigned long)ftrace_return_address(2))
  566. #define CALLER_ADDR3 ((unsigned long)ftrace_return_address(3))
  567. #define CALLER_ADDR4 ((unsigned long)ftrace_return_address(4))
  568. #define CALLER_ADDR5 ((unsigned long)ftrace_return_address(5))
  569. #define CALLER_ADDR6 ((unsigned long)ftrace_return_address(6))
  570. #ifdef CONFIG_IRQSOFF_TRACER
  571. extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
  572. extern void time_hardirqs_off(unsigned long a0, unsigned long a1);
  573. #else
  574. static inline void time_hardirqs_on(unsigned long a0, unsigned long a1) { }
  575. static inline void time_hardirqs_off(unsigned long a0, unsigned long a1) { }
  576. #endif
  577. #ifdef CONFIG_PREEMPT_TRACER
  578. extern void trace_preempt_on(unsigned long a0, unsigned long a1);
  579. extern void trace_preempt_off(unsigned long a0, unsigned long a1);
  580. #else
  581. /*
  582. * Use defines instead of static inlines because some arches will make code out
  583. * of the CALLER_ADDR, when we really want these to be a real nop.
  584. */
  585. # define trace_preempt_on(a0, a1) do { } while (0)
  586. # define trace_preempt_off(a0, a1) do { } while (0)
  587. #endif
  588. #ifdef CONFIG_FTRACE_MCOUNT_RECORD
  589. extern void ftrace_init(void);
  590. #else
  591. static inline void ftrace_init(void) { }
  592. #endif
  593. /*
  594. * Structure that defines an entry function trace.
  595. */
  596. struct ftrace_graph_ent {
  597. unsigned long func; /* Current function */
  598. int depth;
  599. };
  600. /*
  601. * Structure that defines a return function trace.
  602. */
  603. struct ftrace_graph_ret {
  604. unsigned long func; /* Current function */
  605. unsigned long long calltime;
  606. unsigned long long rettime;
  607. /* Number of functions that overran the depth limit for current task */
  608. unsigned long overrun;
  609. int depth;
  610. };
  611. /* Type of the callback handlers for tracing function graph*/
  612. typedef void (*trace_func_graph_ret_t)(struct ftrace_graph_ret *); /* return */
  613. typedef int (*trace_func_graph_ent_t)(struct ftrace_graph_ent *); /* entry */
  614. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  615. /* for init task */
  616. #define INIT_FTRACE_GRAPH .ret_stack = NULL,
  617. /*
  618. * Stack of return addresses for functions
  619. * of a thread.
  620. * Used in struct thread_info
  621. */
  622. struct ftrace_ret_stack {
  623. unsigned long ret;
  624. unsigned long func;
  625. unsigned long long calltime;
  626. unsigned long long subtime;
  627. unsigned long fp;
  628. };
  629. /*
  630. * Primary handler of a function return.
  631. * It relays on ftrace_return_to_handler.
  632. * Defined in entry_32/64.S
  633. */
  634. extern void return_to_handler(void);
  635. extern int
  636. ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth,
  637. unsigned long frame_pointer);
  638. /*
  639. * Sometimes we don't want to trace a function with the function
  640. * graph tracer but we want them to keep traced by the usual function
  641. * tracer if the function graph tracer is not configured.
  642. */
  643. #define __notrace_funcgraph notrace
  644. /*
  645. * We want to which function is an entrypoint of a hardirq.
  646. * That will help us to put a signal on output.
  647. */
  648. #define __irq_entry __attribute__((__section__(".irqentry.text")))
  649. /* Limits of hardirq entrypoints */
  650. extern char __irqentry_text_start[];
  651. extern char __irqentry_text_end[];
  652. #define FTRACE_NOTRACE_DEPTH 65536
  653. #define FTRACE_RETFUNC_DEPTH 50
  654. #define FTRACE_RETSTACK_ALLOC_SIZE 32
  655. extern int register_ftrace_graph(trace_func_graph_ret_t retfunc,
  656. trace_func_graph_ent_t entryfunc);
  657. extern bool ftrace_graph_is_dead(void);
  658. extern void ftrace_graph_stop(void);
  659. /* The current handlers in use */
  660. extern trace_func_graph_ret_t ftrace_graph_return;
  661. extern trace_func_graph_ent_t ftrace_graph_entry;
  662. extern void unregister_ftrace_graph(void);
  663. extern void ftrace_graph_init_task(struct task_struct *t);
  664. extern void ftrace_graph_exit_task(struct task_struct *t);
  665. extern void ftrace_graph_init_idle_task(struct task_struct *t, int cpu);
  666. static inline int task_curr_ret_stack(struct task_struct *t)
  667. {
  668. return t->curr_ret_stack;
  669. }
  670. static inline void pause_graph_tracing(void)
  671. {
  672. atomic_inc(&current->tracing_graph_pause);
  673. }
  674. static inline void unpause_graph_tracing(void)
  675. {
  676. atomic_dec(&current->tracing_graph_pause);
  677. }
  678. #else /* !CONFIG_FUNCTION_GRAPH_TRACER */
  679. #define __notrace_funcgraph
  680. #define __irq_entry
  681. #define INIT_FTRACE_GRAPH
  682. static inline void ftrace_graph_init_task(struct task_struct *t) { }
  683. static inline void ftrace_graph_exit_task(struct task_struct *t) { }
  684. static inline void ftrace_graph_init_idle_task(struct task_struct *t, int cpu) { }
  685. static inline int register_ftrace_graph(trace_func_graph_ret_t retfunc,
  686. trace_func_graph_ent_t entryfunc)
  687. {
  688. return -1;
  689. }
  690. static inline void unregister_ftrace_graph(void) { }
  691. static inline int task_curr_ret_stack(struct task_struct *tsk)
  692. {
  693. return -1;
  694. }
  695. static inline void pause_graph_tracing(void) { }
  696. static inline void unpause_graph_tracing(void) { }
  697. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  698. #ifdef CONFIG_TRACING
  699. /* flags for current->trace */
  700. enum {
  701. TSK_TRACE_FL_TRACE_BIT = 0,
  702. TSK_TRACE_FL_GRAPH_BIT = 1,
  703. };
  704. enum {
  705. TSK_TRACE_FL_TRACE = 1 << TSK_TRACE_FL_TRACE_BIT,
  706. TSK_TRACE_FL_GRAPH = 1 << TSK_TRACE_FL_GRAPH_BIT,
  707. };
  708. static inline void set_tsk_trace_trace(struct task_struct *tsk)
  709. {
  710. set_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
  711. }
  712. static inline void clear_tsk_trace_trace(struct task_struct *tsk)
  713. {
  714. clear_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
  715. }
  716. static inline int test_tsk_trace_trace(struct task_struct *tsk)
  717. {
  718. return tsk->trace & TSK_TRACE_FL_TRACE;
  719. }
  720. static inline void set_tsk_trace_graph(struct task_struct *tsk)
  721. {
  722. set_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
  723. }
  724. static inline void clear_tsk_trace_graph(struct task_struct *tsk)
  725. {
  726. clear_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
  727. }
  728. static inline int test_tsk_trace_graph(struct task_struct *tsk)
  729. {
  730. return tsk->trace & TSK_TRACE_FL_GRAPH;
  731. }
  732. enum ftrace_dump_mode;
  733. extern enum ftrace_dump_mode ftrace_dump_on_oops;
  734. extern void disable_trace_on_warning(void);
  735. extern int __disable_trace_on_warning;
  736. #ifdef CONFIG_PREEMPT
  737. #define INIT_TRACE_RECURSION .trace_recursion = 0,
  738. #endif
  739. #else /* CONFIG_TRACING */
  740. static inline void disable_trace_on_warning(void) { }
  741. #endif /* CONFIG_TRACING */
  742. #ifndef INIT_TRACE_RECURSION
  743. #define INIT_TRACE_RECURSION
  744. #endif
  745. #ifdef CONFIG_FTRACE_SYSCALLS
  746. unsigned long arch_syscall_addr(int nr);
  747. #endif /* CONFIG_FTRACE_SYSCALLS */
  748. #endif /* _LINUX_FTRACE_H */