| 1 | /* |
| 2 | * Copyright (C) 2011 EfficiOS Inc. |
| 3 | * Copyright (C) 2011-2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0-only |
| 6 | * |
| 7 | */ |
| 8 | |
| 9 | #ifndef LTTNG_UST_CTL_INTERNAL_H |
| 10 | #define LTTNG_UST_CTL_INTERNAL_H |
| 11 | |
| 12 | #include "lttng-ust-abi.hpp" |
| 13 | |
| 14 | #include <common/macros.hpp> |
| 15 | |
| 16 | #include <limits.h> |
| 17 | #include <sys/types.h> |
| 18 | |
| 19 | #ifndef LTTNG_UST_UUID_LEN |
| 20 | #define LTTNG_UST_UUID_LEN 16 |
| 21 | #endif |
| 22 | |
| 23 | /* Default unix socket path */ |
| 24 | #define LTTNG_UST_SOCK_FILENAME \ |
| 25 | "lttng-ust-sock-" lttng_ust_stringify(LTTNG_UST_ABI_MAJOR_VERSION_OLDEST_COMPATIBLE) |
| 26 | |
| 27 | /* |
| 28 | * Shared memory files path are automatically related to shm root, e.g. |
| 29 | * /dev/shm under linux. |
| 30 | */ |
| 31 | #define LTTNG_UST_WAIT_FILENAME \ |
| 32 | "lttng-ust-wait-" lttng_ust_stringify(LTTNG_UST_ABI_MAJOR_VERSION_OLDEST_COMPATIBLE) |
| 33 | |
| 34 | struct lttng_ust_ctl_consumer_channel_attr { |
| 35 | enum lttng_ust_abi_chan_type type; |
| 36 | uint64_t subbuf_size; /* bytes */ |
| 37 | uint64_t num_subbuf; /* power of 2 */ |
| 38 | int overwrite; /* 1: overwrite, 0: discard */ |
| 39 | unsigned int switch_timer_interval; /* usec */ |
| 40 | unsigned int read_timer_interval; /* usec */ |
| 41 | enum lttng_ust_abi_output output; /* splice, mmap */ |
| 42 | uint32_t chan_id; /* channel ID */ |
| 43 | unsigned char uuid[LTTNG_UST_UUID_LEN]; /* Trace session unique ID */ |
| 44 | int64_t blocking_timeout; /* Blocking timeout (usec) */ |
| 45 | } LTTNG_PACKED; |
| 46 | |
| 47 | /* |
| 48 | * API used by sessiond. |
| 49 | */ |
| 50 | |
| 51 | struct lttng_ust_context_attr { |
| 52 | enum lttng_ust_abi_context_type ctx; |
| 53 | union { |
| 54 | struct lttng_ust_abi_perf_counter_ctx perf_counter; |
| 55 | struct { |
| 56 | char *provider_name; |
| 57 | char *ctx_name; |
| 58 | } app_ctx; |
| 59 | } u; |
| 60 | }; |
| 61 | |
| 62 | /* |
| 63 | * Error values: all the following functions return: |
| 64 | * >= 0: Success (LTTNG_UST_OK) |
| 65 | * < 0: error code. |
| 66 | */ |
| 67 | int lttng_ust_ctl_register_done(int sock); |
| 68 | int lttng_ust_ctl_create_session(int sock); |
| 69 | int lttng_ust_ctl_create_event(int sock, |
| 70 | struct lttng_ust_abi_event *ev, |
| 71 | struct lttng_ust_abi_object_data *channel_data, |
| 72 | struct lttng_ust_abi_object_data **event_data); |
| 73 | int lttng_ust_ctl_add_context(int sock, |
| 74 | struct lttng_ust_context_attr *ctx, |
| 75 | struct lttng_ust_abi_object_data *obj_data, |
| 76 | struct lttng_ust_abi_object_data **context_data); |
| 77 | int lttng_ust_ctl_set_filter(int sock, |
| 78 | struct lttng_ust_abi_filter_bytecode *bytecode, |
| 79 | struct lttng_ust_abi_object_data *obj_data); |
| 80 | int lttng_ust_ctl_set_capture(int sock, |
| 81 | struct lttng_ust_abi_capture_bytecode *bytecode, |
| 82 | struct lttng_ust_abi_object_data *obj_data); |
| 83 | int lttng_ust_ctl_set_exclusion(int sock, |
| 84 | struct lttng_ust_abi_event_exclusion *exclusion, |
| 85 | struct lttng_ust_abi_object_data *obj_data); |
| 86 | |
| 87 | int lttng_ust_ctl_enable(int sock, struct lttng_ust_abi_object_data *object); |
| 88 | int lttng_ust_ctl_disable(int sock, struct lttng_ust_abi_object_data *object); |
| 89 | int lttng_ust_ctl_start_session(int sock, int handle); |
| 90 | int lttng_ust_ctl_stop_session(int sock, int handle); |
| 91 | |
| 92 | /* |
| 93 | * lttng_ust_ctl_create_event notifier_group creates a event notifier group. It |
| 94 | * establishes the connection with the application by providing a file |
| 95 | * descriptor of the pipe to be used by the application when a event notifier |
| 96 | * of that group is fired. It returns a handle to be used when creating event |
| 97 | * notifier in that group. |
| 98 | */ |
| 99 | int lttng_ust_ctl_create_event_notifier_group( |
| 100 | int sock, int pipe_fd, struct lttng_ust_abi_object_data **event_notifier_group); |
| 101 | |
| 102 | /* |
| 103 | * lttng_ust_ctl_create_event notifier creates a event notifier in a event notifier |
| 104 | * group giving a event notifier description and a event notifier group handle. |
| 105 | * It returns a event notifier handle to be used when enabling the event |
| 106 | * notifier, attaching filter, attaching exclusion, and disabling the event |
| 107 | * notifier. |
| 108 | */ |
| 109 | int lttng_ust_ctl_create_event_notifier(int sock, |
| 110 | struct lttng_ust_abi_event_notifier *event_notifier, |
| 111 | struct lttng_ust_abi_object_data *event_notifier_group, |
| 112 | struct lttng_ust_abi_object_data **event_notifier_data); |
| 113 | |
| 114 | /* |
| 115 | * lttng_ust_ctl_tracepoint_list returns a tracepoint list handle, or negative |
| 116 | * error value. |
| 117 | */ |
| 118 | int lttng_ust_ctl_tracepoint_list(int sock); |
| 119 | |
| 120 | /* |
| 121 | * lttng_ust_ctl_tracepoint_list_get is used to iterate on the tp list |
| 122 | * handle. End is iteration is reached when -LTTNG_UST_ERR_NOENT is |
| 123 | * returned. |
| 124 | */ |
| 125 | int lttng_ust_ctl_tracepoint_list_get(int sock, |
| 126 | int tp_list_handle, |
| 127 | struct lttng_ust_abi_tracepoint_iter *iter); |
| 128 | |
| 129 | /* |
| 130 | * lttng_ust_ctl_tracepoint_field_list returns a tracepoint field list handle, |
| 131 | * or negative error value. |
| 132 | */ |
| 133 | int lttng_ust_ctl_tracepoint_field_list(int sock); |
| 134 | |
| 135 | /* |
| 136 | * lttng_ust_ctl_tracepoint_field_list_get is used to iterate on the tp field |
| 137 | * list handle. End is iteration is reached when -LTTNG_UST_ERR_NOENT is |
| 138 | * returned. |
| 139 | */ |
| 140 | int lttng_ust_ctl_tracepoint_field_list_get(int sock, |
| 141 | int tp_field_list_handle, |
| 142 | struct lttng_ust_abi_field_iter *iter); |
| 143 | |
| 144 | int lttng_ust_ctl_tracer_version(int sock, struct lttng_ust_abi_tracer_version *v); |
| 145 | int lttng_ust_ctl_wait_quiescent(int sock); |
| 146 | |
| 147 | int lttng_ust_ctl_sock_flush_buffer(int sock, struct lttng_ust_abi_object_data *object); |
| 148 | |
| 149 | int lttng_ust_ctl_calibrate(int sock, struct lttng_ust_abi_calibrate *calibrate); |
| 150 | |
| 151 | /* Release object created by members of this API. */ |
| 152 | int lttng_ust_ctl_release_object(int sock, struct lttng_ust_abi_object_data *data); |
| 153 | /* Release handle returned by create session. */ |
| 154 | int lttng_ust_ctl_release_handle(int sock, int handle); |
| 155 | |
| 156 | int lttng_ust_ctl_recv_channel_from_consumer(int sock, |
| 157 | struct lttng_ust_abi_object_data **channel_data); |
| 158 | int lttng_ust_ctl_recv_stream_from_consumer(int sock, |
| 159 | struct lttng_ust_abi_object_data **stream_data); |
| 160 | int lttng_ust_ctl_send_channel_to_ust(int sock, |
| 161 | int session_handle, |
| 162 | struct lttng_ust_abi_object_data *channel_data); |
| 163 | int lttng_ust_ctl_send_stream_to_ust(int sock, |
| 164 | struct lttng_ust_abi_object_data *channel_data, |
| 165 | struct lttng_ust_abi_object_data *stream_data); |
| 166 | |
| 167 | /* |
| 168 | * lttng_ust_ctl_duplicate_ust_object_data allocated a new object in "dest" if |
| 169 | * it succeeds (returns 0). It must be released using |
| 170 | * lttng_ust_ctl_release_object() and then freed with free(). |
| 171 | */ |
| 172 | int lttng_ust_ctl_duplicate_ust_object_data(struct lttng_ust_abi_object_data **dest, |
| 173 | struct lttng_ust_abi_object_data *src); |
| 174 | |
| 175 | /* |
| 176 | * API used by consumer. |
| 177 | */ |
| 178 | |
| 179 | struct lttng_ust_ctl_consumer_channel; |
| 180 | struct lttng_ust_ctl_consumer_stream; |
| 181 | struct lttng_ust_ctl_consumer_channel_attr; |
| 182 | |
| 183 | int lttng_ust_ctl_get_nr_stream_per_channel(); |
| 184 | |
| 185 | struct lttng_ust_ctl_consumer_channel *lttng_ust_ctl_create_channel( |
| 186 | struct lttng_ust_ctl_consumer_channel_attr *attr, const int *stream_fds, int nr_stream_fds); |
| 187 | /* |
| 188 | * Each stream created needs to be destroyed before calling |
| 189 | * lttng_ust_ctl_destroy_channel(). |
| 190 | */ |
| 191 | void lttng_ust_ctl_destroy_channel(struct lttng_ust_ctl_consumer_channel *chan); |
| 192 | |
| 193 | int lttng_ust_ctl_send_channel_to_sessiond(int sock, |
| 194 | struct lttng_ust_ctl_consumer_channel *channel); |
| 195 | int lttng_ust_ctl_channel_close_wait_fd(struct lttng_ust_ctl_consumer_channel *consumer_chan); |
| 196 | int lttng_ust_ctl_channel_close_wakeup_fd(struct lttng_ust_ctl_consumer_channel *consumer_chan); |
| 197 | int lttng_ust_ctl_channel_get_wait_fd(struct lttng_ust_ctl_consumer_channel *consumer_chan); |
| 198 | int lttng_ust_ctl_channel_get_wakeup_fd(struct lttng_ust_ctl_consumer_channel *consumer_chan); |
| 199 | |
| 200 | int lttng_ust_ctl_write_metadata_to_channel(struct lttng_ust_ctl_consumer_channel *channel, |
| 201 | const char *metadata_str, /* NOT null-terminated */ |
| 202 | size_t len); /* metadata length */ |
| 203 | ssize_t lttng_ust_ctl_write_one_packet_to_channel(struct lttng_ust_ctl_consumer_channel *channel, |
| 204 | const char *metadata_str, /* NOT null-terminated |
| 205 | */ |
| 206 | size_t len); /* metadata length */ |
| 207 | |
| 208 | /* |
| 209 | * Send a NULL stream to finish iteration over all streams of a given |
| 210 | * channel. |
| 211 | */ |
| 212 | int lttng_ust_ctl_send_stream_to_sessiond(int sock, struct lttng_ust_ctl_consumer_stream *stream); |
| 213 | int lttng_ust_ctl_stream_close_wait_fd(struct lttng_ust_ctl_consumer_stream *stream); |
| 214 | int lttng_ust_ctl_stream_close_wakeup_fd(struct lttng_ust_ctl_consumer_stream *stream); |
| 215 | int lttng_ust_ctl_stream_get_wait_fd(struct lttng_ust_ctl_consumer_stream *stream); |
| 216 | int lttng_ust_ctl_stream_get_wakeup_fd(struct lttng_ust_ctl_consumer_stream *stream); |
| 217 | |
| 218 | /* Create/destroy stream buffers for read */ |
| 219 | struct lttng_ust_ctl_consumer_stream * |
| 220 | lttng_ust_ctl_create_stream(struct lttng_ust_ctl_consumer_channel *channel, int cpu); |
| 221 | void lttng_ust_ctl_destroy_stream(struct lttng_ust_ctl_consumer_stream *stream); |
| 222 | |
| 223 | /* For mmap mode, readable without "get" operation */ |
| 224 | int lttng_ust_ctl_get_mmap_len(struct lttng_ust_ctl_consumer_stream *stream, unsigned long *len); |
| 225 | int lttng_ust_ctl_get_max_subbuf_size(struct lttng_ust_ctl_consumer_stream *stream, |
| 226 | unsigned long *len); |
| 227 | |
| 228 | /* |
| 229 | * For mmap mode, operate on the current packet (between get/put or |
| 230 | * get_next/put_next). |
| 231 | */ |
| 232 | void *lttng_ust_ctl_get_mmap_base(struct lttng_ust_ctl_consumer_stream *stream); |
| 233 | int lttng_ust_ctl_get_mmap_read_offset(struct lttng_ust_ctl_consumer_stream *stream, |
| 234 | unsigned long *off); |
| 235 | int lttng_ust_ctl_get_subbuf_size(struct lttng_ust_ctl_consumer_stream *stream, unsigned long *len); |
| 236 | int lttng_ust_ctl_get_padded_subbuf_size(struct lttng_ust_ctl_consumer_stream *stream, |
| 237 | unsigned long *len); |
| 238 | int lttng_ust_ctl_get_next_subbuf(struct lttng_ust_ctl_consumer_stream *stream); |
| 239 | int lttng_ust_ctl_put_next_subbuf(struct lttng_ust_ctl_consumer_stream *stream); |
| 240 | |
| 241 | /* snapshot */ |
| 242 | |
| 243 | int lttng_ust_ctl_snapshot(struct lttng_ust_ctl_consumer_stream *stream); |
| 244 | int lttng_ust_ctl_snapshot_sample_positions(struct lttng_ust_ctl_consumer_stream *stream); |
| 245 | int lttng_ust_ctl_snapshot_get_consumed(struct lttng_ust_ctl_consumer_stream *stream, |
| 246 | unsigned long *pos); |
| 247 | int lttng_ust_ctl_snapshot_get_produced(struct lttng_ust_ctl_consumer_stream *stream, |
| 248 | unsigned long *pos); |
| 249 | int lttng_ust_ctl_get_subbuf(struct lttng_ust_ctl_consumer_stream *stream, unsigned long *pos); |
| 250 | int lttng_ust_ctl_put_subbuf(struct lttng_ust_ctl_consumer_stream *stream); |
| 251 | |
| 252 | int lttng_ust_ctl_flush_buffer(struct lttng_ust_ctl_consumer_stream *stream, int producer_active); |
| 253 | int lttng_ust_ctl_clear_buffer(struct lttng_ust_ctl_consumer_stream *stream); |
| 254 | |
| 255 | /* index */ |
| 256 | |
| 257 | /* |
| 258 | * Getters which need to be used on the current packet (between get/put |
| 259 | * or get_next/put_next. |
| 260 | */ |
| 261 | |
| 262 | int lttng_ust_ctl_get_timestamp_begin(struct lttng_ust_ctl_consumer_stream *stream, |
| 263 | uint64_t *timestamp_begin); |
| 264 | int lttng_ust_ctl_get_timestamp_end(struct lttng_ust_ctl_consumer_stream *stream, |
| 265 | uint64_t *timestamp_end); |
| 266 | int lttng_ust_ctl_get_events_discarded(struct lttng_ust_ctl_consumer_stream *stream, |
| 267 | uint64_t *events_discarded); |
| 268 | int lttng_ust_ctl_get_content_size(struct lttng_ust_ctl_consumer_stream *stream, |
| 269 | uint64_t *content_size); |
| 270 | int lttng_ust_ctl_get_packet_size(struct lttng_ust_ctl_consumer_stream *stream, |
| 271 | uint64_t *packet_size); |
| 272 | int lttng_ust_ctl_get_sequence_number(struct lttng_ust_ctl_consumer_stream *stream, uint64_t *seq); |
| 273 | |
| 274 | /* |
| 275 | * Getter returning state invariant for the stream, which can be used |
| 276 | * without "get" operation. |
| 277 | */ |
| 278 | |
| 279 | int lttng_ust_ctl_get_stream_id(struct lttng_ust_ctl_consumer_stream *stream, uint64_t *stream_id); |
| 280 | int lttng_ust_ctl_get_instance_id(struct lttng_ust_ctl_consumer_stream *stream, uint64_t *id); |
| 281 | |
| 282 | /* |
| 283 | * Getter returning the current timestamp as perceived from the |
| 284 | * tracer. |
| 285 | */ |
| 286 | int lttng_ust_ctl_get_current_timestamp(struct lttng_ust_ctl_consumer_stream *stream, uint64_t *ts); |
| 287 | |
| 288 | /* returns whether UST has perf counters support. */ |
| 289 | int lttng_ust_ctl_has_perf_counters(); |
| 290 | |
| 291 | /* Regenerate the statedump. */ |
| 292 | int lttng_ust_ctl_regenerate_statedump(int sock, int handle); |
| 293 | |
| 294 | /* event registry management */ |
| 295 | |
| 296 | enum lttng_ust_ctl_socket_type { |
| 297 | LTTNG_UST_CTL_SOCKET_CMD = 0, |
| 298 | LTTNG_UST_CTL_SOCKET_NOTIFY = 1, |
| 299 | }; |
| 300 | |
| 301 | enum lttng_ust_ctl_notify_cmd { |
| 302 | LTTNG_UST_CTL_NOTIFY_CMD_EVENT = 0, |
| 303 | LTTNG_UST_CTL_NOTIFY_CMD_CHANNEL = 1, |
| 304 | LTTNG_UST_CTL_NOTIFY_CMD_ENUM = 2, |
| 305 | LTTNG_UST_CTL_NOTIFY_CMD_KEY = 3, |
| 306 | }; |
| 307 | |
| 308 | enum lttng_ust_ctl_channel_header { |
| 309 | LTTNG_UST_CTL_CHANNEL_HEADER_UNKNOWN = 0, |
| 310 | LTTNG_UST_CTL_CHANNEL_HEADER_COMPACT = 1, |
| 311 | LTTNG_UST_CTL_CHANNEL_HEADER_LARGE = 2, |
| 312 | }; |
| 313 | |
| 314 | /* event type structures */ |
| 315 | |
| 316 | enum lttng_ust_ctl_abstract_types { |
| 317 | lttng_ust_ctl_atype_integer, |
| 318 | lttng_ust_ctl_atype_enum, /* legacy */ |
| 319 | lttng_ust_ctl_atype_array, /* legacy */ |
| 320 | lttng_ust_ctl_atype_sequence, /* legacy */ |
| 321 | lttng_ust_ctl_atype_string, |
| 322 | lttng_ust_ctl_atype_float, |
| 323 | lttng_ust_ctl_atype_variant, /* legacy */ |
| 324 | lttng_ust_ctl_atype_struct, /* legacy */ |
| 325 | lttng_ust_ctl_atype_enum_nestable, |
| 326 | lttng_ust_ctl_atype_array_nestable, |
| 327 | lttng_ust_ctl_atype_sequence_nestable, |
| 328 | lttng_ust_ctl_atype_struct_nestable, |
| 329 | lttng_ust_ctl_atype_variant_nestable, |
| 330 | NR_LTTNG_UST_CTL_ABSTRACT_TYPES, |
| 331 | }; |
| 332 | |
| 333 | enum lttng_ust_ctl_string_encodings { |
| 334 | lttng_ust_ctl_encode_none = 0, |
| 335 | lttng_ust_ctl_encode_UTF8 = 1, |
| 336 | lttng_ust_ctl_encode_ASCII = 2, |
| 337 | NR_LTTNG_UST_CTL_STRING_ENCODINGS, |
| 338 | }; |
| 339 | |
| 340 | #define LTTNG_UST_CTL_UST_INTEGER_TYPE_PADDING 24 |
| 341 | struct lttng_ust_ctl_integer_type { |
| 342 | uint32_t size; /* in bits */ |
| 343 | uint32_t signedness; |
| 344 | uint32_t reverse_byte_order; |
| 345 | uint32_t base; /* 2, 8, 10, 16, for pretty print */ |
| 346 | int32_t encoding; /* enum lttng_ust_ctl_string_encodings */ |
| 347 | uint16_t alignment; /* in bits */ |
| 348 | char padding[LTTNG_UST_CTL_UST_INTEGER_TYPE_PADDING]; |
| 349 | } LTTNG_PACKED; |
| 350 | |
| 351 | #define LTTNG_UST_CTL_UST_FLOAT_TYPE_PADDING 24 |
| 352 | struct lttng_ust_ctl_float_type { |
| 353 | uint32_t exp_dig; /* exponent digits, in bits */ |
| 354 | uint32_t mant_dig; /* mantissa digits, in bits */ |
| 355 | uint32_t reverse_byte_order; |
| 356 | uint16_t alignment; /* in bits */ |
| 357 | char padding[LTTNG_UST_CTL_UST_FLOAT_TYPE_PADDING]; |
| 358 | } LTTNG_PACKED; |
| 359 | |
| 360 | #define LTTNG_UST_CTL_UST_ENUM_VALUE_PADDING 15 |
| 361 | struct lttng_ust_ctl_enum_value { |
| 362 | uint64_t value; |
| 363 | uint8_t signedness; |
| 364 | char padding[LTTNG_UST_CTL_UST_ENUM_VALUE_PADDING]; |
| 365 | } LTTNG_PACKED; |
| 366 | |
| 367 | enum lttng_ust_ctl_ust_enum_entry_options { |
| 368 | LTTNG_UST_CTL_UST_ENUM_ENTRY_OPTION_IS_AUTO = 1U << 0, |
| 369 | }; |
| 370 | |
| 371 | #define LTTNG_UST_CTL_UST_ENUM_ENTRY_PADDING 32 |
| 372 | struct lttng_ust_ctl_enum_entry { |
| 373 | struct lttng_ust_ctl_enum_value start, end; /* start and end are inclusive */ |
| 374 | char string[LTTNG_UST_ABI_SYM_NAME_LEN]; |
| 375 | union { |
| 376 | struct { |
| 377 | uint32_t options; |
| 378 | } LTTNG_PACKED extra; |
| 379 | char padding[LTTNG_UST_CTL_UST_ENUM_ENTRY_PADDING]; |
| 380 | } u; |
| 381 | } LTTNG_PACKED; |
| 382 | |
| 383 | /* legacy */ |
| 384 | #define LTTNG_UST_CTL_UST_BASIC_TYPE_PADDING 296 |
| 385 | union _lttng_ust_ctl_basic_type { |
| 386 | struct lttng_ust_ctl_integer_type integer; |
| 387 | struct { |
| 388 | char name[LTTNG_UST_ABI_SYM_NAME_LEN]; |
| 389 | struct lttng_ust_ctl_integer_type container_type; |
| 390 | uint64_t id; /* enum ID in sessiond. */ |
| 391 | } enumeration; |
| 392 | struct { |
| 393 | int32_t encoding; /* enum lttng_ust_ctl_string_encodings */ |
| 394 | } string; |
| 395 | struct lttng_ust_ctl_float_type _float; |
| 396 | char padding[LTTNG_UST_CTL_UST_BASIC_TYPE_PADDING]; |
| 397 | } LTTNG_PACKED; |
| 398 | |
| 399 | /* legacy */ |
| 400 | struct lttng_ust_ctl_basic_type { |
| 401 | enum lttng_ust_ctl_abstract_types atype; |
| 402 | union { |
| 403 | union _lttng_ust_ctl_basic_type basic; |
| 404 | } u; |
| 405 | } LTTNG_PACKED; |
| 406 | |
| 407 | /* |
| 408 | * Padding is derived from largest member: u.legacy.sequence which |
| 409 | * contains two basic types, each with LTTNG_UST_CTL_UST_BASIC_TYPE_PADDING. |
| 410 | */ |
| 411 | #define LTTNG_UST_CTL_UST_TYPE_PADDING (2 * LTTNG_UST_CTL_UST_BASIC_TYPE_PADDING) |
| 412 | struct lttng_ust_ctl_type { |
| 413 | enum lttng_ust_ctl_abstract_types atype; |
| 414 | union { |
| 415 | struct lttng_ust_ctl_integer_type integer; |
| 416 | struct lttng_ust_ctl_float_type _float; |
| 417 | struct { |
| 418 | int32_t encoding; /* enum lttng_ust_ctl_string_encodings */ |
| 419 | } string; |
| 420 | struct { |
| 421 | char name[LTTNG_UST_ABI_SYM_NAME_LEN]; |
| 422 | uint64_t id; /* enum ID in sessiond. */ |
| 423 | /* container_type follows after this struct lttng_ust_ctl_field. */ |
| 424 | } enum_nestable; |
| 425 | struct { |
| 426 | uint32_t length; /* num. elems. */ |
| 427 | uint32_t alignment; |
| 428 | /* elem_type follows after this struct lttng_ust_ctl_field. */ |
| 429 | } array_nestable; |
| 430 | struct { |
| 431 | char length_name[LTTNG_UST_ABI_SYM_NAME_LEN]; |
| 432 | uint32_t alignment; /* Alignment before elements. */ |
| 433 | /* elem_type follows after the length_type. */ |
| 434 | } sequence_nestable; |
| 435 | struct { |
| 436 | uint32_t nr_fields; |
| 437 | uint32_t alignment; |
| 438 | /* Followed by nr_fields struct lttng_ust_ctl_field. */ |
| 439 | } struct_nestable; |
| 440 | struct { |
| 441 | uint32_t nr_choices; |
| 442 | char tag_name[LTTNG_UST_ABI_SYM_NAME_LEN]; |
| 443 | uint32_t alignment; |
| 444 | /* Followed by nr_choices struct lttng_ust_ctl_field. */ |
| 445 | } variant_nestable; |
| 446 | |
| 447 | /* Legacy ABI */ |
| 448 | union { |
| 449 | union _lttng_ust_ctl_basic_type basic; |
| 450 | struct { |
| 451 | struct lttng_ust_ctl_basic_type elem_type; |
| 452 | uint32_t length; /* num. elems. */ |
| 453 | } array; |
| 454 | struct { |
| 455 | struct lttng_ust_ctl_basic_type length_type; |
| 456 | struct lttng_ust_ctl_basic_type elem_type; |
| 457 | } sequence; |
| 458 | struct { |
| 459 | uint32_t nr_fields; |
| 460 | /* Followed by nr_fields struct lttng_ust_ctl_field. */ |
| 461 | } _struct; |
| 462 | struct { |
| 463 | uint32_t nr_choices; |
| 464 | char tag_name[LTTNG_UST_ABI_SYM_NAME_LEN]; |
| 465 | /* Followed by nr_choices struct lttng_ust_ctl_field. */ |
| 466 | } variant; |
| 467 | } legacy; |
| 468 | char padding[LTTNG_UST_CTL_UST_TYPE_PADDING]; |
| 469 | } u; |
| 470 | } LTTNG_PACKED; |
| 471 | |
| 472 | #define LTTNG_UST_CTL_UST_FIELD_PADDING 28 |
| 473 | struct lttng_ust_ctl_field { |
| 474 | char name[LTTNG_UST_ABI_SYM_NAME_LEN]; |
| 475 | struct lttng_ust_ctl_type type; |
| 476 | char padding[LTTNG_UST_CTL_UST_FIELD_PADDING]; |
| 477 | } LTTNG_PACKED; |
| 478 | |
| 479 | /* |
| 480 | * Returns 0 on success, negative error value on error. |
| 481 | * If an error other than -LTTNG_UST_ERR_UNSUP_MAJOR is returned, |
| 482 | * the output fields are not populated. |
| 483 | */ |
| 484 | int lttng_ust_ctl_recv_reg_msg(int sock, |
| 485 | enum lttng_ust_ctl_socket_type *type, |
| 486 | uint32_t *major, |
| 487 | uint32_t *minor, |
| 488 | uint32_t *pid, |
| 489 | uint32_t *ppid, |
| 490 | uint32_t *uid, |
| 491 | uint32_t *gid, |
| 492 | uint32_t *bits_per_long, |
| 493 | uint32_t *uint8_t_alignment, |
| 494 | uint32_t *uint16_t_alignment, |
| 495 | uint32_t *uint32_t_alignment, |
| 496 | uint32_t *uint64_t_alignment, |
| 497 | uint32_t *long_alignment, |
| 498 | int *byte_order, |
| 499 | char *name); /* size LTTNG_UST_ABI_PROCNAME_LEN */ |
| 500 | |
| 501 | /* |
| 502 | * Returns 0 on success, negative UST or system error value on error. |
| 503 | * Receive the notification command. The "notify_cmd" can then be used |
| 504 | * by the caller to find out which lttng_ust_ctl_recv_* function should be |
| 505 | * called to receive the notification, and which lttng_ust_ctl_reply_* is |
| 506 | * appropriate. |
| 507 | */ |
| 508 | int lttng_ust_ctl_recv_notify(int sock, enum lttng_ust_ctl_notify_cmd *notify_cmd); |
| 509 | |
| 510 | /* |
| 511 | * Returns 0 on success, negative UST or system error value on error. |
| 512 | */ |
| 513 | int lttng_ust_ctl_recv_register_event(int sock, |
| 514 | int *session_objd, /* session descriptor (output) */ |
| 515 | int *channel_objd, /* channel descriptor (output) */ |
| 516 | char *event_name, /* |
| 517 | * event name (output, |
| 518 | * size LTTNG_UST_ABI_SYM_NAME_LEN) |
| 519 | */ |
| 520 | int *loglevel, |
| 521 | char **signature, /* |
| 522 | * event signature |
| 523 | * (output, dynamically |
| 524 | * allocated, must be free(3)'d |
| 525 | * by the caller if function |
| 526 | * returns success.) |
| 527 | */ |
| 528 | size_t *nr_fields, |
| 529 | struct lttng_ust_ctl_field **fields, |
| 530 | char **model_emf_uri, |
| 531 | uint64_t *user_token); |
| 532 | |
| 533 | /* |
| 534 | * Returns 0 on success, negative error value on error. |
| 535 | */ |
| 536 | int lttng_ust_ctl_reply_register_event(int sock, |
| 537 | uint32_t id, /* id (input) */ |
| 538 | int ret_code); /* return code. 0 ok, negative error */ |
| 539 | |
| 540 | /* |
| 541 | * Returns 0 on success, negative UST or system error value on error. |
| 542 | */ |
| 543 | int lttng_ust_ctl_recv_register_key(int sock, |
| 544 | int *session_objd, /* session descriptor (output) */ |
| 545 | int *map_objd, /* map descriptor (output) */ |
| 546 | uint32_t *dimension, /* |
| 547 | * Against which dimension is |
| 548 | * this key expressed. (output) |
| 549 | */ |
| 550 | uint64_t **dimension_indexes, /* |
| 551 | * Indexes (output, |
| 552 | * dynamically |
| 553 | * allocated, must be |
| 554 | * free(3)'d by the |
| 555 | * caller if function |
| 556 | * returns success.) |
| 557 | * Contains @dimension |
| 558 | * elements. |
| 559 | */ |
| 560 | char **key_string, /* |
| 561 | * key string (output, |
| 562 | * dynamically allocated, must |
| 563 | * be free(3)'d by the caller if |
| 564 | * function returns success.) |
| 565 | */ |
| 566 | uint64_t *user_token); |
| 567 | |
| 568 | /* |
| 569 | * Returns 0 on success, negative error value on error. |
| 570 | */ |
| 571 | int lttng_ust_ctl_reply_register_key(int sock, |
| 572 | uint64_t index, /* Index within dimension (input) */ |
| 573 | int ret_code); /* return code. 0 ok, negative error */ |
| 574 | |
| 575 | /* |
| 576 | * Returns 0 on success, negative UST or system error value on error. |
| 577 | */ |
| 578 | int lttng_ust_ctl_recv_register_enum(int sock, |
| 579 | int *session_objd, |
| 580 | char *enum_name, |
| 581 | struct lttng_ust_ctl_enum_entry **entries, |
| 582 | size_t *nr_entries); |
| 583 | |
| 584 | /* |
| 585 | * Returns 0 on success, negative error value on error. |
| 586 | */ |
| 587 | int lttng_ust_ctl_reply_register_enum(int sock, |
| 588 | uint64_t id, /* enum id (input) */ |
| 589 | int ret_code); |
| 590 | |
| 591 | /* |
| 592 | * Returns 0 on success, negative UST or system error value on error. |
| 593 | */ |
| 594 | int lttng_ust_ctl_recv_register_channel(int sock, |
| 595 | int *session_objd, /* session descriptor (output) */ |
| 596 | int *channel_objd, /* channel descriptor (output) */ |
| 597 | size_t *nr_fields, /* context fields */ |
| 598 | struct lttng_ust_ctl_field **fields); |
| 599 | |
| 600 | /* |
| 601 | * Returns 0 on success, negative error value on error. |
| 602 | */ |
| 603 | int lttng_ust_ctl_reply_register_channel(int sock, |
| 604 | uint32_t chan_id, |
| 605 | enum lttng_ust_ctl_channel_header header_type, |
| 606 | int ret_code); /* return code. 0 ok, negative error */ |
| 607 | |
| 608 | /* |
| 609 | * Counter API. |
| 610 | */ |
| 611 | |
| 612 | enum lttng_ust_ctl_counter_bitness { |
| 613 | LTTNG_UST_CTL_COUNTER_BITNESS_32 = 0, |
| 614 | LTTNG_UST_CTL_COUNTER_BITNESS_64 = 1, |
| 615 | }; |
| 616 | |
| 617 | enum lttng_ust_ctl_counter_arithmetic { |
| 618 | LTTNG_UST_CTL_COUNTER_ARITHMETIC_MODULAR = 0, |
| 619 | LTTNG_UST_CTL_COUNTER_ARITHMETIC_SATURATION = 1, |
| 620 | }; |
| 621 | |
| 622 | enum lttng_ust_ctl_key_type { |
| 623 | LTTNG_UST_CTL_KEY_TYPE_TOKENS = 0, |
| 624 | LTTNG_UST_CTL_KEY_TYPE_INTEGER = 1, |
| 625 | }; |
| 626 | |
| 627 | /* Used as alloc flags. */ |
| 628 | enum lttng_ust_ctl_counter_alloc { |
| 629 | LTTNG_UST_CTL_COUNTER_ALLOC_PER_CPU = (1 << 0), |
| 630 | LTTNG_UST_CTL_COUNTER_ALLOC_GLOBAL = (1 << 1), |
| 631 | }; |
| 632 | |
| 633 | struct lttng_ust_ctl_daemon_counter; |
| 634 | |
| 635 | int lttng_ust_ctl_get_nr_cpu_per_counter(); |
| 636 | |
| 637 | struct lttng_ust_ctl_counter_dimension { |
| 638 | uint64_t size; |
| 639 | uint64_t underflow_index; |
| 640 | uint64_t overflow_index; |
| 641 | enum lttng_ust_ctl_key_type key_type; |
| 642 | uint8_t has_underflow; |
| 643 | uint8_t has_overflow; |
| 644 | }; |
| 645 | |
| 646 | struct lttng_ust_ctl_daemon_counter * |
| 647 | lttng_ust_ctl_create_counter(size_t nr_dimensions, |
| 648 | const struct lttng_ust_ctl_counter_dimension *dimensions, |
| 649 | int64_t global_sum_step, |
| 650 | int global_counter_fd, |
| 651 | int nr_counter_cpu_fds, |
| 652 | const int *counter_cpu_fds, |
| 653 | enum lttng_ust_ctl_counter_bitness bitness, |
| 654 | enum lttng_ust_ctl_counter_arithmetic arithmetic, |
| 655 | uint32_t alloc_flags, |
| 656 | bool coalesce_hits); |
| 657 | |
| 658 | int lttng_ust_ctl_create_counter_data(struct lttng_ust_ctl_daemon_counter *counter, |
| 659 | struct lttng_ust_abi_object_data **counter_data); |
| 660 | |
| 661 | int lttng_ust_ctl_create_counter_global_data(struct lttng_ust_ctl_daemon_counter *counter, |
| 662 | struct lttng_ust_abi_object_data **counter_global_data); |
| 663 | int lttng_ust_ctl_create_counter_cpu_data(struct lttng_ust_ctl_daemon_counter *counter, |
| 664 | int cpu, |
| 665 | struct lttng_ust_abi_object_data **counter_cpu_data); |
| 666 | |
| 667 | /* |
| 668 | * Each counter data and counter cpu data created need to be destroyed |
| 669 | * before calling lttng_ust_ctl_destroy_counter(). |
| 670 | */ |
| 671 | void lttng_ust_ctl_destroy_counter(struct lttng_ust_ctl_daemon_counter *counter); |
| 672 | |
| 673 | int lttng_ust_ctl_send_counter_data_to_ust(int sock, |
| 674 | int parent_handle, |
| 675 | struct lttng_ust_abi_object_data *counter_data); |
| 676 | int lttng_ust_ctl_send_counter_global_data_to_ust( |
| 677 | int sock, |
| 678 | struct lttng_ust_abi_object_data *counter_data, |
| 679 | struct lttng_ust_abi_object_data *counter_global_data); |
| 680 | int lttng_ust_ctl_send_counter_cpu_data_to_ust(int sock, |
| 681 | struct lttng_ust_abi_object_data *counter_data, |
| 682 | struct lttng_ust_abi_object_data *counter_cpu_data); |
| 683 | |
| 684 | int lttng_ust_ctl_counter_read(struct lttng_ust_ctl_daemon_counter *counter, |
| 685 | const size_t *dimension_indexes, |
| 686 | int cpu, |
| 687 | int64_t *value, |
| 688 | bool *overflow, |
| 689 | bool *underflow); |
| 690 | int lttng_ust_ctl_counter_aggregate(struct lttng_ust_ctl_daemon_counter *counter, |
| 691 | const size_t *dimension_indexes, |
| 692 | int64_t *value, |
| 693 | bool *overflow, |
| 694 | bool *underflow); |
| 695 | int lttng_ust_ctl_counter_clear(struct lttng_ust_ctl_daemon_counter *counter, |
| 696 | const size_t *dimension_indexes); |
| 697 | |
| 698 | int lttng_ust_ctl_counter_create_event(int sock, |
| 699 | struct lttng_ust_abi_counter_event *counter_event, |
| 700 | size_t counter_event_len, |
| 701 | struct lttng_ust_abi_object_data *counter_data, |
| 702 | struct lttng_ust_abi_object_data **counter_event_data); |
| 703 | |
| 704 | void lttng_ust_ctl_sigbus_handle(void *addr); |
| 705 | |
| 706 | int lttng_ust_ctl_get_version(uint32_t *major, uint32_t *minor, uint32_t *patchlevel); |
| 707 | |
| 708 | #endif /* LTTNG_UST_CTL_INTERNAL_H */ |