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
))
163 int lttng_probe_register(struct lttng_probe_desc
*desc
)
170 * Check if the provider has already been registered.
172 if (find_provider(desc
->provider
)) {
176 cds_list_add(&desc
->lazy_init_head
, &lazy_probe_init
);
178 DBG("adding probe %s containing %u events to lazy registration list",
179 desc
->provider
, desc
->nr_events
);
181 * If there is at least one active session, we need to register
182 * the probe immediately, since we cannot delay event
183 * registration because they are needed ASAP.
185 if (lttng_session_active())
192 /* Backward compatibility with UST 2.0 */
193 int ltt_probe_register(struct lttng_probe_desc
*desc
)
195 return lttng_probe_register(desc
);
198 void lttng_probe_unregister(struct lttng_probe_desc
*desc
)
202 cds_list_del(&desc
->head
);
204 cds_list_del(&desc
->lazy_init_head
);
205 DBG("just unregistered probe %s", desc
->provider
);
209 /* Backward compatibility with UST 2.0 */
210 void ltt_probe_unregister(struct lttng_probe_desc
*desc
)
212 lttng_probe_unregister(desc
);
215 void lttng_probes_prune_event_list(struct lttng_ust_tracepoint_list
*list
)
217 struct tp_list_entry
*list_entry
, *tmp
;
219 cds_list_for_each_entry_safe(list_entry
, tmp
, &list
->head
, head
) {
220 cds_list_del(&list_entry
->head
);
226 * called with UST lock held.
228 int lttng_probes_get_event_list(struct lttng_ust_tracepoint_list
*list
)
230 struct lttng_probe_desc
*probe_desc
;
232 struct cds_list_head
*probe_list
;
234 probe_list
= lttng_get_probe_list_head();
235 CDS_INIT_LIST_HEAD(&list
->head
);
236 cds_list_for_each_entry(probe_desc
, probe_list
, head
) {
237 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
238 struct tp_list_entry
*list_entry
;
240 list_entry
= zmalloc(sizeof(*list_entry
));
243 cds_list_add(&list_entry
->head
, &list
->head
);
244 strncpy(list_entry
->tp
.name
,
245 probe_desc
->event_desc
[i
]->name
,
246 LTTNG_UST_SYM_NAME_LEN
);
247 list_entry
->tp
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
248 if (!probe_desc
->event_desc
[i
]->loglevel
) {
249 list_entry
->tp
.loglevel
= TRACE_DEFAULT
;
251 list_entry
->tp
.loglevel
= *(*probe_desc
->event_desc
[i
]->loglevel
);
255 if (cds_list_empty(&list
->head
))
259 cds_list_first_entry(&list
->head
, struct tp_list_entry
, head
);
263 lttng_probes_prune_event_list(list
);
268 * Return current iteration position, advance internal iterator to next.
269 * Return NULL if end of list.
271 struct lttng_ust_tracepoint_iter
*
272 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list
*list
)
274 struct tp_list_entry
*entry
;
279 if (entry
->head
.next
== &list
->head
)
282 list
->iter
= cds_list_entry(entry
->head
.next
,
283 struct tp_list_entry
, head
);
287 void lttng_probes_prune_field_list(struct lttng_ust_field_list
*list
)
289 struct tp_field_list_entry
*list_entry
, *tmp
;
291 cds_list_for_each_entry_safe(list_entry
, tmp
, &list
->head
, head
) {
292 cds_list_del(&list_entry
->head
);
298 * called with UST lock held.
300 int lttng_probes_get_field_list(struct lttng_ust_field_list
*list
)
302 struct lttng_probe_desc
*probe_desc
;
304 struct cds_list_head
*probe_list
;
306 probe_list
= lttng_get_probe_list_head();
307 CDS_INIT_LIST_HEAD(&list
->head
);
308 cds_list_for_each_entry(probe_desc
, probe_list
, head
) {
309 for (i
= 0; i
< probe_desc
->nr_events
; i
++) {
310 const struct lttng_event_desc
*event_desc
=
311 probe_desc
->event_desc
[i
];
314 if (event_desc
->nr_fields
== 0) {
315 /* Events without fields. */
316 struct tp_field_list_entry
*list_entry
;
318 list_entry
= zmalloc(sizeof(*list_entry
));
321 cds_list_add(&list_entry
->head
, &list
->head
);
322 strncpy(list_entry
->field
.event_name
,
324 LTTNG_UST_SYM_NAME_LEN
);
325 list_entry
->field
.event_name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
326 list_entry
->field
.field_name
[0] = '\0';
327 list_entry
->field
.type
= LTTNG_UST_FIELD_OTHER
;
328 if (!event_desc
->loglevel
) {
329 list_entry
->field
.loglevel
= TRACE_DEFAULT
;
331 list_entry
->field
.loglevel
= *(*event_desc
->loglevel
);
333 list_entry
->field
.nowrite
= 1;
336 for (j
= 0; j
< event_desc
->nr_fields
; j
++) {
337 const struct lttng_event_field
*event_field
=
338 &event_desc
->fields
[j
];
339 struct tp_field_list_entry
*list_entry
;
341 list_entry
= zmalloc(sizeof(*list_entry
));
344 cds_list_add(&list_entry
->head
, &list
->head
);
345 strncpy(list_entry
->field
.event_name
,
347 LTTNG_UST_SYM_NAME_LEN
);
348 list_entry
->field
.event_name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
349 strncpy(list_entry
->field
.field_name
,
351 LTTNG_UST_SYM_NAME_LEN
);
352 list_entry
->field
.field_name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
353 switch (event_field
->type
.atype
) {
355 list_entry
->field
.type
= LTTNG_UST_FIELD_INTEGER
;
358 list_entry
->field
.type
= LTTNG_UST_FIELD_STRING
;
361 if (event_field
->type
.u
.array
.elem_type
.atype
!= atype_integer
362 || event_field
->type
.u
.array
.elem_type
.u
.basic
.integer
.encoding
== lttng_encode_none
)
363 list_entry
->field
.type
= LTTNG_UST_FIELD_OTHER
;
365 list_entry
->field
.type
= LTTNG_UST_FIELD_STRING
;
368 if (event_field
->type
.u
.sequence
.elem_type
.atype
!= atype_integer
369 || event_field
->type
.u
.sequence
.elem_type
.u
.basic
.integer
.encoding
== lttng_encode_none
)
370 list_entry
->field
.type
= LTTNG_UST_FIELD_OTHER
;
372 list_entry
->field
.type
= LTTNG_UST_FIELD_STRING
;
375 list_entry
->field
.type
= LTTNG_UST_FIELD_FLOAT
;
378 list_entry
->field
.type
= LTTNG_UST_FIELD_ENUM
;
381 list_entry
->field
.type
= LTTNG_UST_FIELD_OTHER
;
383 if (!event_desc
->loglevel
) {
384 list_entry
->field
.loglevel
= TRACE_DEFAULT
;
386 list_entry
->field
.loglevel
= *(*event_desc
->loglevel
);
388 list_entry
->field
.nowrite
= event_field
->nowrite
;
392 if (cds_list_empty(&list
->head
))
396 cds_list_first_entry(&list
->head
,
397 struct tp_field_list_entry
, head
);
401 lttng_probes_prune_field_list(list
);
406 * Return current iteration position, advance internal iterator to next.
407 * Return NULL if end of list.
409 struct lttng_ust_field_iter
*
410 lttng_ust_field_list_get_iter_next(struct lttng_ust_field_list
*list
)
412 struct tp_field_list_entry
*entry
;
417 if (entry
->head
.next
== &list
->head
)
420 list
->iter
= cds_list_entry(entry
->head
.next
,
421 struct tp_field_list_entry
, head
);
422 return &entry
->field
;