aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/linux/ring_buffer.h130
1 files changed, 130 insertions, 0 deletions
diff --git a/include/linux/ring_buffer.h b/include/linux/ring_buffer.h
new file mode 100644
index 000000000000..c52375b8330d
--- /dev/null
+++ b/include/linux/ring_buffer.h
@@ -0,0 +1,130 @@
1#ifndef _LINUX_RING_BUFFER_H
2#define _LINUX_RING_BUFFER_H
3
4#include <linux/mm.h>
5#include <linux/seq_file.h>
6
7struct ring_buffer;
8struct ring_buffer_iter;
9
10/*
11 * Don't reference this struct directly, use functions below.
12 */
13struct ring_buffer_event {
14 u32 type:2, len:3, time_delta:27;
15 u32 array[];
16};
17
18/**
19 * enum ring_buffer_type - internal ring buffer types
20 *
21 * @RINGBUF_TYPE_PADDING: Left over page padding
22 * array is ignored
23 * size is variable depending on how much
24 * padding is needed
25 *
26 * @RINGBUF_TYPE_TIME_EXTEND: Extend the time delta
27 * array[0] = time delta (28 .. 59)
28 * size = 8 bytes
29 *
30 * @RINGBUF_TYPE_TIME_STAMP: Sync time stamp with external clock
31 * array[0] = tv_nsec
32 * array[1] = tv_sec
33 * size = 16 bytes
34 *
35 * @RINGBUF_TYPE_DATA: Data record
36 * If len is zero:
37 * array[0] holds the actual length
38 * array[1..(length+3)/4-1] holds data
39 * else
40 * length = len << 2
41 * array[0..(length+3)/4] holds data
42 */
43enum ring_buffer_type {
44 RINGBUF_TYPE_PADDING,
45 RINGBUF_TYPE_TIME_EXTEND,
46 /* FIXME: RINGBUF_TYPE_TIME_STAMP not implemented */
47 RINGBUF_TYPE_TIME_STAMP,
48 RINGBUF_TYPE_DATA,
49};
50
51unsigned ring_buffer_event_length(struct ring_buffer_event *event);
52void *ring_buffer_event_data(struct ring_buffer_event *event);
53
54/**
55 * ring_buffer_event_time_delta - return the delta timestamp of the event
56 * @event: the event to get the delta timestamp of
57 *
58 * The delta timestamp is the 27 bit timestamp since the last event.
59 */
60static inline unsigned
61ring_buffer_event_time_delta(struct ring_buffer_event *event)
62{
63 return event->time_delta;
64}
65
66void ring_buffer_lock(struct ring_buffer *buffer, unsigned long *flags);
67void ring_buffer_unlock(struct ring_buffer *buffer, unsigned long flags);
68
69/*
70 * size is in bytes for each per CPU buffer.
71 */
72struct ring_buffer *
73ring_buffer_alloc(unsigned long size, unsigned flags);
74void ring_buffer_free(struct ring_buffer *buffer);
75
76int ring_buffer_resize(struct ring_buffer *buffer, unsigned long size);
77
78struct ring_buffer_event *
79ring_buffer_lock_reserve(struct ring_buffer *buffer,
80 unsigned long length,
81 unsigned long *flags);
82int ring_buffer_unlock_commit(struct ring_buffer *buffer,
83 struct ring_buffer_event *event,
84 unsigned long flags);
85int ring_buffer_write(struct ring_buffer *buffer,
86 unsigned long length, void *data);
87
88struct ring_buffer_event *
89ring_buffer_peek(struct ring_buffer *buffer, int cpu, u64 *ts);
90struct ring_buffer_event *
91ring_buffer_consume(struct ring_buffer *buffer, int cpu, u64 *ts);
92
93struct ring_buffer_iter *
94ring_buffer_read_start(struct ring_buffer *buffer, int cpu);
95void ring_buffer_read_finish(struct ring_buffer_iter *iter);
96
97struct ring_buffer_event *
98ring_buffer_iter_peek(struct ring_buffer_iter *iter, u64 *ts);
99struct ring_buffer_event *
100ring_buffer_read(struct ring_buffer_iter *iter, u64 *ts);
101void ring_buffer_iter_reset(struct ring_buffer_iter *iter);
102int ring_buffer_iter_empty(struct ring_buffer_iter *iter);
103
104unsigned long ring_buffer_size(struct ring_buffer *buffer);
105
106void ring_buffer_reset_cpu(struct ring_buffer *buffer, int cpu);
107void ring_buffer_reset(struct ring_buffer *buffer);
108
109int ring_buffer_swap_cpu(struct ring_buffer *buffer_a,
110 struct ring_buffer *buffer_b, int cpu);
111
112int ring_buffer_empty(struct ring_buffer *buffer);
113int ring_buffer_empty_cpu(struct ring_buffer *buffer, int cpu);
114
115void ring_buffer_record_disable(struct ring_buffer *buffer);
116void ring_buffer_record_enable(struct ring_buffer *buffer);
117void ring_buffer_record_disable_cpu(struct ring_buffer *buffer, int cpu);
118void ring_buffer_record_enable_cpu(struct ring_buffer *buffer, int cpu);
119
120unsigned long ring_buffer_entries(struct ring_buffer *buffer);
121unsigned long ring_buffer_overruns(struct ring_buffer *buffer);
122
123u64 ring_buffer_time_stamp(int cpu);
124void ring_buffer_normalize_time_stamp(int cpu, u64 *ts);
125
126enum ring_buffer_flags {
127 RB_FL_OVERWRITE = 1 << 0,
128};
129
130#endif /* _LINUX_RING_BUFFER_H */