From: Mathieu Desnoyers Date: Mon, 15 Mar 2021 20:48:58 +0000 (-0400) Subject: Refactoring: struct lttng_event_desc and lttng_probe_desc X-Git-Tag: v2.13.0-rc1~292 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=dc11f93f7d30cd383e35be41483cc024da59c7b8;p=lttng-ust.git Refactoring: struct lttng_event_desc and lttng_probe_desc - Properly namespace probe registration functions, - Namespace those structures with lttng_ust_ prefix, - Use struct_size extensibility scheme, - Remove padding. Signed-off-by: Mathieu Desnoyers Change-Id: I316a4120d568b663381f4b9eae3e1405a83a1db5 --- diff --git a/include/lttng/ust-events.h b/include/lttng/ust-events.h index d9e15d34..b43b49e1 100644 --- a/include/lttng/ust-events.h +++ b/include/lttng/ust-events.h @@ -274,34 +274,51 @@ struct lttng_ctx { char padding[LTTNG_UST_CTX_PADDING]; }; -#define LTTNG_UST_EVENT_DESC_PADDING 40 -struct lttng_event_desc { +/* + * IMPORTANT: this structure is part of the ABI between the probe and + * UST. Fields need to be only added at the end, never reordered, never + * removed. + * + * The field @struct_size should be used to determine the size of the + * structure. It should be queried before using additional fields added + * at the end of the structure. + */ +struct lttng_ust_event_desc { + uint32_t struct_size; /* Size of this structure. */ const char *name; void (*probe_callback)(void); const struct lttng_event_ctx *ctx; /* context */ const struct lttng_event_field *fields; /* event payload */ unsigned int nr_fields; const int **loglevel; - const char *signature; /* Argument types/names received */ - union { - struct { - const char **model_emf_uri; - } ext; - char padding[LTTNG_UST_EVENT_DESC_PADDING]; - } u; + const char *signature; /* Argument types/names received */ + const char **model_emf_uri; + + /* End of base ABI. Fields below should be used after checking struct_size. */ }; -#define LTTNG_UST_PROBE_DESC_PADDING 12 -struct lttng_probe_desc { +/* + * IMPORTANT: this structure is part of the ABI between the probe and + * UST. Fields need to be only added at the end, never reordered, never + * removed. + * + * The field @struct_size should be used to determine the size of the + * structure. It should be queried before using additional fields added + * at the end of the structure. + */ +struct lttng_ust_probe_desc { + uint32_t struct_size; /* Size of this structure. */ + const char *provider; - const struct lttng_event_desc **event_desc; + const struct lttng_ust_event_desc **event_desc; unsigned int nr_events; struct cds_list_head head; /* chain registered probes */ struct cds_list_head lazy_init_head; int lazy; /* lazy registration */ uint32_t major; uint32_t minor; - char padding[LTTNG_UST_PROBE_DESC_PADDING]; + + /* End of base ABI. Fields below should be used after checking struct_size. */ }; /* Data structures used by the tracer. */ @@ -586,8 +603,8 @@ struct lttng_session { /* End of base ABI. Fields below should be used after checking struct_size. */ }; -int lttng_probe_register(struct lttng_probe_desc *desc); -void lttng_probe_unregister(struct lttng_probe_desc *desc); +int lttng_ust_probe_register(struct lttng_ust_probe_desc *desc); +void lttng_ust_probe_unregister(struct lttng_ust_probe_desc *desc); /* * Can be used by applications that change their procname to clear the ust cached value. diff --git a/include/lttng/ust-tracepoint-event.h b/include/lttng/ust-tracepoint-event.h index 5b3d9a1b..9fbe70e8 100644 --- a/include/lttng/ust-tracepoint-event.h +++ b/include/lttng/ust-tracepoint-event.h @@ -1020,19 +1020,16 @@ static const int * \ static const char * \ __ref_model_emf_uri___##_provider##___##_name \ __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\ -static const struct lttng_event_desc __event_desc___##_provider##_##_name = { \ +static const struct lttng_ust_event_desc __event_desc___##_provider##_##_name = { \ + .struct_size = sizeof(struct lttng_ust_event_desc), \ .name = #_provider ":" #_name, \ - .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template,\ + .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template, \ .ctx = NULL, \ .fields = __event_fields___##_provider##___##_template, \ .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template) - 1, \ .loglevel = &__ref_loglevel___##_provider##___##_name, \ .signature = __tp_event_signature___##_provider##___##_template, \ - .u = { \ - .ext = { \ - .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \ - }, \ - }, \ + .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \ }; #include TRACEPOINT_INCLUDE @@ -1050,7 +1047,7 @@ static const struct lttng_event_desc __event_desc___##_provider##_##_name = { #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \ &__event_desc___##_provider##_##_name, -static const struct lttng_event_desc *_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)[] = { +static const struct lttng_ust_event_desc *_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)[] = { #include TRACEPOINT_INCLUDE NULL, /* Dummy, C99 forbids 0-len array. */ }; @@ -1063,7 +1060,8 @@ static const struct lttng_event_desc *_TP_COMBINE_TOKENS(__event_desc___, TRACEP */ /* non-const because list head will be modified when registered. */ -static struct lttng_probe_desc _TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER) = { +static struct lttng_ust_probe_desc _TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER) = { + .struct_size = sizeof(struct lttng_ust_probe_desc), .provider = __tp_stringify(TRACEPOINT_PROVIDER), .event_desc = _TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER), .nr_events = _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)) - 1, @@ -1109,7 +1107,7 @@ _TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void) * error will appear. */ _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)(); - ret = lttng_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER)); + ret = lttng_ust_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER)); if (ret) { fprintf(stderr, "LTTng-UST: Error (%d) while registering tracepoint probe.\n", ret); abort(); @@ -1125,7 +1123,7 @@ _TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void) TRACEPOINT_PROVIDER)) { return; } - lttng_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER)); + lttng_ust_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER)); } int _TP_COMBINE_TOKENS(__tracepoint_provider_, TRACEPOINT_PROVIDER) diff --git a/liblttng-ust/lttng-bytecode-specialize.c b/liblttng-ust/lttng-bytecode-specialize.c index f571dd60..2982a793 100644 --- a/liblttng-ust/lttng-bytecode-specialize.c +++ b/liblttng-ust/lttng-bytecode-specialize.c @@ -546,7 +546,7 @@ end: return ret; } -static int specialize_payload_lookup(const struct lttng_event_desc *event_desc, +static int specialize_payload_lookup(const struct lttng_ust_event_desc *event_desc, struct bytecode_runtime *runtime, struct load_op *insn, struct vstack_load *load) @@ -623,7 +623,7 @@ end: return ret; } -int lttng_bytecode_specialize(const struct lttng_event_desc *event_desc, +int lttng_bytecode_specialize(const struct lttng_ust_event_desc *event_desc, struct bytecode_runtime *bytecode) { void *pc, *next_pc, *start_pc; diff --git a/liblttng-ust/lttng-bytecode.c b/liblttng-ust/lttng-bytecode.c index 94edbab6..ef458055 100644 --- a/liblttng-ust/lttng-bytecode.c +++ b/liblttng-ust/lttng-bytecode.c @@ -171,7 +171,7 @@ const char *lttng_bytecode_print_op(enum bytecode_op op) } static -int apply_field_reloc(const struct lttng_event_desc *event_desc, +int apply_field_reloc(const struct lttng_ust_event_desc *event_desc, struct bytecode_runtime *runtime, uint32_t runtime_len, uint32_t reloc_offset, @@ -341,7 +341,7 @@ int apply_context_reloc(struct bytecode_runtime *runtime, } static -int apply_reloc(const struct lttng_event_desc *event_desc, +int apply_reloc(const struct lttng_ust_event_desc *event_desc, struct bytecode_runtime *runtime, uint32_t runtime_len, uint32_t reloc_offset, @@ -395,7 +395,7 @@ int bytecode_is_linked(struct lttng_ust_bytecode_node *bytecode, * bytecode runtime. */ static -int link_bytecode(const struct lttng_event_desc *event_desc, +int link_bytecode(const struct lttng_ust_event_desc *event_desc, struct lttng_ctx **ctx, struct lttng_ust_bytecode_node *bytecode, struct cds_list_head *bytecode_runtime_head, @@ -527,7 +527,7 @@ void lttng_bytecode_capture_sync_state(struct lttng_bytecode_runtime *runtime) * This function is called after we confirmed that name enabler and the * instance are name matching (or glob pattern matching). */ -void lttng_enabler_link_bytecode(const struct lttng_event_desc *event_desc, +void lttng_enabler_link_bytecode(const struct lttng_ust_event_desc *event_desc, struct lttng_ctx **ctx, struct cds_list_head *instance_bytecode_head, struct cds_list_head *enabler_bytecode_head) diff --git a/liblttng-ust/lttng-bytecode.h b/liblttng-ust/lttng-bytecode.h index 4e9f97c9..8caf15ec 100644 --- a/liblttng-ust/lttng-bytecode.h +++ b/liblttng-ust/lttng-bytecode.h @@ -325,7 +325,7 @@ void lttng_bytecode_capture_sync_state(struct lttng_bytecode_runtime *runtime); LTTNG_HIDDEN int lttng_bytecode_validate(struct bytecode_runtime *bytecode); LTTNG_HIDDEN -int lttng_bytecode_specialize(const struct lttng_event_desc *event_desc, +int lttng_bytecode_specialize(const struct lttng_ust_event_desc *event_desc, struct bytecode_runtime *bytecode); LTTNG_HIDDEN diff --git a/liblttng-ust/lttng-events.c b/liblttng-ust/lttng-events.c index 5a3aae8d..7dfe6b7a 100644 --- a/liblttng-ust/lttng-events.c +++ b/liblttng-ust/lttng-events.c @@ -250,7 +250,7 @@ static void register_event(struct lttng_ust_event_common *event) { int ret; - const struct lttng_event_desc *desc; + const struct lttng_ust_event_desc *desc; assert(event->priv->registered == 0); desc = event->priv->desc; @@ -266,7 +266,7 @@ static void unregister_event(struct lttng_ust_event_common *event) { int ret; - const struct lttng_event_desc *desc; + const struct lttng_ust_event_desc *desc; assert(event->priv->registered == 1); desc = event->priv->desc; @@ -675,7 +675,7 @@ static inline struct cds_hlist_head *borrow_hash_table_bucket( struct cds_hlist_head *hash_table, unsigned int hash_table_size, - const struct lttng_event_desc *desc) + const struct lttng_ust_event_desc *desc) { const char *event_name; size_t name_len; @@ -692,7 +692,7 @@ struct cds_hlist_head *borrow_hash_table_bucket( * Supports event creation while tracing session is active. */ static -int lttng_event_recorder_create(const struct lttng_event_desc *desc, +int lttng_event_recorder_create(const struct lttng_ust_event_desc *desc, struct lttng_channel *chan) { struct lttng_ust_event_recorder *event_recorder; @@ -761,8 +761,8 @@ int lttng_event_recorder_create(const struct lttng_event_desc *desc, loglevel = *(*event_recorder->parent->priv->desc->loglevel); else loglevel = TRACE_DEFAULT; - if (desc->u.ext.model_emf_uri) - uri = *(desc->u.ext.model_emf_uri); + if (desc->model_emf_uri) + uri = *(desc->model_emf_uri); else uri = NULL; @@ -800,7 +800,7 @@ socket_error: } static -int lttng_event_notifier_create(const struct lttng_event_desc *desc, +int lttng_event_notifier_create(const struct lttng_ust_event_desc *desc, uint64_t token, uint64_t error_counter_index, struct lttng_event_notifier_group *event_notifier_group) { @@ -872,7 +872,7 @@ error: } static -int lttng_desc_match_star_glob_enabler(const struct lttng_event_desc *desc, +int lttng_desc_match_star_glob_enabler(const struct lttng_ust_event_desc *desc, struct lttng_enabler *enabler) { int loglevel = 0; @@ -895,7 +895,7 @@ int lttng_desc_match_star_glob_enabler(const struct lttng_event_desc *desc, } static -int lttng_desc_match_event_enabler(const struct lttng_event_desc *desc, +int lttng_desc_match_event_enabler(const struct lttng_ust_event_desc *desc, struct lttng_enabler *enabler) { int loglevel = 0; @@ -917,7 +917,7 @@ int lttng_desc_match_event_enabler(const struct lttng_event_desc *desc, } static -int lttng_desc_match_enabler(const struct lttng_event_desc *desc, +int lttng_desc_match_enabler(const struct lttng_ust_event_desc *desc, struct lttng_enabler *enabler) { switch (enabler->format_type) { @@ -1005,8 +1005,8 @@ static void lttng_create_event_recorder_if_missing(struct lttng_event_enabler *event_enabler) { struct lttng_session *session = event_enabler->chan->session; - struct lttng_probe_desc *probe_desc; - const struct lttng_event_desc *desc; + struct lttng_ust_probe_desc *probe_desc; + const struct lttng_ust_event_desc *desc; struct lttng_ust_event_recorder_private *event_recorder_priv; int i; struct cds_list_head *probe_list; @@ -1058,7 +1058,7 @@ void lttng_create_event_recorder_if_missing(struct lttng_event_enabler *event_en } static -void probe_provider_event_for_each(struct lttng_probe_desc *provider_desc, +void probe_provider_event_for_each(struct lttng_ust_probe_desc *provider_desc, void (*event_func)(struct lttng_ust_event_common *event)) { struct cds_hlist_node *node, *tmp_node; @@ -1073,7 +1073,7 @@ void probe_provider_event_for_each(struct lttng_probe_desc *provider_desc, * sessions to queue the unregistration of the events. */ for (i = 0; i < provider_desc->nr_events; i++) { - const struct lttng_event_desc *event_desc; + const struct lttng_ust_event_desc *event_desc; struct lttng_event_notifier_group *event_notifier_group; struct lttng_ust_event_recorder_private *event_recorder_priv; struct lttng_ust_event_notifier_private *event_notifier_priv; @@ -1175,7 +1175,7 @@ void _event_enum_destroy(struct lttng_ust_event_common *event) * ust_lock held. */ void lttng_probe_provider_unregister_events( - struct lttng_probe_desc *provider_desc) + struct lttng_ust_probe_desc *provider_desc) { /* * Iterate over all events in the probe provider descriptions and sessions @@ -1708,7 +1708,7 @@ void lttng_session_sync_event_enablers(struct lttng_session *session) /* Support for event notifier is introduced by probe provider major version 2. */ static -bool lttng_ust_probe_supports_event_notifier(struct lttng_probe_desc *probe_desc) +bool lttng_ust_probe_supports_event_notifier(struct lttng_ust_probe_desc *probe_desc) { return probe_desc->major >= 2; } @@ -1718,7 +1718,7 @@ void lttng_create_event_notifier_if_missing( struct lttng_event_notifier_enabler *event_notifier_enabler) { struct lttng_event_notifier_group *event_notifier_group = event_notifier_enabler->group; - struct lttng_probe_desc *probe_desc; + struct lttng_ust_probe_desc *probe_desc; struct cds_list_head *probe_list; int i; @@ -1728,7 +1728,7 @@ void lttng_create_event_notifier_if_missing( for (i = 0; i < probe_desc->nr_events; i++) { int ret; bool found = false; - const struct lttng_event_desc *desc; + const struct lttng_ust_event_desc *desc; struct lttng_ust_event_notifier_private *event_notifier_priv; struct cds_hlist_head *head; struct cds_hlist_node *node; diff --git a/liblttng-ust/lttng-probes.c b/liblttng-ust/lttng-probes.c index 3d3e60e7..d009a874 100644 --- a/liblttng-ust/lttng-probes.c +++ b/liblttng-ust/lttng-probes.c @@ -44,7 +44,7 @@ static int lazy_nesting; * Called under ust lock. */ static -int check_event_provider(struct lttng_probe_desc *desc) +int check_event_provider(struct lttng_ust_probe_desc *desc) { int i; size_t provider_name_len; @@ -64,9 +64,9 @@ int check_event_provider(struct lttng_probe_desc *desc) * Called under ust lock. */ static -void lttng_lazy_probe_register(struct lttng_probe_desc *desc) +void lttng_lazy_probe_register(struct lttng_ust_probe_desc *desc) { - struct lttng_probe_desc *iter; + struct lttng_ust_probe_desc *iter; struct cds_list_head *probe_list; /* @@ -84,7 +84,7 @@ void lttng_lazy_probe_register(struct lttng_probe_desc *desc) */ /* - * We sort the providers by struct lttng_probe_desc pointer + * We sort the providers by struct lttng_ust_probe_desc pointer * address. */ probe_list = &_probe_list; @@ -109,7 +109,7 @@ desc_added: static void fixup_lazy_probes(void) { - struct lttng_probe_desc *iter, *tmp; + struct lttng_ust_probe_desc *iter, *tmp; int ret; lazy_nesting++; @@ -135,7 +135,7 @@ struct cds_list_head *lttng_get_probe_list_head(void) } static -int check_provider_version(struct lttng_probe_desc *desc) +int check_provider_version(struct lttng_ust_probe_desc *desc) { /* * Check tracepoint provider version compatibility. @@ -164,7 +164,7 @@ int check_provider_version(struct lttng_probe_desc *desc) } -int lttng_probe_register(struct lttng_probe_desc *desc) +int lttng_ust_probe_register(struct lttng_ust_probe_desc *desc) { int ret = 0; @@ -197,7 +197,7 @@ int lttng_probe_register(struct lttng_probe_desc *desc) return ret; } -void lttng_probe_unregister(struct lttng_probe_desc *desc) +void lttng_ust_probe_unregister(struct lttng_ust_probe_desc *desc) { lttng_ust_fixup_tls(); @@ -231,7 +231,7 @@ void lttng_probes_prune_event_list(struct lttng_ust_tracepoint_list *list) */ int lttng_probes_get_event_list(struct lttng_ust_tracepoint_list *list) { - struct lttng_probe_desc *probe_desc; + struct lttng_ust_probe_desc *probe_desc; int i; struct cds_list_head *probe_list; @@ -303,7 +303,7 @@ void lttng_probes_prune_field_list(struct lttng_ust_field_list *list) */ int lttng_probes_get_field_list(struct lttng_ust_field_list *list) { - struct lttng_probe_desc *probe_desc; + struct lttng_ust_probe_desc *probe_desc; int i; struct cds_list_head *probe_list; @@ -311,7 +311,7 @@ int lttng_probes_get_field_list(struct lttng_ust_field_list *list) CDS_INIT_LIST_HEAD(&list->head); cds_list_for_each_entry(probe_desc, probe_list, head) { for (i = 0; i < probe_desc->nr_events; i++) { - const struct lttng_event_desc *event_desc = + const struct lttng_ust_event_desc *event_desc = probe_desc->event_desc[i]; int j; diff --git a/liblttng-ust/ust-events-internal.h b/liblttng-ust/ust-events-internal.h index 0cec2870..ac85b711 100644 --- a/liblttng-ust/ust-events-internal.h +++ b/liblttng-ust/ust-events-internal.h @@ -203,7 +203,7 @@ struct lttng_counter_transport { struct lttng_ust_event_common_private { struct lttng_ust_event_common *pub; /* Public event interface */ - const struct lttng_event_desc *desc; + const struct lttng_ust_event_desc *desc; /* Backward references: list of lttng_enabler_ref (ref to enablers) */ struct cds_list_head enablers_ref_head; int registered; /* has reg'd tracepoint probe */ @@ -346,7 +346,7 @@ int lttng_event_enabler_attach_exclusion(struct lttng_event_enabler *enabler, * event_notifier enabler) to ensure each is linked to the provided instance. */ LTTNG_HIDDEN -void lttng_enabler_link_bytecode(const struct lttng_event_desc *event_desc, +void lttng_enabler_link_bytecode(const struct lttng_ust_event_desc *event_desc, struct lttng_ctx **ctx, struct cds_list_head *instance_bytecode_runtime_head, struct cds_list_head *enabler_bytecode_runtime_head); @@ -533,7 +533,7 @@ LTTNG_HIDDEN void lttng_transport_unregister(struct lttng_transport *transport); LTTNG_HIDDEN -void lttng_probe_provider_unregister_events(struct lttng_probe_desc *desc); +void lttng_probe_provider_unregister_events(struct lttng_ust_probe_desc *desc); LTTNG_HIDDEN int lttng_fix_pending_events(void);