1 #ifndef _LINUX_RING_BUFFER_FRONTEND_H
2 #define _LINUX_RING_BUFFER_FRONTEND_H
5 * linux/ringbuffer/frontend.h
7 * (C) Copyright 2005-2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * Ring Buffer Library Synchronization Header (API).
12 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
14 * See ring_buffer_frontend.c for more information on wait-free algorithms.
16 * Dual LGPL v2.1/GPL v2 license.
19 /* Internal helpers */
20 #include "frontend_internal.h"
22 /* Buffer creation/removal and setup operations */
25 * switch_timer_interval is the time interval (in us) to fill sub-buffers with
26 * padding to let readers get those sub-buffers. Used for live streaming.
28 * read_timer_interval is the time interval (in us) to wake up pending readers.
30 * buf_addr is a pointer the the beginning of the preallocated buffer contiguous
31 * address mapping. It is used only by RING_BUFFER_STATIC configuration. It can
32 * be set to NULL for other backends.
36 struct channel
*channel_create(const struct lib_ring_buffer_config
*config
,
37 const char *name
, void *priv
,
39 size_t subbuf_size
, size_t num_subbuf
,
40 unsigned int switch_timer_interval
,
41 unsigned int read_timer_interval
);
44 * channel_destroy returns the private data pointer. It finalizes all channel's
45 * buffers, waits for readers to release all references, and destroys the
49 void *channel_destroy(struct channel
*chan
);
52 /* Buffer read operations */
55 * Iteration on channel cpumask needs to issue a read barrier to match the write
56 * barrier in cpu hotplug. It orders the cpumask read before read of per-cpu
57 * buffer data. The per-cpu buffer is never removed by cpu hotplug; teardown is
58 * only performed at channel destruction.
60 #define for_each_channel_cpu(cpu, chan) \
62 ({ (cpu) = cpumask_next(cpu, (chan)->backend.cpumask); \
63 smp_read_barrier_depends(); (cpu) < nr_cpu_ids; });)
65 extern struct lib_ring_buffer
*channel_get_ring_buffer(
66 const struct lib_ring_buffer_config
*config
,
67 struct channel
*chan
, int cpu
);
68 extern int lib_ring_buffer_open_read(struct lib_ring_buffer
*buf
);
69 extern void lib_ring_buffer_release_read(struct lib_ring_buffer
*buf
);
72 * Read sequence: snapshot, many get_subbuf/put_subbuf, move_consumer.
74 extern int lib_ring_buffer_snapshot(struct lib_ring_buffer
*buf
,
75 unsigned long *consumed
,
76 unsigned long *produced
);
77 extern void lib_ring_buffer_move_consumer(struct lib_ring_buffer
*buf
,
78 unsigned long consumed_new
);
80 extern int lib_ring_buffer_get_subbuf(struct lib_ring_buffer
*buf
,
81 unsigned long consumed
);
82 extern void lib_ring_buffer_put_subbuf(struct lib_ring_buffer
*buf
);
85 * lib_ring_buffer_get_next_subbuf/lib_ring_buffer_put_next_subbuf are helpers
86 * to read sub-buffers sequentially.
88 static inline int lib_ring_buffer_get_next_subbuf(struct lib_ring_buffer
*buf
)
92 ret
= lib_ring_buffer_snapshot(buf
, &buf
->cons_snapshot
,
96 ret
= lib_ring_buffer_get_subbuf(buf
, buf
->cons_snapshot
);
100 static inline void lib_ring_buffer_put_next_subbuf(struct lib_ring_buffer
*buf
)
102 lib_ring_buffer_put_subbuf(buf
);
103 lib_ring_buffer_move_consumer(buf
, subbuf_align(buf
->cons_snapshot
,
107 extern void channel_reset(struct channel
*chan
);
108 extern void lib_ring_buffer_reset(struct lib_ring_buffer
*buf
);
111 unsigned long lib_ring_buffer_get_offset(const struct lib_ring_buffer_config
*config
,
112 struct lib_ring_buffer
*buf
)
114 return v_read(config
, &buf
->offset
);
118 unsigned long lib_ring_buffer_get_consumed(const struct lib_ring_buffer_config
*config
,
119 struct lib_ring_buffer
*buf
)
121 return atomic_long_read(&buf
->consumed
);
125 * Must call lib_ring_buffer_is_finalized before reading counters (memory
126 * ordering enforced with respect to trace teardown).
129 int lib_ring_buffer_is_finalized(const struct lib_ring_buffer_config
*config
,
130 struct lib_ring_buffer
*buf
)
132 int finalized
= ACCESS_ONCE(buf
->finalized
);
134 * Read finalized before counters.
141 int lib_ring_buffer_channel_is_finalized(const struct channel
*chan
)
143 return chan
->finalized
;
147 int lib_ring_buffer_channel_is_disabled(const struct channel
*chan
)
149 return atomic_read(&chan
->record_disabled
);
153 unsigned long lib_ring_buffer_get_read_data_size(
154 const struct lib_ring_buffer_config
*config
,
155 struct lib_ring_buffer
*buf
)
157 return subbuffer_get_read_data_size(config
, &buf
->backend
);
161 unsigned long lib_ring_buffer_get_records_count(
162 const struct lib_ring_buffer_config
*config
,
163 struct lib_ring_buffer
*buf
)
165 return v_read(config
, &buf
->records_count
);
169 unsigned long lib_ring_buffer_get_records_overrun(
170 const struct lib_ring_buffer_config
*config
,
171 struct lib_ring_buffer
*buf
)
173 return v_read(config
, &buf
->records_overrun
);
177 unsigned long lib_ring_buffer_get_records_lost_full(
178 const struct lib_ring_buffer_config
*config
,
179 struct lib_ring_buffer
*buf
)
181 return v_read(config
, &buf
->records_lost_full
);
185 unsigned long lib_ring_buffer_get_records_lost_wrap(
186 const struct lib_ring_buffer_config
*config
,
187 struct lib_ring_buffer
*buf
)
189 return v_read(config
, &buf
->records_lost_wrap
);
193 unsigned long lib_ring_buffer_get_records_lost_big(
194 const struct lib_ring_buffer_config
*config
,
195 struct lib_ring_buffer
*buf
)
197 return v_read(config
, &buf
->records_lost_big
);
201 unsigned long lib_ring_buffer_get_records_read(
202 const struct lib_ring_buffer_config
*config
,
203 struct lib_ring_buffer
*buf
)
205 return v_read(config
, &buf
->backend
.records_read
);
208 #endif /* _LINUX_RING_BUFFER_FRONTEND_H */
This page took 0.044041 seconds and 4 git commands to generate.