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
26 #include <urcu/list.h>
27 #include <urcu/hlist.h>
28 #include <lttng/ust-events.h>
29 #include <lttng/tracepoint.h>
30 #include "tracepoint-internal.h"
35 #include "lttng-tracer-core.h"
38 #include "ust-events-internal.h"
41 * probe list is protected by ust_lock()/ust_unlock().
43 static CDS_LIST_HEAD(_probe_list
);
46 * List of probes registered by not yet processed.
48 static CDS_LIST_HEAD(lazy_probe_init
);
51 * lazy_nesting counter ensures we don't trigger lazy probe registration
52 * fixup while we are performing the fixup. It is protected by the ust
55 static int lazy_nesting
;
58 * Called under ust lock.
61 int check_event_provider(struct lttng_probe_desc
*desc
)
64 size_t provider_name_len
;
66 provider_name_len
= strnlen(desc
->provider
,
67 LTTNG_UST_SYM_NAME_LEN
- 1);
68 for (i
= 0; i
< desc
->nr_events
; i
++) {
69 if (strncmp(desc
->event_desc
[i
]->name
,
72 return 0; /* provider mismatch */
78 * Called under ust lock.
81 void lttng_lazy_probe_register(struct lttng_probe_desc
*desc
)
83 struct lttng_probe_desc
*iter
;
84 struct cds_list_head
*probe_list
;
87 * Each provider enforce that every event name begins with the
88 * provider name. Check this in an assertion for extra
89 * carefulness. This ensures we cannot have duplicate event
90 * names across providers.
92 assert(check_event_provider(desc
));
95 * The provider ensures there are no duplicate event names.
96 * Duplicated TRACEPOINT_EVENT event names would generate a
97 * compile-time error due to duplicated symbol names.
101 * We sort the providers by struct lttng_probe_desc pointer
104 probe_list
= &_probe_list
;
105 cds_list_for_each_entry_reverse(iter
, probe_list
, head
) {
106 BUG_ON(iter
== desc
); /* Should never be in the list twice */
108 /* We belong to the location right after iter. */
109 cds_list_add(&desc
->head
, &iter
->head
);
113 /* We should be added at the head of the list */
114 cds_list_add(&desc
->head
, probe_list
);
116 DBG("just registered probe %s containing %u events",
117 desc
->provider
, desc
->nr_events
);
121 * Called under ust lock.
124 void fixup_lazy_probes(void)
126 struct lttng_probe_desc
*iter
, *tmp
;
130 cds_list_for_each_entry_safe(iter
, tmp
,
131 &lazy_probe_init
, lazy_init_head
) {
132 lttng_lazy_probe_register(iter
);
134 cds_list_del(&iter
->lazy_init_head
);
136 ret
= lttng_fix_pending_events();
142 * Called under ust lock.
144 struct cds_list_head
*lttng_get_probe_list_head(void)
146 if (!lazy_nesting
&& !cds_list_empty(&lazy_probe_init
))
152 int check_provider_version(struct lttng_probe_desc
*desc
)
155 * Check tracepoint provider version compatibility.
157 if (desc
->major
<= LTTNG_UST_PROVIDER_MAJOR
) {
158 DBG("Provider \"%s\" accepted, version %u.%u is compatible "
159 "with LTTng UST provider version %u.%u.",
160 desc
->provider
, desc
->major
, desc
->minor
,
161 LTTNG_UST_PROVIDER_MAJOR
,
162 LTTNG_UST_PROVIDER_MINOR
);
163 if (desc
->major
< LTTNG_UST_PROVIDER_MAJOR
) {
164 DBG("However, some LTTng UST features might not be "
165 "available for this provider unless it is "
166 "recompiled against a more recent LTTng UST.");
168 return 1; /* accept */
170 ERR("Provider \"%s\" rejected, version %u.%u is incompatible "
171 "with LTTng UST provider version %u.%u. Please upgrade "
173 desc
->provider
, desc
->major
, desc
->minor
,
174 LTTNG_UST_PROVIDER_MAJOR
,
175 LTTNG_UST_PROVIDER_MINOR
);
176 return 0; /* reject */
181 int lttng_probe_register(struct lttng_probe_desc
*desc
)
185 lttng_ust_fixup_tls();
188 * If version mismatch, don't register, but don't trigger assert
189 * on caller. The version check just prints an error.
191 if (!check_provider_version(desc
))
196 cds_list_add(&desc
->lazy_init_head
, &lazy_probe_init
);
198 DBG("adding probe %s containing %u events to lazy registration list",
199 desc
->provider
, desc
->nr_events
);
201 * If there is at least one active session, we need to register
202 * the probe immediately, since we cannot delay event
203 * registration because they are needed ASAP.
205 if (lttng_session_active())
208 lttng_fix_pending_event_notifiers();
214 void lttng_probe_unregister(struct lttng_probe_desc
*desc
)
216 lttng_ust_fixup_tls();
218 if (!check_provider_version(desc
))
223 cds_list_del(&desc
->head
);
225 cds_list_del(&desc
->lazy_init_head
);
227 lttng_probe_provider_unregister_events(desc
);
228 DBG("just unregistered probes of provider %s", desc
->provider
);
233 void lttng_probes_prune_event_list(struct lttng_ust_tracepoint_list
*list
)
235 struct tp_list_entry
*list_entry
, *tmp
;
237 cds_list_for_each_entry_safe(list_entry
, tmp
, &list
->head
, head
) {
238 cds_list_del(&list_entry
->head
);
244 * called with UST lock held.
246 int lttng_probes_get_event_list(struct lttng_ust_tracepoint_list
*list
)
248 struct lttng_probe_desc
*probe_desc
;
250 struct cds_list_head
*probe_list
;
252 probe_list
= lttng_get_probe_list_head();
253 CDS_INIT_LIST_HEAD(&list
->head
);
254 cds_list_for_each_entry(probe_desc
, probe_list
, head
) {
255 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
256 struct tp_list_entry
*list_entry
;
258 list_entry
= zmalloc(sizeof(*list_entry
));
261 cds_list_add(&list_entry
->head
, &list
->head
);
262 strncpy(list_entry
->tp
.name
,
263 probe_desc
->event_desc
[i
]->name
,
264 LTTNG_UST_SYM_NAME_LEN
);
265 list_entry
->tp
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
266 if (!probe_desc
->event_desc
[i
]->loglevel
) {
267 list_entry
->tp
.loglevel
= TRACE_DEFAULT
;
269 list_entry
->tp
.loglevel
= *(*probe_desc
->event_desc
[i
]->loglevel
);
273 if (cds_list_empty(&list
->head
))
277 cds_list_first_entry(&list
->head
, struct tp_list_entry
, head
);
281 lttng_probes_prune_event_list(list
);
286 * Return current iteration position, advance internal iterator to next.
287 * Return NULL if end of list.
289 struct lttng_ust_tracepoint_iter
*
290 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list
*list
)
292 struct tp_list_entry
*entry
;
297 if (entry
->head
.next
== &list
->head
)
300 list
->iter
= cds_list_entry(entry
->head
.next
,
301 struct tp_list_entry
, head
);
305 void lttng_probes_prune_field_list(struct lttng_ust_field_list
*list
)
307 struct tp_field_list_entry
*list_entry
, *tmp
;
309 cds_list_for_each_entry_safe(list_entry
, tmp
, &list
->head
, head
) {
310 cds_list_del(&list_entry
->head
);
316 * called with UST lock held.
318 int lttng_probes_get_field_list(struct lttng_ust_field_list
*list
)
320 struct lttng_probe_desc
*probe_desc
;
322 struct cds_list_head
*probe_list
;
324 probe_list
= lttng_get_probe_list_head();
325 CDS_INIT_LIST_HEAD(&list
->head
);
326 cds_list_for_each_entry(probe_desc
, probe_list
, head
) {
327 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
328 const struct lttng_event_desc
*event_desc
=
329 probe_desc
->event_desc
[i
];
332 if (event_desc
->nr_fields
== 0) {
333 /* Events without fields. */
334 struct tp_field_list_entry
*list_entry
;
336 list_entry
= zmalloc(sizeof(*list_entry
));
339 cds_list_add(&list_entry
->head
, &list
->head
);
340 strncpy(list_entry
->field
.event_name
,
342 LTTNG_UST_SYM_NAME_LEN
);
343 list_entry
->field
.event_name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
344 list_entry
->field
.field_name
[0] = '\0';
345 list_entry
->field
.type
= LTTNG_UST_FIELD_OTHER
;
346 if (!event_desc
->loglevel
) {
347 list_entry
->field
.loglevel
= TRACE_DEFAULT
;
349 list_entry
->field
.loglevel
= *(*event_desc
->loglevel
);
351 list_entry
->field
.nowrite
= 1;
354 for (j
= 0; j
< event_desc
->nr_fields
; j
++) {
355 const struct lttng_event_field
*event_field
=
356 &event_desc
->fields
[j
];
357 struct tp_field_list_entry
*list_entry
;
359 list_entry
= zmalloc(sizeof(*list_entry
));
362 cds_list_add(&list_entry
->head
, &list
->head
);
363 strncpy(list_entry
->field
.event_name
,
365 LTTNG_UST_SYM_NAME_LEN
);
366 list_entry
->field
.event_name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
367 strncpy(list_entry
->field
.field_name
,
369 LTTNG_UST_SYM_NAME_LEN
);
370 list_entry
->field
.field_name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
371 switch (event_field
->type
.atype
) {
373 list_entry
->field
.type
= LTTNG_UST_FIELD_INTEGER
;
376 list_entry
->field
.type
= LTTNG_UST_FIELD_STRING
;
379 if (event_field
->type
.u
.legacy
.array
.elem_type
.atype
!= atype_integer
380 || event_field
->type
.u
.legacy
.array
.elem_type
.u
.basic
.integer
.encoding
== lttng_encode_none
)
381 list_entry
->field
.type
= LTTNG_UST_FIELD_OTHER
;
383 list_entry
->field
.type
= LTTNG_UST_FIELD_STRING
;
385 case atype_array_nestable
:
386 if (event_field
->type
.u
.array_nestable
.elem_type
->atype
!= atype_integer
387 || event_field
->type
.u
.array_nestable
.elem_type
->u
.integer
.encoding
== lttng_encode_none
)
388 list_entry
->field
.type
= LTTNG_UST_FIELD_OTHER
;
390 list_entry
->field
.type
= LTTNG_UST_FIELD_STRING
;
393 if (event_field
->type
.u
.legacy
.sequence
.elem_type
.atype
!= atype_integer
394 || event_field
->type
.u
.legacy
.sequence
.elem_type
.u
.basic
.integer
.encoding
== lttng_encode_none
)
395 list_entry
->field
.type
= LTTNG_UST_FIELD_OTHER
;
397 list_entry
->field
.type
= LTTNG_UST_FIELD_STRING
;
399 case atype_sequence_nestable
:
400 if (event_field
->type
.u
.sequence_nestable
.elem_type
->atype
!= atype_integer
401 || event_field
->type
.u
.sequence_nestable
.elem_type
->u
.integer
.encoding
== lttng_encode_none
)
402 list_entry
->field
.type
= LTTNG_UST_FIELD_OTHER
;
404 list_entry
->field
.type
= LTTNG_UST_FIELD_STRING
;
407 list_entry
->field
.type
= LTTNG_UST_FIELD_FLOAT
;
409 case atype_enum
: /* Fall-through */
410 case atype_enum_nestable
:
411 list_entry
->field
.type
= LTTNG_UST_FIELD_ENUM
;
414 list_entry
->field
.type
= LTTNG_UST_FIELD_OTHER
;
416 if (!event_desc
->loglevel
) {
417 list_entry
->field
.loglevel
= TRACE_DEFAULT
;
419 list_entry
->field
.loglevel
= *(*event_desc
->loglevel
);
421 list_entry
->field
.nowrite
= event_field
->nowrite
;
425 if (cds_list_empty(&list
->head
))
429 cds_list_first_entry(&list
->head
,
430 struct tp_field_list_entry
, head
);
434 lttng_probes_prune_field_list(list
);
439 * Return current iteration position, advance internal iterator to next.
440 * Return NULL if end of list.
442 struct lttng_ust_field_iter
*
443 lttng_ust_field_list_get_iter_next(struct lttng_ust_field_list
*list
)
445 struct tp_field_list_entry
*entry
;
450 if (entry
->head
.next
== &list
->head
)
453 list
->iter
= cds_list_entry(entry
->head
.next
,
454 struct tp_field_list_entry
, head
);
455 return &entry
->field
;