]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - kernel/trace/trace.h
ftrace: add a buffer for output
[mirror_ubuntu-zesty-kernel.git] / kernel / trace / trace.h
CommitLineData
bc0c38d1
SR
1#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>
8
9/*
10 * Function trace entry - function address and parent function addres:
11 */
12struct ftrace_entry {
13 unsigned long ip;
14 unsigned long parent_ip;
15};
16
17/*
18 * Context switch trace entry - which task (and prio) we switched from/to:
19 */
20struct ctx_switch_entry {
21 unsigned int prev_pid;
22 unsigned char prev_prio;
23 unsigned char prev_state;
24 unsigned int next_pid;
25 unsigned char next_prio;
26};
27
28/*
29 * The trace entry - the most basic unit of tracing. This is what
30 * is printed in the end as a single line in the trace output, such as:
31 *
32 * bash-15816 [01] 235.197585: idle_cpu <- irq_enter
33 */
34struct trace_entry {
35 char type;
36 char cpu;
37 char flags;
38 char preempt_count;
39 int pid;
40 cycle_t t;
41 unsigned long idx;
42 union {
43 struct ftrace_entry fn;
44 struct ctx_switch_entry ctx;
45 };
46};
47
48#define TRACE_ENTRY_SIZE sizeof(struct trace_entry)
49
50/*
51 * The CPU trace array - it consists of thousands of trace entries
52 * plus some other descriptor data: (for example which task started
53 * the trace, etc.)
54 */
55struct trace_array_cpu {
4c11d7ae 56 struct list_head trace_pages;
bc0c38d1 57 atomic_t disabled;
4e3c3333
IM
58 cycle_t time_offset;
59
c7aafc54 60 /* these fields get copied into max-trace: */
93a588f4
SR
61 unsigned trace_head_idx;
62 unsigned trace_tail_idx;
63 void *trace_head; /* producer */
64 void *trace_tail; /* consumer */
c7aafc54 65 unsigned long trace_idx;
bc0c38d1
SR
66 unsigned long saved_latency;
67 unsigned long critical_start;
68 unsigned long critical_end;
69 unsigned long critical_sequence;
70 unsigned long nice;
71 unsigned long policy;
72 unsigned long rt_priority;
73 cycle_t preempt_timestamp;
74 pid_t pid;
75 uid_t uid;
76 char comm[TASK_COMM_LEN];
77};
78
79struct trace_iterator;
80
81/*
82 * The trace array - an array of per-CPU trace arrays. This is the
83 * highest level data structure that individual tracers deal with.
84 * They have on/off state as well:
85 */
86struct trace_array {
87 unsigned long entries;
88 long ctrl;
89 int cpu;
90 cycle_t time_start;
91 struct trace_array_cpu *data[NR_CPUS];
92};
93
94/*
95 * A specific tracer, represented by methods that operate on a trace array:
96 */
97struct tracer {
98 const char *name;
99 void (*init)(struct trace_array *tr);
100 void (*reset)(struct trace_array *tr);
101 void (*open)(struct trace_iterator *iter);
102 void (*close)(struct trace_iterator *iter);
103 void (*start)(struct trace_iterator *iter);
104 void (*stop)(struct trace_iterator *iter);
105 void (*ctrl_update)(struct trace_array *tr);
60a11774
SR
106#ifdef CONFIG_FTRACE_STARTUP_TEST
107 int (*selftest)(struct tracer *trace,
108 struct trace_array *tr);
109#endif
bc0c38d1
SR
110 struct tracer *next;
111 int print_max;
112};
113
214023c3
SR
114struct trace_seq {
115 unsigned char buffer[PAGE_SIZE];
116 unsigned int len;
117};
118
bc0c38d1
SR
119/*
120 * Trace iterator - used by printout routines who present trace
121 * results to users and which routines might sleep, etc:
122 */
123struct trace_iterator {
214023c3 124 struct trace_seq seq;
bc0c38d1
SR
125 struct trace_array *tr;
126 struct tracer *trace;
4e3c3333 127
bc0c38d1 128 struct trace_entry *ent;
4e3c3333
IM
129 int cpu;
130
131 struct trace_entry *prev_ent;
132 int prev_cpu;
133
bc0c38d1
SR
134 unsigned long iter_flags;
135 loff_t pos;
136 unsigned long next_idx[NR_CPUS];
4c11d7ae
SR
137 struct list_head *next_page[NR_CPUS];
138 unsigned next_page_idx[NR_CPUS];
139 long idx;
bc0c38d1
SR
140};
141
142void notrace tracing_reset(struct trace_array_cpu *data);
143int tracing_open_generic(struct inode *inode, struct file *filp);
144struct dentry *tracing_init_dentry(void);
145void ftrace(struct trace_array *tr,
146 struct trace_array_cpu *data,
147 unsigned long ip,
148 unsigned long parent_ip,
149 unsigned long flags);
150void tracing_sched_switch_trace(struct trace_array *tr,
151 struct trace_array_cpu *data,
152 struct task_struct *prev,
153 struct task_struct *next,
154 unsigned long flags);
155void tracing_record_cmdline(struct task_struct *tsk);
156
157void tracing_start_function_trace(void);
158void tracing_stop_function_trace(void);
159int register_tracer(struct tracer *type);
160void unregister_tracer(struct tracer *type);
161
162extern unsigned long nsecs_to_usecs(unsigned long nsecs);
163
164extern unsigned long tracing_max_latency;
165extern unsigned long tracing_thresh;
166
167void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu);
168void update_max_tr_single(struct trace_array *tr,
169 struct task_struct *tsk, int cpu);
170
171static inline notrace cycle_t now(int cpu)
172{
173 return cpu_clock(cpu);
174}
175
176#ifdef CONFIG_SCHED_TRACER
177extern void notrace
178wakeup_sched_switch(struct task_struct *prev, struct task_struct *next);
179#else
180static inline void
181wakeup_sched_switch(struct task_struct *prev, struct task_struct *next)
182{
183}
184#endif
185
186#ifdef CONFIG_CONTEXT_SWITCH_TRACER
187typedef void
188(*tracer_switch_func_t)(void *private,
189 struct task_struct *prev,
190 struct task_struct *next);
191
192struct tracer_switch_ops {
193 tracer_switch_func_t func;
194 void *private;
195 struct tracer_switch_ops *next;
196};
197
198extern int register_tracer_switch(struct tracer_switch_ops *ops);
199extern int unregister_tracer_switch(struct tracer_switch_ops *ops);
200
201#endif /* CONFIG_CONTEXT_SWITCH_TRACER */
202
203#ifdef CONFIG_DYNAMIC_FTRACE
204extern unsigned long ftrace_update_tot_cnt;
205#endif
206
60a11774
SR
207#ifdef CONFIG_FTRACE_STARTUP_TEST
208#ifdef CONFIG_FTRACE
209extern int trace_selftest_startup_function(struct tracer *trace,
210 struct trace_array *tr);
211#endif
212#ifdef CONFIG_IRQSOFF_TRACER
213extern int trace_selftest_startup_irqsoff(struct tracer *trace,
214 struct trace_array *tr);
215#endif
216#ifdef CONFIG_PREEMPT_TRACER
217extern int trace_selftest_startup_preemptoff(struct tracer *trace,
218 struct trace_array *tr);
219#endif
220#if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER)
221extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
222 struct trace_array *tr);
223#endif
224#ifdef CONFIG_SCHED_TRACER
225extern int trace_selftest_startup_wakeup(struct tracer *trace,
226 struct trace_array *tr);
227#endif
228#ifdef CONFIG_CONTEXT_SWITCH_TRACER
229extern int trace_selftest_startup_sched_switch(struct tracer *trace,
230 struct trace_array *tr);
231#endif
232#endif /* CONFIG_FTRACE_STARTUP_TEST */
233
c7aafc54
IM
234extern void *head_page(struct trace_array_cpu *data);
235
bc0c38d1 236#endif /* _LINUX_KERNEL_TRACE_H */