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
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; only version 2
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.
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.
20 #include <sys/ioctl.h>
22 #include "kernel-ctl.h"
23 #include "kernel-ioctl.h"
25 int kernctl_create_session(int fd
)
27 return ioctl(fd
, LTTNG_KERNEL_SESSION
);
30 /* open the metadata global channel */
31 int kernctl_open_metadata(int fd
, struct lttng_channel_attr
*chops
)
33 return ioctl(fd
, LTTNG_KERNEL_METADATA
, chops
);
36 int kernctl_create_channel(int fd
, struct lttng_channel_attr
*chops
)
38 return ioctl(fd
, LTTNG_KERNEL_CHANNEL
, chops
);
41 int kernctl_create_stream(int fd
)
43 return ioctl(fd
, LTTNG_KERNEL_STREAM
);
46 int kernctl_create_event(int fd
, struct lttng_kernel_event
*ev
)
48 return ioctl(fd
, LTTNG_KERNEL_EVENT
, ev
);
51 int kernctl_add_context(int fd
, struct lttng_kernel_context
*ctx
)
53 return ioctl(fd
, LTTNG_KERNEL_CONTEXT
, ctx
);
57 /* Enable event, channel and session ioctl */
58 int kernctl_enable(int fd
)
60 return ioctl(fd
, LTTNG_KERNEL_ENABLE
);
63 /* Disable event, channel and session ioctl */
64 int kernctl_disable(int fd
)
66 return ioctl(fd
, LTTNG_KERNEL_DISABLE
);
69 int kernctl_start_session(int fd
)
71 return ioctl(fd
, LTTNG_KERNEL_SESSION_START
);
74 int kernctl_stop_session(int fd
)
76 return ioctl(fd
, LTTNG_KERNEL_SESSION_STOP
);
80 int kernctl_tracepoint_list(int fd
)
82 return ioctl(fd
, LTTNG_KERNEL_TRACEPOINT_LIST
);
85 int kernctl_tracer_version(int fd
, struct lttng_kernel_tracer_version
*v
)
87 return ioctl(fd
, LTTNG_KERNEL_TRACER_VERSION
, v
);
90 int kernctl_wait_quiescent(int fd
)
92 return ioctl(fd
, LTTNG_KERNEL_WAIT_QUIESCENT
);
95 int kernctl_calibrate(int fd
, struct lttng_kernel_calibrate
*calibrate
)
97 return ioctl(fd
, LTTNG_KERNEL_CALIBRATE
, calibrate
);
101 int kernctl_buffer_flush(int fd
)
103 return ioctl(fd
, RING_BUFFER_FLUSH
);
107 /* Buffer operations */
109 /* For mmap mode, readable without "get" operation */
111 /* returns the length to mmap. */
112 int kernctl_get_mmap_len(int fd
, unsigned long *len
)
114 return ioctl(fd
, RING_BUFFER_GET_MMAP_LEN
, len
);
117 /* returns the maximum size for sub-buffers. */
118 int kernctl_get_max_subbuf_size(int fd
, unsigned long *len
)
120 return ioctl(fd
, RING_BUFFER_GET_MAX_SUBBUF_SIZE
, len
);
124 * For mmap mode, operate on the current packet (between get/put or
125 * get_next/put_next).
128 /* returns the offset of the subbuffer belonging to the mmap reader. */
129 int kernctl_get_mmap_read_offset(int fd
, unsigned long *off
)
131 return ioctl(fd
, RING_BUFFER_GET_MMAP_READ_OFFSET
, off
);
134 /* returns the size of the current sub-buffer, without padding (for mmap). */
135 int kernctl_get_subbuf_size(int fd
, unsigned long *len
)
137 return ioctl(fd
, RING_BUFFER_GET_SUBBUF_SIZE
, len
);
140 /* returns the size of the current sub-buffer, without padding (for mmap). */
141 int kernctl_get_padded_subbuf_size(int fd
, unsigned long *len
)
143 return ioctl(fd
, RING_BUFFER_GET_PADDED_SUBBUF_SIZE
, len
);
146 /* Get exclusive read access to the next sub-buffer that can be read. */
147 int kernctl_get_next_subbuf(int fd
)
149 return ioctl(fd
, RING_BUFFER_GET_NEXT_SUBBUF
);
153 /* Release exclusive sub-buffer access, move consumer forward. */
154 int kernctl_put_next_subbuf(int fd
)
156 return ioctl(fd
, RING_BUFFER_PUT_NEXT_SUBBUF
);
161 /* Get a snapshot of the current ring buffer producer and consumer positions */
162 int kernctl_snapshot(int fd
)
164 return ioctl(fd
, RING_BUFFER_SNAPSHOT
);
167 /* Get the consumer position (iteration start) */
168 int kernctl_snapshot_get_consumed(int fd
, unsigned long *pos
)
170 return ioctl(fd
, RING_BUFFER_SNAPSHOT_GET_CONSUMED
, pos
);
173 /* Get the producer position (iteration end) */
174 int kernctl_snapshot_get_produced(int fd
, unsigned long *pos
)
176 return ioctl(fd
, RING_BUFFER_SNAPSHOT_GET_PRODUCED
, pos
);
179 /* Get exclusive read access to the specified sub-buffer position */
180 int kernctl_get_subbuf(int fd
, unsigned long *len
)
182 return ioctl(fd
, RING_BUFFER_GET_SUBBUF
, len
);
185 /* Release exclusive sub-buffer access */
186 int kernctl_put_subbuf(int fd
)
188 return ioctl(fd
, RING_BUFFER_PUT_SUBBUF
);