1 #ifndef _LINUX_RING_BUFFER_H
2 #define _LINUX_RING_BUFFER_H
4 #include <linux/kmemcheck.h>
6 #include <linux/seq_file.h>
9 struct ring_buffer_iter
;
12 * Don't refer to this struct directly, use functions below.
14 struct ring_buffer_event
{
15 kmemcheck_bitfield_begin(bitfield
);
16 u32 type_len
:5, time_delta
:27;
17 kmemcheck_bitfield_end(bitfield
);
23 * enum ring_buffer_type - internal ring buffer types
25 * @RINGBUF_TYPE_PADDING: Left over page padding or discarded event
28 * size is variable depending on how much
30 * If time_delta is non zero:
31 * array[0] holds the actual length
32 * size = 4 + length (bytes)
34 * @RINGBUF_TYPE_TIME_EXTEND: Extend the time delta
35 * array[0] = time delta (28 .. 59)
38 * @RINGBUF_TYPE_TIME_STAMP: Sync time stamp with external clock
40 * array[1..2] = tv_sec
43 * <= @RINGBUF_TYPE_DATA_TYPE_LEN_MAX:
45 * If type_len is zero:
46 * array[0] holds the actual length
47 * array[1..(length+3)/4] holds data
48 * size = 4 + length (bytes)
50 * length = type_len << 2
51 * array[0..(length+3)/4-1] holds data
52 * size = 4 + length (bytes)
54 enum ring_buffer_type
{
55 RINGBUF_TYPE_DATA_TYPE_LEN_MAX
= 28,
57 RINGBUF_TYPE_TIME_EXTEND
,
58 /* FIXME: RINGBUF_TYPE_TIME_STAMP not implemented */
59 RINGBUF_TYPE_TIME_STAMP
,
62 unsigned ring_buffer_event_length(struct ring_buffer_event
*event
);
63 void *ring_buffer_event_data(struct ring_buffer_event
*event
);
66 * ring_buffer_discard_commit will remove an event that has not
67 * ben committed yet. If this is used, then ring_buffer_unlock_commit
68 * must not be called on the discarded event. This function
69 * will try to remove the event from the ring buffer completely
70 * if another event has not been written after it.
75 * ring_buffer_discard_commit(buffer, event);
77 * ring_buffer_unlock_commit(buffer, event);
79 void ring_buffer_discard_commit(struct ring_buffer
*buffer
,
80 struct ring_buffer_event
*event
);
83 * size is in bytes for each per CPU buffer.
86 __ring_buffer_alloc(unsigned long size
, unsigned flags
, struct lock_class_key
*key
);
89 * Because the ring buffer is generic, if other users of the ring buffer get
90 * traced by ftrace, it can produce lockdep warnings. We need to keep each
91 * ring buffer's lock class separate.
93 #define ring_buffer_alloc(size, flags) \
95 static struct lock_class_key __key; \
96 __ring_buffer_alloc((size), (flags), &__key); \
99 void ring_buffer_free(struct ring_buffer
*buffer
);
101 int ring_buffer_resize(struct ring_buffer
*buffer
, unsigned long size
);
103 struct ring_buffer_event
*ring_buffer_lock_reserve(struct ring_buffer
*buffer
,
104 unsigned long length
);
105 int ring_buffer_unlock_commit(struct ring_buffer
*buffer
,
106 struct ring_buffer_event
*event
);
107 int ring_buffer_write(struct ring_buffer
*buffer
,
108 unsigned long length
, void *data
);
110 struct ring_buffer_event
*
111 ring_buffer_peek(struct ring_buffer
*buffer
, int cpu
, u64
*ts
,
112 unsigned long *lost_events
);
113 struct ring_buffer_event
*
114 ring_buffer_consume(struct ring_buffer
*buffer
, int cpu
, u64
*ts
,
115 unsigned long *lost_events
);
117 struct ring_buffer_iter
*
118 ring_buffer_read_prepare(struct ring_buffer
*buffer
, int cpu
);
119 void ring_buffer_read_prepare_sync(void);
120 void ring_buffer_read_start(struct ring_buffer_iter
*iter
);
121 void ring_buffer_read_finish(struct ring_buffer_iter
*iter
);
123 struct ring_buffer_event
*
124 ring_buffer_iter_peek(struct ring_buffer_iter
*iter
, u64
*ts
);
125 struct ring_buffer_event
*
126 ring_buffer_read(struct ring_buffer_iter
*iter
, u64
*ts
);
127 void ring_buffer_iter_reset(struct ring_buffer_iter
*iter
);
128 int ring_buffer_iter_empty(struct ring_buffer_iter
*iter
);
130 unsigned long ring_buffer_size(struct ring_buffer
*buffer
);
132 void ring_buffer_reset_cpu(struct ring_buffer
*buffer
, int cpu
);
133 void ring_buffer_reset(struct ring_buffer
*buffer
);
135 #ifdef CONFIG_RING_BUFFER_ALLOW_SWAP
136 int ring_buffer_swap_cpu(struct ring_buffer
*buffer_a
,
137 struct ring_buffer
*buffer_b
, int cpu
);
140 ring_buffer_swap_cpu(struct ring_buffer
*buffer_a
,
141 struct ring_buffer
*buffer_b
, int cpu
)
147 int ring_buffer_empty(struct ring_buffer
*buffer
);
148 int ring_buffer_empty_cpu(struct ring_buffer
*buffer
, int cpu
);
150 void ring_buffer_record_disable(struct ring_buffer
*buffer
);
151 void ring_buffer_record_enable(struct ring_buffer
*buffer
);
152 void ring_buffer_record_disable_cpu(struct ring_buffer
*buffer
, int cpu
);
153 void ring_buffer_record_enable_cpu(struct ring_buffer
*buffer
, int cpu
);
155 unsigned long ring_buffer_entries(struct ring_buffer
*buffer
);
156 unsigned long ring_buffer_overruns(struct ring_buffer
*buffer
);
157 unsigned long ring_buffer_entries_cpu(struct ring_buffer
*buffer
, int cpu
);
158 unsigned long ring_buffer_overrun_cpu(struct ring_buffer
*buffer
, int cpu
);
159 unsigned long ring_buffer_commit_overrun_cpu(struct ring_buffer
*buffer
, int cpu
);
161 u64
ring_buffer_time_stamp(struct ring_buffer
*buffer
, int cpu
);
162 void ring_buffer_normalize_time_stamp(struct ring_buffer
*buffer
,
164 void ring_buffer_set_clock(struct ring_buffer
*buffer
,
167 size_t ring_buffer_page_len(void *page
);
170 void *ring_buffer_alloc_read_page(struct ring_buffer
*buffer
);
171 void ring_buffer_free_read_page(struct ring_buffer
*buffer
, void *data
);
172 int ring_buffer_read_page(struct ring_buffer
*buffer
, void **data_page
,
173 size_t len
, int cpu
, int full
);
177 int ring_buffer_print_entry_header(struct trace_seq
*s
);
178 int ring_buffer_print_page_header(struct trace_seq
*s
);
180 enum ring_buffer_flags
{
181 RB_FL_OVERWRITE
= 1 << 0,
184 #endif /* _LINUX_RING_BUFFER_H */