Cygwin: Pass file paths instead of file descriptors over UNIX sockets
[lttng-ust.git] / libringbuffer / frontend.h
... / ...
CommitLineData
1#ifndef _LTTNG_RING_BUFFER_FRONTEND_H
2#define _LTTNG_RING_BUFFER_FRONTEND_H
3
4/*
5 * libringbuffer/frontend.h
6 *
7 * Ring Buffer Library Synchronization Header (API).
8 *
9 * Copyright (C) 2005-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; only
14 * version 2.1 of the License.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 *
25 *
26 * Author:
27 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
28 *
29 * See ring_buffer_frontend.c for more information on wait-free algorithms.
30 */
31
32#include <urcu/compiler.h>
33#include <urcu/uatomic.h>
34
35#include "smp.h"
36/* Internal helpers */
37#include "frontend_internal.h"
38
39/* Buffer creation/removal and setup operations */
40
41/*
42 * switch_timer_interval is the time interval (in us) to fill sub-buffers with
43 * padding to let readers get those sub-buffers. Used for live streaming.
44 *
45 * read_timer_interval is the time interval (in us) to wake up pending readers.
46 *
47 * buf_addr is a pointer the the beginning of the preallocated buffer contiguous
48 * address mapping. It is used only by RING_BUFFER_STATIC configuration. It can
49 * be set to NULL for other backends.
50 *
51 * priv_data (output) is set to a pointer into a "priv_data_len"-sized
52 * memory area for client-specific data. This memory is managed by lib
53 * ring buffer. priv_data_align is the alignment required for the
54 * private data area.
55 */
56
57extern
58struct lttng_ust_shm_handle *channel_create(const struct lttng_ust_lib_ring_buffer_config *config,
59 const char *name,
60 void **priv_data,
61 size_t priv_data_align,
62 size_t priv_data_size,
63 void *priv_data_init,
64 void *buf_addr,
65 size_t subbuf_size, size_t num_subbuf,
66 unsigned int switch_timer_interval,
67 unsigned int read_timer_interval,
68 int **shm_fd, char **shm_path,
69 int **wait_fd, char **wait_pipe_path,
70 uint64_t **memory_map_size);
71
72/* channel_handle_create - for consumer. */
73extern
74struct lttng_ust_shm_handle *channel_handle_create(int shm_fd, int wait_fd,
75 uint64_t memory_map_size);
76
77/* channel_handle_add_stream - for consumer. */
78extern
79int channel_handle_add_stream(struct lttng_ust_shm_handle *handle,
80 int shm_fd, int wait_fd, uint64_t memory_map_size);
81
82/*
83 * channel_destroy finalizes all channel's buffers, waits for readers to
84 * release all references, and destroys the channel.
85 */
86extern
87void channel_destroy(struct channel *chan, struct lttng_ust_shm_handle *handle,
88 int shadow);
89
90
91/* Buffer read operations */
92
93/*
94 * Iteration on channel cpumask needs to issue a read barrier to match the write
95 * barrier in cpu hotplug. It orders the cpumask read before read of per-cpu
96 * buffer data. The per-cpu buffer is never removed by cpu hotplug; teardown is
97 * only performed at channel destruction.
98 */
99#define for_each_channel_cpu(cpu, chan) \
100 for_each_possible_cpu(cpu)
101
102extern struct lttng_ust_lib_ring_buffer *channel_get_ring_buffer(
103 const struct lttng_ust_lib_ring_buffer_config *config,
104 struct channel *chan, int cpu,
105 struct lttng_ust_shm_handle *handle,
106 int **shm_fd, char **shm_path,
107 int **wait_fd, char **wait_pipe_path,
108 uint64_t **memory_map_size);
109extern int lib_ring_buffer_open_read(struct lttng_ust_lib_ring_buffer *buf,
110 struct lttng_ust_shm_handle *handle,
111 int shadow);
112extern void lib_ring_buffer_release_read(struct lttng_ust_lib_ring_buffer *buf,
113 struct lttng_ust_shm_handle *handle,
114 int shadow);
115
116/*
117 * Read sequence: snapshot, many get_subbuf/put_subbuf, move_consumer.
118 */
119extern int lib_ring_buffer_snapshot(struct lttng_ust_lib_ring_buffer *buf,
120 unsigned long *consumed,
121 unsigned long *produced,
122 struct lttng_ust_shm_handle *handle);
123extern void lib_ring_buffer_move_consumer(struct lttng_ust_lib_ring_buffer *buf,
124 unsigned long consumed_new,
125 struct lttng_ust_shm_handle *handle);
126
127extern int lib_ring_buffer_get_subbuf(struct lttng_ust_lib_ring_buffer *buf,
128 unsigned long consumed,
129 struct lttng_ust_shm_handle *handle);
130extern void lib_ring_buffer_put_subbuf(struct lttng_ust_lib_ring_buffer *buf,
131 struct lttng_ust_shm_handle *handle);
132
133/*
134 * lib_ring_buffer_get_next_subbuf/lib_ring_buffer_put_next_subbuf are helpers
135 * to read sub-buffers sequentially.
136 */
137static inline int lib_ring_buffer_get_next_subbuf(struct lttng_ust_lib_ring_buffer *buf,
138 struct lttng_ust_shm_handle *handle)
139{
140 int ret;
141
142 ret = lib_ring_buffer_snapshot(buf, &buf->cons_snapshot,
143 &buf->prod_snapshot, handle);
144 if (ret)
145 return ret;
146 ret = lib_ring_buffer_get_subbuf(buf, buf->cons_snapshot, handle);
147 return ret;
148}
149
150static inline
151void lib_ring_buffer_put_next_subbuf(struct lttng_ust_lib_ring_buffer *buf,
152 struct lttng_ust_shm_handle *handle)
153{
154 lib_ring_buffer_put_subbuf(buf, handle);
155 lib_ring_buffer_move_consumer(buf, subbuf_align(buf->cons_snapshot,
156 shmp(handle, buf->backend.chan)), handle);
157}
158
159extern void channel_reset(struct channel *chan);
160extern void lib_ring_buffer_reset(struct lttng_ust_lib_ring_buffer *buf,
161 struct lttng_ust_shm_handle *handle);
162
163static inline
164unsigned long lib_ring_buffer_get_offset(const struct lttng_ust_lib_ring_buffer_config *config,
165 struct lttng_ust_lib_ring_buffer *buf)
166{
167 return v_read(config, &buf->offset);
168}
169
170static inline
171unsigned long lib_ring_buffer_get_consumed(const struct lttng_ust_lib_ring_buffer_config *config,
172 struct lttng_ust_lib_ring_buffer *buf)
173{
174 return uatomic_read(&buf->consumed);
175}
176
177/*
178 * Must call lib_ring_buffer_is_finalized before reading counters (memory
179 * ordering enforced with respect to trace teardown).
180 */
181static inline
182int lib_ring_buffer_is_finalized(const struct lttng_ust_lib_ring_buffer_config *config,
183 struct lttng_ust_lib_ring_buffer *buf)
184{
185 int finalized = CMM_ACCESS_ONCE(buf->finalized);
186 /*
187 * Read finalized before counters.
188 */
189 cmm_smp_rmb();
190 return finalized;
191}
192
193static inline
194int lib_ring_buffer_channel_is_finalized(const struct channel *chan)
195{
196 return chan->finalized;
197}
198
199static inline
200int lib_ring_buffer_channel_is_disabled(const struct channel *chan)
201{
202 return uatomic_read(&chan->record_disabled);
203}
204
205static inline
206unsigned long lib_ring_buffer_get_read_data_size(
207 const struct lttng_ust_lib_ring_buffer_config *config,
208 struct lttng_ust_lib_ring_buffer *buf,
209 struct lttng_ust_shm_handle *handle)
210{
211 return subbuffer_get_read_data_size(config, &buf->backend, handle);
212}
213
214static inline
215unsigned long lib_ring_buffer_get_records_count(
216 const struct lttng_ust_lib_ring_buffer_config *config,
217 struct lttng_ust_lib_ring_buffer *buf)
218{
219 return v_read(config, &buf->records_count);
220}
221
222static inline
223unsigned long lib_ring_buffer_get_records_overrun(
224 const struct lttng_ust_lib_ring_buffer_config *config,
225 struct lttng_ust_lib_ring_buffer *buf)
226{
227 return v_read(config, &buf->records_overrun);
228}
229
230static inline
231unsigned long lib_ring_buffer_get_records_lost_full(
232 const struct lttng_ust_lib_ring_buffer_config *config,
233 struct lttng_ust_lib_ring_buffer *buf)
234{
235 return v_read(config, &buf->records_lost_full);
236}
237
238static inline
239unsigned long lib_ring_buffer_get_records_lost_wrap(
240 const struct lttng_ust_lib_ring_buffer_config *config,
241 struct lttng_ust_lib_ring_buffer *buf)
242{
243 return v_read(config, &buf->records_lost_wrap);
244}
245
246static inline
247unsigned long lib_ring_buffer_get_records_lost_big(
248 const struct lttng_ust_lib_ring_buffer_config *config,
249 struct lttng_ust_lib_ring_buffer *buf)
250{
251 return v_read(config, &buf->records_lost_big);
252}
253
254static inline
255unsigned long lib_ring_buffer_get_records_read(
256 const struct lttng_ust_lib_ring_buffer_config *config,
257 struct lttng_ust_lib_ring_buffer *buf)
258{
259 return v_read(config, &buf->backend.records_read);
260}
261
262#endif /* _LTTNG_RING_BUFFER_FRONTEND_H */
This page took 0.024049 seconds and 4 git commands to generate.