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 <lttng-kernel-ctl.h>
24 #include "kernel-ioctl.h"
26 int kernctl_create_session(int fd
)
28 return ioctl(fd
, LTTNG_KERNEL_SESSION
);
31 /* open the metadata global channel */
32 int kernctl_open_metadata(int fd
, struct lttng_channel_attr
*chops
)
34 return ioctl(fd
, LTTNG_KERNEL_METADATA
, chops
);
37 int kernctl_create_channel(int fd
, struct lttng_channel_attr
*chops
)
39 return ioctl(fd
, LTTNG_KERNEL_CHANNEL
, chops
);
42 int kernctl_create_stream(int fd
)
44 return ioctl(fd
, LTTNG_KERNEL_STREAM
);
47 int kernctl_create_event(int fd
, struct lttng_kernel_event
*ev
)
49 return ioctl(fd
, LTTNG_KERNEL_EVENT
, ev
);
52 int kernctl_add_context(int fd
, struct lttng_kernel_context
*ctx
)
54 return ioctl(fd
, LTTNG_KERNEL_CONTEXT
, ctx
);
58 /* Enable event, channel and session ioctl */
59 int kernctl_enable(int fd
)
61 return ioctl(fd
, LTTNG_KERNEL_ENABLE
);
64 /* Disable event, channel and session ioctl */
65 int kernctl_disable(int fd
)
67 return ioctl(fd
, LTTNG_KERNEL_DISABLE
);
70 int kernctl_start_session(int fd
)
72 return ioctl(fd
, LTTNG_KERNEL_SESSION_START
);
75 int kernctl_stop_session(int fd
)
77 return ioctl(fd
, LTTNG_KERNEL_SESSION_STOP
);
81 int kernctl_tracepoint_list(int fd
)
83 return ioctl(fd
, LTTNG_KERNEL_TRACEPOINT_LIST
);
86 int kernctl_tracer_version(int fd
, struct lttng_kernel_tracer_version
*v
)
88 return ioctl(fd
, LTTNG_KERNEL_TRACER_VERSION
, v
);
91 int kernctl_wait_quiescent(int fd
)
93 return ioctl(fd
, LTTNG_KERNEL_WAIT_QUIESCENT
);
96 int kernctl_calibrate(int fd
, struct lttng_kernel_calibrate
*calibrate
)
98 return ioctl(fd
, LTTNG_KERNEL_CALIBRATE
, calibrate
);
102 int kernctl_buffer_flush(int fd
)
104 return ioctl(fd
, RING_BUFFER_FLUSH
);
108 /* Buffer operations */
110 /* For mmap mode, readable without "get" operation */
112 /* returns the length to mmap. */
113 int kernctl_get_mmap_len(int fd
, unsigned long *len
)
115 return ioctl(fd
, RING_BUFFER_GET_MMAP_LEN
, len
);
118 /* returns the maximum size for sub-buffers. */
119 int kernctl_get_max_subbuf_size(int fd
, unsigned long *len
)
121 return ioctl(fd
, RING_BUFFER_GET_MAX_SUBBUF_SIZE
, len
);
125 * For mmap mode, operate on the current packet (between get/put or
126 * get_next/put_next).
129 /* returns the offset of the subbuffer belonging to the mmap reader. */
130 int kernctl_get_mmap_read_offset(int fd
, unsigned long *off
)
132 return ioctl(fd
, RING_BUFFER_GET_MMAP_READ_OFFSET
, off
);
135 /* returns the size of the current sub-buffer, without padding (for mmap). */
136 int kernctl_get_subbuf_size(int fd
, unsigned long *len
)
138 return ioctl(fd
, RING_BUFFER_GET_SUBBUF_SIZE
, len
);
141 /* returns the size of the current sub-buffer, without padding (for mmap). */
142 int kernctl_get_padded_subbuf_size(int fd
, unsigned long *len
)
144 return ioctl(fd
, RING_BUFFER_GET_PADDED_SUBBUF_SIZE
, len
);
147 /* Get exclusive read access to the next sub-buffer that can be read. */
148 int kernctl_get_next_subbuf(int fd
)
150 return ioctl(fd
, RING_BUFFER_GET_NEXT_SUBBUF
);
154 /* Release exclusive sub-buffer access, move consumer forward. */
155 int kernctl_put_next_subbuf(int fd
)
157 return ioctl(fd
, RING_BUFFER_PUT_NEXT_SUBBUF
);
162 /* Get a snapshot of the current ring buffer producer and consumer positions */
163 int kernctl_snapshot(int fd
)
165 return ioctl(fd
, RING_BUFFER_SNAPSHOT
);
168 /* Get the consumer position (iteration start) */
169 int kernctl_snapshot_get_consumed(int fd
, unsigned long *pos
)
171 return ioctl(fd
, RING_BUFFER_SNAPSHOT_GET_CONSUMED
, pos
);
174 /* Get the producer position (iteration end) */
175 int kernctl_snapshot_get_produced(int fd
, unsigned long *pos
)
177 return ioctl(fd
, RING_BUFFER_SNAPSHOT_GET_PRODUCED
, pos
);
180 /* Get exclusive read access to the specified sub-buffer position */
181 int kernctl_get_subbuf(int fd
, unsigned long *len
)
183 return ioctl(fd
, RING_BUFFER_GET_SUBBUF
, len
);
186 /* Release exclusive sub-buffer access */
187 int kernctl_put_subbuf(int fd
)
189 return ioctl(fd
, RING_BUFFER_PUT_SUBBUF
);