blob: 3422489fad5ed965575df9c6067fd8d3a23b248d [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;
Frederic Weisbeckerd7ad44b2008-10-31 13:20:08 +010052extern struct tracer sched_switch_trace; /* Used by the boot tracer */
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020053
54/*
55 * Context switch trace entry - which task (and prio) we switched from/to:
56 */
57struct ctx_switch_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040058 struct trace_entry ent;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020059 unsigned int prev_pid;
60 unsigned char prev_prio;
61 unsigned char prev_state;
62 unsigned int next_pid;
63 unsigned char next_prio;
Peter Zijlstrabac524d2008-05-12 21:20:53 +020064 unsigned char next_state;
Peter Zijlstra80b5e942008-09-04 10:24:16 +020065 unsigned int next_cpu;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +020066};
67
68/*
Ingo Molnarf0a920d2008-05-12 21:20:47 +020069 * Special (free-form) trace entry:
70 */
71struct special_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040072 struct trace_entry ent;
Ingo Molnarf0a920d2008-05-12 21:20:47 +020073 unsigned long arg1;
74 unsigned long arg2;
75 unsigned long arg3;
76};
77
78/*
Ingo Molnar86387f72008-05-12 21:20:51 +020079 * Stack-trace entry:
80 */
81
Ingo Molnar74f4e362008-05-12 21:21:15 +020082#define FTRACE_STACK_ENTRIES 8
Ingo Molnar86387f72008-05-12 21:20:51 +020083
84struct stack_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040085 struct trace_entry ent;
Ingo Molnar86387f72008-05-12 21:20:51 +020086 unsigned long caller[FTRACE_STACK_ENTRIES];
87};
88
89/*
Steven Rostedtdd0e5452008-08-01 12:26:41 -040090 * ftrace_printk entry:
91 */
92struct print_entry {
Steven Rostedt777e2082008-09-29 23:02:42 -040093 struct trace_entry ent;
Steven Rostedtdd0e5452008-08-01 12:26:41 -040094 unsigned long ip;
95 char buf[];
96};
97
Steven Rostedt777e2082008-09-29 23:02:42 -040098#define TRACE_OLD_SIZE 88
99
100struct trace_field_cont {
101 unsigned char type;
102 /* Temporary till we get rid of this completely */
103 char buf[TRACE_OLD_SIZE - 1];
104};
105
106struct trace_mmiotrace_rw {
107 struct trace_entry ent;
108 struct mmiotrace_rw rw;
109};
110
111struct trace_mmiotrace_map {
112 struct trace_entry ent;
113 struct mmiotrace_map map;
114};
115
116struct trace_boot {
117 struct trace_entry ent;
118 struct boot_trace initcall;
119};
120
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400121/*
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300122 * trace_flag_type is an enumeration that holds different
123 * states when a trace occurs. These are:
Steven Rostedt92444892008-10-24 09:42:59 -0400124 * IRQS_OFF - interrupts were disabled
125 * IRQS_NOSUPPORT - arch does not support irqs_disabled_flags
126 * NEED_RESCED - reschedule is requested
127 * HARDIRQ - inside an interrupt handler
128 * SOFTIRQ - inside a softirq handler
129 * CONT - multiple entries hold the trace item
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300130 */
131enum trace_flag_type {
132 TRACE_FLAG_IRQS_OFF = 0x01,
Steven Rostedt92444892008-10-24 09:42:59 -0400133 TRACE_FLAG_IRQS_NOSUPPORT = 0x02,
134 TRACE_FLAG_NEED_RESCHED = 0x04,
135 TRACE_FLAG_HARDIRQ = 0x08,
136 TRACE_FLAG_SOFTIRQ = 0x10,
137 TRACE_FLAG_CONT = 0x20,
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300138};
139
Pekka Paalanen5bf9a1e2008-09-16 22:06:42 +0300140#define TRACE_BUF_SIZE 1024
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200141
142/*
143 * The CPU trace array - it consists of thousands of trace entries
144 * plus some other descriptor data: (for example which task started
145 * the trace, etc.)
146 */
147struct trace_array_cpu {
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200148 atomic_t disabled;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200149
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200150 /* these fields get copied into max-trace: */
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200151 unsigned long trace_idx;
Steven Rostedt53d0aa72008-05-12 21:21:01 +0200152 unsigned long overrun;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200153 unsigned long saved_latency;
154 unsigned long critical_start;
155 unsigned long critical_end;
156 unsigned long critical_sequence;
157 unsigned long nice;
158 unsigned long policy;
159 unsigned long rt_priority;
160 cycle_t preempt_timestamp;
161 pid_t pid;
162 uid_t uid;
163 char comm[TASK_COMM_LEN];
164};
165
166struct trace_iterator;
167
168/*
169 * The trace array - an array of per-CPU trace arrays. This is the
170 * highest level data structure that individual tracers deal with.
171 * They have on/off state as well:
172 */
173struct trace_array {
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400174 struct ring_buffer *buffer;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200175 unsigned long entries;
176 long ctrl;
177 int cpu;
178 cycle_t time_start;
Steven Rostedtb3806b42008-05-12 21:20:46 +0200179 struct task_struct *waiter;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200180 struct trace_array_cpu *data[NR_CPUS];
181};
182
Steven Rostedt7104f302008-10-01 10:52:51 -0400183#define FTRACE_CMP_TYPE(var, type) \
184 __builtin_types_compatible_p(typeof(var), type *)
185
186#undef IF_ASSIGN
187#define IF_ASSIGN(var, entry, etype, id) \
188 if (FTRACE_CMP_TYPE(var, etype)) { \
189 var = (typeof(var))(entry); \
190 WARN_ON(id && (entry)->type != id); \
191 break; \
192 }
193
194/* Will cause compile errors if type is not found. */
195extern void __ftrace_bad_type(void);
196
197/*
198 * The trace_assign_type is a verifier that the entry type is
199 * the same as the type being assigned. To add new types simply
200 * add a line with the following format:
201 *
202 * IF_ASSIGN(var, ent, type, id);
203 *
204 * Where "type" is the trace type that includes the trace_entry
205 * as the "ent" item. And "id" is the trace identifier that is
206 * used in the trace_type enum.
207 *
208 * If the type can have more than one id, then use zero.
209 */
210#define trace_assign_type(var, ent) \
211 do { \
212 IF_ASSIGN(var, ent, struct ftrace_entry, TRACE_FN); \
213 IF_ASSIGN(var, ent, struct ctx_switch_entry, 0); \
214 IF_ASSIGN(var, ent, struct trace_field_cont, TRACE_CONT); \
215 IF_ASSIGN(var, ent, struct stack_entry, TRACE_STACK); \
216 IF_ASSIGN(var, ent, struct print_entry, TRACE_PRINT); \
217 IF_ASSIGN(var, ent, struct special_entry, 0); \
218 IF_ASSIGN(var, ent, struct trace_mmiotrace_rw, \
219 TRACE_MMIO_RW); \
220 IF_ASSIGN(var, ent, struct trace_mmiotrace_map, \
221 TRACE_MMIO_MAP); \
222 IF_ASSIGN(var, ent, struct trace_boot, TRACE_BOOT); \
223 __ftrace_bad_type(); \
224 } while (0)
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +0200225
226/* Return values for print_line callback */
227enum print_line_t {
228 TRACE_TYPE_PARTIAL_LINE = 0, /* Retry after flushing the seq */
229 TRACE_TYPE_HANDLED = 1,
230 TRACE_TYPE_UNHANDLED = 2 /* Relay to other output functions */
231};
232
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200233/*
234 * A specific tracer, represented by methods that operate on a trace array:
235 */
236struct tracer {
237 const char *name;
238 void (*init)(struct trace_array *tr);
239 void (*reset)(struct trace_array *tr);
Steven Rostedt90369902008-11-05 16:05:44 -0500240 void (*start)(struct trace_array *tr);
241 void (*stop)(struct trace_array *tr);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200242 void (*open)(struct trace_iterator *iter);
Steven Rostedt107bad82008-05-12 21:21:01 +0200243 void (*pipe_open)(struct trace_iterator *iter);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200244 void (*close)(struct trace_iterator *iter);
Steven Rostedt107bad82008-05-12 21:21:01 +0200245 ssize_t (*read)(struct trace_iterator *iter,
246 struct file *filp, char __user *ubuf,
247 size_t cnt, loff_t *ppos);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200248 void (*ctrl_update)(struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200249#ifdef CONFIG_FTRACE_STARTUP_TEST
250 int (*selftest)(struct tracer *trace,
251 struct trace_array *tr);
252#endif
Frederic Weisbecker2c4f0352008-09-29 20:18:34 +0200253 enum print_line_t (*print_line)(struct trace_iterator *iter);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200254 struct tracer *next;
255 int print_max;
256};
257
Steven Rostedt214023c2008-05-12 21:20:46 +0200258struct trace_seq {
259 unsigned char buffer[PAGE_SIZE];
260 unsigned int len;
Pekka Paalanen6c6c2792008-05-12 21:21:02 +0200261 unsigned int readpos;
Steven Rostedt214023c2008-05-12 21:20:46 +0200262};
263
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200264/*
265 * Trace iterator - used by printout routines who present trace
266 * results to users and which routines might sleep, etc:
267 */
268struct trace_iterator {
269 struct trace_array *tr;
270 struct tracer *trace;
Steven Rostedt107bad82008-05-12 21:21:01 +0200271 void *private;
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400272 struct ring_buffer_iter *buffer_iter[NR_CPUS];
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200273
Steven Rostedt53d0aa72008-05-12 21:21:01 +0200274 /* The below is zeroed out in pipe_read */
275 struct trace_seq seq;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200276 struct trace_entry *ent;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200277 int cpu;
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400278 u64 ts;
Ingo Molnar4e3c3332008-05-12 21:20:45 +0200279
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200280 unsigned long iter_flags;
281 loff_t pos;
Steven Rostedt4c11d7a2008-05-12 21:20:43 +0200282 long idx;
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200283};
284
Steven Rostedt90369902008-11-05 16:05:44 -0500285int tracing_is_enabled(void);
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300286void trace_wake_up(void);
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400287void tracing_reset(struct trace_array *tr, int cpu);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200288int tracing_open_generic(struct inode *inode, struct file *filp);
289struct dentry *tracing_init_dentry(void);
Ingo Molnard618b3e2008-05-12 21:20:49 +0200290void init_tracer_sysprof_debugfs(struct dentry *d_tracer);
291
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300292struct trace_entry *tracing_get_trace_entry(struct trace_array *tr,
293 struct trace_array_cpu *data);
294void tracing_generic_entry_update(struct trace_entry *entry,
Steven Rostedt38697052008-10-01 13:14:09 -0400295 unsigned long flags,
296 int pc);
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300297
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200298void ftrace(struct trace_array *tr,
299 struct trace_array_cpu *data,
300 unsigned long ip,
301 unsigned long parent_ip,
Steven Rostedt38697052008-10-01 13:14:09 -0400302 unsigned long flags, int pc);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200303void tracing_sched_switch_trace(struct trace_array *tr,
304 struct trace_array_cpu *data,
305 struct task_struct *prev,
306 struct task_struct *next,
Steven Rostedt38697052008-10-01 13:14:09 -0400307 unsigned long flags, int pc);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200308void tracing_record_cmdline(struct task_struct *tsk);
Ingo Molnar57422792008-05-12 21:20:51 +0200309
310void tracing_sched_wakeup_trace(struct trace_array *tr,
311 struct trace_array_cpu *data,
312 struct task_struct *wakee,
313 struct task_struct *cur,
Steven Rostedt38697052008-10-01 13:14:09 -0400314 unsigned long flags, int pc);
Ingo Molnarf0a920d2008-05-12 21:20:47 +0200315void trace_special(struct trace_array *tr,
316 struct trace_array_cpu *data,
317 unsigned long arg1,
318 unsigned long arg2,
Steven Rostedt38697052008-10-01 13:14:09 -0400319 unsigned long arg3, int pc);
Steven Rostedt6fb44b72008-05-12 21:20:49 +0200320void trace_function(struct trace_array *tr,
321 struct trace_array_cpu *data,
322 unsigned long ip,
323 unsigned long parent_ip,
Steven Rostedt38697052008-10-01 13:14:09 -0400324 unsigned long flags, int pc);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200325
Steven Rostedt41bc8142008-05-22 11:49:22 -0400326void tracing_start_cmdline_record(void);
327void tracing_stop_cmdline_record(void);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200328int register_tracer(struct tracer *type);
329void unregister_tracer(struct tracer *type);
330
331extern unsigned long nsecs_to_usecs(unsigned long nsecs);
332
333extern unsigned long tracing_max_latency;
334extern unsigned long tracing_thresh;
335
336void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
337void update_max_tr_single(struct trace_array *tr,
338 struct task_struct *tsk, int cpu);
339
Ingo Molnare309b412008-05-12 21:20:51 +0200340extern cycle_t ftrace_now(int cpu);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200341
Steven Rostedt606576c2008-10-06 19:06:12 -0400342#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedt001b6762008-07-10 20:58:10 -0400343void tracing_start_function_trace(void);
344void tracing_stop_function_trace(void);
345#else
346# define tracing_start_function_trace() do { } while (0)
347# define tracing_stop_function_trace() do { } while (0)
348#endif
349
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200350#ifdef CONFIG_CONTEXT_SWITCH_TRACER
351typedef void
352(*tracer_switch_func_t)(void *private,
Mathieu Desnoyers5b82a1b2008-05-12 21:21:10 +0200353 void *__rq,
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200354 struct task_struct *prev,
355 struct task_struct *next);
356
357struct tracer_switch_ops {
358 tracer_switch_func_t func;
359 void *private;
360 struct tracer_switch_ops *next;
361};
362
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200363#endif /* CONFIG_CONTEXT_SWITCH_TRACER */
364
365#ifdef CONFIG_DYNAMIC_FTRACE
366extern unsigned long ftrace_update_tot_cnt;
Steven Rostedtd05cdb22008-05-12 21:20:54 +0200367#define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
368extern int DYN_FTRACE_TEST_NAME(void);
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200369#endif
370
Steven Rostedt60a11772008-05-12 21:20:44 +0200371#ifdef CONFIG_FTRACE_STARTUP_TEST
Steven Rostedt60a11772008-05-12 21:20:44 +0200372extern int trace_selftest_startup_function(struct tracer *trace,
373 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200374extern int trace_selftest_startup_irqsoff(struct tracer *trace,
375 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200376extern int trace_selftest_startup_preemptoff(struct tracer *trace,
377 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200378extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
379 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200380extern int trace_selftest_startup_wakeup(struct tracer *trace,
381 struct trace_array *tr);
Steven Noonanfb1b6d82008-09-19 03:06:43 -0700382extern int trace_selftest_startup_nop(struct tracer *trace,
383 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200384extern int trace_selftest_startup_sched_switch(struct tracer *trace,
385 struct trace_array *tr);
Ingo Molnara6dd24f2008-05-12 21:20:47 +0200386extern int trace_selftest_startup_sysprof(struct tracer *trace,
387 struct trace_array *tr);
Steven Rostedt60a11772008-05-12 21:20:44 +0200388#endif /* CONFIG_FTRACE_STARTUP_TEST */
389
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200390extern void *head_page(struct trace_array_cpu *data);
Thomas Gleixner72829bc2008-05-23 21:37:28 +0200391extern int trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300392extern void trace_seq_print_cont(struct trace_seq *s,
393 struct trace_iterator *iter);
Pekka Paalanen6c6c2792008-05-12 21:21:02 +0200394extern ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
395 size_t cnt);
Thomas Gleixner72829bc2008-05-23 21:37:28 +0200396extern long ns2usecs(cycle_t nsec);
Pekka Paalanen801fe402008-09-16 21:58:24 +0300397extern int trace_vprintk(unsigned long ip, const char *fmt, va_list args);
Ingo Molnarc7aafc52008-05-12 21:20:45 +0200398
Ingo Molnar4e655512008-05-12 21:20:52 +0200399extern unsigned long trace_flags;
400
Steven Rostedt4fcdae82008-05-12 21:21:00 +0200401/*
402 * trace_iterator_flags is an enumeration that defines bit
403 * positions into trace_flags that controls the output.
404 *
405 * NOTE: These bits must match the trace_options array in
406 * trace.c.
407 */
Ingo Molnar4e655512008-05-12 21:20:52 +0200408enum trace_iterator_flags {
409 TRACE_ITER_PRINT_PARENT = 0x01,
410 TRACE_ITER_SYM_OFFSET = 0x02,
411 TRACE_ITER_SYM_ADDR = 0x04,
412 TRACE_ITER_VERBOSE = 0x08,
413 TRACE_ITER_RAW = 0x10,
414 TRACE_ITER_HEX = 0x20,
415 TRACE_ITER_BIN = 0x40,
416 TRACE_ITER_BLOCK = 0x80,
417 TRACE_ITER_STACKTRACE = 0x100,
Ingo Molnar4ac3ba42008-05-12 21:20:52 +0200418 TRACE_ITER_SCHED_TREE = 0x200,
Peter Zijlstraf09ce572008-09-04 10:24:14 +0200419 TRACE_ITER_PRINTK = 0x400,
Steven Rostedtb2a866f2008-11-03 23:15:57 -0500420 TRACE_ITER_PREEMPTONLY = 0x800,
Ingo Molnar4e655512008-05-12 21:20:52 +0200421};
422
Frédéric Weisbecker43a15382008-09-21 20:16:30 +0200423extern struct tracer nop_trace;
424
Steven Rostedt8f0a0562008-11-03 23:15:55 -0500425/**
426 * ftrace_preempt_disable - disable preemption scheduler safe
427 *
428 * When tracing can happen inside the scheduler, there exists
429 * cases that the tracing might happen before the need_resched
430 * flag is checked. If this happens and the tracer calls
431 * preempt_enable (after a disable), a schedule might take place
432 * causing an infinite recursion.
433 *
434 * To prevent this, we read the need_recshed flag before
435 * disabling preemption. When we want to enable preemption we
436 * check the flag, if it is set, then we call preempt_enable_no_resched.
437 * Otherwise, we call preempt_enable.
438 *
439 * The rational for doing the above is that if need resched is set
440 * and we have yet to reschedule, we are either in an atomic location
441 * (where we do not need to check for scheduling) or we are inside
442 * the scheduler and do not want to resched.
443 */
444static inline int ftrace_preempt_disable(void)
445{
446 int resched;
447
448 resched = need_resched();
449 preempt_disable_notrace();
450
451 return resched;
452}
453
454/**
455 * ftrace_preempt_enable - enable preemption scheduler safe
456 * @resched: the return value from ftrace_preempt_disable
457 *
458 * This is a scheduler safe way to enable preemption and not miss
459 * any preemption checks. The disabled saved the state of preemption.
460 * If resched is set, then we were either inside an atomic or
461 * are inside the scheduler (we would have already scheduled
462 * otherwise). In this case, we do not want to call normal
463 * preempt_enable, but preempt_enable_no_resched instead.
464 */
465static inline void ftrace_preempt_enable(int resched)
466{
467 if (resched)
468 preempt_enable_no_resched_notrace();
469 else
470 preempt_enable_notrace();
471}
472
Steven Rostedtbc0c38d2008-05-12 21:20:42 +0200473#endif /* _LINUX_KERNEL_TRACE_H */