d7c0545ef8b26e4426de9ab2970a6a978a326dd4
[safe/jmp/linux-2.6] / drivers / oprofile / cpu_buffer.h
1 /**
2  * @file cpu_buffer.h
3  *
4  * @remark Copyright 2002-2009 OProfile authors
5  * @remark Read the file COPYING
6  *
7  * @author John Levon <levon@movementarian.org>
8  * @author Robert Richter <robert.richter@amd.com>
9  */
10
11 #ifndef OPROFILE_CPU_BUFFER_H
12 #define OPROFILE_CPU_BUFFER_H
13
14 #include <linux/types.h>
15 #include <linux/spinlock.h>
16 #include <linux/workqueue.h>
17 #include <linux/cache.h>
18 #include <linux/sched.h>
19 #include <linux/ring_buffer.h>
20
21 struct task_struct;
22
23 int alloc_cpu_buffers(void);
24 void free_cpu_buffers(void);
25
26 void start_cpu_work(void);
27 void end_cpu_work(void);
28
29 /* CPU buffer is composed of such entries (which are
30  * also used for context switch notes)
31  */
32 struct op_sample {
33         unsigned long eip;
34         unsigned long event;
35         unsigned long data[0];
36 };
37
38 struct op_entry {
39         struct ring_buffer_event *event;
40         struct op_sample *sample;
41         unsigned long irq_flags;
42         unsigned long size;
43         unsigned long *data;
44 };
45
46 struct oprofile_cpu_buffer {
47         unsigned long buffer_size;
48         struct task_struct *last_task;
49         int last_is_kernel;
50         int tracing;
51         unsigned long sample_received;
52         unsigned long sample_lost_overflow;
53         unsigned long backtrace_aborted;
54         unsigned long sample_invalid_eip;
55         int cpu;
56         struct delayed_work work;
57 };
58
59 DECLARE_PER_CPU(struct oprofile_cpu_buffer, cpu_buffer);
60
61 /*
62  * Resets the cpu buffer to a sane state.
63  *
64  * reset these to invalid values; the next sample collected will
65  * populate the buffer with proper values to initialize the buffer
66  */
67 static inline void op_cpu_buffer_reset(int cpu)
68 {
69         struct oprofile_cpu_buffer *cpu_buf = &per_cpu(cpu_buffer, cpu);
70
71         cpu_buf->last_is_kernel = -1;
72         cpu_buf->last_task = NULL;
73 }
74
75 struct op_sample
76 *op_cpu_buffer_write_reserve(struct op_entry *entry, unsigned long size);
77 int op_cpu_buffer_write_commit(struct op_entry *entry);
78 struct op_sample *op_cpu_buffer_read_entry(struct op_entry *entry, int cpu);
79 unsigned long op_cpu_buffer_entries(int cpu);
80
81 /* transient events for the CPU buffer -> event buffer */
82 #define CPU_IS_KERNEL 1
83 #define CPU_TRACE_BEGIN 2
84 #define IBS_FETCH_BEGIN 3
85 #define IBS_OP_BEGIN    4
86
87 #endif /* OPROFILE_CPU_BUFFER_H */