trace.h 18 KB

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