X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=liblttng-ust%2Flttng-probes.c;h=00ce54cb36a9117338cecf4cc1bc3496f0b94227;hb=f574bfb4d81b26d3cfc0243868d138e33470a950;hp=e473b9890c9395f73121736a6dc6333399e373a1;hpb=7dd08bec735b428479201f9f84d59c78deabdf57;p=lttng-ust.git diff --git a/liblttng-ust/lttng-probes.c b/liblttng-ust/lttng-probes.c index e473b989..00ce54cb 100644 --- a/liblttng-ust/lttng-probes.c +++ b/liblttng-ust/lttng-probes.c @@ -1,25 +1,12 @@ /* - * lttng-probes.c + * SPDX-License-Identifier: LGPL-2.1-only * - * Holds LTTng probes registry. - * - * Copyright 2010-2012 (c) - Mathieu Desnoyers - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; only - * version 2.1 of the License. + * Copyright 2010-2012 (C) Mathieu Desnoyers * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Holds LTTng probes registry. */ +#define _LGPL_SOURCE #include #include #include @@ -28,73 +15,80 @@ #include #include "tracepoint-internal.h" #include -#include +#include #include #include "lttng-tracer-core.h" #include "jhash.h" #include "error.h" +#include "ust-events-internal.h" /* * probe list is protected by ust_lock()/ust_unlock(). */ -static CDS_LIST_HEAD(probe_list); +static CDS_LIST_HEAD(_probe_list); -static -const struct lttng_probe_desc *find_provider(const char *provider) -{ - struct lttng_probe_desc *iter; +/* + * List of probes registered by not yet processed. + */ +static CDS_LIST_HEAD(lazy_probe_init); - cds_list_for_each_entry(iter, &probe_list, head) { - if (!strcmp(iter->provider, provider)) - return iter; - } - return NULL; -} +/* + * lazy_nesting counter ensures we don't trigger lazy probe registration + * fixup while we are performing the fixup. It is protected by the ust + * mutex. + */ +static int lazy_nesting; +/* + * Called under ust lock. + */ static -const struct lttng_event_desc *find_event(const char *name) +int check_event_provider(struct lttng_ust_probe_desc *desc) { - struct lttng_probe_desc *probe_desc; int i; + size_t provider_name_len; - cds_list_for_each_entry(probe_desc, &probe_list, head) { - for (i = 0; i < probe_desc->nr_events; i++) { - if (!strncmp(probe_desc->event_desc[i]->name, name, - LTTNG_UST_SYM_NAME_LEN - 1)) - return probe_desc->event_desc[i]; - } + provider_name_len = strnlen(desc->provider, + LTTNG_UST_ABI_SYM_NAME_LEN - 1); + for (i = 0; i < desc->nr_events; i++) { + if (strncmp(desc->event_desc[i]->name, + desc->provider, + provider_name_len)) + return 0; /* provider mismatch */ } - return NULL; + return 1; } -int lttng_probe_register(struct lttng_probe_desc *desc) +/* + * Called under ust lock. + */ +static +void lttng_lazy_probe_register(struct lttng_ust_probe_desc *desc) { - struct lttng_probe_desc *iter; - int ret = 0; - int i; + struct lttng_ust_probe_desc *iter; + struct cds_list_head *probe_list; - ust_lock(); - if (find_provider(desc->provider)) { - ret = -EEXIST; - goto end; - } /* - * TODO: This is O(N^2). Turn into a hash table when probe registration - * overhead becomes an issue. + * Each provider enforce that every event name begins with the + * provider name. Check this in an assertion for extra + * carefulness. This ensures we cannot have duplicate event + * names across providers. */ - for (i = 0; i < desc->nr_events; i++) { - if (find_event(desc->event_desc[i]->name)) { - ret = -EEXIST; - goto end; - } - } + assert(check_event_provider(desc)); /* - * We sort the providers by struct lttng_probe_desc pointer + * The provider ensures there are no duplicate event names. + * Duplicated TRACEPOINT_EVENT event names would generate a + * compile-time error due to duplicated symbol names. + */ + + /* + * We sort the providers by struct lttng_ust_probe_desc pointer * address. */ - cds_list_for_each_entry_reverse(iter, &probe_list, head) { + probe_list = &_probe_list; + cds_list_for_each_entry_reverse(iter, probe_list, head) { BUG_ON(iter == desc); /* Should never be in the list twice */ if (iter < desc) { /* We belong to the location right after iter. */ @@ -103,62 +97,123 @@ int lttng_probe_register(struct lttng_probe_desc *desc) } } /* We should be added at the head of the list */ - cds_list_add(&desc->head, &probe_list); + cds_list_add(&desc->head, probe_list); desc_added: DBG("just registered probe %s containing %u events", desc->provider, desc->nr_events); - /* - * fix the events awaiting probe load. - */ - for (i = 0; i < desc->nr_events; i++) { - const struct lttng_event_desc *ed; - - ed = desc->event_desc[i]; - DBG("Registered event probe \"%s\" with signature \"%s\"", - ed->name, ed->signature); - ret = pending_probe_fix_events(ed); - assert(!ret); - } -end: - ust_unlock(); - return ret; } -/* Backward compatibility with UST 2.0 */ -int ltt_probe_register(struct lttng_probe_desc *desc) +/* + * Called under ust lock. + */ +static +void fixup_lazy_probes(void) { - return lttng_probe_register(desc); + struct lttng_ust_probe_desc *iter, *tmp; + int ret; + + lazy_nesting++; + cds_list_for_each_entry_safe(iter, tmp, + &lazy_probe_init, lazy_init_head) { + lttng_lazy_probe_register(iter); + iter->lazy = 0; + cds_list_del(&iter->lazy_init_head); + } + ret = lttng_fix_pending_events(); + assert(!ret); + lazy_nesting--; } -void lttng_probe_unregister(struct lttng_probe_desc *desc) +/* + * Called under ust lock. + */ +struct cds_list_head *lttng_get_probe_list_head(void) { - ust_lock(); - cds_list_del(&desc->head); - DBG("just unregistered probe %s", desc->provider); - ust_unlock(); + if (!lazy_nesting && !cds_list_empty(&lazy_probe_init)) + fixup_lazy_probes(); + return &_probe_list; } -/* Backward compatibility with UST 2.0 */ -void ltt_probe_unregister(struct lttng_probe_desc *desc) +static +int check_provider_version(struct lttng_ust_probe_desc *desc) { - lttng_probe_unregister(desc); + /* + * Check tracepoint provider version compatibility. + */ + if (desc->major <= LTTNG_UST_PROVIDER_MAJOR) { + DBG("Provider \"%s\" accepted, version %u.%u is compatible " + "with LTTng UST provider version %u.%u.", + desc->provider, desc->major, desc->minor, + LTTNG_UST_PROVIDER_MAJOR, + LTTNG_UST_PROVIDER_MINOR); + if (desc->major < LTTNG_UST_PROVIDER_MAJOR) { + DBG("However, some LTTng UST features might not be " + "available for this provider unless it is " + "recompiled against a more recent LTTng UST."); + } + return 1; /* accept */ + } else { + ERR("Provider \"%s\" rejected, version %u.%u is incompatible " + "with LTTng UST provider version %u.%u. Please upgrade " + "LTTng UST.", + desc->provider, desc->major, desc->minor, + LTTNG_UST_PROVIDER_MAJOR, + LTTNG_UST_PROVIDER_MINOR); + return 0; /* reject */ + } } -/* - * called with UST lock held. - */ -const struct lttng_event_desc *lttng_event_get(const char *name) + +int lttng_ust_probe_register(struct lttng_ust_probe_desc *desc) { - const struct lttng_event_desc *event; + int ret = 0; - event = find_event(name); - if (!event) - return NULL; - return event; + lttng_ust_fixup_tls(); + + /* + * If version mismatch, don't register, but don't trigger assert + * on caller. The version check just prints an error. + */ + if (!check_provider_version(desc)) + return 0; + + ust_lock_nocheck(); + + cds_list_add(&desc->lazy_init_head, &lazy_probe_init); + desc->lazy = 1; + DBG("adding probe %s containing %u events to lazy registration list", + desc->provider, desc->nr_events); + /* + * If there is at least one active session, we need to register + * the probe immediately, since we cannot delay event + * registration because they are needed ASAP. + */ + if (lttng_session_active()) + fixup_lazy_probes(); + + lttng_fix_pending_event_notifiers(); + + ust_unlock(); + return ret; } -void lttng_event_put(const struct lttng_event_desc *event) +void lttng_ust_probe_unregister(struct lttng_ust_probe_desc *desc) { + lttng_ust_fixup_tls(); + + if (!check_provider_version(desc)) + return; + + ust_lock_nocheck(); + if (!desc->lazy) + cds_list_del(&desc->head); + else + cds_list_del(&desc->lazy_init_head); + + lttng_probe_provider_unregister_events(desc); + DBG("just unregistered probes of provider %s", desc->provider); + + ust_unlock(); } void lttng_probes_prune_event_list(struct lttng_ust_tracepoint_list *list) @@ -176,11 +231,13 @@ 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; + probe_list = lttng_get_probe_list_head(); CDS_INIT_LIST_HEAD(&list->head); - cds_list_for_each_entry(probe_desc, &probe_list, head) { + cds_list_for_each_entry(probe_desc, probe_list, head) { for (i = 0; i < probe_desc->nr_events; i++) { struct tp_list_entry *list_entry; @@ -190,8 +247,8 @@ int lttng_probes_get_event_list(struct lttng_ust_tracepoint_list *list) cds_list_add(&list_entry->head, &list->head); strncpy(list_entry->tp.name, probe_desc->event_desc[i]->name, - LTTNG_UST_SYM_NAME_LEN); - list_entry->tp.name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0'; + LTTNG_UST_ABI_SYM_NAME_LEN); + list_entry->tp.name[LTTNG_UST_ABI_SYM_NAME_LEN - 1] = '\0'; if (!probe_desc->event_desc[i]->loglevel) { list_entry->tp.loglevel = TRACE_DEFAULT; } else { @@ -215,7 +272,7 @@ err_nomem: * Return current iteration position, advance internal iterator to next. * Return NULL if end of list. */ -struct lttng_ust_tracepoint_iter * +struct lttng_ust_abi_tracepoint_iter * lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list *list) { struct tp_list_entry *entry; @@ -246,13 +303,15 @@ 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; + probe_list = lttng_get_probe_list_head(); CDS_INIT_LIST_HEAD(&list->head); - cds_list_for_each_entry(probe_desc, &probe_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; @@ -266,10 +325,10 @@ int lttng_probes_get_field_list(struct lttng_ust_field_list *list) cds_list_add(&list_entry->head, &list->head); strncpy(list_entry->field.event_name, event_desc->name, - LTTNG_UST_SYM_NAME_LEN); - list_entry->field.event_name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0'; + LTTNG_UST_ABI_SYM_NAME_LEN); + list_entry->field.event_name[LTTNG_UST_ABI_SYM_NAME_LEN - 1] = '\0'; list_entry->field.field_name[0] = '\0'; - list_entry->field.type = LTTNG_UST_FIELD_OTHER; + list_entry->field.type = LTTNG_UST_ABI_FIELD_OTHER; if (!event_desc->loglevel) { list_entry->field.loglevel = TRACE_DEFAULT; } else { @@ -279,8 +338,8 @@ int lttng_probes_get_field_list(struct lttng_ust_field_list *list) } for (j = 0; j < event_desc->nr_fields; j++) { - const struct lttng_event_field *event_field = - &event_desc->fields[j]; + const struct lttng_ust_event_field *event_field = + event_desc->fields[j]; struct tp_field_list_entry *list_entry; list_entry = zmalloc(sizeof(*list_entry)); @@ -289,41 +348,39 @@ int lttng_probes_get_field_list(struct lttng_ust_field_list *list) cds_list_add(&list_entry->head, &list->head); strncpy(list_entry->field.event_name, event_desc->name, - LTTNG_UST_SYM_NAME_LEN); - list_entry->field.event_name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0'; + LTTNG_UST_ABI_SYM_NAME_LEN); + list_entry->field.event_name[LTTNG_UST_ABI_SYM_NAME_LEN - 1] = '\0'; strncpy(list_entry->field.field_name, event_field->name, - LTTNG_UST_SYM_NAME_LEN); - list_entry->field.field_name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0'; - switch (event_field->type.atype) { - case atype_integer: - list_entry->field.type = LTTNG_UST_FIELD_INTEGER; + LTTNG_UST_ABI_SYM_NAME_LEN); + list_entry->field.field_name[LTTNG_UST_ABI_SYM_NAME_LEN - 1] = '\0'; + switch (event_field->type->type) { + case lttng_ust_type_integer: + list_entry->field.type = LTTNG_UST_ABI_FIELD_INTEGER; break; - case atype_string: - list_entry->field.type = LTTNG_UST_FIELD_STRING; + case lttng_ust_type_string: + list_entry->field.type = LTTNG_UST_ABI_FIELD_STRING; break; - case atype_array: - if (event_field->type.u.array.elem_type.atype != atype_integer - || event_field->type.u.array.elem_type.u.basic.integer.encoding == lttng_encode_none) - list_entry->field.type = LTTNG_UST_FIELD_OTHER; + case lttng_ust_type_array: + if (lttng_ust_get_type_array(event_field->type)->encoding == lttng_ust_string_encoding_none) + list_entry->field.type = LTTNG_UST_ABI_FIELD_OTHER; else - list_entry->field.type = LTTNG_UST_FIELD_STRING; + list_entry->field.type = LTTNG_UST_ABI_FIELD_STRING; break; - case atype_sequence: - if (event_field->type.u.sequence.elem_type.atype != atype_integer - || event_field->type.u.sequence.elem_type.u.basic.integer.encoding == lttng_encode_none) - list_entry->field.type = LTTNG_UST_FIELD_OTHER; + case lttng_ust_type_sequence: + if (lttng_ust_get_type_sequence(event_field->type)->encoding == lttng_ust_string_encoding_none) + list_entry->field.type = LTTNG_UST_ABI_FIELD_OTHER; else - list_entry->field.type = LTTNG_UST_FIELD_STRING; + list_entry->field.type = LTTNG_UST_ABI_FIELD_STRING; break; - case atype_float: - list_entry->field.type = LTTNG_UST_FIELD_FLOAT; + case lttng_ust_type_float: + list_entry->field.type = LTTNG_UST_ABI_FIELD_FLOAT; break; - case atype_enum: - list_entry->field.type = LTTNG_UST_FIELD_ENUM; + case lttng_ust_type_enum: + list_entry->field.type = LTTNG_UST_ABI_FIELD_ENUM; break; default: - list_entry->field.type = LTTNG_UST_FIELD_OTHER; + list_entry->field.type = LTTNG_UST_ABI_FIELD_OTHER; } if (!event_desc->loglevel) { list_entry->field.loglevel = TRACE_DEFAULT; @@ -351,7 +408,7 @@ err_nomem: * Return current iteration position, advance internal iterator to next. * Return NULL if end of list. */ -struct lttng_ust_field_iter * +struct lttng_ust_abi_field_iter * lttng_ust_field_list_get_iter_next(struct lttng_ust_field_list *list) { struct tp_field_list_entry *entry; @@ -366,58 +423,3 @@ struct lttng_ust_field_iter * struct tp_field_list_entry, head); return &entry->field; } - -/* - * marshall all probes/all events and create those that fit the - * wildcard. Add them to the events list as created. - */ -void lttng_probes_create_wildcard_events(struct wildcard_entry *entry, - struct session_wildcard *wildcard) -{ - struct lttng_probe_desc *probe_desc; - struct lttng_ust_event event_param; - int i; - - 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; - int match = 0; - - event_desc = probe_desc->event_desc[i]; - /* compare excluding final '*' */ - assert(strlen(entry->name) > 0); - if (strcmp(event_desc->name, "lttng_ust:metadata") - && (strlen(entry->name) == 1 - || !strncmp(event_desc->name, entry->name, - strlen(entry->name) - 1))) { - if (lttng_loglevel_match(event_desc, - entry->loglevel_type, - entry->loglevel)) { - match = 1; - } - } - if (match) { - struct lttng_event *ev; - int ret; - - memcpy(&event_param, &wildcard->event_param, - sizeof(event_param)); - strncpy(event_param.name, - event_desc->name, - sizeof(event_param.name)); - event_param.name[sizeof(event_param.name) - 1] = '\0'; - /* create event */ - ret = lttng_event_create(wildcard->chan, - &event_param, &ev); - if (ret) { - DBG("Error creating event"); - continue; - } - cds_list_add(&ev->wildcard_list, - &wildcard->events); - } - } - } - lttng_filter_wildcard_link_bytecode(wildcard); -} -