| 1 | /* |
| 2 | * Copyright (C) 2011 - Julien Desfossez <julien.desfossez@polymtl.ca> |
| 3 | * Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 4 | * |
| 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 |
| 8 | * of the License. |
| 9 | * |
| 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. |
| 14 | * |
| 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. |
| 18 | */ |
| 19 | |
| 20 | #include <sys/ioctl.h> |
| 21 | |
| 22 | #include "kernel-ioctl.h" |
| 23 | #include "libkernelctl.h" |
| 24 | |
| 25 | int kernctl_add_context(int fd, struct lttng_kernel_context *ctx) |
| 26 | { |
| 27 | return ioctl(fd, LTTNG_KERNEL_CONTEXT, ctx); |
| 28 | } |
| 29 | |
| 30 | int kernctl_buffer_flush(int fd) |
| 31 | { |
| 32 | return ioctl(fd, RING_BUFFER_FLUSH); |
| 33 | } |
| 34 | |
| 35 | int kernctl_create_channel(int fd, struct lttng_channel_attr *chops) |
| 36 | { |
| 37 | return ioctl(fd, LTTNG_KERNEL_CHANNEL, chops); |
| 38 | } |
| 39 | |
| 40 | int kernctl_create_event(int fd, struct lttng_kernel_event *ev) |
| 41 | { |
| 42 | return ioctl(fd, LTTNG_KERNEL_EVENT, ev); |
| 43 | } |
| 44 | |
| 45 | int kernctl_create_session(int fd) |
| 46 | { |
| 47 | return ioctl(fd, LTTNG_KERNEL_SESSION); |
| 48 | } |
| 49 | |
| 50 | int kernctl_create_stream(int fd) |
| 51 | { |
| 52 | return ioctl(fd, LTTNG_KERNEL_STREAM); |
| 53 | } |
| 54 | |
| 55 | /* Enable event, channel and session ioctl */ |
| 56 | int kernctl_enable(int fd) |
| 57 | { |
| 58 | return ioctl(fd, LTTNG_KERNEL_ENABLE); |
| 59 | } |
| 60 | |
| 61 | /* Disable event, channel and session ioctl */ |
| 62 | int kernctl_disable(int fd) |
| 63 | { |
| 64 | return ioctl(fd, LTTNG_KERNEL_DISABLE); |
| 65 | } |
| 66 | |
| 67 | /* returns the maximum size for sub-buffers. */ |
| 68 | int kernctl_get_max_subbuf_size(int fd, unsigned long *len) |
| 69 | { |
| 70 | return ioctl(fd, RING_BUFFER_GET_MAX_SUBBUF_SIZE, len); |
| 71 | } |
| 72 | |
| 73 | /* returns the length to mmap. */ |
| 74 | int kernctl_get_mmap_len(int fd, unsigned long *len) |
| 75 | { |
| 76 | return ioctl(fd, RING_BUFFER_GET_MMAP_LEN, len); |
| 77 | } |
| 78 | |
| 79 | /* returns the offset of the subbuffer belonging to the mmap reader. */ |
| 80 | int kernctl_get_mmap_read_offset(int fd, unsigned long *off) |
| 81 | { |
| 82 | return ioctl(fd, RING_BUFFER_GET_MMAP_READ_OFFSET, off); |
| 83 | } |
| 84 | |
| 85 | /* Get exclusive read access to the next sub-buffer that can be read. */ |
| 86 | int kernctl_get_next_subbuf(int fd) |
| 87 | { |
| 88 | return ioctl(fd, RING_BUFFER_GET_NEXT_SUBBUF); |
| 89 | } |
| 90 | |
| 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) |
| 93 | { |
| 94 | return ioctl(fd, RING_BUFFER_GET_PADDED_SUBBUF_SIZE, len); |
| 95 | } |
| 96 | |
| 97 | /* Get exclusive read access to the specified sub-buffer position */ |
| 98 | int kernctl_get_subbuf(int fd, unsigned long *len) |
| 99 | { |
| 100 | return ioctl(fd, RING_BUFFER_GET_SUBBUF, len); |
| 101 | } |
| 102 | |
| 103 | /* returns the size of the current sub-buffer, without padding (for mmap). */ |
| 104 | int kernctl_get_subbuf_size(int fd, unsigned long *len) |
| 105 | { |
| 106 | return ioctl(fd, RING_BUFFER_GET_SUBBUF_SIZE, len); |
| 107 | } |
| 108 | |
| 109 | /* open the metadata global channel */ |
| 110 | int kernctl_open_metadata(int fd, struct lttng_channel_attr *chops) |
| 111 | { |
| 112 | return ioctl(fd, LTTNG_KERNEL_METADATA, chops); |
| 113 | } |
| 114 | |
| 115 | /* Release exclusive sub-buffer access, move consumer forward. */ |
| 116 | int kernctl_put_next_subbuf(int fd) |
| 117 | { |
| 118 | return ioctl(fd, RING_BUFFER_PUT_NEXT_SUBBUF); |
| 119 | } |
| 120 | |
| 121 | /* Release exclusive sub-buffer access */ |
| 122 | int kernctl_put_subbuf(int fd) |
| 123 | { |
| 124 | return ioctl(fd, RING_BUFFER_PUT_SUBBUF); |
| 125 | } |
| 126 | |
| 127 | /* Get a snapshot of the current ring buffer producer and consumer positions */ |
| 128 | int kernctl_snapshot(int fd) |
| 129 | { |
| 130 | return ioctl(fd, RING_BUFFER_SNAPSHOT); |
| 131 | } |
| 132 | |
| 133 | /* Get the consumer position (iteration start) */ |
| 134 | int kernctl_snapshot_get_consumed(int fd, unsigned long *pos) |
| 135 | { |
| 136 | return ioctl(fd, RING_BUFFER_SNAPSHOT_GET_CONSUMED, pos); |
| 137 | } |
| 138 | |
| 139 | /* Get the producer position (iteration end) */ |
| 140 | int kernctl_snapshot_get_produced(int fd, unsigned long *pos) |
| 141 | { |
| 142 | return ioctl(fd, RING_BUFFER_SNAPSHOT_GET_PRODUCED, pos); |
| 143 | } |
| 144 | |
| 145 | int kernctl_start_session(int fd) |
| 146 | { |
| 147 | return ioctl(fd, LTTNG_KERNEL_SESSION_START); |
| 148 | } |
| 149 | |
| 150 | int kernctl_stop_session(int fd) |
| 151 | { |
| 152 | return ioctl(fd, LTTNG_KERNEL_SESSION_STOP); |
| 153 | } |
| 154 | |
| 155 | int kernctl_tracepoint_list(int fd) |
| 156 | { |
| 157 | return ioctl(fd, LTTNG_KERNEL_TRACEPOINT_LIST); |
| 158 | } |
| 159 | |
| 160 | int kernctl_tracer_version(int fd, struct lttng_kernel_tracer_version *v) |
| 161 | { |
| 162 | return ioctl(fd, LTTNG_KERNEL_TRACER_VERSION, v); |
| 163 | } |
| 164 | |
| 165 | int kernctl_wait_quiescent(int fd) |
| 166 | { |
| 167 | return ioctl(fd, LTTNG_KERNEL_WAIT_QUIESCENT); |
| 168 | } |