4 * Holds LTTng probes registry.
6 * Copyright 2010-2012 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; only
11 * version 2.1 of the License.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #include <urcu/list.h>
26 #include <urcu/hlist.h>
27 #include <lttng/ust-events.h>
28 #include <lttng/tracepoint.h>
29 #include "tracepoint-internal.h"
34 #include "lttng-tracer-core.h"
39 * probe list is protected by ust_lock()/ust_unlock().
41 static CDS_LIST_HEAD(_probe_list
);
44 * List of probes registered by not yet processed.
46 static CDS_LIST_HEAD(lazy_probe_init
);
49 * lazy_nesting counter ensures we don't trigger lazy probe registration
50 * fixup while we are performing the fixup. It is protected by the ust
53 static int lazy_nesting
;
56 * Called under ust lock.
59 int check_event_provider(struct lttng_probe_desc
*desc
)
62 size_t provider_name_len
;
64 provider_name_len
= strnlen(desc
->provider
,
65 LTTNG_UST_SYM_NAME_LEN
- 1);
66 for (i
= 0; i
< desc
->nr_events
; i
++) {
67 if (strncmp(desc
->event_desc
[i
]->name
,
70 return 0; /* provider mismatch */
76 * Called under ust lock.
79 void lttng_lazy_probe_register(struct lttng_probe_desc
*desc
)
81 struct lttng_probe_desc
*iter
;
82 struct cds_list_head
*probe_list
;
85 * Each provider enforce that every event name begins with the
86 * provider name. Check this in an assertion for extra
87 * carefulness. This ensures we cannot have duplicate event
88 * names across providers.
90 assert(check_event_provider(desc
));
93 * The provider ensures there are no duplicate event names.
94 * Duplicated TRACEPOINT_EVENT event names would generate a
95 * compile-time error due to duplicated symbol names.
99 * We sort the providers by struct lttng_probe_desc pointer
102 probe_list
= &_probe_list
;
103 cds_list_for_each_entry_reverse(iter
, probe_list
, head
) {
104 BUG_ON(iter
== desc
); /* Should never be in the list twice */
106 /* We belong to the location right after iter. */
107 cds_list_add(&desc
->head
, &iter
->head
);
111 /* We should be added at the head of the list */
112 cds_list_add(&desc
->head
, probe_list
);
114 DBG("just registered probe %s containing %u events",
115 desc
->provider
, desc
->nr_events
);
119 * Called under ust lock.
122 void fixup_lazy_probes(void)
124 struct lttng_probe_desc
*iter
, *tmp
;
128 cds_list_for_each_entry_safe(iter
, tmp
,
129 &lazy_probe_init
, lazy_init_head
) {
130 lttng_lazy_probe_register(iter
);
132 cds_list_del(&iter
->lazy_init_head
);
134 ret
= lttng_fix_pending_events();
140 * Called under ust lock.
142 struct cds_list_head
*lttng_get_probe_list_head(void)
144 if (!lazy_nesting
&& !cds_list_empty(&lazy_probe_init
))
150 const struct lttng_probe_desc
*find_provider(const char *provider
)
152 struct lttng_probe_desc
*iter
;
153 struct cds_list_head
*probe_list
;
155 probe_list
= lttng_get_probe_list_head();
156 cds_list_for_each_entry(iter
, probe_list
, head
) {
157 if (!strcmp(iter
->provider
, provider
))
164 int check_provider_version(struct lttng_probe_desc
*desc
)
167 * Check tracepoint provider version compatibility.
169 if (desc
->major
<= LTTNG_UST_PROVIDER_MAJOR
) {
170 DBG("Provider \"%s\" accepted, version %u.%u is compatible "
171 "with LTTng UST provider version %u.%u.",
172 desc
->provider
, desc
->major
, desc
->minor
,
173 LTTNG_UST_PROVIDER_MAJOR
,
174 LTTNG_UST_PROVIDER_MINOR
);
175 if (desc
->major
< LTTNG_UST_PROVIDER_MAJOR
) {
176 DBG("However, some LTTng UST features might not be "
177 "available for this provider unless it is "
178 "recompiled against a more recent LTTng UST.");
180 return 1; /* accept */
182 ERR("Provider \"%s\" rejected, version %u.%u is incompatible "
183 "with LTTng UST provider version %u.%u. Please upgrade "
185 desc
->provider
, desc
->major
, desc
->minor
,
186 LTTNG_UST_PROVIDER_MAJOR
,
187 LTTNG_UST_PROVIDER_MINOR
);
188 return 0; /* reject */
193 int lttng_probe_register(struct lttng_probe_desc
*desc
)
198 * If version mismatch, don't register, but don't trigger assert
199 * on caller. The version check just prints an error.
201 if (!check_provider_version(desc
))
207 * Check if the provider has already been registered.
209 if (find_provider(desc
->provider
)) {
213 cds_list_add(&desc
->lazy_init_head
, &lazy_probe_init
);
215 DBG("adding probe %s containing %u events to lazy registration list",
216 desc
->provider
, desc
->nr_events
);
218 * If there is at least one active session, we need to register
219 * the probe immediately, since we cannot delay event
220 * registration because they are needed ASAP.
222 if (lttng_session_active())
229 /* Backward compatibility with UST 2.0 */
230 int ltt_probe_register(struct lttng_probe_desc
*desc
)
232 return lttng_probe_register(desc
);
235 void lttng_probe_unregister(struct lttng_probe_desc
*desc
)
237 if (!check_provider_version(desc
))
242 cds_list_del(&desc
->head
);
244 cds_list_del(&desc
->lazy_init_head
);
245 DBG("just unregistered probe %s", desc
->provider
);
249 /* Backward compatibility with UST 2.0 */
250 void ltt_probe_unregister(struct lttng_probe_desc
*desc
)
252 lttng_probe_unregister(desc
);
255 void lttng_probes_prune_event_list(struct lttng_ust_tracepoint_list
*list
)
257 struct tp_list_entry
*list_entry
, *tmp
;
259 cds_list_for_each_entry_safe(list_entry
, tmp
, &list
->head
, head
) {
260 cds_list_del(&list_entry
->head
);
266 * called with UST lock held.
268 int lttng_probes_get_event_list(struct lttng_ust_tracepoint_list
*list
)
270 struct lttng_probe_desc
*probe_desc
;
272 struct cds_list_head
*probe_list
;
274 probe_list
= lttng_get_probe_list_head();
275 CDS_INIT_LIST_HEAD(&list
->head
);
276 cds_list_for_each_entry(probe_desc
, probe_list
, head
) {
277 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
278 struct tp_list_entry
*list_entry
;
280 list_entry
= zmalloc(sizeof(*list_entry
));
283 cds_list_add(&list_entry
->head
, &list
->head
);
284 strncpy(list_entry
->tp
.name
,
285 probe_desc
->event_desc
[i
]->name
,
286 LTTNG_UST_SYM_NAME_LEN
);
287 list_entry
->tp
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
288 if (!probe_desc
->event_desc
[i
]->loglevel
) {
289 list_entry
->tp
.loglevel
= TRACE_DEFAULT
;
291 list_entry
->tp
.loglevel
= *(*probe_desc
->event_desc
[i
]->loglevel
);
295 if (cds_list_empty(&list
->head
))
299 cds_list_first_entry(&list
->head
, struct tp_list_entry
, head
);
303 lttng_probes_prune_event_list(list
);
308 * Return current iteration position, advance internal iterator to next.
309 * Return NULL if end of list.
311 struct lttng_ust_tracepoint_iter
*
312 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list
*list
)
314 struct tp_list_entry
*entry
;
319 if (entry
->head
.next
== &list
->head
)
322 list
->iter
= cds_list_entry(entry
->head
.next
,
323 struct tp_list_entry
, head
);
327 void lttng_probes_prune_field_list(struct lttng_ust_field_list
*list
)
329 struct tp_field_list_entry
*list_entry
, *tmp
;
331 cds_list_for_each_entry_safe(list_entry
, tmp
, &list
->head
, head
) {
332 cds_list_del(&list_entry
->head
);
338 * called with UST lock held.
340 int lttng_probes_get_field_list(struct lttng_ust_field_list
*list
)
342 struct lttng_probe_desc
*probe_desc
;
344 struct cds_list_head
*probe_list
;
346 probe_list
= lttng_get_probe_list_head();
347 CDS_INIT_LIST_HEAD(&list
->head
);
348 cds_list_for_each_entry(probe_desc
, probe_list
, head
) {
349 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
350 const struct lttng_event_desc
*event_desc
=
351 probe_desc
->event_desc
[i
];
354 if (event_desc
->nr_fields
== 0) {
355 /* Events without fields. */
356 struct tp_field_list_entry
*list_entry
;
358 list_entry
= zmalloc(sizeof(*list_entry
));
361 cds_list_add(&list_entry
->head
, &list
->head
);
362 strncpy(list_entry
->field
.event_name
,
364 LTTNG_UST_SYM_NAME_LEN
);
365 list_entry
->field
.event_name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
366 list_entry
->field
.field_name
[0] = '\0';
367 list_entry
->field
.type
= LTTNG_UST_FIELD_OTHER
;
368 if (!event_desc
->loglevel
) {
369 list_entry
->field
.loglevel
= TRACE_DEFAULT
;
371 list_entry
->field
.loglevel
= *(*event_desc
->loglevel
);
373 list_entry
->field
.nowrite
= 1;
376 for (j
= 0; j
< event_desc
->nr_fields
; j
++) {
377 const struct lttng_event_field
*event_field
=
378 &event_desc
->fields
[j
];
379 struct tp_field_list_entry
*list_entry
;
381 list_entry
= zmalloc(sizeof(*list_entry
));
384 cds_list_add(&list_entry
->head
, &list
->head
);
385 strncpy(list_entry
->field
.event_name
,
387 LTTNG_UST_SYM_NAME_LEN
);
388 list_entry
->field
.event_name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
389 strncpy(list_entry
->field
.field_name
,
391 LTTNG_UST_SYM_NAME_LEN
);
392 list_entry
->field
.field_name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
393 switch (event_field
->type
.atype
) {
395 list_entry
->field
.type
= LTTNG_UST_FIELD_INTEGER
;
398 list_entry
->field
.type
= LTTNG_UST_FIELD_STRING
;
401 if (event_field
->type
.u
.array
.elem_type
.atype
!= atype_integer
402 || event_field
->type
.u
.array
.elem_type
.u
.basic
.integer
.encoding
== lttng_encode_none
)
403 list_entry
->field
.type
= LTTNG_UST_FIELD_OTHER
;
405 list_entry
->field
.type
= LTTNG_UST_FIELD_STRING
;
408 if (event_field
->type
.u
.sequence
.elem_type
.atype
!= atype_integer
409 || event_field
->type
.u
.sequence
.elem_type
.u
.basic
.integer
.encoding
== lttng_encode_none
)
410 list_entry
->field
.type
= LTTNG_UST_FIELD_OTHER
;
412 list_entry
->field
.type
= LTTNG_UST_FIELD_STRING
;
415 list_entry
->field
.type
= LTTNG_UST_FIELD_FLOAT
;
418 list_entry
->field
.type
= LTTNG_UST_FIELD_ENUM
;
421 list_entry
->field
.type
= LTTNG_UST_FIELD_OTHER
;
423 if (!event_desc
->loglevel
) {
424 list_entry
->field
.loglevel
= TRACE_DEFAULT
;
426 list_entry
->field
.loglevel
= *(*event_desc
->loglevel
);
428 list_entry
->field
.nowrite
= event_field
->nowrite
;
432 if (cds_list_empty(&list
->head
))
436 cds_list_first_entry(&list
->head
,
437 struct tp_field_list_entry
, head
);
441 lttng_probes_prune_field_list(list
);
446 * Return current iteration position, advance internal iterator to next.
447 * Return NULL if end of list.
449 struct lttng_ust_field_iter
*
450 lttng_ust_field_list_get_iter_next(struct lttng_ust_field_list
*list
)
452 struct tp_field_list_entry
*entry
;
457 if (entry
->head
.next
== &list
->head
)
460 list
->iter
= cds_list_entry(entry
->head
.next
,
461 struct tp_field_list_entry
, head
);
462 return &entry
->field
;