| 1 | /* |
| 2 | * SPDX-License-Identifier: GPL-2.0-only |
| 3 | * |
| 4 | * Copyright (C) 2011 Julien Desfossez <julien.desfossez@polymtl.ca> |
| 5 | * Copyright (C) 2011-2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 6 | */ |
| 7 | |
| 8 | #ifndef _LTTNG_UST_CTL_H |
| 9 | #define _LTTNG_UST_CTL_H |
| 10 | |
| 11 | #include <limits.h> |
| 12 | #include <stddef.h> |
| 13 | #include <stdint.h> |
| 14 | #include <stdbool.h> |
| 15 | #include <sys/types.h> |
| 16 | |
| 17 | #include <lttng/ust-abi.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-" \ |
| 26 | __ust_stringify(LTTNG_UST_ABI_MAJOR_VERSION) |
| 27 | |
| 28 | /* |
| 29 | * Shared memory files path are automatically related to shm root, e.g. |
| 30 | * /dev/shm under linux. |
| 31 | */ |
| 32 | #define LTTNG_UST_WAIT_FILENAME \ |
| 33 | "lttng-ust-wait-" \ |
| 34 | __ust_stringify(LTTNG_UST_ABI_MAJOR_VERSION) |
| 35 | |
| 36 | struct lttng_ust_shm_handle; |
| 37 | struct lttng_ust_lib_ring_buffer; |
| 38 | |
| 39 | struct ustctl_consumer_channel_attr { |
| 40 | enum lttng_ust_abi_chan_type type; |
| 41 | uint64_t subbuf_size; /* bytes */ |
| 42 | uint64_t num_subbuf; /* power of 2 */ |
| 43 | int overwrite; /* 1: overwrite, 0: discard */ |
| 44 | unsigned int switch_timer_interval; /* usec */ |
| 45 | unsigned int read_timer_interval; /* usec */ |
| 46 | enum lttng_ust_abi_output output; /* splice, mmap */ |
| 47 | uint32_t chan_id; /* channel ID */ |
| 48 | unsigned char uuid[LTTNG_UST_UUID_LEN]; /* Trace session unique ID */ |
| 49 | int64_t blocking_timeout; /* Blocking timeout (usec) */ |
| 50 | } __attribute__((packed)); |
| 51 | |
| 52 | /* |
| 53 | * API used by sessiond. |
| 54 | */ |
| 55 | |
| 56 | struct lttng_ust_context_attr { |
| 57 | enum lttng_ust_abi_context_type ctx; |
| 58 | union { |
| 59 | struct lttng_ust_abi_perf_counter_ctx perf_counter; |
| 60 | struct { |
| 61 | char *provider_name; |
| 62 | char *ctx_name; |
| 63 | } app_ctx; |
| 64 | } u; |
| 65 | }; |
| 66 | |
| 67 | /* |
| 68 | * Error values: all the following functions return: |
| 69 | * >= 0: Success (LTTNG_UST_OK) |
| 70 | * < 0: error code. |
| 71 | */ |
| 72 | int ustctl_register_done(int sock); |
| 73 | int ustctl_create_session(int sock); |
| 74 | int ustctl_create_event(int sock, struct lttng_ust_abi_event *ev, |
| 75 | struct lttng_ust_abi_object_data *channel_data, |
| 76 | struct lttng_ust_abi_object_data **event_data); |
| 77 | int ustctl_add_context(int sock, struct lttng_ust_context_attr *ctx, |
| 78 | struct lttng_ust_abi_object_data *obj_data, |
| 79 | struct lttng_ust_abi_object_data **context_data); |
| 80 | int ustctl_set_filter(int sock, struct lttng_ust_abi_filter_bytecode *bytecode, |
| 81 | struct lttng_ust_abi_object_data *obj_data); |
| 82 | int ustctl_set_capture(int sock, struct lttng_ust_abi_capture_bytecode *bytecode, |
| 83 | struct lttng_ust_abi_object_data *obj_data); |
| 84 | int ustctl_set_exclusion(int sock, struct lttng_ust_abi_event_exclusion *exclusion, |
| 85 | struct lttng_ust_abi_object_data *obj_data); |
| 86 | |
| 87 | int ustctl_enable(int sock, struct lttng_ust_abi_object_data *object); |
| 88 | int ustctl_disable(int sock, struct lttng_ust_abi_object_data *object); |
| 89 | int ustctl_start_session(int sock, int handle); |
| 90 | int ustctl_stop_session(int sock, int handle); |
| 91 | |
| 92 | /* |
| 93 | * ustctl_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 ustctl_create_event_notifier_group(int sock, int pipe_fd, |
| 100 | struct lttng_ust_abi_object_data **event_notifier_group); |
| 101 | |
| 102 | /* |
| 103 | * ustctl_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 ustctl_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 | * ustctl_tracepoint_list returns a tracepoint list handle, or negative |
| 116 | * error value. |
| 117 | */ |
| 118 | int ustctl_tracepoint_list(int sock); |
| 119 | |
| 120 | /* |
| 121 | * ustctl_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 ustctl_tracepoint_list_get(int sock, int tp_list_handle, |
| 126 | struct lttng_ust_abi_tracepoint_iter *iter); |
| 127 | |
| 128 | /* |
| 129 | * ustctl_tracepoint_field_list returns a tracepoint field list handle, |
| 130 | * or negative error value. |
| 131 | */ |
| 132 | int ustctl_tracepoint_field_list(int sock); |
| 133 | |
| 134 | /* |
| 135 | * ustctl_tracepoint_field_list_get is used to iterate on the tp field |
| 136 | * list handle. End is iteration is reached when -LTTNG_UST_ERR_NOENT is |
| 137 | * returned. |
| 138 | */ |
| 139 | int ustctl_tracepoint_field_list_get(int sock, int tp_field_list_handle, |
| 140 | struct lttng_ust_abi_field_iter *iter); |
| 141 | |
| 142 | int ustctl_tracer_version(int sock, struct lttng_ust_abi_tracer_version *v); |
| 143 | int ustctl_wait_quiescent(int sock); |
| 144 | |
| 145 | int ustctl_sock_flush_buffer(int sock, struct lttng_ust_abi_object_data *object); |
| 146 | |
| 147 | int ustctl_calibrate(int sock, struct lttng_ust_abi_calibrate *calibrate); |
| 148 | |
| 149 | /* Release object created by members of this API. */ |
| 150 | int ustctl_release_object(int sock, struct lttng_ust_abi_object_data *data); |
| 151 | /* Release handle returned by create session. */ |
| 152 | int ustctl_release_handle(int sock, int handle); |
| 153 | |
| 154 | int ustctl_recv_channel_from_consumer(int sock, |
| 155 | struct lttng_ust_abi_object_data **channel_data); |
| 156 | int ustctl_recv_stream_from_consumer(int sock, |
| 157 | struct lttng_ust_abi_object_data **stream_data); |
| 158 | int ustctl_send_channel_to_ust(int sock, int session_handle, |
| 159 | struct lttng_ust_abi_object_data *channel_data); |
| 160 | int ustctl_send_stream_to_ust(int sock, |
| 161 | struct lttng_ust_abi_object_data *channel_data, |
| 162 | struct lttng_ust_abi_object_data *stream_data); |
| 163 | |
| 164 | /* |
| 165 | * ustctl_duplicate_ust_object_data allocated a new object in "dest" if |
| 166 | * it succeeds (returns 0). It must be released using |
| 167 | * ustctl_release_object() and then freed with free(). |
| 168 | */ |
| 169 | int ustctl_duplicate_ust_object_data(struct lttng_ust_abi_object_data **dest, |
| 170 | struct lttng_ust_abi_object_data *src); |
| 171 | |
| 172 | /* |
| 173 | * API used by consumer. |
| 174 | */ |
| 175 | |
| 176 | struct ustctl_consumer_channel; |
| 177 | struct ustctl_consumer_stream; |
| 178 | struct ustctl_consumer_channel_attr; |
| 179 | |
| 180 | int ustctl_get_nr_stream_per_channel(void); |
| 181 | |
| 182 | struct ustctl_consumer_channel * |
| 183 | ustctl_create_channel(struct ustctl_consumer_channel_attr *attr, |
| 184 | const int *stream_fds, int nr_stream_fds); |
| 185 | /* |
| 186 | * Each stream created needs to be destroyed before calling |
| 187 | * ustctl_destroy_channel(). |
| 188 | */ |
| 189 | void ustctl_destroy_channel(struct ustctl_consumer_channel *chan); |
| 190 | |
| 191 | int ustctl_send_channel_to_sessiond(int sock, |
| 192 | struct ustctl_consumer_channel *channel); |
| 193 | int ustctl_channel_close_wait_fd(struct ustctl_consumer_channel *consumer_chan); |
| 194 | int ustctl_channel_close_wakeup_fd(struct ustctl_consumer_channel *consumer_chan); |
| 195 | int ustctl_channel_get_wait_fd(struct ustctl_consumer_channel *consumer_chan); |
| 196 | int ustctl_channel_get_wakeup_fd(struct ustctl_consumer_channel *consumer_chan); |
| 197 | |
| 198 | int ustctl_write_metadata_to_channel( |
| 199 | struct ustctl_consumer_channel *channel, |
| 200 | const char *metadata_str, /* NOT null-terminated */ |
| 201 | size_t len); /* metadata length */ |
| 202 | ssize_t ustctl_write_one_packet_to_channel( |
| 203 | struct ustctl_consumer_channel *channel, |
| 204 | const char *metadata_str, /* NOT null-terminated */ |
| 205 | size_t len); /* metadata length */ |
| 206 | |
| 207 | /* |
| 208 | * Send a NULL stream to finish iteration over all streams of a given |
| 209 | * channel. |
| 210 | */ |
| 211 | int ustctl_send_stream_to_sessiond(int sock, |
| 212 | struct ustctl_consumer_stream *stream); |
| 213 | int ustctl_stream_close_wait_fd(struct ustctl_consumer_stream *stream); |
| 214 | int ustctl_stream_close_wakeup_fd(struct ustctl_consumer_stream *stream); |
| 215 | int ustctl_stream_get_wait_fd(struct ustctl_consumer_stream *stream); |
| 216 | int ustctl_stream_get_wakeup_fd(struct ustctl_consumer_stream *stream); |
| 217 | |
| 218 | /* Create/destroy stream buffers for read */ |
| 219 | struct ustctl_consumer_stream * |
| 220 | ustctl_create_stream(struct ustctl_consumer_channel *channel, |
| 221 | int cpu); |
| 222 | void ustctl_destroy_stream(struct ustctl_consumer_stream *stream); |
| 223 | |
| 224 | /* For mmap mode, readable without "get" operation */ |
| 225 | int ustctl_get_mmap_len(struct ustctl_consumer_stream *stream, |
| 226 | unsigned long *len); |
| 227 | int ustctl_get_max_subbuf_size(struct ustctl_consumer_stream *stream, |
| 228 | unsigned long *len); |
| 229 | |
| 230 | /* |
| 231 | * For mmap mode, operate on the current packet (between get/put or |
| 232 | * get_next/put_next). |
| 233 | */ |
| 234 | void *ustctl_get_mmap_base(struct ustctl_consumer_stream *stream); |
| 235 | int ustctl_get_mmap_read_offset(struct ustctl_consumer_stream *stream, |
| 236 | unsigned long *off); |
| 237 | int ustctl_get_subbuf_size(struct ustctl_consumer_stream *stream, |
| 238 | unsigned long *len); |
| 239 | int ustctl_get_padded_subbuf_size(struct ustctl_consumer_stream *stream, |
| 240 | unsigned long *len); |
| 241 | int ustctl_get_next_subbuf(struct ustctl_consumer_stream *stream); |
| 242 | int ustctl_put_next_subbuf(struct ustctl_consumer_stream *stream); |
| 243 | |
| 244 | /* snapshot */ |
| 245 | |
| 246 | int ustctl_snapshot(struct ustctl_consumer_stream *stream); |
| 247 | int ustctl_snapshot_sample_positions(struct ustctl_consumer_stream *stream); |
| 248 | int ustctl_snapshot_get_consumed(struct ustctl_consumer_stream *stream, |
| 249 | unsigned long *pos); |
| 250 | int ustctl_snapshot_get_produced(struct ustctl_consumer_stream *stream, |
| 251 | unsigned long *pos); |
| 252 | int ustctl_get_subbuf(struct ustctl_consumer_stream *stream, |
| 253 | unsigned long *pos); |
| 254 | int ustctl_put_subbuf(struct ustctl_consumer_stream *stream); |
| 255 | |
| 256 | void ustctl_flush_buffer(struct ustctl_consumer_stream *stream, |
| 257 | int producer_active); |
| 258 | void ustctl_clear_buffer(struct ustctl_consumer_stream *stream); |
| 259 | |
| 260 | /* index */ |
| 261 | |
| 262 | /* |
| 263 | * Getters which need to be used on the current packet (between get/put |
| 264 | * or get_next/put_next. |
| 265 | */ |
| 266 | |
| 267 | int ustctl_get_timestamp_begin(struct ustctl_consumer_stream *stream, |
| 268 | uint64_t *timestamp_begin); |
| 269 | int ustctl_get_timestamp_end(struct ustctl_consumer_stream *stream, |
| 270 | uint64_t *timestamp_end); |
| 271 | int ustctl_get_events_discarded(struct ustctl_consumer_stream *stream, |
| 272 | uint64_t *events_discarded); |
| 273 | int ustctl_get_content_size(struct ustctl_consumer_stream *stream, |
| 274 | uint64_t *content_size); |
| 275 | int ustctl_get_packet_size(struct ustctl_consumer_stream *stream, |
| 276 | uint64_t *packet_size); |
| 277 | int ustctl_get_sequence_number(struct ustctl_consumer_stream *stream, |
| 278 | uint64_t *seq); |
| 279 | |
| 280 | /* |
| 281 | * Getter returning state invariant for the stream, which can be used |
| 282 | * without "get" operation. |
| 283 | */ |
| 284 | |
| 285 | int ustctl_get_stream_id(struct ustctl_consumer_stream *stream, |
| 286 | uint64_t *stream_id); |
| 287 | int ustctl_get_instance_id(struct ustctl_consumer_stream *stream, |
| 288 | uint64_t *id); |
| 289 | |
| 290 | /* |
| 291 | * Getter returning the current timestamp as perceived from the |
| 292 | * tracer. |
| 293 | */ |
| 294 | int ustctl_get_current_timestamp(struct ustctl_consumer_stream *stream, |
| 295 | uint64_t *ts); |
| 296 | |
| 297 | /* returns whether UST has perf counters support. */ |
| 298 | int ustctl_has_perf_counters(void); |
| 299 | |
| 300 | /* Regenerate the statedump. */ |
| 301 | int ustctl_regenerate_statedump(int sock, int handle); |
| 302 | |
| 303 | /* event registry management */ |
| 304 | |
| 305 | enum ustctl_socket_type { |
| 306 | USTCTL_SOCKET_CMD = 0, |
| 307 | USTCTL_SOCKET_NOTIFY = 1, |
| 308 | }; |
| 309 | |
| 310 | enum ustctl_notify_cmd { |
| 311 | USTCTL_NOTIFY_CMD_EVENT = 0, |
| 312 | USTCTL_NOTIFY_CMD_CHANNEL = 1, |
| 313 | USTCTL_NOTIFY_CMD_ENUM = 2, |
| 314 | }; |
| 315 | |
| 316 | enum ustctl_channel_header { |
| 317 | USTCTL_CHANNEL_HEADER_UNKNOWN = 0, |
| 318 | USTCTL_CHANNEL_HEADER_COMPACT = 1, |
| 319 | USTCTL_CHANNEL_HEADER_LARGE = 2, |
| 320 | }; |
| 321 | |
| 322 | /* event type structures */ |
| 323 | |
| 324 | enum ustctl_abstract_types { |
| 325 | ustctl_atype_integer, |
| 326 | ustctl_atype_enum, /* legacy */ |
| 327 | ustctl_atype_array, /* legacy */ |
| 328 | ustctl_atype_sequence, /* legacy */ |
| 329 | ustctl_atype_string, |
| 330 | ustctl_atype_float, |
| 331 | ustctl_atype_variant, /* legacy */ |
| 332 | ustctl_atype_struct, /* legacy */ |
| 333 | ustctl_atype_enum_nestable, |
| 334 | ustctl_atype_array_nestable, |
| 335 | ustctl_atype_sequence_nestable, |
| 336 | ustctl_atype_struct_nestable, |
| 337 | ustctl_atype_variant_nestable, |
| 338 | NR_USTCTL_ABSTRACT_TYPES, |
| 339 | }; |
| 340 | |
| 341 | enum ustctl_string_encodings { |
| 342 | ustctl_encode_none = 0, |
| 343 | ustctl_encode_UTF8 = 1, |
| 344 | ustctl_encode_ASCII = 2, |
| 345 | NR_USTCTL_STRING_ENCODINGS, |
| 346 | }; |
| 347 | |
| 348 | #define USTCTL_UST_INTEGER_TYPE_PADDING 24 |
| 349 | struct ustctl_integer_type { |
| 350 | uint32_t size; /* in bits */ |
| 351 | uint32_t signedness; |
| 352 | uint32_t reverse_byte_order; |
| 353 | uint32_t base; /* 2, 8, 10, 16, for pretty print */ |
| 354 | int32_t encoding; /* enum ustctl_string_encodings */ |
| 355 | uint16_t alignment; /* in bits */ |
| 356 | char padding[USTCTL_UST_INTEGER_TYPE_PADDING]; |
| 357 | } __attribute__((packed)); |
| 358 | |
| 359 | #define USTCTL_UST_FLOAT_TYPE_PADDING 24 |
| 360 | struct ustctl_float_type { |
| 361 | uint32_t exp_dig; /* exponent digits, in bits */ |
| 362 | uint32_t mant_dig; /* mantissa digits, in bits */ |
| 363 | uint32_t reverse_byte_order; |
| 364 | uint16_t alignment; /* in bits */ |
| 365 | char padding[USTCTL_UST_FLOAT_TYPE_PADDING]; |
| 366 | } __attribute__((packed)); |
| 367 | |
| 368 | #define USTCTL_UST_ENUM_VALUE_PADDING 15 |
| 369 | struct ustctl_enum_value { |
| 370 | uint64_t value; |
| 371 | uint8_t signedness; |
| 372 | char padding[USTCTL_UST_ENUM_VALUE_PADDING]; |
| 373 | } __attribute__((packed)); |
| 374 | |
| 375 | enum ustctl_ust_enum_entry_options { |
| 376 | USTCTL_UST_ENUM_ENTRY_OPTION_IS_AUTO = 1U << 0, |
| 377 | }; |
| 378 | |
| 379 | #define USTCTL_UST_ENUM_ENTRY_PADDING 32 |
| 380 | struct ustctl_enum_entry { |
| 381 | struct ustctl_enum_value start, end; /* start and end are inclusive */ |
| 382 | char string[LTTNG_UST_ABI_SYM_NAME_LEN]; |
| 383 | union { |
| 384 | struct { |
| 385 | uint32_t options; |
| 386 | } __attribute__((packed)) extra; |
| 387 | char padding[USTCTL_UST_ENUM_ENTRY_PADDING]; |
| 388 | } u; |
| 389 | } __attribute__((packed)); |
| 390 | |
| 391 | /* legacy */ |
| 392 | #define USTCTL_UST_BASIC_TYPE_PADDING 296 |
| 393 | union _ustctl_basic_type { |
| 394 | struct ustctl_integer_type integer; |
| 395 | struct { |
| 396 | char name[LTTNG_UST_ABI_SYM_NAME_LEN]; |
| 397 | struct ustctl_integer_type container_type; |
| 398 | uint64_t id; /* enum ID in sessiond. */ |
| 399 | } enumeration; |
| 400 | struct { |
| 401 | int32_t encoding; /* enum ustctl_string_encodings */ |
| 402 | } string; |
| 403 | struct ustctl_float_type _float; |
| 404 | char padding[USTCTL_UST_BASIC_TYPE_PADDING]; |
| 405 | } __attribute__((packed)); |
| 406 | |
| 407 | /* legacy */ |
| 408 | struct ustctl_basic_type { |
| 409 | enum ustctl_abstract_types atype; |
| 410 | union { |
| 411 | union _ustctl_basic_type basic; |
| 412 | } u; |
| 413 | } __attribute__((packed)); |
| 414 | |
| 415 | /* |
| 416 | * Padding is derived from largest member: u.legacy.sequence which |
| 417 | * contains two basic types, each with USTCTL_UST_BASIC_TYPE_PADDING. |
| 418 | */ |
| 419 | #define USTCTL_UST_TYPE_PADDING (2 * USTCTL_UST_BASIC_TYPE_PADDING) |
| 420 | struct ustctl_type { |
| 421 | enum ustctl_abstract_types atype; |
| 422 | union { |
| 423 | struct ustctl_integer_type integer; |
| 424 | struct ustctl_float_type _float; |
| 425 | struct { |
| 426 | int32_t encoding; /* enum ustctl_string_encodings */ |
| 427 | } string; |
| 428 | struct { |
| 429 | char name[LTTNG_UST_ABI_SYM_NAME_LEN]; |
| 430 | uint64_t id; /* enum ID in sessiond. */ |
| 431 | /* container_type follows after this struct ustctl_field. */ |
| 432 | } enum_nestable; |
| 433 | struct { |
| 434 | uint32_t length; /* num. elems. */ |
| 435 | uint32_t alignment; |
| 436 | /* elem_type follows after this struct ustctl_field. */ |
| 437 | } array_nestable; |
| 438 | struct { |
| 439 | char length_name[LTTNG_UST_ABI_SYM_NAME_LEN]; |
| 440 | uint32_t alignment; /* Alignment before elements. */ |
| 441 | /* elem_type follows after the length_type. */ |
| 442 | } sequence_nestable; |
| 443 | struct { |
| 444 | uint32_t nr_fields; |
| 445 | uint32_t alignment; |
| 446 | /* Followed by nr_fields struct ustctl_field. */ |
| 447 | } struct_nestable; |
| 448 | struct { |
| 449 | uint32_t nr_choices; |
| 450 | char tag_name[LTTNG_UST_ABI_SYM_NAME_LEN]; |
| 451 | uint32_t alignment; |
| 452 | /* Followed by nr_choices struct ustctl_field. */ |
| 453 | } variant_nestable; |
| 454 | |
| 455 | /* Legacy ABI */ |
| 456 | union { |
| 457 | union _ustctl_basic_type basic; |
| 458 | struct { |
| 459 | struct ustctl_basic_type elem_type; |
| 460 | uint32_t length; /* num. elems. */ |
| 461 | } array; |
| 462 | struct { |
| 463 | struct ustctl_basic_type length_type; |
| 464 | struct ustctl_basic_type elem_type; |
| 465 | } sequence; |
| 466 | struct { |
| 467 | uint32_t nr_fields; |
| 468 | /* Followed by nr_fields struct ustctl_field. */ |
| 469 | } _struct; |
| 470 | struct { |
| 471 | uint32_t nr_choices; |
| 472 | char tag_name[LTTNG_UST_ABI_SYM_NAME_LEN]; |
| 473 | /* Followed by nr_choices struct ustctl_field. */ |
| 474 | } variant; |
| 475 | } legacy; |
| 476 | char padding[USTCTL_UST_TYPE_PADDING]; |
| 477 | } u; |
| 478 | } __attribute__((packed)); |
| 479 | |
| 480 | #define USTCTL_UST_FIELD_PADDING 28 |
| 481 | struct ustctl_field { |
| 482 | char name[LTTNG_UST_ABI_SYM_NAME_LEN]; |
| 483 | struct ustctl_type type; |
| 484 | char padding[USTCTL_UST_FIELD_PADDING]; |
| 485 | } __attribute__((packed)); |
| 486 | |
| 487 | /* |
| 488 | * Returns 0 on success, negative error value on error. |
| 489 | * If an error other than -LTTNG_UST_ERR_UNSUP_MAJOR is returned, |
| 490 | * the output fields are not populated. |
| 491 | */ |
| 492 | int ustctl_recv_reg_msg(int sock, |
| 493 | enum ustctl_socket_type *type, |
| 494 | uint32_t *major, |
| 495 | uint32_t *minor, |
| 496 | uint32_t *pid, |
| 497 | uint32_t *ppid, |
| 498 | uint32_t *uid, |
| 499 | uint32_t *gid, |
| 500 | uint32_t *bits_per_long, |
| 501 | uint32_t *uint8_t_alignment, |
| 502 | uint32_t *uint16_t_alignment, |
| 503 | uint32_t *uint32_t_alignment, |
| 504 | uint32_t *uint64_t_alignment, |
| 505 | uint32_t *long_alignment, |
| 506 | int *byte_order, |
| 507 | char *name); /* size LTTNG_UST_ABI_PROCNAME_LEN */ |
| 508 | |
| 509 | /* |
| 510 | * Returns 0 on success, negative UST or system error value on error. |
| 511 | * Receive the notification command. The "notify_cmd" can then be used |
| 512 | * by the caller to find out which ustctl_recv_* function should be |
| 513 | * called to receive the notification, and which ustctl_reply_* is |
| 514 | * appropriate. |
| 515 | */ |
| 516 | int ustctl_recv_notify(int sock, enum ustctl_notify_cmd *notify_cmd); |
| 517 | |
| 518 | /* |
| 519 | * Returns 0 on success, negative UST or system error value on error. |
| 520 | */ |
| 521 | int ustctl_recv_register_event(int sock, |
| 522 | int *session_objd, /* session descriptor (output) */ |
| 523 | int *channel_objd, /* channel descriptor (output) */ |
| 524 | char *event_name, /* |
| 525 | * event name (output, |
| 526 | * size LTTNG_UST_ABI_SYM_NAME_LEN) |
| 527 | */ |
| 528 | int *loglevel, |
| 529 | char **signature, /* |
| 530 | * event signature |
| 531 | * (output, dynamically |
| 532 | * allocated, must be free(3)'d |
| 533 | * by the caller if function |
| 534 | * returns success.) |
| 535 | */ |
| 536 | size_t *nr_fields, |
| 537 | struct ustctl_field **fields, |
| 538 | char **model_emf_uri); |
| 539 | |
| 540 | /* |
| 541 | * Returns 0 on success, negative error value on error. |
| 542 | */ |
| 543 | int ustctl_reply_register_event(int sock, |
| 544 | uint32_t id, /* event id (input) */ |
| 545 | int ret_code); /* return code. 0 ok, negative error */ |
| 546 | |
| 547 | /* |
| 548 | * Returns 0 on success, negative UST or system error value on error. |
| 549 | */ |
| 550 | int ustctl_recv_register_enum(int sock, |
| 551 | int *session_objd, |
| 552 | char *enum_name, |
| 553 | struct ustctl_enum_entry **entries, |
| 554 | size_t *nr_entries); |
| 555 | |
| 556 | /* |
| 557 | * Returns 0 on success, negative error value on error. |
| 558 | */ |
| 559 | int ustctl_reply_register_enum(int sock, |
| 560 | uint64_t id, /* enum id (input) */ |
| 561 | int ret_code); |
| 562 | |
| 563 | /* |
| 564 | * Returns 0 on success, negative UST or system error value on error. |
| 565 | */ |
| 566 | int ustctl_recv_register_channel(int sock, |
| 567 | int *session_objd, /* session descriptor (output) */ |
| 568 | int *channel_objd, /* channel descriptor (output) */ |
| 569 | size_t *nr_fields, /* context fields */ |
| 570 | struct ustctl_field **fields); |
| 571 | |
| 572 | /* |
| 573 | * Returns 0 on success, negative error value on error. |
| 574 | */ |
| 575 | int ustctl_reply_register_channel(int sock, |
| 576 | uint32_t chan_id, |
| 577 | enum ustctl_channel_header header_type, |
| 578 | int ret_code); /* return code. 0 ok, negative error */ |
| 579 | |
| 580 | /* |
| 581 | * Counter API. |
| 582 | */ |
| 583 | |
| 584 | enum ustctl_counter_bitness { |
| 585 | USTCTL_COUNTER_BITNESS_32 = 0, |
| 586 | USTCTL_COUNTER_BITNESS_64 = 1, |
| 587 | }; |
| 588 | |
| 589 | enum ustctl_counter_arithmetic { |
| 590 | USTCTL_COUNTER_ARITHMETIC_MODULAR = 0, |
| 591 | USTCTL_COUNTER_ARITHMETIC_SATURATION = 1, |
| 592 | }; |
| 593 | |
| 594 | /* Used as alloc flags. */ |
| 595 | enum ustctl_counter_alloc { |
| 596 | USTCTL_COUNTER_ALLOC_PER_CPU = (1 << 0), |
| 597 | USTCTL_COUNTER_ALLOC_GLOBAL = (1 << 1), |
| 598 | }; |
| 599 | |
| 600 | struct ustctl_daemon_counter; |
| 601 | |
| 602 | int ustctl_get_nr_cpu_per_counter(void); |
| 603 | |
| 604 | struct ustctl_counter_dimension { |
| 605 | uint64_t size; |
| 606 | uint64_t underflow_index; |
| 607 | uint64_t overflow_index; |
| 608 | uint8_t has_underflow; |
| 609 | uint8_t has_overflow; |
| 610 | }; |
| 611 | |
| 612 | struct ustctl_daemon_counter * |
| 613 | ustctl_create_counter(size_t nr_dimensions, |
| 614 | const struct ustctl_counter_dimension *dimensions, |
| 615 | int64_t global_sum_step, |
| 616 | int global_counter_fd, |
| 617 | int nr_counter_cpu_fds, |
| 618 | const int *counter_cpu_fds, |
| 619 | enum ustctl_counter_bitness bitness, |
| 620 | enum ustctl_counter_arithmetic arithmetic, |
| 621 | uint32_t alloc_flags, |
| 622 | bool coalesce_hits); |
| 623 | |
| 624 | int ustctl_create_counter_data(struct ustctl_daemon_counter *counter, |
| 625 | struct lttng_ust_abi_object_data **counter_data); |
| 626 | |
| 627 | int ustctl_create_counter_global_data(struct ustctl_daemon_counter *counter, |
| 628 | struct lttng_ust_abi_object_data **counter_global_data); |
| 629 | int ustctl_create_counter_cpu_data(struct ustctl_daemon_counter *counter, int cpu, |
| 630 | struct lttng_ust_abi_object_data **counter_cpu_data); |
| 631 | |
| 632 | /* |
| 633 | * Each counter data and counter cpu data created need to be destroyed |
| 634 | * before calling ustctl_destroy_counter(). |
| 635 | */ |
| 636 | void ustctl_destroy_counter(struct ustctl_daemon_counter *counter); |
| 637 | |
| 638 | int ustctl_send_counter_data_to_ust(int sock, int parent_handle, |
| 639 | struct lttng_ust_abi_object_data *counter_data); |
| 640 | int ustctl_send_counter_global_data_to_ust(int sock, |
| 641 | struct lttng_ust_abi_object_data *counter_data, |
| 642 | struct lttng_ust_abi_object_data *counter_global_data); |
| 643 | int ustctl_send_counter_cpu_data_to_ust(int sock, |
| 644 | struct lttng_ust_abi_object_data *counter_data, |
| 645 | struct lttng_ust_abi_object_data *counter_cpu_data); |
| 646 | |
| 647 | int ustctl_counter_read(struct ustctl_daemon_counter *counter, |
| 648 | const size_t *dimension_indexes, |
| 649 | int cpu, int64_t *value, |
| 650 | bool *overflow, bool *underflow); |
| 651 | int ustctl_counter_aggregate(struct ustctl_daemon_counter *counter, |
| 652 | const size_t *dimension_indexes, |
| 653 | int64_t *value, |
| 654 | bool *overflow, bool *underflow); |
| 655 | int ustctl_counter_clear(struct ustctl_daemon_counter *counter, |
| 656 | const size_t *dimension_indexes); |
| 657 | |
| 658 | #endif /* _LTTNG_UST_CTL_H */ |