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