Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /** |
2 | * @file cpu_buffer.h | |
3 | * | |
2cc28b9f | 4 | * @remark Copyright 2002-2009 OProfile authors |
1da177e4 LT |
5 | * @remark Read the file COPYING |
6 | * | |
7 | * @author John Levon <levon@movementarian.org> | |
2cc28b9f | 8 | * @author Robert Richter <robert.richter@amd.com> |
1da177e4 LT |
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> | |
608dfddd | 18 | #include <linux/sched.h> |
6dad828b | 19 | #include <linux/ring_buffer.h> |
6a18037d | 20 | |
1da177e4 | 21 | struct task_struct; |
6a18037d | 22 | |
1da177e4 LT |
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; | |
2cc28b9f | 35 | unsigned long data[0]; |
1da177e4 | 36 | }; |
6a18037d | 37 | |
6dad828b RR |
38 | struct op_entry { |
39 | struct ring_buffer_event *event; | |
40 | struct op_sample *sample; | |
41 | unsigned long irq_flags; | |
2cc28b9f RR |
42 | unsigned long size; |
43 | unsigned long *data; | |
6dad828b RR |
44 | }; |
45 | ||
1da177e4 | 46 | struct oprofile_cpu_buffer { |
1da177e4 | 47 | unsigned long buffer_size; |
25ad2913 | 48 | struct task_struct *last_task; |
1da177e4 LT |
49 | int last_is_kernel; |
50 | int tracing; | |
1da177e4 LT |
51 | unsigned long sample_received; |
52 | unsigned long sample_lost_overflow; | |
53 | unsigned long backtrace_aborted; | |
df9d177a | 54 | unsigned long sample_invalid_eip; |
1da177e4 | 55 | int cpu; |
c4028958 | 56 | struct delayed_work work; |
8b8b4988 | 57 | }; |
1da177e4 | 58 | |
608dfddd | 59 | DECLARE_PER_CPU(struct oprofile_cpu_buffer, cpu_buffer); |
1da177e4 | 60 | |
fbc9bf9f RR |
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 | */ | |
6d2c53f3 | 67 | static inline void op_cpu_buffer_reset(int cpu) |
fbc9bf9f RR |
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 | } | |
1da177e4 | 74 | |
2cc28b9f RR |
75 | struct op_sample |
76 | *op_cpu_buffer_write_reserve(struct op_entry *entry, unsigned long size); | |
9966718d | 77 | int op_cpu_buffer_write_commit(struct op_entry *entry); |
2d87b14c | 78 | struct op_sample *op_cpu_buffer_read_entry(struct op_entry *entry, int cpu); |
9966718d | 79 | unsigned long op_cpu_buffer_entries(int cpu); |
bf589e32 | 80 | |
d9928c25 RR |
81 | /* returns the remaining free size of data in the entry */ |
82 | static inline | |
83 | int op_cpu_buffer_add_data(struct op_entry *entry, unsigned long val) | |
84 | { | |
85 | if (!entry->size) | |
86 | return 0; | |
87 | *entry->data = val; | |
88 | entry->size--; | |
89 | entry->data++; | |
90 | return entry->size; | |
91 | } | |
92 | ||
bd7dc46f RR |
93 | /* returns the size of data in the entry */ |
94 | static inline | |
95 | int op_cpu_buffer_get_size(struct op_entry *entry) | |
96 | { | |
97 | return entry->size; | |
98 | } | |
99 | ||
100 | /* returns 0 if empty or the size of data including the current value */ | |
101 | static inline | |
102 | int op_cpu_buffer_get_data(struct op_entry *entry, unsigned long *val) | |
103 | { | |
104 | int size = entry->size; | |
105 | if (!size) | |
106 | return 0; | |
107 | *val = *entry->data; | |
108 | entry->size--; | |
109 | entry->data++; | |
110 | return size; | |
111 | } | |
112 | ||
ae735e99 RR |
113 | /* extra data flags */ |
114 | #define KERNEL_CTX_SWITCH (1UL << 0) | |
115 | #define IS_KERNEL (1UL << 1) | |
116 | #define TRACE_BEGIN (1UL << 2) | |
117 | #define USER_CTX_SWITCH (1UL << 3) | |
1da177e4 LT |
118 | |
119 | #endif /* OPROFILE_CPU_BUFFER_H */ |