Fix: Stream allocation and insertion consistency
[lttng-tools.git] / src / common / kernel-ctl / kernel-ctl.c
CommitLineData
ee0326c0 1/*
16421f6e
DG
2 * Copyright (C) 2011 - Julien Desfossez <julien.desfossez@polymtl.ca>
3 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
ee0326c0 4 *
d14d33bf
AM
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License, version 2 only,
7 * as published by the Free Software Foundation.
ee0326c0
DG
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
d14d33bf
AM
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
ee0326c0 17 */
16421f6e 18
95ba0f2f 19#define __USE_LINUX_IOCTL_DEFS
16421f6e
DG
20#include <sys/ioctl.h>
21
10a8a223 22#include "kernel-ctl.h"
16421f6e 23#include "kernel-ioctl.h"
16421f6e 24
964ccb60 25int kernctl_create_session(int fd)
d65106b1 26{
964ccb60 27 return ioctl(fd, LTTNG_KERNEL_SESSION);
d65106b1
DG
28}
29
964ccb60
MD
30/* open the metadata global channel */
31int kernctl_open_metadata(int fd, struct lttng_channel_attr *chops)
f3ed775e 32{
964ccb60 33 return ioctl(fd, LTTNG_KERNEL_METADATA, chops);
f3ed775e
DG
34}
35
36int kernctl_create_channel(int fd, struct lttng_channel_attr *chops)
16421f6e 37{
9cb98350 38 return ioctl(fd, LTTNG_KERNEL_CHANNEL, chops);
16421f6e
DG
39}
40
964ccb60 41int kernctl_create_stream(int fd)
16421f6e 42{
964ccb60 43 return ioctl(fd, LTTNG_KERNEL_STREAM);
16421f6e
DG
44}
45
964ccb60 46int kernctl_create_event(int fd, struct lttng_kernel_event *ev)
16421f6e 47{
964ccb60 48 return ioctl(fd, LTTNG_KERNEL_EVENT, ev);
16421f6e
DG
49}
50
964ccb60 51int kernctl_add_context(int fd, struct lttng_kernel_context *ctx)
16421f6e 52{
964ccb60 53 return ioctl(fd, LTTNG_KERNEL_CONTEXT, ctx);
16421f6e
DG
54}
55
964ccb60 56
f3ed775e
DG
57/* Enable event, channel and session ioctl */
58int kernctl_enable(int fd)
59{
60 return ioctl(fd, LTTNG_KERNEL_ENABLE);
61}
62
63/* Disable event, channel and session ioctl */
64int kernctl_disable(int fd)
65{
66 return ioctl(fd, LTTNG_KERNEL_DISABLE);
67}
68
964ccb60 69int kernctl_start_session(int fd)
16421f6e 70{
964ccb60
MD
71 return ioctl(fd, LTTNG_KERNEL_SESSION_START);
72}
73
74int kernctl_stop_session(int fd)
75{
76 return ioctl(fd, LTTNG_KERNEL_SESSION_STOP);
16421f6e
DG
77}
78
964ccb60
MD
79
80int kernctl_tracepoint_list(int fd)
81{
82 return ioctl(fd, LTTNG_KERNEL_TRACEPOINT_LIST);
83}
84
85int kernctl_tracer_version(int fd, struct lttng_kernel_tracer_version *v)
86{
87 return ioctl(fd, LTTNG_KERNEL_TRACER_VERSION, v);
88}
89
90int kernctl_wait_quiescent(int fd)
91{
92 return ioctl(fd, LTTNG_KERNEL_WAIT_QUIESCENT);
93}
94
95int kernctl_calibrate(int fd, struct lttng_kernel_calibrate *calibrate)
96{
97 return ioctl(fd, LTTNG_KERNEL_CALIBRATE, calibrate);
98}
99
100
101int kernctl_buffer_flush(int fd)
102{
103 return ioctl(fd, RING_BUFFER_FLUSH);
104}
105
106
107/* Buffer operations */
108
109/* For mmap mode, readable without "get" operation */
110
16421f6e
DG
111/* returns the length to mmap. */
112int kernctl_get_mmap_len(int fd, unsigned long *len)
113{
114 return ioctl(fd, RING_BUFFER_GET_MMAP_LEN, len);
115}
116
964ccb60
MD
117/* returns the maximum size for sub-buffers. */
118int kernctl_get_max_subbuf_size(int fd, unsigned long *len)
119{
120 return ioctl(fd, RING_BUFFER_GET_MAX_SUBBUF_SIZE, len);
121}
122
123/*
124 * For mmap mode, operate on the current packet (between get/put or
125 * get_next/put_next).
126 */
127
16421f6e
DG
128/* returns the offset of the subbuffer belonging to the mmap reader. */
129int kernctl_get_mmap_read_offset(int fd, unsigned long *off)
130{
131 return ioctl(fd, RING_BUFFER_GET_MMAP_READ_OFFSET, off);
132}
133
964ccb60
MD
134/* returns the size of the current sub-buffer, without padding (for mmap). */
135int kernctl_get_subbuf_size(int fd, unsigned long *len)
16421f6e 136{
964ccb60 137 return ioctl(fd, RING_BUFFER_GET_SUBBUF_SIZE, len);
16421f6e
DG
138}
139
140/* returns the size of the current sub-buffer, without padding (for mmap). */
141int kernctl_get_padded_subbuf_size(int fd, unsigned long *len)
142{
143 return ioctl(fd, RING_BUFFER_GET_PADDED_SUBBUF_SIZE, len);
144}
145
964ccb60
MD
146/* Get exclusive read access to the next sub-buffer that can be read. */
147int kernctl_get_next_subbuf(int fd)
16421f6e 148{
964ccb60 149 return ioctl(fd, RING_BUFFER_GET_NEXT_SUBBUF);
16421f6e
DG
150}
151
d4a1283e 152
16421f6e
DG
153/* Release exclusive sub-buffer access, move consumer forward. */
154int kernctl_put_next_subbuf(int fd)
155{
156 return ioctl(fd, RING_BUFFER_PUT_NEXT_SUBBUF);
157}
158
964ccb60 159/* snapshot */
16421f6e
DG
160
161/* Get a snapshot of the current ring buffer producer and consumer positions */
162int kernctl_snapshot(int fd)
163{
164 return ioctl(fd, RING_BUFFER_SNAPSHOT);
165}
166
167/* Get the consumer position (iteration start) */
168int kernctl_snapshot_get_consumed(int fd, unsigned long *pos)
169{
170 return ioctl(fd, RING_BUFFER_SNAPSHOT_GET_CONSUMED, pos);
171}
172
173/* Get the producer position (iteration end) */
174int kernctl_snapshot_get_produced(int fd, unsigned long *pos)
175{
176 return ioctl(fd, RING_BUFFER_SNAPSHOT_GET_PRODUCED, pos);
177}
178
964ccb60
MD
179/* Get exclusive read access to the specified sub-buffer position */
180int kernctl_get_subbuf(int fd, unsigned long *len)
f3ed775e 181{
964ccb60 182 return ioctl(fd, RING_BUFFER_GET_SUBBUF, len);
f3ed775e 183}
d0254c7c 184
964ccb60
MD
185/* Release exclusive sub-buffer access */
186int kernctl_put_subbuf(int fd)
d0254c7c 187{
964ccb60 188 return ioctl(fd, RING_BUFFER_PUT_SUBBUF);
d0254c7c 189}
00e2e675
DG
190
191/* Set the stream_id */
192int kernctl_set_stream_id(int fd, unsigned long *stream_id)
193{
194 return ioctl(fd, RING_BUFFER_SET_STREAM_ID, stream_id);
195}
196
197/* Get the offset of the stream_id in the packet header */
198int kernctl_get_net_stream_id_offset(int fd, unsigned long *offset)
199{
200 return ioctl(fd, LTTNG_KERNEL_STREAM_ID_OFFSET, offset);
201
202}
This page took 0.062709 seconds and 4 git commands to generate.