From 0f825a63e2b14424244335c3b28c14c26158a423 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 29 Jul 2024 09:55:50 -0400 Subject: [PATCH] Adapt to LTTng-UST ABI/control API updates MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Adapt to ABI/control API updates introduced by LTTng-UST commit 24f7193c9b91 ("Introduce extension points for trace hit counters") Note that this commit reverts back to uint32_t for channel event ids. UST notification LTTNG_UST_CTL_NOTIFY_CMD_KEY is currently handled as -LTTNG_UST_ERR_NOSYS (TODO). The type of the argument to is_max_event_id() is changed to lttng::sessiond::ust::event_id to match the newly introduced event_id type definition. Likewise for the registry_channel _next_event_id member. Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau Change-Id: I6299b07c02d35b067aed5e94f11353d3cc14f24c --- src/bin/lttng-sessiond/ust-abi-internal.hpp | 78 +++++++++++++++---- src/bin/lttng-sessiond/ust-app.cpp | 9 ++- src/bin/lttng-sessiond/ust-ctl-internal.hpp | 44 ++++++++++- .../lttng-sessiond/ust-registry-channel.cpp | 2 +- .../lttng-sessiond/ust-registry-channel.hpp | 4 +- 5 files changed, 117 insertions(+), 20 deletions(-) diff --git a/src/bin/lttng-sessiond/ust-abi-internal.hpp b/src/bin/lttng-sessiond/ust-abi-internal.hpp index b69d6b148..474dfd6f1 100644 --- a/src/bin/lttng-sessiond/ust-abi-internal.hpp +++ b/src/bin/lttng-sessiond/ust-abi-internal.hpp @@ -138,33 +138,80 @@ enum lttng_ust_abi_counter_bitness { 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. */ +struct lttng_ust_abi_key_token { + uint32_t len; /* length of child structure. */ + uint32_t type; /* enum lttng_ust_abi_key_token_type */ + /* + * The size of this structure is fixed because it is embedded into + * children structures. + */ } LTTNG_PACKED; -struct lttng_ust_abi_key_token { - uint32_t len; /* length of this structure. */ - uint32_t type; /* enum lttng_ust_key_token_type */ +/* Length of this structure excludes the following string. */ +struct lttng_ust_abi_key_token_string { + struct lttng_ust_abi_key_token parent; + uint32_t string_len; /* string length (includes \0) */ - /* Followed by a struct lttng_ust_abi_counter_key_string for LTTNG_UST_ABI_KEY_TOKEN_STRING. - */ + char str[]; /* Null-terminated string following this structure. */ } LTTNG_PACKED; +/* + * token types event_name and provider_name don't have specific fields, + * so they do not need to derive their own specific child structure. + */ + +/* + * Dimension indexing: All events should use the same key type to index + * a given map dimension. + */ +enum lttng_ust_abi_key_type { + LTTNG_UST_ABI_KEY_TYPE_TOKENS = 0, /* Dimension key is a set of tokens. */ + LTTNG_UST_ABI_KEY_TYPE_INTEGER = 1, /* Dimension key is an integer value. */ +}; + struct lttng_ust_abi_counter_key_dimension { - uint32_t len; /* length of this structure */ + uint32_t len; /* length of child structure */ + uint32_t key_type; /* enum lttng_ust_abi_key_type */ + /* + * The size of this structure is fixed because it is embedded into + * children structures. + */ +} LTTNG_PACKED; + +struct lttng_ust_abi_counter_key_dimension_tokens { + struct lttng_ust_abi_counter_key_dimension parent; uint32_t nr_key_tokens; - /* Followed by a variable-length array of key tokens */ + /* Followed by an array of nr_key_tokens struct lttng_ust_abi_key_token elements. */ } LTTNG_PACKED; +/* + * The "integer" key type is not implemented yet, but when it will be + * introduced in the future, its specific key dimension will allow + * defining the function to apply over input argument, bytecode to run + * and so on. + */ + +enum lttng_ust_abi_counter_action { + LTTNG_UST_ABI_COUNTER_ACTION_INCREMENT = 0, + + /* + * Can be extended with additional actions, such as decrement, + * set value, run bytecode, and so on. + */ +}; + struct lttng_ust_abi_counter_event { - uint32_t len; /* length of this structure */ + uint32_t len; /* length of this structure */ + uint32_t action; /* enum lttng_ust_abi_counter_action */ struct lttng_ust_abi_event event; - uint32_t number_key_dimensions; /* array of dimensions is an array of var. len. elements. */ + uint32_t number_key_dimensions; /* array of dimensions is an array of var. len. elements. */ - /* Followed by a variable-length array of key dimensions */ + /* + * Followed by additional data specific to the action, and by a + * variable-length array of key dimensions. + */ } LTTNG_PACKED; enum lttng_ust_abi_counter_dimension_flags { @@ -173,8 +220,9 @@ enum lttng_ust_abi_counter_dimension_flags { }; struct lttng_ust_abi_counter_dimension { - uint32_t flags; /* enum lttng_ust_abi_counter_dimension_flags */ - uint64_t size; /* dimension size */ + uint32_t key_type; /* enum lttng_ust_abi_key_type */ + uint32_t flags; /* enum lttng_ust_abi_counter_dimension_flags */ + uint64_t size; /* dimension size (count of entries) */ uint64_t underflow_index; uint64_t overflow_index; } LTTNG_PACKED; diff --git a/src/bin/lttng-sessiond/ust-app.cpp b/src/bin/lttng-sessiond/ust-app.cpp index 9fef3cdcb..61d3774bf 100644 --- a/src/bin/lttng-sessiond/ust-app.cpp +++ b/src/bin/lttng-sessiond/ust-app.cpp @@ -6994,6 +6994,13 @@ int ust_app_recv_notify(int sock) break; } + case LTTNG_UST_CTL_NOTIFY_CMD_KEY: + { + DBG2("UST app ustctl register key received"); + ret = -LTTNG_UST_ERR_NOSYS; + //TODO + goto error; + } default: /* Should NEVER happen. */ abort(); @@ -7906,4 +7913,4 @@ void ust_app_put(struct ust_app *app) lttng_ht *ust_app_get_all() { return ust_app_ht; -} \ No newline at end of file +} diff --git a/src/bin/lttng-sessiond/ust-ctl-internal.hpp b/src/bin/lttng-sessiond/ust-ctl-internal.hpp index 998f884a2..79e07d9e8 100644 --- a/src/bin/lttng-sessiond/ust-ctl-internal.hpp +++ b/src/bin/lttng-sessiond/ust-ctl-internal.hpp @@ -300,6 +300,7 @@ enum lttng_ust_ctl_notify_cmd { LTTNG_UST_CTL_NOTIFY_CMD_EVENT = 0, LTTNG_UST_CTL_NOTIFY_CMD_CHANNEL = 1, LTTNG_UST_CTL_NOTIFY_CMD_ENUM = 2, + LTTNG_UST_CTL_NOTIFY_CMD_KEY = 3, }; enum lttng_ust_ctl_channel_header { @@ -531,9 +532,44 @@ int lttng_ust_ctl_recv_register_event(int sock, * Returns 0 on success, negative error value on error. */ int lttng_ust_ctl_reply_register_event(int sock, - uint64_t id, /* id (input) */ + uint32_t id, /* id (input) */ int ret_code); /* return code. 0 ok, negative error */ +/* + * Returns 0 on success, negative UST or system error value on error. + */ +int lttng_ust_ctl_recv_register_key(int sock, + int *session_objd, /* session descriptor (output) */ + int *map_objd, /* map descriptor (output) */ + uint32_t *dimension, /* + * Against which dimension is + * this key expressed. (output) + */ + uint64_t **dimension_indexes, /* + * Indexes (output, + * dynamically + * allocated, must be + * free(3)'d by the + * caller if function + * returns success.) + * Contains @dimension + * elements. + */ + char **key_string, /* + * key string (output, + * dynamically allocated, must + * be free(3)'d by the caller if + * function returns success.) + */ + uint64_t *user_token); + +/* + * Returns 0 on success, negative error value on error. + */ +int lttng_ust_ctl_reply_register_key(int sock, + uint64_t index, /* Index within dimension (input) */ + int ret_code); /* return code. 0 ok, negative error */ + /* * Returns 0 on success, negative UST or system error value on error. */ @@ -581,6 +617,11 @@ enum lttng_ust_ctl_counter_arithmetic { LTTNG_UST_CTL_COUNTER_ARITHMETIC_SATURATION = 1, }; +enum lttng_ust_ctl_key_type { + LTTNG_UST_CTL_KEY_TYPE_TOKENS = 0, + LTTNG_UST_CTL_KEY_TYPE_INTEGER = 1, +}; + /* Used as alloc flags. */ enum lttng_ust_ctl_counter_alloc { LTTNG_UST_CTL_COUNTER_ALLOC_PER_CPU = (1 << 0), @@ -595,6 +636,7 @@ struct lttng_ust_ctl_counter_dimension { uint64_t size; uint64_t underflow_index; uint64_t overflow_index; + enum lttng_ust_ctl_key_type key_type; uint8_t has_underflow; uint8_t has_overflow; }; diff --git a/src/bin/lttng-sessiond/ust-registry-channel.cpp b/src/bin/lttng-sessiond/ust-registry-channel.cpp index 84ae5a448..29c90756f 100644 --- a/src/bin/lttng-sessiond/ust-registry-channel.cpp +++ b/src/bin/lttng-sessiond/ust-registry-channel.cpp @@ -22,7 +22,7 @@ namespace lst = lttng::sessiond::trace; namespace lsu = lttng::sessiond::ust; namespace { -bool is_max_event_id(uint32_t id) +bool is_max_event_id(lttng::sessiond::ust::event_id id) { return id == UINT32_MAX; } diff --git a/src/bin/lttng-sessiond/ust-registry-channel.hpp b/src/bin/lttng-sessiond/ust-registry-channel.hpp index 4d847a2b0..f0a5350a0 100644 --- a/src/bin/lttng-sessiond/ust-registry-channel.hpp +++ b/src/bin/lttng-sessiond/ust-registry-channel.hpp @@ -26,7 +26,7 @@ namespace ust { class registry_event; -using event_id = uint64_t; +using event_id = uint32_t; class registry_channel : public lttng::sessiond::trace::stream_class { public: @@ -74,7 +74,7 @@ public: /* For delayed reclaim */ struct rcu_head _rcu_head; /* Once this value reaches UINT32_MAX, no more id can be allocated. */ - uint32_t _next_event_id; + event_id _next_event_id; private: void _accept_on_event_classes( -- 2.34.1