1 #ifndef _LINUX_RING_BUFFER_H
2 #define _LINUX_RING_BUFFER_H
5 #include <linux/seq_file.h>
8 struct ring_buffer_iter;
11 * Don't refer to this struct directly, use functions below.
13 struct ring_buffer_event {
14 u32 type:2, len:3, time_delta:27;
19 * enum ring_buffer_type - internal ring buffer types
21 * @RINGBUF_TYPE_PADDING: Left over page padding or discarded event
24 * size is variable depending on how much
26 * If time_delta is non zero:
27 * everything else same as RINGBUF_TYPE_DATA
29 * @RINGBUF_TYPE_TIME_EXTEND: Extend the time delta
30 * array[0] = time delta (28 .. 59)
33 * @RINGBUF_TYPE_TIME_STAMP: Sync time stamp with external clock
35 * array[1..2] = tv_sec
38 * @RINGBUF_TYPE_DATA: Data record
40 * array[0] holds the actual length
41 * array[1..(length+3)/4] holds data
42 * size = 4 + 4 + length (bytes)
45 * array[0..(length+3)/4-1] holds data
46 * size = 4 + length (bytes)
48 enum ring_buffer_type {
50 RINGBUF_TYPE_TIME_EXTEND,
51 /* FIXME: RINGBUF_TYPE_TIME_STAMP not implemented */
52 RINGBUF_TYPE_TIME_STAMP,
56 unsigned ring_buffer_event_length(struct ring_buffer_event *event);
57 void *ring_buffer_event_data(struct ring_buffer_event *event);
60 * ring_buffer_event_time_delta - return the delta timestamp of the event
61 * @event: the event to get the delta timestamp of
63 * The delta timestamp is the 27 bit timestamp since the last event.
65 static inline unsigned
66 ring_buffer_event_time_delta(struct ring_buffer_event *event)
68 return event->time_delta;
72 * ring_buffer_event_discard can discard any event in the ring buffer.
73 * it is up to the caller to protect against a reader from
74 * consuming it or a writer from wrapping and replacing it.
76 * No external protection is needed if this is called before
77 * the event is commited. But in that case it would be better to
78 * use ring_buffer_discard_commit.
80 * Note, if an event that has not been committed is discarded
81 * with ring_buffer_event_discard, it must still be committed.
83 void ring_buffer_event_discard(struct ring_buffer_event *event);
86 * ring_buffer_discard_commit will remove an event that has not
87 * ben committed yet. If this is used, then ring_buffer_unlock_commit
88 * must not be called on the discarded event. This function
89 * will try to remove the event from the ring buffer completely
90 * if another event has not been written after it.
95 * ring_buffer_discard_commit(buffer, event);
97 * ring_buffer_unlock_commit(buffer, event);
99 void ring_buffer_discard_commit(struct ring_buffer *buffer,
100 struct ring_buffer_event *event);
103 * size is in bytes for each per CPU buffer.
106 ring_buffer_alloc(unsigned long size, unsigned flags);
107 void ring_buffer_free(struct ring_buffer *buffer);
109 int ring_buffer_resize(struct ring_buffer *buffer, unsigned long size);
111 struct ring_buffer_event *ring_buffer_lock_reserve(struct ring_buffer *buffer,
112 unsigned long length);
113 int ring_buffer_unlock_commit(struct ring_buffer *buffer,
114 struct ring_buffer_event *event);
115 int ring_buffer_write(struct ring_buffer *buffer,
116 unsigned long length, void *data);
118 struct ring_buffer_event *
119 ring_buffer_peek(struct ring_buffer *buffer, int cpu, u64 *ts);
120 struct ring_buffer_event *
121 ring_buffer_consume(struct ring_buffer *buffer, int cpu, u64 *ts);
123 struct ring_buffer_iter *
124 ring_buffer_read_start(struct ring_buffer *buffer, int cpu);
125 void ring_buffer_read_finish(struct ring_buffer_iter *iter);
127 struct ring_buffer_event *
128 ring_buffer_iter_peek(struct ring_buffer_iter *iter, u64 *ts);
129 struct ring_buffer_event *
130 ring_buffer_read(struct ring_buffer_iter *iter, u64 *ts);
131 void ring_buffer_iter_reset(struct ring_buffer_iter *iter);
132 int ring_buffer_iter_empty(struct ring_buffer_iter *iter);
134 unsigned long ring_buffer_size(struct ring_buffer *buffer);
136 void ring_buffer_reset_cpu(struct ring_buffer *buffer, int cpu);
137 void ring_buffer_reset(struct ring_buffer *buffer);
139 int ring_buffer_swap_cpu(struct ring_buffer *buffer_a,
140 struct ring_buffer *buffer_b, int cpu);
142 int ring_buffer_empty(struct ring_buffer *buffer);
143 int ring_buffer_empty_cpu(struct ring_buffer *buffer, int cpu);
145 void ring_buffer_record_disable(struct ring_buffer *buffer);
146 void ring_buffer_record_enable(struct ring_buffer *buffer);
147 void ring_buffer_record_disable_cpu(struct ring_buffer *buffer, int cpu);
148 void ring_buffer_record_enable_cpu(struct ring_buffer *buffer, int cpu);
150 unsigned long ring_buffer_entries(struct ring_buffer *buffer);
151 unsigned long ring_buffer_overruns(struct ring_buffer *buffer);
152 unsigned long ring_buffer_entries_cpu(struct ring_buffer *buffer, int cpu);
153 unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu);
155 u64 ring_buffer_time_stamp(struct ring_buffer *buffer, int cpu);
156 void ring_buffer_normalize_time_stamp(struct ring_buffer *buffer,
158 void ring_buffer_set_clock(struct ring_buffer *buffer,
161 size_t ring_buffer_page_len(void *page);
164 void *ring_buffer_alloc_read_page(struct ring_buffer *buffer);
165 void ring_buffer_free_read_page(struct ring_buffer *buffer, void *data);
166 int ring_buffer_read_page(struct ring_buffer *buffer, void **data_page,
167 size_t len, int cpu, int full);
169 enum ring_buffer_flags {
170 RB_FL_OVERWRITE = 1 << 0,
173 #endif /* _LINUX_RING_BUFFER_H */