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"
40 * probe list is protected by ust_lock()/ust_unlock().
42 static CDS_LIST_HEAD(_probe_list
);
45 * List of probes registered by not yet processed.
47 static CDS_LIST_HEAD(lazy_probe_init
);
50 * lazy_nesting counter ensures we don't trigger lazy probe registration
51 * fixup while we are performing the fixup. It is protected by the ust
54 static int lazy_nesting
;
57 * Called under ust lock.
60 int check_event_provider(struct lttng_probe_desc
*desc
)
63 size_t provider_name_len
;
65 provider_name_len
= strnlen(desc
->provider
,
66 LTTNG_UST_SYM_NAME_LEN
- 1);
67 for (i
= 0; i
< desc
->nr_events
; i
++) {
68 if (strncmp(desc
->event_desc
[i
]->name
,
71 return 0; /* provider mismatch */
77 * Called under ust lock.
80 void lttng_lazy_probe_register(struct lttng_probe_desc
*desc
)
82 struct lttng_probe_desc
*iter
;
83 struct cds_list_head
*probe_list
;
86 * Each provider enforce that every event name begins with the
87 * provider name. Check this in an assertion for extra
88 * carefulness. This ensures we cannot have duplicate event
89 * names across providers.
91 assert(check_event_provider(desc
));
94 * The provider ensures there are no duplicate event names.
95 * Duplicated TRACEPOINT_EVENT event names would generate a
96 * compile-time error due to duplicated symbol names.
100 * We sort the providers by struct lttng_probe_desc pointer
103 probe_list
= &_probe_list
;
104 cds_list_for_each_entry_reverse(iter
, probe_list
, head
) {
105 BUG_ON(iter
== desc
); /* Should never be in the list twice */
107 /* We belong to the location right after iter. */
108 cds_list_add(&desc
->head
, &iter
->head
);
112 /* We should be added at the head of the list */
113 cds_list_add(&desc
->head
, probe_list
);
115 DBG("just registered probe %s containing %u events",
116 desc
->provider
, desc
->nr_events
);
120 * Called under ust lock.
123 void fixup_lazy_probes(void)
125 struct lttng_probe_desc
*iter
, *tmp
;
129 cds_list_for_each_entry_safe(iter
, tmp
,
130 &lazy_probe_init
, lazy_init_head
) {
131 lttng_lazy_probe_register(iter
);
133 cds_list_del(&iter
->lazy_init_head
);
135 ret
= lttng_fix_pending_events();
141 * Called under ust lock.
143 struct cds_list_head
*lttng_get_probe_list_head(void)
145 if (!lazy_nesting
&& !cds_list_empty(&lazy_probe_init
))
151 int check_provider_version(struct lttng_probe_desc
*desc
)
154 * Check tracepoint provider version compatibility.
156 if (desc
->major
<= LTTNG_UST_PROVIDER_MAJOR
) {
157 DBG("Provider \"%s\" accepted, version %u.%u is compatible "
158 "with LTTng UST provider version %u.%u.",
159 desc
->provider
, desc
->major
, desc
->minor
,
160 LTTNG_UST_PROVIDER_MAJOR
,
161 LTTNG_UST_PROVIDER_MINOR
);
162 if (desc
->major
< LTTNG_UST_PROVIDER_MAJOR
) {
163 DBG("However, some LTTng UST features might not be "
164 "available for this provider unless it is "
165 "recompiled against a more recent LTTng UST.");
167 return 1; /* accept */
169 ERR("Provider \"%s\" rejected, version %u.%u is incompatible "
170 "with LTTng UST provider version %u.%u. Please upgrade "
172 desc
->provider
, desc
->major
, desc
->minor
,
173 LTTNG_UST_PROVIDER_MAJOR
,
174 LTTNG_UST_PROVIDER_MINOR
);
175 return 0; /* reject */
180 int lttng_probe_register(struct lttng_probe_desc
*desc
)
184 lttng_ust_fixup_tls();
187 * If version mismatch, don't register, but don't trigger assert
188 * on caller. The version check just prints an error.
190 if (!check_provider_version(desc
))
195 cds_list_add(&desc
->lazy_init_head
, &lazy_probe_init
);
197 DBG("adding probe %s containing %u events to lazy registration list",
198 desc
->provider
, desc
->nr_events
);
200 * If there is at least one active session, we need to register
201 * the probe immediately, since we cannot delay event
202 * registration because they are needed ASAP.
204 if (lttng_session_active())
211 /* Backward compatibility with UST 2.0 */
212 int ltt_probe_register(struct lttng_probe_desc
*desc
)
214 return lttng_probe_register(desc
);
217 void lttng_probe_unregister(struct lttng_probe_desc
*desc
)
219 lttng_ust_fixup_tls();
221 if (!check_provider_version(desc
))
226 cds_list_del(&desc
->head
);
228 cds_list_del(&desc
->lazy_init_head
);
229 DBG("just unregistered probe %s", desc
->provider
);
233 /* Backward compatibility with UST 2.0 */
234 void ltt_probe_unregister(struct lttng_probe_desc
*desc
)
236 lttng_probe_unregister(desc
);
239 void lttng_probes_prune_event_list(struct lttng_ust_tracepoint_list
*list
)
241 struct tp_list_entry
*list_entry
, *tmp
;
243 cds_list_for_each_entry_safe(list_entry
, tmp
, &list
->head
, head
) {
244 cds_list_del(&list_entry
->head
);
250 * called with UST lock held.
252 int lttng_probes_get_event_list(struct lttng_ust_tracepoint_list
*list
)
254 struct lttng_probe_desc
*probe_desc
;
256 struct cds_list_head
*probe_list
;
258 probe_list
= lttng_get_probe_list_head();
259 CDS_INIT_LIST_HEAD(&list
->head
);
260 cds_list_for_each_entry(probe_desc
, probe_list
, head
) {
261 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
262 struct tp_list_entry
*list_entry
;
264 list_entry
= zmalloc(sizeof(*list_entry
));
267 cds_list_add(&list_entry
->head
, &list
->head
);
268 strncpy(list_entry
->tp
.name
,
269 probe_desc
->event_desc
[i
]->name
,
270 LTTNG_UST_SYM_NAME_LEN
);
271 list_entry
->tp
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
272 if (!probe_desc
->event_desc
[i
]->loglevel
) {
273 list_entry
->tp
.loglevel
= TRACE_DEFAULT
;
275 list_entry
->tp
.loglevel
= *(*probe_desc
->event_desc
[i
]->loglevel
);
279 if (cds_list_empty(&list
->head
))
283 cds_list_first_entry(&list
->head
, struct tp_list_entry
, head
);
287 lttng_probes_prune_event_list(list
);
292 * Return current iteration position, advance internal iterator to next.
293 * Return NULL if end of list.
295 struct lttng_ust_tracepoint_iter
*
296 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list
*list
)
298 struct tp_list_entry
*entry
;
303 if (entry
->head
.next
== &list
->head
)
306 list
->iter
= cds_list_entry(entry
->head
.next
,
307 struct tp_list_entry
, head
);
311 void lttng_probes_prune_field_list(struct lttng_ust_field_list
*list
)
313 struct tp_field_list_entry
*list_entry
, *tmp
;
315 cds_list_for_each_entry_safe(list_entry
, tmp
, &list
->head
, head
) {
316 cds_list_del(&list_entry
->head
);
322 * called with UST lock held.
324 int lttng_probes_get_field_list(struct lttng_ust_field_list
*list
)
326 struct lttng_probe_desc
*probe_desc
;
328 struct cds_list_head
*probe_list
;
330 probe_list
= lttng_get_probe_list_head();
331 CDS_INIT_LIST_HEAD(&list
->head
);
332 cds_list_for_each_entry(probe_desc
, probe_list
, head
) {
333 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
334 const struct lttng_event_desc
*event_desc
=
335 probe_desc
->event_desc
[i
];
338 if (event_desc
->nr_fields
== 0) {
339 /* Events without fields. */
340 struct tp_field_list_entry
*list_entry
;
342 list_entry
= zmalloc(sizeof(*list_entry
));
345 cds_list_add(&list_entry
->head
, &list
->head
);
346 strncpy(list_entry
->field
.event_name
,
348 LTTNG_UST_SYM_NAME_LEN
);
349 list_entry
->field
.event_name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
350 list_entry
->field
.field_name
[0] = '\0';
351 list_entry
->field
.type
= LTTNG_UST_FIELD_OTHER
;
352 if (!event_desc
->loglevel
) {
353 list_entry
->field
.loglevel
= TRACE_DEFAULT
;
355 list_entry
->field
.loglevel
= *(*event_desc
->loglevel
);
357 list_entry
->field
.nowrite
= 1;
360 for (j
= 0; j
< event_desc
->nr_fields
; j
++) {
361 const struct lttng_event_field
*event_field
=
362 &event_desc
->fields
[j
];
363 struct tp_field_list_entry
*list_entry
;
365 list_entry
= zmalloc(sizeof(*list_entry
));
368 cds_list_add(&list_entry
->head
, &list
->head
);
369 strncpy(list_entry
->field
.event_name
,
371 LTTNG_UST_SYM_NAME_LEN
);
372 list_entry
->field
.event_name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
373 strncpy(list_entry
->field
.field_name
,
375 LTTNG_UST_SYM_NAME_LEN
);
376 list_entry
->field
.field_name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
377 switch (event_field
->type
.atype
) {
379 list_entry
->field
.type
= LTTNG_UST_FIELD_INTEGER
;
382 list_entry
->field
.type
= LTTNG_UST_FIELD_STRING
;
385 if (event_field
->type
.u
.array
.elem_type
.atype
!= atype_integer
386 || event_field
->type
.u
.array
.elem_type
.u
.basic
.integer
.encoding
== lttng_encode_none
)
387 list_entry
->field
.type
= LTTNG_UST_FIELD_OTHER
;
389 list_entry
->field
.type
= LTTNG_UST_FIELD_STRING
;
392 if (event_field
->type
.u
.sequence
.elem_type
.atype
!= atype_integer
393 || event_field
->type
.u
.sequence
.elem_type
.u
.basic
.integer
.encoding
== lttng_encode_none
)
394 list_entry
->field
.type
= LTTNG_UST_FIELD_OTHER
;
396 list_entry
->field
.type
= LTTNG_UST_FIELD_STRING
;
399 list_entry
->field
.type
= LTTNG_UST_FIELD_FLOAT
;
402 list_entry
->field
.type
= LTTNG_UST_FIELD_ENUM
;
405 list_entry
->field
.type
= LTTNG_UST_FIELD_OTHER
;
407 if (!event_desc
->loglevel
) {
408 list_entry
->field
.loglevel
= TRACE_DEFAULT
;
410 list_entry
->field
.loglevel
= *(*event_desc
->loglevel
);
412 list_entry
->field
.nowrite
= event_field
->nowrite
;
416 if (cds_list_empty(&list
->head
))
420 cds_list_first_entry(&list
->head
,
421 struct tp_field_list_entry
, head
);
425 lttng_probes_prune_field_list(list
);
430 * Return current iteration position, advance internal iterator to next.
431 * Return NULL if end of list.
433 struct lttng_ust_field_iter
*
434 lttng_ust_field_list_get_iter_next(struct lttng_ust_field_list
*list
)
436 struct tp_field_list_entry
*entry
;
441 if (entry
->head
.next
== &list
->head
)
444 list
->iter
= cds_list_entry(entry
->head
.next
,
445 struct tp_field_list_entry
, head
);
446 return &entry
->field
;