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-ioctl.h"
23 #include "libkernelctl.h"
25 int kernctl_add_context(int fd
, struct lttng_kernel_context
*ctx
)
27 return ioctl(fd
, LTTNG_KERNEL_CONTEXT
, ctx
);
30 int kernctl_buffer_flush(int fd
)
32 return ioctl(fd
, RING_BUFFER_FLUSH
);
35 int kernctl_create_channel(int fd
, struct lttng_channel_attr
*chops
)
37 return ioctl(fd
, LTTNG_KERNEL_CHANNEL
, chops
);
40 int kernctl_create_event(int fd
, struct lttng_kernel_event
*ev
)
42 return ioctl(fd
, LTTNG_KERNEL_EVENT
, ev
);
45 int kernctl_create_session(int fd
)
47 return ioctl(fd
, LTTNG_KERNEL_SESSION
);
50 int kernctl_create_stream(int fd
)
52 return ioctl(fd
, LTTNG_KERNEL_STREAM
);
55 /* Enable event, channel and session ioctl */
56 int kernctl_enable(int fd
)
58 return ioctl(fd
, LTTNG_KERNEL_ENABLE
);
61 /* Disable event, channel and session ioctl */
62 int kernctl_disable(int fd
)
64 return ioctl(fd
, LTTNG_KERNEL_DISABLE
);
67 /* returns the maximum size for sub-buffers. */
68 int kernctl_get_max_subbuf_size(int fd
, unsigned long *len
)
70 return ioctl(fd
, RING_BUFFER_GET_MAX_SUBBUF_SIZE
, len
);
73 /* returns the length to mmap. */
74 int kernctl_get_mmap_len(int fd
, unsigned long *len
)
76 return ioctl(fd
, RING_BUFFER_GET_MMAP_LEN
, len
);
79 /* returns the offset of the subbuffer belonging to the mmap reader. */
80 int kernctl_get_mmap_read_offset(int fd
, unsigned long *off
)
82 return ioctl(fd
, RING_BUFFER_GET_MMAP_READ_OFFSET
, off
);
85 /* Get exclusive read access to the next sub-buffer that can be read. */
86 int kernctl_get_next_subbuf(int fd
)
88 return ioctl(fd
, RING_BUFFER_GET_NEXT_SUBBUF
);
91 /* returns the size of the current sub-buffer, without padding (for mmap). */
92 int kernctl_get_padded_subbuf_size(int fd
, unsigned long *len
)
94 return ioctl(fd
, RING_BUFFER_GET_PADDED_SUBBUF_SIZE
, len
);
97 /* Get exclusive read access to the specified sub-buffer position */
98 int kernctl_get_subbuf(int fd
, unsigned long *len
)
100 return ioctl(fd
, RING_BUFFER_GET_SUBBUF
, len
);
103 /* returns the size of the current sub-buffer, without padding (for mmap). */
104 int kernctl_get_subbuf_size(int fd
, unsigned long *len
)
106 return ioctl(fd
, RING_BUFFER_GET_SUBBUF_SIZE
, len
);
109 /* open the metadata global channel */
110 int kernctl_open_metadata(int fd
, struct lttng_channel_attr
*chops
)
112 return ioctl(fd
, LTTNG_KERNEL_METADATA
, chops
);
115 /* Release exclusive sub-buffer access, move consumer forward. */
116 int kernctl_put_next_subbuf(int fd
)
118 return ioctl(fd
, RING_BUFFER_PUT_NEXT_SUBBUF
);
121 /* Release exclusive sub-buffer access */
122 int kernctl_put_subbuf(int fd
)
124 return ioctl(fd
, RING_BUFFER_PUT_SUBBUF
);
127 /* Get a snapshot of the current ring buffer producer and consumer positions */
128 int kernctl_snapshot(int fd
)
130 return ioctl(fd
, RING_BUFFER_SNAPSHOT
);
133 /* Get the consumer position (iteration start) */
134 int kernctl_snapshot_get_consumed(int fd
, unsigned long *pos
)
136 return ioctl(fd
, RING_BUFFER_SNAPSHOT_GET_CONSUMED
, pos
);
139 /* Get the producer position (iteration end) */
140 int kernctl_snapshot_get_produced(int fd
, unsigned long *pos
)
142 return ioctl(fd
, RING_BUFFER_SNAPSHOT_GET_PRODUCED
, pos
);
145 int kernctl_start_session(int fd
)
147 return ioctl(fd
, LTTNG_KERNEL_SESSION_START
);
150 int kernctl_stop_session(int fd
)
152 return ioctl(fd
, LTTNG_KERNEL_SESSION_STOP
);
155 int kernctl_tracepoint_list(int fd
)
157 return ioctl(fd
, LTTNG_KERNEL_TRACEPOINT_LIST
);
160 int kernctl_tracer_version(int fd
, struct lttng_kernel_tracer_version
*v
)
162 return ioctl(fd
, LTTNG_KERNEL_TRACER_VERSION
, v
);
165 int kernctl_wait_quiescent(int fd
)
167 return ioctl(fd
, LTTNG_KERNEL_WAIT_QUIESCENT
);
170 int kernctl_calibrate(int fd
, struct lttng_kernel_calibrate
*calibrate
)
172 return ioctl(fd
, LTTNG_KERNEL_CALIBRATE
, calibrate
);