Allow consumer to flush buffers, fix alignment bug
[lttng-ust.git] / liblttng-ust-ctl / ustctl.c
CommitLineData
57773204
MD
1/*
2 * Copyright (C) 2011 - Julien Desfossez <julien.desfossez@polymtl.ca>
3 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; only version 2
8 * of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20#include <string.h>
4318ae1b
MD
21#include <lttng/ust-ctl.h>
22#include <lttng/ust-abi.h>
23#include <lttng/usterr-signal-safe.h>
24#include <lttng/ust-comm.h>
c1fca457 25#include <lttng/ust-events.h>
57773204
MD
26
27#include "../libringbuffer/backend.h"
28#include "../libringbuffer/frontend.h"
29
6b120308
MD
30volatile enum ust_loglevel ust_loglevel;
31
57773204 32static
61f02aea 33void init_object(struct lttng_ust_object_data *data)
57773204
MD
34{
35 data->handle = -1;
36 data->shm_fd = -1;
37 data->wait_fd = -1;
38 data->memory_map_size = 0;
39}
40
5f9d3dbc 41void ustctl_release_object(int sock, struct lttng_ust_object_data *data)
57773204
MD
42{
43 struct ustcomm_ust_msg lum;
44 struct ustcomm_ust_reply lur;
45 int ret;
46
47 if (data->shm_fd >= 0)
48 close(data->shm_fd);
49 if (data->wait_fd >= 0)
50 close(data->wait_fd);
51 memset(&lum, 0, sizeof(lum));
52 lum.handle = data->handle;
53 lum.cmd = LTTNG_UST_RELEASE;
54 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
55 assert(!ret);
56 free(data);
57}
58
1c5e467e
MD
59/*
60 * Send registration done packet to the application.
61 */
62int ustctl_register_done(int sock)
63{
64 struct ustcomm_ust_msg lum;
65 struct ustcomm_ust_reply lur;
66 int ret;
67
68 DBG("Sending register done command to %d", sock);
69 memset(&lum, 0, sizeof(lum));
70 lum.handle = LTTNG_UST_ROOT_HANDLE;
71 lum.cmd = LTTNG_UST_REGISTER_DONE;
72 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
73 if (ret)
74 return ret;
75 if (lur.ret_code != USTCOMM_OK) {
76 DBG("Return code: %s", ustcomm_get_readable_code(lur.ret_code));
77 goto error;
78 }
79 return 0;
80
81error:
82 return -1;
83}
84
57773204
MD
85/*
86 * returns session handle.
87 */
88int ustctl_create_session(int sock)
89{
90 struct ustcomm_ust_msg lum;
91 struct ustcomm_ust_reply lur;
92 int ret, session_handle;
93
94 /* Create session */
95 memset(&lum, 0, sizeof(lum));
96 lum.handle = LTTNG_UST_ROOT_HANDLE;
97 lum.cmd = LTTNG_UST_SESSION;
98 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
99 if (ret)
100 return ret;
101 session_handle = lur.ret_val;
102 DBG("received session handle %u", session_handle);
103 return session_handle;
104}
105
106/* open the metadata global channel */
107int ustctl_open_metadata(int sock, int session_handle,
108 struct lttng_ust_channel_attr *chops,
61f02aea 109 struct lttng_ust_object_data **_metadata_data)
57773204
MD
110{
111 struct ustcomm_ust_msg lum;
112 struct ustcomm_ust_reply lur;
61f02aea 113 struct lttng_ust_object_data *metadata_data;
57773204
MD
114 int ret;
115
116 metadata_data = malloc(sizeof(*metadata_data));
117 if (!metadata_data)
118 return -ENOMEM;
119 init_object(metadata_data);
120 /* Create metadata channel */
121 memset(&lum, 0, sizeof(lum));
122 lum.handle = session_handle;
123 lum.cmd = LTTNG_UST_METADATA;
124 lum.u.channel.overwrite = chops->overwrite;
125 lum.u.channel.subbuf_size = chops->subbuf_size;
126 lum.u.channel.num_subbuf = chops->num_subbuf;
127 lum.u.channel.switch_timer_interval = chops->switch_timer_interval;
128 lum.u.channel.read_timer_interval = chops->read_timer_interval;
129 lum.u.channel.output = chops->output;
130 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
131 if (ret) {
132 free(metadata_data);
133 return ret;
134 }
135 if (lur.ret_code != USTCOMM_OK) {
136 free(metadata_data);
137 return lur.ret_code;
138 }
139 metadata_data->handle = lur.ret_val;
140 DBG("received metadata handle %u", metadata_data->handle);
141 metadata_data->memory_map_size = lur.u.channel.memory_map_size;
142 /* get shm fd */
143 ret = ustcomm_recv_fd(sock);
144 if (ret < 0)
145 goto error;
146 metadata_data->shm_fd = ret;
147 /* get wait fd */
148 ret = ustcomm_recv_fd(sock);
149 if (ret < 0)
150 goto error;
151 metadata_data->wait_fd = ret;
152 *_metadata_data = metadata_data;
153 return 0;
154
155error:
5f9d3dbc 156 ustctl_release_object(sock, metadata_data);
57773204
MD
157 return -EINVAL;
158}
159
160int ustctl_create_channel(int sock, int session_handle,
161 struct lttng_ust_channel_attr *chops,
61f02aea 162 struct lttng_ust_object_data **_channel_data)
57773204
MD
163{
164 struct ustcomm_ust_msg lum;
165 struct ustcomm_ust_reply lur;
61f02aea 166 struct lttng_ust_object_data *channel_data;
57773204
MD
167 int ret;
168
169 channel_data = malloc(sizeof(*channel_data));
170 if (!channel_data)
171 return -ENOMEM;
172 init_object(channel_data);
173 /* Create metadata channel */
174 memset(&lum, 0, sizeof(lum));
175 lum.handle = session_handle;
176 lum.cmd = LTTNG_UST_CHANNEL;
177 lum.u.channel.overwrite = chops->overwrite;
178 lum.u.channel.subbuf_size = chops->subbuf_size;
179 lum.u.channel.num_subbuf = chops->num_subbuf;
180 lum.u.channel.switch_timer_interval = chops->switch_timer_interval;
181 lum.u.channel.read_timer_interval = chops->read_timer_interval;
182 lum.u.channel.output = chops->output;
183 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
184 if (ret) {
185 free(channel_data);
186 return ret;
187 }
188 if (lur.ret_code != USTCOMM_OK) {
189 free(channel_data);
190 return lur.ret_code;
191 }
192 channel_data->handle = lur.ret_val;
193 DBG("received channel handle %u", channel_data->handle);
194 channel_data->memory_map_size = lur.u.channel.memory_map_size;
195 /* get shm fd */
196 ret = ustcomm_recv_fd(sock);
197 if (ret < 0)
198 goto error;
199 channel_data->shm_fd = ret;
200 /* get wait fd */
201 ret = ustcomm_recv_fd(sock);
202 if (ret < 0)
203 goto error;
204 channel_data->wait_fd = ret;
205 *_channel_data = channel_data;
206 return 0;
207
208error:
5f9d3dbc 209 ustctl_release_object(sock, channel_data);
57773204
MD
210 return -EINVAL;
211}
212
213/*
214 * Return -ENOENT if no more stream is available for creation.
215 * Return 0 on success.
216 * Return negative error value on error.
217 */
61f02aea
MD
218int ustctl_create_stream(int sock, struct lttng_ust_object_data *channel_data,
219 struct lttng_ust_object_data **_stream_data)
57773204
MD
220{
221 struct ustcomm_ust_msg lum;
222 struct ustcomm_ust_reply lur;
61f02aea 223 struct lttng_ust_object_data *stream_data;
57773204
MD
224 int ret, fd;
225
226 stream_data = malloc(sizeof(*stream_data));
227 if (!stream_data)
228 return -ENOMEM;
229 init_object(stream_data);
230 memset(&lum, 0, sizeof(lum));
231 lum.handle = channel_data->handle;
232 lum.cmd = LTTNG_UST_STREAM;
233 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
234 if (ret) {
235 free(stream_data);
236 return ret;
237 }
238 if (lur.ret_code != USTCOMM_OK) {
239 free(stream_data);
240 return lur.ret_code;
241 }
242
243 stream_data->handle = lur.ret_val;
244 DBG("received stream handle %u", stream_data->handle);
245 stream_data->memory_map_size = lur.u.stream.memory_map_size;
246 /* get shm fd */
247 fd = ustcomm_recv_fd(sock);
248 if (fd < 0)
249 goto error;
250 stream_data->shm_fd = fd;
251 /* get wait fd */
252 fd = ustcomm_recv_fd(sock);
253 if (fd < 0)
254 goto error;
255 stream_data->wait_fd = fd;
256 *_stream_data = stream_data;
257 return ret;
258
259error:
5f9d3dbc 260 ustctl_release_object(sock, stream_data);
57773204
MD
261 return -EINVAL;
262}
263
264int ustctl_create_event(int sock, struct lttng_ust_event *ev,
61f02aea
MD
265 struct lttng_ust_object_data *channel_data,
266 struct lttng_ust_object_data **_event_data)
57773204
MD
267{
268 struct ustcomm_ust_msg lum;
269 struct ustcomm_ust_reply lur;
61f02aea 270 struct lttng_ust_object_data *event_data;
57773204
MD
271 int ret;
272
273 event_data = malloc(sizeof(*event_data));
274 if (!event_data)
275 return -ENOMEM;
276 init_object(event_data);
277 memset(&lum, 0, sizeof(lum));
278 lum.handle = channel_data->handle;
279 lum.cmd = LTTNG_UST_EVENT;
280 strncpy(lum.u.event.name, ev->name,
281 LTTNG_UST_SYM_NAME_LEN);
282 lum.u.event.instrumentation = ev->instrumentation;
283 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
284 if (ret) {
285 free(event_data);
286 return ret;
287 }
288 event_data->handle = lur.ret_val;
289 DBG("received event handle %u", event_data->handle);
290 *_event_data = event_data;
291 return 0;
292}
293
294int ustctl_add_context(int sock, struct lttng_ust_context *ctx,
61f02aea
MD
295 struct lttng_ust_object_data *obj_data,
296 struct lttng_ust_object_data **_context_data)
57773204
MD
297{
298 struct ustcomm_ust_msg lum;
299 struct ustcomm_ust_reply lur;
61f02aea 300 struct lttng_ust_object_data *context_data;
57773204
MD
301 int ret;
302
303 context_data = malloc(sizeof(*context_data));
304 if (!context_data)
305 return -ENOMEM;
306 init_object(context_data);
307 memset(&lum, 0, sizeof(lum));
3039d8ed 308 lum.handle = obj_data->handle;
57773204
MD
309 lum.cmd = LTTNG_UST_CONTEXT;
310 lum.u.context.ctx = ctx->ctx;
311 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
312 if (ret) {
313 free(context_data);
314 return ret;
315 }
316 context_data->handle = lur.ret_val;
317 DBG("received context handle %u", context_data->handle);
318 *_context_data = context_data;
319 return ret;
320}
321
322/* Enable event, channel and session ioctl */
61f02aea 323int ustctl_enable(int sock, struct lttng_ust_object_data *object)
57773204
MD
324{
325 struct ustcomm_ust_msg lum;
326 struct ustcomm_ust_reply lur;
327 int ret;
328
329 memset(&lum, 0, sizeof(lum));
330 lum.handle = object->handle;
331 lum.cmd = LTTNG_UST_ENABLE;
332 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
333 if (ret)
334 return ret;
335 DBG("enabled handle %u", object->handle);
336 return 0;
337}
338
339/* Disable event, channel and session ioctl */
61f02aea 340int ustctl_disable(int sock, struct lttng_ust_object_data *object)
57773204
MD
341{
342 struct ustcomm_ust_msg lum;
343 struct ustcomm_ust_reply lur;
344 int ret;
345
346 memset(&lum, 0, sizeof(lum));
347 lum.handle = object->handle;
348 lum.cmd = LTTNG_UST_DISABLE;
349 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
350 if (ret)
351 return ret;
352 DBG("disable handle %u", object->handle);
353 return 0;
354}
355
4a6ca058 356int ustctl_start_session(int sock, int handle)
57773204 357{
61f02aea 358 struct lttng_ust_object_data obj;
4a6ca058
MD
359
360 obj.handle = handle;
361 return ustctl_enable(sock, &obj);
57773204
MD
362}
363
4a6ca058 364int ustctl_stop_session(int sock, int handle)
57773204 365{
61f02aea 366 struct lttng_ust_object_data obj;
4a6ca058
MD
367
368 obj.handle = handle;
369 return ustctl_disable(sock, &obj);
57773204
MD
370}
371
372
373int ustctl_tracepoint_list(int sock)
374{
375 return -ENOSYS; /* not implemented */
376}
377
378int ustctl_tracer_version(int sock, struct lttng_ust_tracer_version *v)
379{
380 struct ustcomm_ust_msg lum;
381 struct ustcomm_ust_reply lur;
382 int ret;
383
384 memset(&lum, 0, sizeof(lum));
385 lum.handle = LTTNG_UST_ROOT_HANDLE;
386 lum.cmd = LTTNG_UST_TRACER_VERSION;
387 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
388 if (ret)
389 return ret;
390 memcpy(v, &lur.u.version, sizeof(*v));
391 DBG("received tracer version");
392 return 0;
393}
394
395int ustctl_wait_quiescent(int sock)
396{
397 struct ustcomm_ust_msg lum;
398 struct ustcomm_ust_reply lur;
399 int ret;
400
401 memset(&lum, 0, sizeof(lum));
402 lum.handle = LTTNG_UST_ROOT_HANDLE;
403 lum.cmd = LTTNG_UST_WAIT_QUIESCENT;
404 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
405 if (ret)
406 return ret;
407 DBG("waited for quiescent state");
408 return 0;
409}
410
411int ustctl_calibrate(int sock, struct lttng_ust_calibrate *calibrate)
412{
413 return -ENOSYS;
414}
415
416/* Buffer operations */
417
418/* Map channel shm into process memory */
38fae1d3 419struct lttng_ust_shm_handle *ustctl_map_channel(struct lttng_ust_object_data *chan_data)
57773204 420{
38fae1d3 421 struct lttng_ust_shm_handle *handle;
57773204
MD
422 struct channel *chan;
423 size_t chan_size;
c1fca457 424 struct lttng_ust_lib_ring_buffer_config *config;
57773204
MD
425
426 handle = channel_handle_create(chan_data->shm_fd,
427 chan_data->wait_fd,
428 chan_data->memory_map_size);
429 if (!handle) {
430 ERR("create handle error");
431 return NULL;
432 }
433 /*
38fae1d3 434 * Set to -1 because the lttng_ust_shm_handle destruction will take care
57773204
MD
435 * of closing shm_fd and wait_fd.
436 */
437 chan_data->shm_fd = -1;
438 chan_data->wait_fd = -1;
439
440 /*
441 * TODO: add consistency checks to be resilient if the
442 * application try to feed us with incoherent channel structure
443 * values.
444 */
445 chan = shmp(handle, handle->chan);
446 /* chan is object 0. This is hardcoded. */
447 chan_size = handle->table->objects[0].allocated_len;
448 handle->shadow_chan = malloc(chan_size);
449 if (!handle->shadow_chan) {
450 channel_destroy(chan, handle, 1);
451 return NULL;
452 }
453 memcpy(handle->shadow_chan, chan, chan_size);
bbc70d1b
MD
454 /*
455 * The callback pointers in the producer are invalid in the
c1fca457 456 * consumer. We need to look them up here.
bbc70d1b 457 */
c1fca457
MD
458 config = &handle->shadow_chan->backend.config;
459 switch (config->client_type) {
460 case LTTNG_CLIENT_METADATA:
461 memcpy(&config->cb, lttng_client_callbacks_metadata,
462 sizeof(config->cb));
463 break;
464 case LTTNG_CLIENT_DISCARD:
465 memcpy(&config->cb, lttng_client_callbacks_discard,
466 sizeof(config->cb));
467 break;
468 case LTTNG_CLIENT_OVERWRITE:
469 memcpy(&config->cb, lttng_client_callbacks_overwrite,
470 sizeof(config->cb));
471 break;
472 default:
473 ERR("Unknown client type %d", config->client_type);
474 channel_destroy(chan, handle, 1);
475 return NULL;
476 }
57773204
MD
477 return handle;
478}
479
480/* Add stream to channel shm and map its shm into process memory */
38fae1d3 481int ustctl_add_stream(struct lttng_ust_shm_handle *handle,
61f02aea 482 struct lttng_ust_object_data *stream_data)
57773204
MD
483{
484 int ret;
485
486 if (!stream_data->handle)
487 return -ENOENT;
488 /* map stream */
489 ret = channel_handle_add_stream(handle,
490 stream_data->shm_fd,
491 stream_data->wait_fd,
492 stream_data->memory_map_size);
493 if (ret) {
494 ERR("add stream error\n");
495 return ret;
496 }
497 /*
38fae1d3 498 * Set to -1 because the lttng_ust_shm_handle destruction will take care
57773204
MD
499 * of closing shm_fd and wait_fd.
500 */
501 stream_data->shm_fd = -1;
502 stream_data->wait_fd = -1;
503 return 0;
504}
505
38fae1d3 506void ustctl_unmap_channel(struct lttng_ust_shm_handle *handle)
5224b5c8
MD
507{
508 struct channel *chan;
509
510 chan = shmp(handle, handle->chan);
511 channel_destroy(chan, handle, 1);
512}
513
4cfec15c 514struct lttng_ust_lib_ring_buffer *ustctl_open_stream_read(struct lttng_ust_shm_handle *handle,
6e922b24
MD
515 int cpu)
516{
517 struct channel *chan = handle->shadow_chan;
518 int shm_fd, wait_fd;
519 uint64_t memory_map_size;
4cfec15c 520 struct lttng_ust_lib_ring_buffer *buf;
6e922b24
MD
521 int ret;
522
523 buf = channel_get_ring_buffer(&chan->backend.config,
524 chan, cpu, handle, &shm_fd, &wait_fd, &memory_map_size);
525 if (!buf)
526 return NULL;
527 ret = lib_ring_buffer_open_read(buf, handle, 1);
528 if (ret)
529 return NULL;
530 return buf;
531}
532
38fae1d3 533void ustctl_close_stream_read(struct lttng_ust_shm_handle *handle,
4cfec15c 534 struct lttng_ust_lib_ring_buffer *buf)
6e922b24
MD
535{
536 lib_ring_buffer_release_read(buf, handle, 1);
537}
538
57773204
MD
539/* For mmap mode, readable without "get" operation */
540
38fae1d3 541void *ustctl_get_mmap_base(struct lttng_ust_shm_handle *handle,
4cfec15c 542 struct lttng_ust_lib_ring_buffer *buf)
9095efe9
MD
543{
544 return shmp(handle, buf->backend.memory_map);
545}
546
57773204 547/* returns the length to mmap. */
38fae1d3 548int ustctl_get_mmap_len(struct lttng_ust_shm_handle *handle,
4cfec15c 549 struct lttng_ust_lib_ring_buffer *buf,
57773204
MD
550 unsigned long *len)
551{
552 unsigned long mmap_buf_len;
553 struct channel *chan = handle->shadow_chan;
554
555 if (chan->backend.config.output != RING_BUFFER_MMAP)
556 return -EINVAL;
557 mmap_buf_len = chan->backend.buf_size;
558 if (chan->backend.extra_reader_sb)
559 mmap_buf_len += chan->backend.subbuf_size;
560 if (mmap_buf_len > INT_MAX)
561 return -EFBIG;
562 *len = mmap_buf_len;
563 return 0;
564}
565
566/* returns the maximum size for sub-buffers. */
38fae1d3 567int ustctl_get_max_subbuf_size(struct lttng_ust_shm_handle *handle,
4cfec15c 568 struct lttng_ust_lib_ring_buffer *buf,
57773204
MD
569 unsigned long *len)
570{
571 struct channel *chan = handle->shadow_chan;
572
573 *len = chan->backend.subbuf_size;
574 return 0;
575}
576
577/*
578 * For mmap mode, operate on the current packet (between get/put or
579 * get_next/put_next).
580 */
581
582/* returns the offset of the subbuffer belonging to the mmap reader. */
38fae1d3 583int ustctl_get_mmap_read_offset(struct lttng_ust_shm_handle *handle,
4cfec15c 584 struct lttng_ust_lib_ring_buffer *buf, unsigned long *off)
57773204
MD
585{
586 struct channel *chan = handle->shadow_chan;
587 unsigned long sb_bindex;
588
589 if (chan->backend.config.output != RING_BUFFER_MMAP)
590 return -EINVAL;
591 sb_bindex = subbuffer_id_get_index(&chan->backend.config,
592 buf->backend.buf_rsb.id);
593 *off = shmp(handle, shmp_index(handle, buf->backend.array, sb_bindex)->shmp)->mmap_offset;
594 return 0;
595}
596
597/* returns the size of the current sub-buffer, without padding (for mmap). */
38fae1d3 598int ustctl_get_subbuf_size(struct lttng_ust_shm_handle *handle,
4cfec15c 599 struct lttng_ust_lib_ring_buffer *buf, unsigned long *len)
57773204
MD
600{
601 struct channel *chan = handle->shadow_chan;
602
603 *len = lib_ring_buffer_get_read_data_size(&chan->backend.config, buf,
604 handle);
605 return 0;
606}
607
608/* returns the size of the current sub-buffer, without padding (for mmap). */
38fae1d3 609int ustctl_get_padded_subbuf_size(struct lttng_ust_shm_handle *handle,
4cfec15c 610 struct lttng_ust_lib_ring_buffer *buf, unsigned long *len)
57773204
MD
611{
612 struct channel *chan = handle->shadow_chan;
613
614 *len = lib_ring_buffer_get_read_data_size(&chan->backend.config, buf,
615 handle);
616 *len = PAGE_ALIGN(*len);
617 return 0;
618}
619
620/* Get exclusive read access to the next sub-buffer that can be read. */
38fae1d3 621int ustctl_get_next_subbuf(struct lttng_ust_shm_handle *handle,
4cfec15c 622 struct lttng_ust_lib_ring_buffer *buf)
57773204
MD
623{
624 return lib_ring_buffer_get_next_subbuf(buf, handle);
625}
626
627
628/* Release exclusive sub-buffer access, move consumer forward. */
38fae1d3 629int ustctl_put_next_subbuf(struct lttng_ust_shm_handle *handle,
4cfec15c 630 struct lttng_ust_lib_ring_buffer *buf)
57773204
MD
631{
632 lib_ring_buffer_put_next_subbuf(buf, handle);
633 return 0;
634}
635
636/* snapshot */
637
638/* Get a snapshot of the current ring buffer producer and consumer positions */
38fae1d3 639int ustctl_snapshot(struct lttng_ust_shm_handle *handle,
4cfec15c 640 struct lttng_ust_lib_ring_buffer *buf)
57773204
MD
641{
642 return lib_ring_buffer_snapshot(buf, &buf->cons_snapshot,
643 &buf->prod_snapshot, handle);
644}
645
646/* Get the consumer position (iteration start) */
38fae1d3 647int ustctl_snapshot_get_consumed(struct lttng_ust_shm_handle *handle,
4cfec15c 648 struct lttng_ust_lib_ring_buffer *buf, unsigned long *pos)
57773204
MD
649{
650 *pos = buf->cons_snapshot;
651 return 0;
652}
653
654/* Get the producer position (iteration end) */
38fae1d3 655int ustctl_snapshot_get_produced(struct lttng_ust_shm_handle *handle,
4cfec15c 656 struct lttng_ust_lib_ring_buffer *buf, unsigned long *pos)
57773204
MD
657{
658 *pos = buf->prod_snapshot;
659 return 0;
660}
661
662/* Get exclusive read access to the specified sub-buffer position */
38fae1d3 663int ustctl_get_subbuf(struct lttng_ust_shm_handle *handle,
4cfec15c 664 struct lttng_ust_lib_ring_buffer *buf, unsigned long *pos)
57773204
MD
665{
666 return lib_ring_buffer_get_subbuf(buf, *pos, handle);
667}
668
669/* Release exclusive sub-buffer access */
38fae1d3 670int ustctl_put_subbuf(struct lttng_ust_shm_handle *handle,
4cfec15c 671 struct lttng_ust_lib_ring_buffer *buf)
57773204
MD
672{
673 lib_ring_buffer_put_subbuf(buf, handle);
674 return 0;
675}
676
02a15cfb 677void ustctl_flush_buffer(struct lttng_ust_shm_handle *handle,
b52190f2
MD
678 struct lttng_ust_lib_ring_buffer *buf,
679 int producer_active)
57773204 680{
b52190f2
MD
681 lib_ring_buffer_switch_slow(buf,
682 producer_active ? SWITCH_ACTIVE : SWITCH_FLUSH,
683 handle);
57773204 684}
This page took 0.052121 seconds and 4 git commands to generate.