blob: 978145088fb8641cacc2b4c6a91092b5796141bc [file] [log] [blame]
Steven Rostedtbc0c38d2008-05-12 21:20:42 +02001#ifndef _LINUX_KERNEL_TRACE_H
2#define _LINUX_KERNEL_TRACE_H
3
4#include <linux/fs.h>
5#include <asm/atomic.h>
6#include <linux/sched.h>
7#include <linux/clocksource.h>
Steven Rostedt3928a8a2008-09-29 23:02:41 -04008#include <linux/ring_buffer.h>
Pekka Paalanenbd8ac682008-05-12 21:20:57 +02009#include <linux/mmiotrace.h>
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +010010#include <linux/ftrace.h>
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020011
Thomas Gleixner72829bc2008-05-23 21:37:28 +020012enum trace_type {
13 __TRACE_FIRST_TYPE = 0,
14
15 TRACE_FN,
16 TRACE_CTX,
17 TRACE_WAKE,
Steven Rostedtdd0e5452008-08-01 12:26:41 -040018 TRACE_CONT,
Thomas Gleixner72829bc2008-05-23 21:37:28 +020019 TRACE_STACK,
Steven Rostedtdd0e5452008-08-01 12:26:41 -040020 TRACE_PRINT,
Thomas Gleixner72829bc2008-05-23 21:37:28 +020021 TRACE_SPECIAL,
Pekka Paalanenbd8ac682008-05-12 21:20:57 +020022 TRACE_MMIO_RW,
23 TRACE_MMIO_MAP,
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +010024 TRACE_BOOT,
Thomas Gleixner72829bc2008-05-23 21:37:28 +020025
26 __TRACE_LAST_TYPE
27};
28
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020029/*
Steven Rostedt777e2082008-09-29 23:02:42 -040030 * The trace entry - the most basic unit of tracing. This is what
31 * is printed in the end as a single line in the trace output, such as:
32 *
33 * bash-15816 [01] 235.197585: idle_cpu <- irq_enter
34 */
35struct trace_entry {
36 unsigned char type;
37 unsigned char cpu;
38 unsigned char flags;
39 unsigned char preempt_count;
40 int pid;
41};
42
43/*
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020044 * Function trace entry - function address and parent function addres:
45 */
46struct ftrace_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040047 struct trace_entry ent;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020048 unsigned long ip;
49 unsigned long parent_ip;
50};
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +010051extern struct tracer boot_tracer;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020052
53/*
54 * Context switch trace entry - which task (and prio) we switched from/to:
55 */
56struct ctx_switch_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040057 struct trace_entry ent;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020058 unsigned int prev_pid;
59 unsigned char prev_prio;
60 unsigned char prev_state;
61 unsigned int next_pid;
62 unsigned char next_prio;
Peter Zijlstrabac524d2008-05-12 21:20:53 +020063 unsigned char next_state;
Peter Zijlstra80b5e942008-09-04 10:24:16 +020064 unsigned int next_cpu;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020065};
66
67/*
Ingo Molnarf0a920d2008-05-12 21:20:47 +020068 * Special (free-form) trace entry:
69 */
70struct special_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040071 struct trace_entry ent;
Ingo Molnarf0a920d2008-05-12 21:20:47 +020072 unsigned long arg1;
73 unsigned long arg2;
74 unsigned long arg3;
75};
76
77/*
Ingo Molnar86387f72008-05-12 21:20:51 +020078 * Stack-trace entry:
79 */
80
Ingo Molnar74f4e362008-05-12 21:21:15 +020081#define FTRACE_STACK_ENTRIES 8
Ingo Molnar86387f72008-05-12 21:20:51 +020082
83struct stack_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040084 struct trace_entry ent;
Ingo Molnar86387f72008-05-12 21:20:51 +020085 unsigned long caller[FTRACE_STACK_ENTRIES];
86};
87
88/*
Steven Rostedtdd0e5452008-08-01 12:26:41 -040089 * ftrace_printk entry:
90 */
91struct print_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040092 struct trace_entry ent;
Steven Rostedtdd0e5452008-08-01 12:26:41 -040093 unsigned long ip;
94 char buf[];
95};
96
Steven Rostedt777e2082008-09-29 23:02:42 -040097#define TRACE_OLD_SIZE 88
98
99struct trace_field_cont {
100 unsigned char type;
101 /* Temporary till we get rid of this completely */
102 char buf[TRACE_OLD_SIZE - 1];
103};
104
105struct trace_mmiotrace_rw {
106 struct trace_entry ent;
107 struct mmiotrace_rw rw;
108};
109
110struct trace_mmiotrace_map {
111 struct trace_entry ent;
112 struct mmiotrace_map map;
113};
114
115struct trace_boot {
116 struct trace_entry ent;
117 struct boot_trace initcall;
118};
119
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400120/*
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300121 * trace_flag_type is an enumeration that holds different
122 * states when a trace occurs. These are:
Steven Rostedt92444892008-10-24 09:42:59 -0400123 * IRQS_OFF - interrupts were disabled
124 * IRQS_NOSUPPORT - arch does not support irqs_disabled_flags
125 * NEED_RESCED - reschedule is requested
126 * HARDIRQ - inside an interrupt handler
127 * SOFTIRQ - inside a softirq handler
128 * CONT - multiple entries hold the trace item
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300129 */
130enum trace_flag_type {
131 TRACE_FLAG_IRQS_OFF = 0x01,
Steven Rostedt92444892008-10-24 09:42:59 -0400132 TRACE_FLAG_IRQS_NOSUPPORT = 0x02,
133 TRACE_FLAG_NEED_RESCHED = 0x04,
134 TRACE_FLAG_HARDIRQ = 0x08,
135 TRACE_FLAG_SOFTIRQ = 0x10,
136 TRACE_FLAG_CONT = 0x20,
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300137};
138
Pekka Paalanen5bf9a1e2008-09-16 22:06:42 +0300139#define TRACE_BUF_SIZE 1024
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200140
141/*
142 * The CPU trace array - it consists of thousands of trace entries
143 * plus some other descriptor data: (for example which task started
144 * the trace, etc.)
145 */
146struct trace_array_cpu {
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200147 atomic_t disabled;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200148
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200149 /* these fields get copied into max-trace: */
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200150 unsigned long trace_idx;
Steven Rostedt53d0aa72008-05-12 21:21:01 +0200151 unsigned long overrun;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200152 unsigned long saved_latency;
153 unsigned long critical_start;
154 unsigned long critical_end;
155 unsigned long critical_sequence;
156 unsigned long nice;
157 unsigned long policy;
158 unsigned long rt_priority;
159 cycle_t preempt_timestamp;
160 pid_t pid;
161 uid_t uid;
162 char comm[TASK_COMM_LEN];
163};
164
165struct trace_iterator;
166
167/*
168 * The trace array - an array of per-CPU trace arrays. This is the
169 * highest level data structure that individual tracers deal with.
170 * They have on/off state as well:
171 */
172struct trace_array {
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400173 struct ring_buffer *buffer;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200174 unsigned long entries;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200175 int cpu;
176 cycle_t time_start;
Steven Rostedtb3806b42008-05-12 21:20:46 +0200177 struct task_struct *waiter;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200178 struct trace_array_cpu *data[NR_CPUS];
179};
180
Steven Rostedt7104f302008-10-01 10:52:51 -0400181#define FTRACE_CMP_TYPE(var, type) \
182 __builtin_types_compatible_p(typeof(var), type *)
183
184#undef IF_ASSIGN
185#define IF_ASSIGN(var, entry, etype, id) \
186 if (FTRACE_CMP_TYPE(var, etype)) { \
187 var = (typeof(var))(entry); \
188 WARN_ON(id && (entry)->type != id); \
189 break; \
190 }
191
192/* Will cause compile errors if type is not found. */
193extern void __ftrace_bad_type(void);
194
195/*
196 * The trace_assign_type is a verifier that the entry type is
197 * the same as the type being assigned. To add new types simply
198 * add a line with the following format:
199 *
200 * IF_ASSIGN(var, ent, type, id);
201 *
202 * Where "type" is the trace type that includes the trace_entry
203 * as the "ent" item. And "id" is the trace identifier that is
204 * used in the trace_type enum.
205 *
206 * If the type can have more than one id, then use zero.
207 */
208#define trace_assign_type(var, ent) \
209 do { \
210 IF_ASSIGN(var, ent, struct ftrace_entry, TRACE_FN); \
211 IF_ASSIGN(var, ent, struct ctx_switch_entry, 0); \
212 IF_ASSIGN(var, ent, struct trace_field_cont, TRACE_CONT); \
213 IF_ASSIGN(var, ent, struct stack_entry, TRACE_STACK); \
214 IF_ASSIGN(var, ent, struct print_entry, TRACE_PRINT); \
215 IF_ASSIGN(var, ent, struct special_entry, 0); \
216 IF_ASSIGN(var, ent, struct trace_mmiotrace_rw, \
217 TRACE_MMIO_RW); \
218 IF_ASSIGN(var, ent, struct trace_mmiotrace_map, \
219 TRACE_MMIO_MAP); \
220 IF_ASSIGN(var, ent, struct trace_boot, TRACE_BOOT); \
221 __ftrace_bad_type(); \
222 } while (0)
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +0200223
224/* Return values for print_line callback */
225enum print_line_t {
226 TRACE_TYPE_PARTIAL_LINE = 0, /* Retry after flushing the seq */
227 TRACE_TYPE_HANDLED = 1,
228 TRACE_TYPE_UNHANDLED = 2 /* Relay to other output functions */
229};
230
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200231/*
232 * A specific tracer, represented by methods that operate on a trace array:
233 */
234struct tracer {
235 const char *name;
236 void (*init)(struct trace_array *tr);
237 void (*reset)(struct trace_array *tr);
Steven Rostedt90369902008-11-05 16:05:44 -0500238 void (*start)(struct trace_array *tr);
239 void (*stop)(struct trace_array *tr);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200240 void (*open)(struct trace_iterator *iter);
Steven Rostedt107bad82008-05-12 21:21:01 +0200241 void (*pipe_open)(struct trace_iterator *iter);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200242 void (*close)(struct trace_iterator *iter);
Steven Rostedt107bad82008-05-12 21:21:01 +0200243 ssize_t (*read)(struct trace_iterator *iter,
244 struct file *filp, char __user *ubuf,
245 size_t cnt, loff_t *ppos);
Steven Rostedt60a11772008-05-12 21:20:44 +0200246#ifdef CONFIG_FTRACE_STARTUP_TEST
247 int (*selftest)(struct tracer *trace,
248 struct trace_array *tr);
249#endif
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +0200250 enum print_line_t (*print_line)(struct trace_iterator *iter);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200251 struct tracer *next;
252 int print_max;
253};
254
Steven Rostedt214023c2008-05-12 21:20:46 +0200255struct trace_seq {
256 unsigned char buffer[PAGE_SIZE];
257 unsigned int len;
Pekka Paalanen6c6c2792008-05-12 21:21:02 +0200258 unsigned int readpos;
Steven Rostedt214023c2008-05-12 21:20:46 +0200259};
260
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200261/*
262 * Trace iterator - used by printout routines who present trace
263 * results to users and which routines might sleep, etc:
264 */
265struct trace_iterator {
266 struct trace_array *tr;
267 struct tracer *trace;
Steven Rostedt107bad82008-05-12 21:21:01 +0200268 void *private;
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400269 struct ring_buffer_iter *buffer_iter[NR_CPUS];
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200270
Steven Rostedt53d0aa72008-05-12 21:21:01 +0200271 /* The below is zeroed out in pipe_read */
272 struct trace_seq seq;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200273 struct trace_entry *ent;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200274 int cpu;
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400275 u64 ts;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200276
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200277 unsigned long iter_flags;
278 loff_t pos;
Steven Rostedt4c11d7a2008-05-12 21:20:43 +0200279 long idx;
Steven Rostedta3097202008-11-07 22:36:02 -0500280
281 cpumask_t started;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200282};
283
Steven Rostedt90369902008-11-05 16:05:44 -0500284int tracing_is_enabled(void);
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300285void trace_wake_up(void);
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400286void tracing_reset(struct trace_array *tr, int cpu);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200287int tracing_open_generic(struct inode *inode, struct file *filp);
288struct dentry *tracing_init_dentry(void);
Ingo Molnard618b3e2008-05-12 21:20:49 +0200289void init_tracer_sysprof_debugfs(struct dentry *d_tracer);
290
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300291struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
292 struct trace_array_cpu *data);
293void tracing_generic_entry_update(struct trace_entry *entry,
Steven Rostedt38697052008-10-01 13:14:09 -0400294 unsigned long flags,
295 int pc);
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300296
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200297void ftrace(struct trace_array *tr,
298 struct trace_array_cpu *data,
299 unsigned long ip,
300 unsigned long parent_ip,
Steven Rostedt38697052008-10-01 13:14:09 -0400301 unsigned long flags, int pc);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200302void tracing_sched_switch_trace(struct trace_array *tr,
303 struct trace_array_cpu *data,
304 struct task_struct *prev,
305 struct task_struct *next,
Steven Rostedt38697052008-10-01 13:14:09 -0400306 unsigned long flags, int pc);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200307void tracing_record_cmdline(struct task_struct *tsk);
Ingo Molnar57422792008-05-12 21:20:51 +0200308
309void tracing_sched_wakeup_trace(struct trace_array *tr,
310 struct trace_array_cpu *data,
311 struct task_struct *wakee,
312 struct task_struct *cur,
Steven Rostedt38697052008-10-01 13:14:09 -0400313 unsigned long flags, int pc);
Ingo Molnarf0a920d2008-05-12 21:20:47 +0200314void trace_special(struct trace_array *tr,
315 struct trace_array_cpu *data,
316 unsigned long arg1,
317 unsigned long arg2,
Steven Rostedt38697052008-10-01 13:14:09 -0400318 unsigned long arg3, int pc);
Steven Rostedt6fb44b72008-05-12 21:20:49 +0200319void trace_function(struct trace_array *tr,
320 struct trace_array_cpu *data,
321 unsigned long ip,
322 unsigned long parent_ip,
Steven Rostedt38697052008-10-01 13:14:09 -0400323 unsigned long flags, int pc);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200324
Steven Rostedt41bc8142008-05-22 11:49:22 -0400325void tracing_start_cmdline_record(void);
326void tracing_stop_cmdline_record(void);
Steven Rostedte168e052008-11-07 22:36:02 -0500327void tracing_sched_switch_assign_trace(struct trace_array *tr);
328void tracing_stop_sched_switch_record(void);
329void tracing_start_sched_switch_record(void);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200330int register_tracer(struct tracer *type);
331void unregister_tracer(struct tracer *type);
332
333extern unsigned long nsecs_to_usecs(unsigned long nsecs);
334
335extern unsigned long tracing_max_latency;
336extern unsigned long tracing_thresh;
337
338void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
339void update_max_tr_single(struct trace_array *tr,
340 struct task_struct *tsk, int cpu);
341
Ingo Molnare309b412008-05-12 21:20:51 +0200342extern cycle_t ftrace_now(int cpu);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200343
Steven Rostedt606576c2008-10-06 19:06:12 -0400344#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedt001b6762008-07-10 20:58:10 -0400345void tracing_start_function_trace(void);
346void tracing_stop_function_trace(void);
347#else
348# define tracing_start_function_trace() do { } while (0)
349# define tracing_stop_function_trace() do { } while (0)
350#endif
351
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200352#ifdef CONFIG_CONTEXT_SWITCH_TRACER
353typedef void
354(*tracer_switch_func_t)(void *private,
Mathieu Desnoyers5b82a1b2008-05-12 21:21:10 +0200355 void *__rq,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200356 struct task_struct *prev,
357 struct task_struct *next);
358
359struct tracer_switch_ops {
360 tracer_switch_func_t func;
361 void *private;
362 struct tracer_switch_ops *next;
363};
364
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200365#endif /* CONFIG_CONTEXT_SWITCH_TRACER */
366
367#ifdef CONFIG_DYNAMIC_FTRACE
368extern unsigned long ftrace_update_tot_cnt;
Steven Rostedtd05cdb22008-05-12 21:20:54 +0200369#define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
370extern int DYN_FTRACE_TEST_NAME(void);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200371#endif
372
Steven Rostedt60a11772008-05-12 21:20:44 +0200373#ifdef CONFIG_FTRACE_STARTUP_TEST
Steven Rostedt60a11772008-05-12 21:20:44 +0200374extern int trace_selftest_startup_function(struct tracer *trace,
375 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200376extern int trace_selftest_startup_irqsoff(struct tracer *trace,
377 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200378extern int trace_selftest_startup_preemptoff(struct tracer *trace,
379 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200380extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
381 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200382extern int trace_selftest_startup_wakeup(struct tracer *trace,
383 struct trace_array *tr);
Steven Noonanfb1b6d82008-09-19 03:06:43 -0700384extern int trace_selftest_startup_nop(struct tracer *trace,
385 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200386extern int trace_selftest_startup_sched_switch(struct tracer *trace,
387 struct trace_array *tr);
Ingo Molnara6dd24f2008-05-12 21:20:47 +0200388extern int trace_selftest_startup_sysprof(struct tracer *trace,
389 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200390#endif /* CONFIG_FTRACE_STARTUP_TEST */
391
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200392extern void *head_page(struct trace_array_cpu *data);
Thomas Gleixner72829bc2008-05-23 21:37:28 +0200393extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300394extern void trace_seq_print_cont(struct trace_seq *s,
395 struct trace_iterator *iter);
Pekka Paalanen6c6c2792008-05-12 21:21:02 +0200396extern ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
397 size_t cnt);
Thomas Gleixner72829bc2008-05-23 21:37:28 +0200398extern long ns2usecs(cycle_t nsec);
Pekka Paalanen801fe402008-09-16 21:58:24 +0300399extern int trace_vprintk(unsigned long ip, const char *fmt, va_list args);
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200400
Ingo Molnar4e655512008-05-12 21:20:52 +0200401extern unsigned long trace_flags;
402
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200403/*
404 * trace_iterator_flags is an enumeration that defines bit
405 * positions into trace_flags that controls the output.
406 *
407 * NOTE: These bits must match the trace_options array in
408 * trace.c.
409 */
Ingo Molnar4e655512008-05-12 21:20:52 +0200410enum trace_iterator_flags {
411 TRACE_ITER_PRINT_PARENT = 0x01,
412 TRACE_ITER_SYM_OFFSET = 0x02,
413 TRACE_ITER_SYM_ADDR = 0x04,
414 TRACE_ITER_VERBOSE = 0x08,
415 TRACE_ITER_RAW = 0x10,
416 TRACE_ITER_HEX = 0x20,
417 TRACE_ITER_BIN = 0x40,
418 TRACE_ITER_BLOCK = 0x80,
419 TRACE_ITER_STACKTRACE = 0x100,
Ingo Molnar4ac3ba42008-05-12 21:20:52 +0200420 TRACE_ITER_SCHED_TREE = 0x200,
Peter Zijlstraf09ce572008-09-04 10:24:14 +0200421 TRACE_ITER_PRINTK = 0x400,
Steven Rostedtb2a866f2008-11-03 23:15:57 -0500422 TRACE_ITER_PREEMPTONLY = 0x800,
Ingo Molnar4e655512008-05-12 21:20:52 +0200423};
424
Frédéric Weisbecker43a15382008-09-21 20:16:30 +0200425extern struct tracer nop_trace;
426
Steven Rostedt8f0a0562008-11-03 23:15:55 -0500427/**
428 * ftrace_preempt_disable - disable preemption scheduler safe
429 *
430 * When tracing can happen inside the scheduler, there exists
431 * cases that the tracing might happen before the need_resched
432 * flag is checked. If this happens and the tracer calls
433 * preempt_enable (after a disable), a schedule might take place
434 * causing an infinite recursion.
435 *
436 * To prevent this, we read the need_recshed flag before
437 * disabling preemption. When we want to enable preemption we
438 * check the flag, if it is set, then we call preempt_enable_no_resched.
439 * Otherwise, we call preempt_enable.
440 *
441 * The rational for doing the above is that if need resched is set
442 * and we have yet to reschedule, we are either in an atomic location
443 * (where we do not need to check for scheduling) or we are inside
444 * the scheduler and do not want to resched.
445 */
446static inline int ftrace_preempt_disable(void)
447{
448 int resched;
449
450 resched = need_resched();
451 preempt_disable_notrace();
452
453 return resched;
454}
455
456/**
457 * ftrace_preempt_enable - enable preemption scheduler safe
458 * @resched: the return value from ftrace_preempt_disable
459 *
460 * This is a scheduler safe way to enable preemption and not miss
461 * any preemption checks. The disabled saved the state of preemption.
462 * If resched is set, then we were either inside an atomic or
463 * are inside the scheduler (we would have already scheduled
464 * otherwise). In this case, we do not want to call normal
465 * preempt_enable, but preempt_enable_no_resched instead.
466 */
467static inline void ftrace_preempt_enable(int resched)
468{
469 if (resched)
470 preempt_enable_no_resched_notrace();
471 else
472 preempt_enable_notrace();
473}
474
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200475#endif /* _LINUX_KERNEL_TRACE_H */