aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/ring_buffer.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/ring_buffer.h')
-rw-r--r--include/linux/ring_buffer.h70
1 files changed, 62 insertions, 8 deletions
diff --git a/include/linux/ring_buffer.h b/include/linux/ring_buffer.h
index e1b7b2173885..29f8599e6bea 100644
--- a/include/linux/ring_buffer.h
+++ b/include/linux/ring_buffer.h
@@ -1,6 +1,7 @@
1#ifndef _LINUX_RING_BUFFER_H 1#ifndef _LINUX_RING_BUFFER_H
2#define _LINUX_RING_BUFFER_H 2#define _LINUX_RING_BUFFER_H
3 3
4#include <linux/kmemcheck.h>
4#include <linux/mm.h> 5#include <linux/mm.h>
5#include <linux/seq_file.h> 6#include <linux/seq_file.h>
6 7
@@ -11,7 +12,10 @@ struct ring_buffer_iter;
11 * Don't refer to this struct directly, use functions below. 12 * Don't refer to this struct directly, use functions below.
12 */ 13 */
13struct ring_buffer_event { 14struct ring_buffer_event {
14 u32 type:2, len:3, time_delta:27; 15 kmemcheck_bitfield_begin(bitfield);
16 u32 type_len:5, time_delta:27;
17 kmemcheck_bitfield_end(bitfield);
18
15 u32 array[]; 19 u32 array[];
16}; 20};
17 21
@@ -24,7 +28,8 @@ struct ring_buffer_event {
24 * size is variable depending on how much 28 * size is variable depending on how much
25 * padding is needed 29 * padding is needed
26 * If time_delta is non zero: 30 * If time_delta is non zero:
27 * everything else same as RINGBUF_TYPE_DATA 31 * array[0] holds the actual length
32 * size = 4 + length (bytes)
28 * 33 *
29 * @RINGBUF_TYPE_TIME_EXTEND: Extend the time delta 34 * @RINGBUF_TYPE_TIME_EXTEND: Extend the time delta
30 * array[0] = time delta (28 .. 59) 35 * array[0] = time delta (28 .. 59)
@@ -35,22 +40,23 @@ struct ring_buffer_event {
35 * array[1..2] = tv_sec 40 * array[1..2] = tv_sec
36 * size = 16 bytes 41 * size = 16 bytes
37 * 42 *
38 * @RINGBUF_TYPE_DATA: Data record 43 * <= @RINGBUF_TYPE_DATA_TYPE_LEN_MAX:
39 * If len is zero: 44 * Data record
45 * If type_len is zero:
40 * array[0] holds the actual length 46 * array[0] holds the actual length
41 * array[1..(length+3)/4] holds data 47 * array[1..(length+3)/4] holds data
42 * size = 4 + 4 + length (bytes) 48 * size = 4 + length (bytes)
43 * else 49 * else
44 * length = len << 2 50 * length = type_len << 2
45 * array[0..(length+3)/4-1] holds data 51 * array[0..(length+3)/4-1] holds data
46 * size = 4 + length (bytes) 52 * size = 4 + length (bytes)
47 */ 53 */
48enum ring_buffer_type { 54enum ring_buffer_type {
55 RINGBUF_TYPE_DATA_TYPE_LEN_MAX = 28,
49 RINGBUF_TYPE_PADDING, 56 RINGBUF_TYPE_PADDING,
50 RINGBUF_TYPE_TIME_EXTEND, 57 RINGBUF_TYPE_TIME_EXTEND,
51 /* FIXME: RINGBUF_TYPE_TIME_STAMP not implemented */ 58 /* FIXME: RINGBUF_TYPE_TIME_STAMP not implemented */
52 RINGBUF_TYPE_TIME_STAMP, 59 RINGBUF_TYPE_TIME_STAMP,
53 RINGBUF_TYPE_DATA,
54}; 60};
55 61
56unsigned ring_buffer_event_length(struct ring_buffer_event *event); 62unsigned ring_buffer_event_length(struct ring_buffer_event *event);
@@ -68,13 +74,54 @@ ring_buffer_event_time_delta(struct ring_buffer_event *event)
68 return event->time_delta; 74 return event->time_delta;
69} 75}
70 76
77/*
78 * ring_buffer_event_discard can discard any event in the ring buffer.
79 * it is up to the caller to protect against a reader from
80 * consuming it or a writer from wrapping and replacing it.
81 *
82 * No external protection is needed if this is called before
83 * the event is commited. But in that case it would be better to
84 * use ring_buffer_discard_commit.
85 *
86 * Note, if an event that has not been committed is discarded
87 * with ring_buffer_event_discard, it must still be committed.
88 */
71void ring_buffer_event_discard(struct ring_buffer_event *event); 89void ring_buffer_event_discard(struct ring_buffer_event *event);
72 90
73/* 91/*
92 * ring_buffer_discard_commit will remove an event that has not
93 * ben committed yet. If this is used, then ring_buffer_unlock_commit
94 * must not be called on the discarded event. This function
95 * will try to remove the event from the ring buffer completely
96 * if another event has not been written after it.
97 *
98 * Example use:
99 *
100 * if (some_condition)
101 * ring_buffer_discard_commit(buffer, event);
102 * else
103 * ring_buffer_unlock_commit(buffer, event);
104 */
105void ring_buffer_discard_commit(struct ring_buffer *buffer,
106 struct ring_buffer_event *event);
107
108/*
74 * size is in bytes for each per CPU buffer. 109 * size is in bytes for each per CPU buffer.
75 */ 110 */
76struct ring_buffer * 111struct ring_buffer *
77ring_buffer_alloc(unsigned long size, unsigned flags); 112__ring_buffer_alloc(unsigned long size, unsigned flags, struct lock_class_key *key);
113
114/*
115 * Because the ring buffer is generic, if other users of the ring buffer get
116 * traced by ftrace, it can produce lockdep warnings. We need to keep each
117 * ring buffer's lock class separate.
118 */
119#define ring_buffer_alloc(size, flags) \
120({ \
121 static struct lock_class_key __key; \
122 __ring_buffer_alloc((size), (flags), &__key); \
123})
124
78void ring_buffer_free(struct ring_buffer *buffer); 125void ring_buffer_free(struct ring_buffer *buffer);
79 126
80int ring_buffer_resize(struct ring_buffer *buffer, unsigned long size); 127int ring_buffer_resize(struct ring_buffer *buffer, unsigned long size);
@@ -122,6 +169,8 @@ unsigned long ring_buffer_entries(struct ring_buffer *buffer);
122unsigned long ring_buffer_overruns(struct ring_buffer *buffer); 169unsigned long ring_buffer_overruns(struct ring_buffer *buffer);
123unsigned long ring_buffer_entries_cpu(struct ring_buffer *buffer, int cpu); 170unsigned long ring_buffer_entries_cpu(struct ring_buffer *buffer, int cpu);
124unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu); 171unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu);
172unsigned long ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu);
173unsigned long ring_buffer_nmi_dropped_cpu(struct ring_buffer *buffer, int cpu);
125 174
126u64 ring_buffer_time_stamp(struct ring_buffer *buffer, int cpu); 175u64 ring_buffer_time_stamp(struct ring_buffer *buffer, int cpu);
127void ring_buffer_normalize_time_stamp(struct ring_buffer *buffer, 176void ring_buffer_normalize_time_stamp(struct ring_buffer *buffer,
@@ -137,6 +186,11 @@ void ring_buffer_free_read_page(struct ring_buffer *buffer, void *data);
137int ring_buffer_read_page(struct ring_buffer *buffer, void **data_page, 186int ring_buffer_read_page(struct ring_buffer *buffer, void **data_page,
138 size_t len, int cpu, int full); 187 size_t len, int cpu, int full);
139 188
189struct trace_seq;
190
191int ring_buffer_print_entry_header(struct trace_seq *s);
192int ring_buffer_print_page_header(struct trace_seq *s);
193
140enum ring_buffer_flags { 194enum ring_buffer_flags {
141 RB_FL_OVERWRITE = 1 << 0, 195 RB_FL_OVERWRITE = 1 << 0,
142}; 196};