trace.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. #ifndef _LINUX_KERNEL_TRACE_H
  2. #define _LINUX_KERNEL_TRACE_H
  3. #include <linux/fs.h>
  4. #include <asm/atomic.h>
  5. #include <linux/sched.h>
  6. #include <linux/clocksource.h>
  7. #include <linux/ring_buffer.h>
  8. #include <linux/mmiotrace.h>
  9. #include <linux/ftrace.h>
  10. #include <trace/boot.h>
  11. enum trace_type {
  12. __TRACE_FIRST_TYPE = 0,
  13. TRACE_FN,
  14. TRACE_CTX,
  15. TRACE_WAKE,
  16. TRACE_CONT,
  17. TRACE_STACK,
  18. TRACE_PRINT,
  19. TRACE_SPECIAL,
  20. TRACE_MMIO_RW,
  21. TRACE_MMIO_MAP,
  22. TRACE_BRANCH,
  23. TRACE_BOOT_CALL,
  24. TRACE_BOOT_RET,
  25. TRACE_GRAPH_RET,
  26. TRACE_GRAPH_ENT,
  27. TRACE_USER_STACK,
  28. TRACE_HW_BRANCHES,
  29. TRACE_POWER,
  30. __TRACE_LAST_TYPE
  31. };
  32. /*
  33. * The trace entry - the most basic unit of tracing. This is what
  34. * is printed in the end as a single line in the trace output, such as:
  35. *
  36. * bash-15816 [01] 235.197585: idle_cpu <- irq_enter
  37. */
  38. struct trace_entry {
  39. unsigned char type;
  40. unsigned char cpu;
  41. unsigned char flags;
  42. unsigned char preempt_count;
  43. int pid;
  44. int tgid;
  45. };
  46. /*
  47. * Function trace entry - function address and parent function addres:
  48. */
  49. struct ftrace_entry {
  50. struct trace_entry ent;
  51. unsigned long ip;
  52. unsigned long parent_ip;
  53. };
  54. /* Function call entry */
  55. struct ftrace_graph_ent_entry {
  56. struct trace_entry ent;
  57. struct ftrace_graph_ent graph_ent;
  58. };
  59. /* Function return entry */
  60. struct ftrace_graph_ret_entry {
  61. struct trace_entry ent;
  62. struct ftrace_graph_ret ret;
  63. };
  64. extern struct tracer boot_tracer;
  65. /*
  66. * Context switch trace entry - which task (and prio) we switched from/to:
  67. */
  68. struct ctx_switch_entry {
  69. struct trace_entry ent;
  70. unsigned int prev_pid;
  71. unsigned char prev_prio;
  72. unsigned char prev_state;
  73. unsigned int next_pid;
  74. unsigned char next_prio;
  75. unsigned char next_state;
  76. unsigned int next_cpu;
  77. };
  78. /*
  79. * Special (free-form) trace entry:
  80. */
  81. struct special_entry {
  82. struct trace_entry ent;
  83. unsigned long arg1;
  84. unsigned long arg2;
  85. unsigned long arg3;
  86. };
  87. /*
  88. * Stack-trace entry:
  89. */
  90. #define FTRACE_STACK_ENTRIES 8
  91. struct stack_entry {
  92. struct trace_entry ent;
  93. unsigned long caller[FTRACE_STACK_ENTRIES];
  94. };
  95. struct userstack_entry {
  96. struct trace_entry ent;
  97. unsigned long caller[FTRACE_STACK_ENTRIES];
  98. };
  99. /*
  100. * ftrace_printk entry:
  101. */
  102. struct print_entry {
  103. struct trace_entry ent;
  104. unsigned long ip;
  105. int depth;
  106. char buf[];
  107. };
  108. #define TRACE_OLD_SIZE 88
  109. struct trace_field_cont {
  110. unsigned char type;
  111. /* Temporary till we get rid of this completely */
  112. char buf[TRACE_OLD_SIZE - 1];
  113. };
  114. struct trace_mmiotrace_rw {
  115. struct trace_entry ent;
  116. struct mmiotrace_rw rw;
  117. };
  118. struct trace_mmiotrace_map {
  119. struct trace_entry ent;
  120. struct mmiotrace_map map;
  121. };
  122. struct trace_boot_call {
  123. struct trace_entry ent;
  124. struct boot_trace_call boot_call;
  125. };
  126. struct trace_boot_ret {
  127. struct trace_entry ent;
  128. struct boot_trace_ret boot_ret;
  129. };
  130. #define TRACE_FUNC_SIZE 30
  131. #define TRACE_FILE_SIZE 20
  132. struct trace_branch {
  133. struct trace_entry ent;
  134. unsigned line;
  135. char func[TRACE_FUNC_SIZE+1];
  136. char file[TRACE_FILE_SIZE+1];
  137. char correct;
  138. };
  139. struct hw_branch_entry {
  140. struct trace_entry ent;
  141. u64 from;
  142. u64 to;
  143. };
  144. struct trace_power {
  145. struct trace_entry ent;
  146. struct power_trace state_data;
  147. };
  148. /*
  149. * trace_flag_type is an enumeration that holds different
  150. * states when a trace occurs. These are:
  151. * IRQS_OFF - interrupts were disabled
  152. * IRQS_NOSUPPORT - arch does not support irqs_disabled_flags
  153. * NEED_RESCED - reschedule is requested
  154. * HARDIRQ - inside an interrupt handler
  155. * SOFTIRQ - inside a softirq handler
  156. * CONT - multiple entries hold the trace item
  157. */
  158. enum trace_flag_type {
  159. TRACE_FLAG_IRQS_OFF = 0x01,
  160. TRACE_FLAG_IRQS_NOSUPPORT = 0x02,
  161. TRACE_FLAG_NEED_RESCHED = 0x04,
  162. TRACE_FLAG_HARDIRQ = 0x08,
  163. TRACE_FLAG_SOFTIRQ = 0x10,
  164. TRACE_FLAG_CONT = 0x20,
  165. };
  166. #define TRACE_BUF_SIZE 1024
  167. /*
  168. * The CPU trace array - it consists of thousands of trace entries
  169. * plus some other descriptor data: (for example which task started
  170. * the trace, etc.)
  171. */
  172. struct trace_array_cpu {
  173. atomic_t disabled;
  174. /* these fields get copied into max-trace: */
  175. unsigned long trace_idx;
  176. unsigned long overrun;
  177. unsigned long saved_latency;
  178. unsigned long critical_start;
  179. unsigned long critical_end;
  180. unsigned long critical_sequence;
  181. unsigned long nice;
  182. unsigned long policy;
  183. unsigned long rt_priority;
  184. cycle_t preempt_timestamp;
  185. pid_t pid;
  186. uid_t uid;
  187. char comm[TASK_COMM_LEN];
  188. };
  189. struct trace_iterator;
  190. /*
  191. * The trace array - an array of per-CPU trace arrays. This is the
  192. * highest level data structure that individual tracers deal with.
  193. * They have on/off state as well:
  194. */
  195. struct trace_array {
  196. struct ring_buffer *buffer;
  197. unsigned long entries;
  198. int cpu;
  199. cycle_t time_start;
  200. struct task_struct *waiter;
  201. struct trace_array_cpu *data[NR_CPUS];
  202. };
  203. #define FTRACE_CMP_TYPE(var, type) \
  204. __builtin_types_compatible_p(typeof(var), type *)
  205. #undef IF_ASSIGN
  206. #define IF_ASSIGN(var, entry, etype, id) \
  207. if (FTRACE_CMP_TYPE(var, etype)) { \
  208. var = (typeof(var))(entry); \
  209. WARN_ON(id && (entry)->type != id); \
  210. break; \
  211. }
  212. /* Will cause compile errors if type is not found. */
  213. extern void __ftrace_bad_type(void);
  214. /*
  215. * The trace_assign_type is a verifier that the entry type is
  216. * the same as the type being assigned. To add new types simply
  217. * add a line with the following format:
  218. *
  219. * IF_ASSIGN(var, ent, type, id);
  220. *
  221. * Where "type" is the trace type that includes the trace_entry
  222. * as the "ent" item. And "id" is the trace identifier that is
  223. * used in the trace_type enum.
  224. *
  225. * If the type can have more than one id, then use zero.
  226. */
  227. #define trace_assign_type(var, ent) \
  228. do { \
  229. IF_ASSIGN(var, ent, struct ftrace_entry, TRACE_FN); \
  230. IF_ASSIGN(var, ent, struct ctx_switch_entry, 0); \
  231. IF_ASSIGN(var, ent, struct trace_field_cont, TRACE_CONT); \
  232. IF_ASSIGN(var, ent, struct stack_entry, TRACE_STACK); \
  233. IF_ASSIGN(var, ent, struct userstack_entry, TRACE_USER_STACK);\
  234. IF_ASSIGN(var, ent, struct print_entry, TRACE_PRINT); \
  235. IF_ASSIGN(var, ent, struct special_entry, 0); \
  236. IF_ASSIGN(var, ent, struct trace_mmiotrace_rw, \
  237. TRACE_MMIO_RW); \
  238. IF_ASSIGN(var, ent, struct trace_mmiotrace_map, \
  239. TRACE_MMIO_MAP); \
  240. IF_ASSIGN(var, ent, struct trace_boot_call, TRACE_BOOT_CALL);\
  241. IF_ASSIGN(var, ent, struct trace_boot_ret, TRACE_BOOT_RET);\
  242. IF_ASSIGN(var, ent, struct trace_branch, TRACE_BRANCH); \
  243. IF_ASSIGN(var, ent, struct ftrace_graph_ent_entry, \
  244. TRACE_GRAPH_ENT); \
  245. IF_ASSIGN(var, ent, struct ftrace_graph_ret_entry, \
  246. TRACE_GRAPH_RET); \
  247. IF_ASSIGN(var, ent, struct hw_branch_entry, TRACE_HW_BRANCHES);\
  248. IF_ASSIGN(var, ent, struct trace_power, TRACE_POWER); \
  249. __ftrace_bad_type(); \
  250. } while (0)
  251. /* Return values for print_line callback */
  252. enum print_line_t {
  253. TRACE_TYPE_PARTIAL_LINE = 0, /* Retry after flushing the seq */
  254. TRACE_TYPE_HANDLED = 1,
  255. TRACE_TYPE_UNHANDLED = 2 /* Relay to other output functions */
  256. };
  257. /*
  258. * An option specific to a tracer. This is a boolean value.
  259. * The bit is the bit index that sets its value on the
  260. * flags value in struct tracer_flags.
  261. */
  262. struct tracer_opt {
  263. const char *name; /* Will appear on the trace_options file */
  264. u32 bit; /* Mask assigned in val field in tracer_flags */
  265. };
  266. /*
  267. * The set of specific options for a tracer. Your tracer
  268. * have to set the initial value of the flags val.
  269. */
  270. struct tracer_flags {
  271. u32 val;
  272. struct tracer_opt *opts;
  273. };
  274. /* Makes more easy to define a tracer opt */
  275. #define TRACER_OPT(s, b) .name = #s, .bit = b
  276. /*
  277. * A specific tracer, represented by methods that operate on a trace array:
  278. */
  279. struct tracer {
  280. const char *name;
  281. /* Your tracer should raise a warning if init fails */
  282. int (*init)(struct trace_array *tr);
  283. void (*reset)(struct trace_array *tr);
  284. void (*start)(struct trace_array *tr);
  285. void (*stop)(struct trace_array *tr);
  286. void (*open)(struct trace_iterator *iter);
  287. void (*pipe_open)(struct trace_iterator *iter);
  288. void (*close)(struct trace_iterator *iter);
  289. ssize_t (*read)(struct trace_iterator *iter,
  290. struct file *filp, char __user *ubuf,
  291. size_t cnt, loff_t *ppos);
  292. #ifdef CONFIG_FTRACE_STARTUP_TEST
  293. int (*selftest)(struct tracer *trace,
  294. struct trace_array *tr);
  295. #endif
  296. void (*print_header)(struct seq_file *m);
  297. enum print_line_t (*print_line)(struct trace_iterator *iter);
  298. /* If you handled the flag setting, return 0 */
  299. int (*set_flag)(u32 old_flags, u32 bit, int set);
  300. struct tracer *next;
  301. int print_max;
  302. struct tracer_flags *flags;
  303. };
  304. struct trace_seq {
  305. unsigned char buffer[PAGE_SIZE];
  306. unsigned int len;
  307. unsigned int readpos;
  308. };
  309. /*
  310. * Trace iterator - used by printout routines who present trace
  311. * results to users and which routines might sleep, etc:
  312. */
  313. struct trace_iterator {
  314. struct trace_array *tr;
  315. struct tracer *trace;
  316. void *private;
  317. struct ring_buffer_iter *buffer_iter[NR_CPUS];
  318. /* The below is zeroed out in pipe_read */
  319. struct trace_seq seq;
  320. struct trace_entry *ent;
  321. int cpu;
  322. u64 ts;
  323. unsigned long iter_flags;
  324. loff_t pos;
  325. long idx;
  326. cpumask_var_t started;
  327. };
  328. int tracing_is_enabled(void);
  329. void trace_wake_up(void);
  330. void tracing_reset(struct trace_array *tr, int cpu);
  331. void tracing_reset_online_cpus(struct trace_array *tr);
  332. int tracing_open_generic(struct inode *inode, struct file *filp);
  333. struct dentry *tracing_init_dentry(void);
  334. void init_tracer_sysprof_debugfs(struct dentry *d_tracer);
  335. struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
  336. struct trace_array_cpu *data);
  337. void tracing_generic_entry_update(struct trace_entry *entry,
  338. unsigned long flags,
  339. int pc);
  340. void ftrace(struct trace_array *tr,
  341. struct trace_array_cpu *data,
  342. unsigned long ip,
  343. unsigned long parent_ip,
  344. unsigned long flags, int pc);
  345. void tracing_sched_switch_trace(struct trace_array *tr,
  346. struct trace_array_cpu *data,
  347. struct task_struct *prev,
  348. struct task_struct *next,
  349. unsigned long flags, int pc);
  350. void tracing_record_cmdline(struct task_struct *tsk);
  351. void tracing_sched_wakeup_trace(struct trace_array *tr,
  352. struct trace_array_cpu *data,
  353. struct task_struct *wakee,
  354. struct task_struct *cur,
  355. unsigned long flags, int pc);
  356. void trace_special(struct trace_array *tr,
  357. struct trace_array_cpu *data,
  358. unsigned long arg1,
  359. unsigned long arg2,
  360. unsigned long arg3, int pc);
  361. void trace_function(struct trace_array *tr,
  362. struct trace_array_cpu *data,
  363. unsigned long ip,
  364. unsigned long parent_ip,
  365. unsigned long flags, int pc);
  366. void trace_graph_return(struct ftrace_graph_ret *trace);
  367. int trace_graph_entry(struct ftrace_graph_ent *trace);
  368. void trace_hw_branch(struct trace_array *tr, u64 from, u64 to);
  369. void tracing_start_cmdline_record(void);
  370. void tracing_stop_cmdline_record(void);
  371. void tracing_sched_switch_assign_trace(struct trace_array *tr);
  372. void tracing_stop_sched_switch_record(void);
  373. void tracing_start_sched_switch_record(void);
  374. int register_tracer(struct tracer *type);
  375. void unregister_tracer(struct tracer *type);
  376. extern unsigned long nsecs_to_usecs(unsigned long nsecs);
  377. extern unsigned long tracing_max_latency;
  378. extern unsigned long tracing_thresh;
  379. void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
  380. void update_max_tr_single(struct trace_array *tr,
  381. struct task_struct *tsk, int cpu);
  382. extern cycle_t ftrace_now(int cpu);
  383. #ifdef CONFIG_FUNCTION_TRACER
  384. void tracing_start_function_trace(void);
  385. void tracing_stop_function_trace(void);
  386. #else
  387. # define tracing_start_function_trace() do { } while (0)
  388. # define tracing_stop_function_trace() do { } while (0)
  389. #endif
  390. #ifdef CONFIG_CONTEXT_SWITCH_TRACER
  391. typedef void
  392. (*tracer_switch_func_t)(void *private,
  393. void *__rq,
  394. struct task_struct *prev,
  395. struct task_struct *next);
  396. struct tracer_switch_ops {
  397. tracer_switch_func_t func;
  398. void *private;
  399. struct tracer_switch_ops *next;
  400. };
  401. char *trace_find_cmdline(int pid);
  402. #endif /* CONFIG_CONTEXT_SWITCH_TRACER */
  403. #ifdef CONFIG_DYNAMIC_FTRACE
  404. extern unsigned long ftrace_update_tot_cnt;
  405. #define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
  406. extern int DYN_FTRACE_TEST_NAME(void);
  407. #endif
  408. #ifdef CONFIG_FTRACE_STARTUP_TEST
  409. extern int trace_selftest_startup_function(struct tracer *trace,
  410. struct trace_array *tr);
  411. extern int trace_selftest_startup_irqsoff(struct tracer *trace,
  412. struct trace_array *tr);
  413. extern int trace_selftest_startup_preemptoff(struct tracer *trace,
  414. struct trace_array *tr);
  415. extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
  416. struct trace_array *tr);
  417. extern int trace_selftest_startup_wakeup(struct tracer *trace,
  418. struct trace_array *tr);
  419. extern int trace_selftest_startup_nop(struct tracer *trace,
  420. struct trace_array *tr);
  421. extern int trace_selftest_startup_sched_switch(struct tracer *trace,
  422. struct trace_array *tr);
  423. extern int trace_selftest_startup_sysprof(struct tracer *trace,
  424. struct trace_array *tr);
  425. extern int trace_selftest_startup_branch(struct tracer *trace,
  426. struct trace_array *tr);
  427. #endif /* CONFIG_FTRACE_STARTUP_TEST */
  428. extern void *head_page(struct trace_array_cpu *data);
  429. extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
  430. extern void trace_seq_print_cont(struct trace_seq *s,
  431. struct trace_iterator *iter);
  432. extern int
  433. seq_print_ip_sym(struct trace_seq *s, unsigned long ip,
  434. unsigned long sym_flags);
  435. extern ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
  436. size_t cnt);
  437. extern long ns2usecs(cycle_t nsec);
  438. extern int
  439. trace_vprintk(unsigned long ip, int depth, const char *fmt, va_list args);
  440. extern unsigned long trace_flags;
  441. /* Standard output formatting function used for function return traces */
  442. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  443. extern enum print_line_t print_graph_function(struct trace_iterator *iter);
  444. #ifdef CONFIG_DYNAMIC_FTRACE
  445. /* TODO: make this variable */
  446. #define FTRACE_GRAPH_MAX_FUNCS 32
  447. extern int ftrace_graph_count;
  448. extern unsigned long ftrace_graph_funcs[FTRACE_GRAPH_MAX_FUNCS];
  449. static inline int ftrace_graph_addr(unsigned long addr)
  450. {
  451. int i;
  452. if (!ftrace_graph_count || test_tsk_trace_graph(current))
  453. return 1;
  454. for (i = 0; i < ftrace_graph_count; i++) {
  455. if (addr == ftrace_graph_funcs[i])
  456. return 1;
  457. }
  458. return 0;
  459. }
  460. #else
  461. static inline int ftrace_trace_addr(unsigned long addr)
  462. {
  463. return 1;
  464. }
  465. static inline int ftrace_graph_addr(unsigned long addr)
  466. {
  467. return 1;
  468. }
  469. #endif /* CONFIG_DYNAMIC_FTRACE */
  470. #else /* CONFIG_FUNCTION_GRAPH_TRACER */
  471. static inline enum print_line_t
  472. print_graph_function(struct trace_iterator *iter)
  473. {
  474. return TRACE_TYPE_UNHANDLED;
  475. }
  476. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  477. extern struct pid *ftrace_pid_trace;
  478. static inline int ftrace_trace_task(struct task_struct *task)
  479. {
  480. if (!ftrace_pid_trace)
  481. return 1;
  482. return test_tsk_trace_trace(task);
  483. }
  484. /*
  485. * trace_iterator_flags is an enumeration that defines bit
  486. * positions into trace_flags that controls the output.
  487. *
  488. * NOTE: These bits must match the trace_options array in
  489. * trace.c.
  490. */
  491. enum trace_iterator_flags {
  492. TRACE_ITER_PRINT_PARENT = 0x01,
  493. TRACE_ITER_SYM_OFFSET = 0x02,
  494. TRACE_ITER_SYM_ADDR = 0x04,
  495. TRACE_ITER_VERBOSE = 0x08,
  496. TRACE_ITER_RAW = 0x10,
  497. TRACE_ITER_HEX = 0x20,
  498. TRACE_ITER_BIN = 0x40,
  499. TRACE_ITER_BLOCK = 0x80,
  500. TRACE_ITER_STACKTRACE = 0x100,
  501. TRACE_ITER_SCHED_TREE = 0x200,
  502. TRACE_ITER_PRINTK = 0x400,
  503. TRACE_ITER_PREEMPTONLY = 0x800,
  504. TRACE_ITER_BRANCH = 0x1000,
  505. TRACE_ITER_ANNOTATE = 0x2000,
  506. TRACE_ITER_USERSTACKTRACE = 0x4000,
  507. TRACE_ITER_SYM_USEROBJ = 0x8000,
  508. TRACE_ITER_PRINTK_MSGONLY = 0x10000
  509. };
  510. /*
  511. * TRACE_ITER_SYM_MASK masks the options in trace_flags that
  512. * control the output of kernel symbols.
  513. */
  514. #define TRACE_ITER_SYM_MASK \
  515. (TRACE_ITER_PRINT_PARENT|TRACE_ITER_SYM_OFFSET|TRACE_ITER_SYM_ADDR)
  516. extern struct tracer nop_trace;
  517. /**
  518. * ftrace_preempt_disable - disable preemption scheduler safe
  519. *
  520. * When tracing can happen inside the scheduler, there exists
  521. * cases that the tracing might happen before the need_resched
  522. * flag is checked. If this happens and the tracer calls
  523. * preempt_enable (after a disable), a schedule might take place
  524. * causing an infinite recursion.
  525. *
  526. * To prevent this, we read the need_recshed flag before
  527. * disabling preemption. When we want to enable preemption we
  528. * check the flag, if it is set, then we call preempt_enable_no_resched.
  529. * Otherwise, we call preempt_enable.
  530. *
  531. * The rational for doing the above is that if need resched is set
  532. * and we have yet to reschedule, we are either in an atomic location
  533. * (where we do not need to check for scheduling) or we are inside
  534. * the scheduler and do not want to resched.
  535. */
  536. static inline int ftrace_preempt_disable(void)
  537. {
  538. int resched;
  539. resched = need_resched();
  540. preempt_disable_notrace();
  541. return resched;
  542. }
  543. /**
  544. * ftrace_preempt_enable - enable preemption scheduler safe
  545. * @resched: the return value from ftrace_preempt_disable
  546. *
  547. * This is a scheduler safe way to enable preemption and not miss
  548. * any preemption checks. The disabled saved the state of preemption.
  549. * If resched is set, then we were either inside an atomic or
  550. * are inside the scheduler (we would have already scheduled
  551. * otherwise). In this case, we do not want to call normal
  552. * preempt_enable, but preempt_enable_no_resched instead.
  553. */
  554. static inline void ftrace_preempt_enable(int resched)
  555. {
  556. if (resched)
  557. preempt_enable_no_resched_notrace();
  558. else
  559. preempt_enable_notrace();
  560. }
  561. #ifdef CONFIG_BRANCH_TRACER
  562. extern int enable_branch_tracing(struct trace_array *tr);
  563. extern void disable_branch_tracing(void);
  564. static inline int trace_branch_enable(struct trace_array *tr)
  565. {
  566. if (trace_flags & TRACE_ITER_BRANCH)
  567. return enable_branch_tracing(tr);
  568. return 0;
  569. }
  570. static inline void trace_branch_disable(void)
  571. {
  572. /* due to races, always disable */
  573. disable_branch_tracing();
  574. }
  575. #else
  576. static inline int trace_branch_enable(struct trace_array *tr)
  577. {
  578. return 0;
  579. }
  580. static inline void trace_branch_disable(void)
  581. {
  582. }
  583. #endif /* CONFIG_BRANCH_TRACER */
  584. #endif /* _LINUX_KERNEL_TRACE_H */