2 * Copyright (C) 2011 - Julien Desfossez <julien.desfossez@polymtl.ca>
3 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
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.
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.
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.
19 #include <sys/ioctl.h>
21 #include "kernel-ctl.h"
22 #include "kernel-ioctl.h"
24 int kernctl_create_session(int fd
)
26 return ioctl(fd
, LTTNG_KERNEL_SESSION
);
29 /* open the metadata global channel */
30 int kernctl_open_metadata(int fd
, struct lttng_channel_attr
*chops
)
32 return ioctl(fd
, LTTNG_KERNEL_METADATA
, chops
);
35 int kernctl_create_channel(int fd
, struct lttng_channel_attr
*chops
)
37 return ioctl(fd
, LTTNG_KERNEL_CHANNEL
, chops
);
40 int kernctl_create_stream(int fd
)
42 return ioctl(fd
, LTTNG_KERNEL_STREAM
);
45 int kernctl_create_event(int fd
, struct lttng_kernel_event
*ev
)
47 return ioctl(fd
, LTTNG_KERNEL_EVENT
, ev
);
50 int kernctl_add_context(int fd
, struct lttng_kernel_context
*ctx
)
52 return ioctl(fd
, LTTNG_KERNEL_CONTEXT
, ctx
);
56 /* Enable event, channel and session ioctl */
57 int kernctl_enable(int fd
)
59 return ioctl(fd
, LTTNG_KERNEL_ENABLE
);
62 /* Disable event, channel and session ioctl */
63 int kernctl_disable(int fd
)
65 return ioctl(fd
, LTTNG_KERNEL_DISABLE
);
68 int kernctl_start_session(int fd
)
70 return ioctl(fd
, LTTNG_KERNEL_SESSION_START
);
73 int kernctl_stop_session(int fd
)
75 return ioctl(fd
, LTTNG_KERNEL_SESSION_STOP
);
79 int kernctl_tracepoint_list(int fd
)
81 return ioctl(fd
, LTTNG_KERNEL_TRACEPOINT_LIST
);
84 int kernctl_tracer_version(int fd
, struct lttng_kernel_tracer_version
*v
)
86 return ioctl(fd
, LTTNG_KERNEL_TRACER_VERSION
, v
);
89 int kernctl_wait_quiescent(int fd
)
91 return ioctl(fd
, LTTNG_KERNEL_WAIT_QUIESCENT
);
94 int kernctl_calibrate(int fd
, struct lttng_kernel_calibrate
*calibrate
)
96 return ioctl(fd
, LTTNG_KERNEL_CALIBRATE
, calibrate
);
100 int kernctl_buffer_flush(int fd
)
102 return ioctl(fd
, RING_BUFFER_FLUSH
);
106 /* Buffer operations */
108 /* For mmap mode, readable without "get" operation */
110 /* returns the length to mmap. */
111 int kernctl_get_mmap_len(int fd
, unsigned long *len
)
113 return ioctl(fd
, RING_BUFFER_GET_MMAP_LEN
, len
);
116 /* returns the maximum size for sub-buffers. */
117 int kernctl_get_max_subbuf_size(int fd
, unsigned long *len
)
119 return ioctl(fd
, RING_BUFFER_GET_MAX_SUBBUF_SIZE
, len
);
123 * For mmap mode, operate on the current packet (between get/put or
124 * get_next/put_next).
127 /* returns the offset of the subbuffer belonging to the mmap reader. */
128 int kernctl_get_mmap_read_offset(int fd
, unsigned long *off
)
130 return ioctl(fd
, RING_BUFFER_GET_MMAP_READ_OFFSET
, off
);
133 /* returns the size of the current sub-buffer, without padding (for mmap). */
134 int kernctl_get_subbuf_size(int fd
, unsigned long *len
)
136 return ioctl(fd
, RING_BUFFER_GET_SUBBUF_SIZE
, len
);
139 /* returns the size of the current sub-buffer, without padding (for mmap). */
140 int kernctl_get_padded_subbuf_size(int fd
, unsigned long *len
)
142 return ioctl(fd
, RING_BUFFER_GET_PADDED_SUBBUF_SIZE
, len
);
145 /* Get exclusive read access to the next sub-buffer that can be read. */
146 int kernctl_get_next_subbuf(int fd
)
148 return ioctl(fd
, RING_BUFFER_GET_NEXT_SUBBUF
);
152 /* Release exclusive sub-buffer access, move consumer forward. */
153 int kernctl_put_next_subbuf(int fd
)
155 return ioctl(fd
, RING_BUFFER_PUT_NEXT_SUBBUF
);
160 /* Get a snapshot of the current ring buffer producer and consumer positions */
161 int kernctl_snapshot(int fd
)
163 return ioctl(fd
, RING_BUFFER_SNAPSHOT
);
166 /* Get the consumer position (iteration start) */
167 int kernctl_snapshot_get_consumed(int fd
, unsigned long *pos
)
169 return ioctl(fd
, RING_BUFFER_SNAPSHOT_GET_CONSUMED
, pos
);
172 /* Get the producer position (iteration end) */
173 int kernctl_snapshot_get_produced(int fd
, unsigned long *pos
)
175 return ioctl(fd
, RING_BUFFER_SNAPSHOT_GET_PRODUCED
, pos
);
178 /* Get exclusive read access to the specified sub-buffer position */
179 int kernctl_get_subbuf(int fd
, unsigned long *len
)
181 return ioctl(fd
, RING_BUFFER_GET_SUBBUF
, len
);
184 /* Release exclusive sub-buffer access */
185 int kernctl_put_subbuf(int fd
)
187 return ioctl(fd
, RING_BUFFER_PUT_SUBBUF
);