From: Francis Deslauriers Date: Fri, 28 May 2021 12:57:47 +0000 (-0400) Subject: sessiond: ust: Update UST definitions for counters X-Git-Url: http://git.lttng.org./?a=commitdiff_plain;h=d038d337ac4e4e53096c03c8f44f6368c4b6e409;p=lttng-tools.git sessiond: ust: Update UST definitions for counters Update the internal ust-abi and ust-ctl headers to match LTTng-UST's changes to support counter events. Signed-off-by: Francis Deslauriers Signed-off-by: Jérémie Galarneau Change-Id: I85fdb02710eaecebab950407d12c85ebfe27615f Depends-on: lttng-ust: I1a706cf60059c7106525cf484d4a290c38e197c7 --- diff --git a/src/bin/lttng-sessiond/ust-abi-internal.hpp b/src/bin/lttng-sessiond/ust-abi-internal.hpp index a2a0dcabb..b69d6b148 100644 --- a/src/bin/lttng-sessiond/ust-abi-internal.hpp +++ b/src/bin/lttng-sessiond/ust-abi-internal.hpp @@ -20,10 +20,10 @@ #error "LTTNG_PACKED should be defined" #endif -#ifndef __ust_stringify -#define __ust_stringify1(x) #x -#define __ust_stringify(x) __ust_stringify1(x) -#endif /* __ust_stringify */ +#ifndef lttng_ust_stringify +#define lttng_ust_stringify1(x) #x +#define lttng_ust_stringify(x) lttng_ust_stringify1(x) +#endif /* lttng_ust_stringify */ #define LTTNG_UST_ABI_SYM_NAME_LEN 256 #define LTTNG_UST_ABI_PROCNAME_LEN 16 @@ -32,10 +32,12 @@ #define LTTNG_UST_ABI_COMM_MAGIC 0xC57C57C5 /* Version for ABI between liblttng-ust, sessiond, consumerd */ -#define LTTNG_UST_ABI_MAJOR_VERSION 9 +#define LTTNG_UST_ABI_MAJOR_VERSION 10 #define LTTNG_UST_ABI_MAJOR_VERSION_OLDEST_COMPATIBLE 8 #define LTTNG_UST_ABI_MINOR_VERSION 0 +#define LTTNG_UST_ABI_CMD_MAX_LEN 4096U + enum lttng_ust_abi_instrumentation { LTTNG_UST_ABI_TRACEPOINT = 0, LTTNG_UST_ABI_PROBE = 1, @@ -89,43 +91,6 @@ struct lttng_ust_abi_stream { */ } LTTNG_PACKED; -#define LTTNG_UST_ABI_COUNTER_DIMENSION_MAX 4 - -enum lttng_ust_abi_counter_arithmetic { - LTTNG_UST_ABI_COUNTER_ARITHMETIC_MODULAR = 0, - LTTNG_UST_ABI_COUNTER_ARITHMETIC_SATURATION = 1, -}; - -enum lttng_ust_abi_counter_bitness { - LTTNG_UST_ABI_COUNTER_BITNESS_32 = 0, - LTTNG_UST_ABI_COUNTER_BITNESS_64 = 1, -}; - -struct lttng_ust_abi_counter_dimension { - uint64_t size; - uint64_t underflow_index; - uint64_t overflow_index; - uint8_t has_underflow; - uint8_t has_overflow; -} LTTNG_PACKED; - -#define LTTNG_UST_ABI_COUNTER_CONF_PADDING1 67 -struct lttng_ust_abi_counter_conf { - uint32_t arithmetic; /* enum lttng_ust_abi_counter_arithmetic */ - uint32_t bitness; /* enum lttng_ust_abi_counter_bitness */ - uint32_t number_dimensions; - int64_t global_sum_step; - struct lttng_ust_abi_counter_dimension dimensions[LTTNG_UST_ABI_COUNTER_DIMENSION_MAX]; - uint8_t coalesce_hits; - char padding[LTTNG_UST_ABI_COUNTER_CONF_PADDING1]; -} LTTNG_PACKED; - -struct lttng_ust_abi_counter_value { - uint32_t number_dimensions; - uint64_t dimension_indexes[LTTNG_UST_ABI_COUNTER_DIMENSION_MAX]; - int64_t value; -} LTTNG_PACKED; - #define LTTNG_UST_ABI_EVENT_PADDING1 8 #define LTTNG_UST_ABI_EVENT_PADDING2 (LTTNG_UST_ABI_SYM_NAME_LEN + 32) struct lttng_ust_abi_event { @@ -157,25 +122,86 @@ struct lttng_ust_abi_event_notifier_notification { char padding[LTTNG_UST_ABI_EVENT_NOTIFIER_NOTIFICATION_PADDING]; } LTTNG_PACKED; -#define LTTNG_UST_ABI_COUNTER_PADDING1 (LTTNG_UST_ABI_SYM_NAME_LEN + 32) -#define LTTNG_UST_ABI_COUNTER_DATA_MAX_LEN 4096U -struct lttng_ust_abi_counter { - uint64_t len; - char padding[LTTNG_UST_ABI_COUNTER_PADDING1]; - char data[]; /* variable sized data */ +enum lttng_ust_abi_key_token_type { + LTTNG_UST_ABI_KEY_TOKEN_STRING = 0, /* arg: strtab_offset. */ + LTTNG_UST_ABI_KEY_TOKEN_EVENT_NAME = 1, /* no arg. */ + LTTNG_UST_ABI_KEY_TOKEN_PROVIDER_NAME = 2, /* no arg. */ +}; + +enum lttng_ust_abi_counter_arithmetic { + LTTNG_UST_ABI_COUNTER_ARITHMETIC_MODULAR = 0, + LTTNG_UST_ABI_COUNTER_ARITHMETIC_SATURATION = 1, +}; + +enum lttng_ust_abi_counter_bitness { + LTTNG_UST_ABI_COUNTER_BITNESS_32 = 0, + LTTNG_UST_ABI_COUNTER_BITNESS_64 = 1, +}; + +struct lttng_ust_abi_counter_key_string { + uint32_t string_len; /* string length (includes \0) */ + char str[]; /* Null-terminated string. */ +} LTTNG_PACKED; + +struct lttng_ust_abi_key_token { + uint32_t len; /* length of this structure. */ + uint32_t type; /* enum lttng_ust_key_token_type */ + + /* Followed by a struct lttng_ust_abi_counter_key_string for LTTNG_UST_ABI_KEY_TOKEN_STRING. + */ +} LTTNG_PACKED; + +struct lttng_ust_abi_counter_key_dimension { + uint32_t len; /* length of this structure */ + uint32_t nr_key_tokens; + + /* Followed by a variable-length array of key tokens */ +} LTTNG_PACKED; + +struct lttng_ust_abi_counter_event { + uint32_t len; /* length of this structure */ + + struct lttng_ust_abi_event event; + uint32_t number_key_dimensions; /* array of dimensions is an array of var. len. elements. */ + + /* Followed by a variable-length array of key dimensions */ +} LTTNG_PACKED; + +enum lttng_ust_abi_counter_dimension_flags { + LTTNG_UST_ABI_COUNTER_DIMENSION_FLAG_UNDERFLOW = (1 << 0), + LTTNG_UST_ABI_COUNTER_DIMENSION_FLAG_OVERFLOW = (1 << 1), +}; + +struct lttng_ust_abi_counter_dimension { + uint32_t flags; /* enum lttng_ust_abi_counter_dimension_flags */ + uint64_t size; /* dimension size */ + uint64_t underflow_index; + uint64_t overflow_index; +} LTTNG_PACKED; + +enum lttng_ust_abi_counter_conf_flags { + LTTNG_UST_ABI_COUNTER_CONF_FLAG_COALESCE_HITS = (1 << 0), +}; + +struct lttng_ust_abi_counter_conf { + uint32_t len; /* Length of fields before var. len. data. */ + uint32_t flags; /* enum lttng_ust_abi_counter_conf_flags */ + uint32_t arithmetic; /* enum lttng_ust_abi_counter_arithmetic */ + uint32_t bitness; /* enum lttng_ust_abi_counter_bitness */ + int64_t global_sum_step; + uint32_t number_dimensions; + uint32_t elem_len; /* array stride (size of lttng_ust_abi_counter_dimension) */ } LTTNG_PACKED; -#define LTTNG_UST_ABI_COUNTER_GLOBAL_PADDING1 (LTTNG_UST_ABI_SYM_NAME_LEN + 32) struct lttng_ust_abi_counter_global { - uint64_t len; /* shm len */ - char padding[LTTNG_UST_ABI_COUNTER_GLOBAL_PADDING1]; + uint32_t len; /* Length of this structure */ + uint64_t shm_len; /* shm len */ } LTTNG_PACKED; -#define LTTNG_UST_ABI_COUNTER_CPU_PADDING1 (LTTNG_UST_ABI_SYM_NAME_LEN + 32) struct lttng_ust_abi_counter_cpu { - uint64_t len; /* shm len */ + uint32_t len; /* Length of this structure */ + uint64_t shm_len; /* shm len */ uint32_t cpu_nr; - char padding[LTTNG_UST_ABI_COUNTER_CPU_PADDING1]; } LTTNG_PACKED; enum lttng_ust_abi_field_type { @@ -281,6 +307,7 @@ enum lttng_ust_abi_object_type { LTTNG_UST_ABI_OBJECT_TYPE_COUNTER = 6, LTTNG_UST_ABI_OBJECT_TYPE_COUNTER_GLOBAL = 7, LTTNG_UST_ABI_OBJECT_TYPE_COUNTER_CPU = 8, + LTTNG_UST_ABI_OBJECT_TYPE_COUNTER_EVENT = 9, }; #define LTTNG_UST_ABI_OBJECT_DATA_PADDING1 32 @@ -358,9 +385,10 @@ struct lttng_ust_abi_event_exclusion { char names[LTTNG_UST_ABI_SYM_NAME_LEN][0]; } LTTNG_PACKED; -#define LTTNG_UST_ABI_CMD(minor) (minor) -#define LTTNG_UST_ABI_CMDR(minor, type) (minor) -#define LTTNG_UST_ABI_CMDW(minor, type) (minor) +#define LTTNG_UST_ABI_CMD(minor) (minor) +#define LTTNG_UST_ABI_CMDR(minor, type) (minor) +#define LTTNG_UST_ABI_CMDW(minor, type) (minor) +#define LTTNG_UST_ABI_CMDV(minor, var_len_cmd_type) (minor) /* Handled by object descriptor */ #define LTTNG_UST_ABI_RELEASE LTTNG_UST_ABI_CMD(0x1) @@ -404,17 +432,20 @@ struct lttng_ust_abi_event_exclusion { /* Event notifier group commands */ #define LTTNG_UST_ABI_EVENT_NOTIFIER_CREATE \ - LTTNG_UST_ABI_CMDW(0xB0, struct lttng_ust_abi_event_notifier) + LTTNG_UST_ABI_CMDV(0xB0, struct lttng_ust_abi_event_notifier) /* Event notifier commands */ #define LTTNG_UST_ABI_CAPTURE LTTNG_UST_ABI_CMD(0xB6) /* Session and event notifier group commands */ -#define LTTNG_UST_ABI_COUNTER LTTNG_UST_ABI_CMDW(0xC0, struct lttng_ust_abi_counter) +/* (0xC0) reserved for old ABI. */ +#define LTTNG_UST_ABI_COUNTER LTTNG_UST_ABI_CMDV(0xC1, struct lttng_ust_abi_counter_conf) /* Counter commands */ -#define LTTNG_UST_ABI_COUNTER_GLOBAL LTTNG_UST_ABI_CMDW(0xD0, struct lttng_ust_abi_counter_global) -#define LTTNG_UST_ABI_COUNTER_CPU LTTNG_UST_ABI_CMDW(0xD1, struct lttng_ust_abi_counter_cpu) +/* (0xD0, 0xD1) reserved for old ABI. */ +#define LTTNG_UST_ABI_COUNTER_GLOBAL LTTNG_UST_ABI_CMDV(0xD2, struct lttng_ust_abi_counter_global) +#define LTTNG_UST_ABI_COUNTER_CPU LTTNG_UST_ABI_CMDV(0xD3, struct lttng_ust_abi_counter_cpu) +#define LTTNG_UST_ABI_COUNTER_EVENT LTTNG_UST_ABI_CMDV(0xD4, struct lttng_ust_abi_counter_event) #define LTTNG_UST_ABI_ROOT_HANDLE 0 diff --git a/src/bin/lttng-sessiond/ust-app.cpp b/src/bin/lttng-sessiond/ust-app.cpp index 39f126b7a..9fef3cdcb 100644 --- a/src/bin/lttng-sessiond/ust-app.cpp +++ b/src/bin/lttng-sessiond/ust-app.cpp @@ -6617,7 +6617,7 @@ static int add_event_ust_registry(int sock, char *raw_model_emf_uri) { int ret, ret_code; - uint32_t event_id = 0; + lsu::event_id event_id = 0; uint64_t chan_reg_key; struct ust_app *app; struct ust_app_channel *ua_chan; @@ -6663,7 +6663,7 @@ static int add_event_ust_registry(int sock, try { auto& channel = locked_registry->channel(chan_reg_key); - /* event_id is set on success. */ + /* id is set on success. */ channel.add_event( sobjd, cobjd, @@ -6725,7 +6725,7 @@ static int add_event_ust_registry(int sock, return ret; } - DBG3("UST registry event %s with id %" PRId32 " added successfully", name, event_id); + DBG_FMT("UST registry event successfully added: name={}, id={}", name, event_id); return ret; } @@ -6857,6 +6857,7 @@ int ust_app_recv_notify(int sock) int sobjd, cobjd, loglevel_value; char name[LTTNG_UST_ABI_SYM_NAME_LEN], *sig, *model_emf_uri; size_t nr_fields; + uint64_t tracer_token = 0; struct lttng_ust_ctl_field *fields; DBG2("UST app ustctl register event received"); @@ -6869,7 +6870,8 @@ int ust_app_recv_notify(int sock) &sig, &nr_fields, &fields, - &model_emf_uri); + &model_emf_uri, + &tracer_token); if (ret < 0) { if (ret == -EPIPE || ret == -LTTNG_UST_ERR_EXITING) { DBG3("UST app recv event failed. Application died: sock = %d", diff --git a/src/bin/lttng-sessiond/ust-ctl-internal.hpp b/src/bin/lttng-sessiond/ust-ctl-internal.hpp index 79b863ce2..998f884a2 100644 --- a/src/bin/lttng-sessiond/ust-ctl-internal.hpp +++ b/src/bin/lttng-sessiond/ust-ctl-internal.hpp @@ -20,17 +20,14 @@ /* Default unix socket path */ #define LTTNG_UST_SOCK_FILENAME \ - "lttng-ust-sock-" __ust_stringify(LTTNG_UST_ABI_MAJOR_VERSION_OLDEST_COMPATIBLE) + "lttng-ust-sock-" lttng_ust_stringify(LTTNG_UST_ABI_MAJOR_VERSION_OLDEST_COMPATIBLE) /* * Shared memory files path are automatically related to shm root, e.g. * /dev/shm under linux. */ #define LTTNG_UST_WAIT_FILENAME \ - "lttng-ust-wait-" __ust_stringify(LTTNG_UST_ABI_MAJOR_VERSION_OLDEST_COMPATIBLE) - -struct lttng_ust_shm_handle; -struct lttng_ust_lib_ring_buffer; + "lttng-ust-wait-" lttng_ust_stringify(LTTNG_UST_ABI_MAJOR_VERSION_OLDEST_COMPATIBLE) struct lttng_ust_ctl_consumer_channel_attr { enum lttng_ust_abi_chan_type type; @@ -181,7 +178,7 @@ struct lttng_ust_ctl_consumer_channel; struct lttng_ust_ctl_consumer_stream; struct lttng_ust_ctl_consumer_channel_attr; -int lttng_ust_ctl_get_nr_stream_per_channel(); +int lttng_ust_ctl_get_nr_stream_per_channel(void); struct lttng_ust_ctl_consumer_channel *lttng_ust_ctl_create_channel( struct lttng_ust_ctl_consumer_channel_attr *attr, const int *stream_fds, int nr_stream_fds); @@ -287,7 +284,7 @@ int lttng_ust_ctl_get_instance_id(struct lttng_ust_ctl_consumer_stream *stream, int lttng_ust_ctl_get_current_timestamp(struct lttng_ust_ctl_consumer_stream *stream, uint64_t *ts); /* returns whether UST has perf counters support. */ -int lttng_ust_ctl_has_perf_counters(); +int lttng_ust_ctl_has_perf_counters(void); /* Regenerate the statedump. */ int lttng_ust_ctl_regenerate_statedump(int sock, int handle); @@ -527,13 +524,14 @@ int lttng_ust_ctl_recv_register_event(int sock, */ size_t *nr_fields, struct lttng_ust_ctl_field **fields, - char **model_emf_uri); + char **model_emf_uri, + uint64_t *user_token); /* * Returns 0 on success, negative error value on error. */ int lttng_ust_ctl_reply_register_event(int sock, - uint32_t id, /* event id (input) */ + uint64_t id, /* id (input) */ int ret_code); /* return code. 0 ok, negative error */ /* @@ -591,7 +589,7 @@ enum lttng_ust_ctl_counter_alloc { struct lttng_ust_ctl_daemon_counter; -int lttng_ust_ctl_get_nr_cpu_per_counter(); +int lttng_ust_ctl_get_nr_cpu_per_counter(void); struct lttng_ust_ctl_counter_dimension { uint64_t size; @@ -653,6 +651,14 @@ int lttng_ust_ctl_counter_aggregate(struct lttng_ust_ctl_daemon_counter *counter int lttng_ust_ctl_counter_clear(struct lttng_ust_ctl_daemon_counter *counter, const size_t *dimension_indexes); +int lttng_ust_ctl_counter_create_event(int sock, + struct lttng_ust_abi_counter_event *counter_event, + size_t counter_event_len, + struct lttng_ust_abi_object_data *counter_data, + struct lttng_ust_abi_object_data **counter_event_data); + void lttng_ust_ctl_sigbus_handle(void *addr); +int lttng_ust_ctl_get_version(uint32_t *major, uint32_t *minor, uint32_t *patchlevel); + #endif /* LTTNG_UST_CTL_INTERNAL_H */ diff --git a/src/bin/lttng-sessiond/ust-registry-channel.cpp b/src/bin/lttng-sessiond/ust-registry-channel.cpp index 93e031733..84ae5a448 100644 --- a/src/bin/lttng-sessiond/ust-registry-channel.cpp +++ b/src/bin/lttng-sessiond/ust-registry-channel.cpp @@ -377,9 +377,9 @@ void lsu::registry_channel::add_event(int session_objd, nonstd::optional model_emf_uri, lttng_buffer_type buffer_type, const ust_app& app, - uint32_t& out_event_id) + lsu::event_id& out_event_id) { - uint32_t event_id; + lsu::event_id event_id; struct cds_lfht_node *nptr; const lttng::urcu::read_lock_guard read_lock_guard; diff --git a/src/bin/lttng-sessiond/ust-registry-channel.hpp b/src/bin/lttng-sessiond/ust-registry-channel.hpp index 636de94aa..4d847a2b0 100644 --- a/src/bin/lttng-sessiond/ust-registry-channel.hpp +++ b/src/bin/lttng-sessiond/ust-registry-channel.hpp @@ -26,6 +26,8 @@ namespace ust { class registry_event; +using event_id = uint64_t; + class registry_channel : public lttng::sessiond::trace::stream_class { public: using registered_listener_fn = std::function; @@ -46,7 +48,7 @@ public: nonstd::optional model_emf_uri, lttng_buffer_type buffer_type, const ust_app& app, - uint32_t& out_event_id); + event_id& out_event_id); ~registry_channel() override; registry_channel(const registry_channel&) = delete; registry_channel(registry_channel&&) = delete;