Commit | Line | Data |
---|---|---|
7a8e76a3 SR |
1 | #ifndef _LINUX_RING_BUFFER_H |
2 | #define _LINUX_RING_BUFFER_H | |
3 | ||
1744a21d | 4 | #include <linux/kmemcheck.h> |
7a8e76a3 SR |
5 | #include <linux/mm.h> |
6 | #include <linux/seq_file.h> | |
7 | ||
8 | struct ring_buffer; | |
9 | struct ring_buffer_iter; | |
10 | ||
11 | /* | |
c3706f00 | 12 | * Don't refer to this struct directly, use functions below. |
7a8e76a3 SR |
13 | */ |
14 | struct ring_buffer_event { | |
1744a21d | 15 | kmemcheck_bitfield_begin(bitfield); |
334d4169 | 16 | u32 type_len:5, time_delta:27; |
1744a21d VN |
17 | kmemcheck_bitfield_end(bitfield); |
18 | ||
7a8e76a3 SR |
19 | u32 array[]; |
20 | }; | |
21 | ||
22 | /** | |
23 | * enum ring_buffer_type - internal ring buffer types | |
24 | * | |
2d622719 TZ |
25 | * @RINGBUF_TYPE_PADDING: Left over page padding or discarded event |
26 | * If time_delta is 0: | |
27 | * array is ignored | |
28 | * size is variable depending on how much | |
7a8e76a3 | 29 | * padding is needed |
2d622719 | 30 | * If time_delta is non zero: |
334d4169 LJ |
31 | * array[0] holds the actual length |
32 | * size = 4 + length (bytes) | |
7a8e76a3 SR |
33 | * |
34 | * @RINGBUF_TYPE_TIME_EXTEND: Extend the time delta | |
35 | * array[0] = time delta (28 .. 59) | |
36 | * size = 8 bytes | |
37 | * | |
38 | * @RINGBUF_TYPE_TIME_STAMP: Sync time stamp with external clock | |
361b73d5 LJ |
39 | * array[0] = tv_nsec |
40 | * array[1..2] = tv_sec | |
7a8e76a3 SR |
41 | * size = 16 bytes |
42 | * | |
334d4169 LJ |
43 | * <= @RINGBUF_TYPE_DATA_TYPE_LEN_MAX: |
44 | * Data record | |
45 | * If type_len is zero: | |
7a8e76a3 | 46 | * array[0] holds the actual length |
361b73d5 | 47 | * array[1..(length+3)/4] holds data |
334d4169 | 48 | * size = 4 + length (bytes) |
7a8e76a3 | 49 | * else |
334d4169 | 50 | * length = type_len << 2 |
361b73d5 LJ |
51 | * array[0..(length+3)/4-1] holds data |
52 | * size = 4 + length (bytes) | |
7a8e76a3 SR |
53 | */ |
54 | enum ring_buffer_type { | |
334d4169 | 55 | RINGBUF_TYPE_DATA_TYPE_LEN_MAX = 28, |
7a8e76a3 SR |
56 | RINGBUF_TYPE_PADDING, |
57 | RINGBUF_TYPE_TIME_EXTEND, | |
58 | /* FIXME: RINGBUF_TYPE_TIME_STAMP not implemented */ | |
59 | RINGBUF_TYPE_TIME_STAMP, | |
7a8e76a3 SR |
60 | }; |
61 | ||
62 | unsigned ring_buffer_event_length(struct ring_buffer_event *event); | |
63 | void *ring_buffer_event_data(struct ring_buffer_event *event); | |
64 | ||
65 | /** | |
66 | * ring_buffer_event_time_delta - return the delta timestamp of the event | |
67 | * @event: the event to get the delta timestamp of | |
68 | * | |
69 | * The delta timestamp is the 27 bit timestamp since the last event. | |
70 | */ | |
71 | static inline unsigned | |
72 | ring_buffer_event_time_delta(struct ring_buffer_event *event) | |
73 | { | |
74 | return event->time_delta; | |
75 | } | |
76 | ||
fa1b47dd SR |
77 | /* |
78 | * ring_buffer_discard_commit will remove an event that has not | |
79 | * ben committed yet. If this is used, then ring_buffer_unlock_commit | |
80 | * must not be called on the discarded event. This function | |
81 | * will try to remove the event from the ring buffer completely | |
82 | * if another event has not been written after it. | |
83 | * | |
84 | * Example use: | |
85 | * | |
86 | * if (some_condition) | |
87 | * ring_buffer_discard_commit(buffer, event); | |
88 | * else | |
89 | * ring_buffer_unlock_commit(buffer, event); | |
90 | */ | |
91 | void ring_buffer_discard_commit(struct ring_buffer *buffer, | |
92 | struct ring_buffer_event *event); | |
93 | ||
7a8e76a3 SR |
94 | /* |
95 | * size is in bytes for each per CPU buffer. | |
96 | */ | |
97 | struct ring_buffer * | |
1f8a6a10 PZ |
98 | __ring_buffer_alloc(unsigned long size, unsigned flags, struct lock_class_key *key); |
99 | ||
100 | /* | |
101 | * Because the ring buffer is generic, if other users of the ring buffer get | |
102 | * traced by ftrace, it can produce lockdep warnings. We need to keep each | |
103 | * ring buffer's lock class separate. | |
104 | */ | |
105 | #define ring_buffer_alloc(size, flags) \ | |
106 | ({ \ | |
107 | static struct lock_class_key __key; \ | |
108 | __ring_buffer_alloc((size), (flags), &__key); \ | |
109 | }) | |
110 | ||
7a8e76a3 SR |
111 | void ring_buffer_free(struct ring_buffer *buffer); |
112 | ||
113 | int ring_buffer_resize(struct ring_buffer *buffer, unsigned long size); | |
114 | ||
0a987751 ACM |
115 | struct ring_buffer_event *ring_buffer_lock_reserve(struct ring_buffer *buffer, |
116 | unsigned long length); | |
7a8e76a3 | 117 | int ring_buffer_unlock_commit(struct ring_buffer *buffer, |
0a987751 | 118 | struct ring_buffer_event *event); |
7a8e76a3 SR |
119 | int ring_buffer_write(struct ring_buffer *buffer, |
120 | unsigned long length, void *data); | |
121 | ||
122 | struct ring_buffer_event * | |
123 | ring_buffer_peek(struct ring_buffer *buffer, int cpu, u64 *ts); | |
124 | struct ring_buffer_event * | |
125 | ring_buffer_consume(struct ring_buffer *buffer, int cpu, u64 *ts); | |
126 | ||
127 | struct ring_buffer_iter * | |
128 | ring_buffer_read_start(struct ring_buffer *buffer, int cpu); | |
129 | void ring_buffer_read_finish(struct ring_buffer_iter *iter); | |
130 | ||
131 | struct ring_buffer_event * | |
132 | ring_buffer_iter_peek(struct ring_buffer_iter *iter, u64 *ts); | |
133 | struct ring_buffer_event * | |
134 | ring_buffer_read(struct ring_buffer_iter *iter, u64 *ts); | |
135 | void ring_buffer_iter_reset(struct ring_buffer_iter *iter); | |
136 | int ring_buffer_iter_empty(struct ring_buffer_iter *iter); | |
137 | ||
138 | unsigned long ring_buffer_size(struct ring_buffer *buffer); | |
139 | ||
140 | void ring_buffer_reset_cpu(struct ring_buffer *buffer, int cpu); | |
141 | void ring_buffer_reset(struct ring_buffer *buffer); | |
142 | ||
85bac32c | 143 | #ifdef CONFIG_RING_BUFFER_ALLOW_SWAP |
7a8e76a3 SR |
144 | int ring_buffer_swap_cpu(struct ring_buffer *buffer_a, |
145 | struct ring_buffer *buffer_b, int cpu); | |
85bac32c SR |
146 | #else |
147 | static inline int | |
148 | ring_buffer_swap_cpu(struct ring_buffer *buffer_a, | |
149 | struct ring_buffer *buffer_b, int cpu) | |
150 | { | |
151 | return -ENODEV; | |
152 | } | |
153 | #endif | |
7a8e76a3 SR |
154 | |
155 | int ring_buffer_empty(struct ring_buffer *buffer); | |
156 | int ring_buffer_empty_cpu(struct ring_buffer *buffer, int cpu); | |
157 | ||
158 | void ring_buffer_record_disable(struct ring_buffer *buffer); | |
159 | void ring_buffer_record_enable(struct ring_buffer *buffer); | |
160 | void ring_buffer_record_disable_cpu(struct ring_buffer *buffer, int cpu); | |
161 | void ring_buffer_record_enable_cpu(struct ring_buffer *buffer, int cpu); | |
162 | ||
163 | unsigned long ring_buffer_entries(struct ring_buffer *buffer); | |
164 | unsigned long ring_buffer_overruns(struct ring_buffer *buffer); | |
e09373f2 RR |
165 | unsigned long ring_buffer_entries_cpu(struct ring_buffer *buffer, int cpu); |
166 | unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu); | |
f0d2c681 | 167 | unsigned long ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu); |
7a8e76a3 | 168 | |
37886f6a SR |
169 | u64 ring_buffer_time_stamp(struct ring_buffer *buffer, int cpu); |
170 | void ring_buffer_normalize_time_stamp(struct ring_buffer *buffer, | |
171 | int cpu, u64 *ts); | |
172 | void ring_buffer_set_clock(struct ring_buffer *buffer, | |
173 | u64 (*clock)(void)); | |
7a8e76a3 | 174 | |
ef7a4a16 SR |
175 | size_t ring_buffer_page_len(void *page); |
176 | ||
177 | ||
8789a9e7 SR |
178 | void *ring_buffer_alloc_read_page(struct ring_buffer *buffer); |
179 | void ring_buffer_free_read_page(struct ring_buffer *buffer, void *data); | |
ef7a4a16 SR |
180 | int ring_buffer_read_page(struct ring_buffer *buffer, void **data_page, |
181 | size_t len, int cpu, int full); | |
8789a9e7 | 182 | |
d1b182a8 SR |
183 | struct trace_seq; |
184 | ||
185 | int ring_buffer_print_entry_header(struct trace_seq *s); | |
186 | int ring_buffer_print_page_header(struct trace_seq *s); | |
187 | ||
7a8e76a3 SR |
188 | enum ring_buffer_flags { |
189 | RB_FL_OVERWRITE = 1 << 0, | |
190 | }; | |
191 | ||
192 | #endif /* _LINUX_RING_BUFFER_H */ |