Add channel ID field to attr
[lttng-ust.git] / liblttng-ust / lttng-events.c
1 /*
2 * lttng-events.c
3 *
4 * Holds LTTng per-session event registry.
5 *
6 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 *
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.
12 *
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.
17 *
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
21 */
22
23 #define _GNU_SOURCE
24 #include <stdio.h>
25 #include <urcu/list.h>
26 #include <urcu/hlist.h>
27 #include <pthread.h>
28 #include <errno.h>
29 #include <sys/shm.h>
30 #include <sys/ipc.h>
31 #include <stdint.h>
32 #include <stddef.h>
33 #include <inttypes.h>
34 #include <time.h>
35 #include <lttng/ust-endian.h>
36 #include "clock.h"
37
38 #include <urcu-bp.h>
39 #include <urcu/compiler.h>
40 #include <urcu/uatomic.h>
41 #include <urcu/arch.h>
42
43 #include <lttng/tracepoint.h>
44 #include <lttng/ust-events.h>
45
46 #include <usterr-signal-safe.h>
47 #include <helper.h>
48 #include <ust-ctl.h>
49 #include <ust-comm.h>
50 #include "error.h"
51 #include "compat.h"
52 #include "lttng-ust-uuid.h"
53
54 #include "tracepoint-internal.h"
55 #include "lttng-tracer.h"
56 #include "lttng-tracer-core.h"
57 #include "wait.h"
58 #include "../libringbuffer/shm.h"
59 #include "jhash.h"
60
61 /*
62 * The sessions mutex is the centralized mutex across UST tracing
63 * control and probe registration. All operations within this file are
64 * called by the communication thread, under ust_lock protection.
65 */
66 static pthread_mutex_t sessions_mutex = PTHREAD_MUTEX_INITIALIZER;
67
68 void ust_lock(void)
69 {
70 pthread_mutex_lock(&sessions_mutex);
71 }
72
73 void ust_unlock(void)
74 {
75 pthread_mutex_unlock(&sessions_mutex);
76 }
77
78 static CDS_LIST_HEAD(sessions);
79
80 static void _lttng_event_destroy(struct lttng_event *event);
81
82 static
83 void lttng_session_lazy_sync_enablers(struct lttng_session *session);
84 static
85 void lttng_session_sync_enablers(struct lttng_session *session);
86 static
87 void lttng_enabler_destroy(struct lttng_enabler *enabler);
88
89 /*
90 * Called with ust lock held.
91 */
92 int lttng_session_active(void)
93 {
94 struct lttng_session *iter;
95
96 cds_list_for_each_entry(iter, &sessions, node) {
97 if (iter->active)
98 return 1;
99 }
100 return 0;
101 }
102
103 static
104 int lttng_loglevel_match(int loglevel,
105 unsigned int has_loglevel,
106 enum lttng_ust_loglevel_type req_type,
107 int req_loglevel)
108 {
109 if (req_type == LTTNG_UST_LOGLEVEL_ALL)
110 return 1;
111 if (!has_loglevel)
112 loglevel = TRACE_DEFAULT;
113 switch (req_type) {
114 case LTTNG_UST_LOGLEVEL_RANGE:
115 if (loglevel <= req_loglevel || req_loglevel == -1)
116 return 1;
117 else
118 return 0;
119 case LTTNG_UST_LOGLEVEL_SINGLE:
120 if (loglevel == req_loglevel || req_loglevel == -1)
121 return 1;
122 else
123 return 0;
124 case LTTNG_UST_LOGLEVEL_ALL:
125 default:
126 return 1;
127 }
128 }
129
130 void synchronize_trace(void)
131 {
132 synchronize_rcu();
133 }
134
135 struct lttng_session *lttng_session_create(void)
136 {
137 struct lttng_session *session;
138 int i;
139
140 session = zmalloc(sizeof(struct lttng_session));
141 if (!session)
142 return NULL;
143 CDS_INIT_LIST_HEAD(&session->chan_head);
144 CDS_INIT_LIST_HEAD(&session->events_head);
145 CDS_INIT_LIST_HEAD(&session->enablers_head);
146 for (i = 0; i < LTTNG_UST_EVENT_HT_SIZE; i++)
147 CDS_INIT_HLIST_HEAD(&session->events_ht.table[i]);
148 cds_list_add(&session->node, &sessions);
149 return session;
150 }
151
152 /*
153 * Only used internally at session destruction.
154 */
155 static
156 void _lttng_channel_unmap(struct lttng_channel *lttng_chan)
157 {
158 struct channel *chan;
159 struct lttng_ust_shm_handle *handle;
160
161 cds_list_del(&lttng_chan->node);
162 lttng_destroy_context(lttng_chan->ctx);
163 chan = lttng_chan->chan;
164 handle = lttng_chan->handle;
165 /*
166 * note: lttng_chan is private data contained within handle. It
167 * will be freed along with the handle.
168 */
169 channel_destroy(chan, handle, 0);
170 }
171
172 static
173 void register_event(struct lttng_event *event)
174 {
175 int ret;
176 const struct lttng_event_desc *desc;
177
178 assert(event->registered == 0);
179 desc = event->desc;
180 ret = __tracepoint_probe_register(desc->name,
181 desc->probe_callback,
182 event, desc->signature);
183 WARN_ON_ONCE(ret);
184 if (!ret)
185 event->registered = 1;
186 }
187
188 static
189 void unregister_event(struct lttng_event *event)
190 {
191 int ret;
192 const struct lttng_event_desc *desc;
193
194 assert(event->registered == 1);
195 desc = event->desc;
196 ret = __tracepoint_probe_unregister(desc->name,
197 desc->probe_callback,
198 event);
199 WARN_ON_ONCE(ret);
200 if (!ret)
201 event->registered = 0;
202 }
203
204 /*
205 * Only used internally at session destruction.
206 */
207 static
208 void _lttng_event_unregister(struct lttng_event *event)
209 {
210 if (event->registered)
211 unregister_event(event);
212 }
213
214 void lttng_session_destroy(struct lttng_session *session)
215 {
216 struct lttng_channel *chan, *tmpchan;
217 struct lttng_event *event, *tmpevent;
218 struct lttng_enabler *enabler, *tmpenabler;
219
220 CMM_ACCESS_ONCE(session->active) = 0;
221 cds_list_for_each_entry(event, &session->events_head, node) {
222 _lttng_event_unregister(event);
223 }
224 synchronize_trace(); /* Wait for in-flight events to complete */
225 cds_list_for_each_entry_safe(enabler, tmpenabler,
226 &session->enablers_head, node)
227 lttng_enabler_destroy(enabler);
228 cds_list_for_each_entry_safe(event, tmpevent,
229 &session->events_head, node)
230 _lttng_event_destroy(event);
231 cds_list_for_each_entry_safe(chan, tmpchan, &session->chan_head, node)
232 _lttng_channel_unmap(chan);
233 cds_list_del(&session->node);
234 free(session);
235 }
236
237 int lttng_session_enable(struct lttng_session *session)
238 {
239 int ret = 0;
240 struct lttng_channel *chan;
241 int notify_socket;
242
243 if (session->active) {
244 ret = -EBUSY;
245 goto end;
246 }
247
248 notify_socket = lttng_get_notify_socket(session->owner);
249 if (notify_socket < 0)
250 return notify_socket;
251
252 /* Set transient enabler state to "enabled" */
253 session->tstate = 1;
254 /* We need to sync enablers with session before activation. */
255 lttng_session_sync_enablers(session);
256
257 /*
258 * Snapshot the number of events per channel to know the type of header
259 * we need to use.
260 */
261 cds_list_for_each_entry(chan, &session->chan_head, node) {
262 const struct lttng_ctx *ctx;
263 const struct lttng_event_field *fields = NULL;
264 size_t nr_fields = 0;
265 uint32_t chan_id;
266
267 /* don't change it if session stop/restart */
268 if (chan->header_type)
269 continue;
270 ctx = chan->ctx;
271 if (ctx) {
272 nr_fields = ctx->nr_fields;
273 fields = &ctx->fields->event_field;
274 }
275 ret = ustcomm_register_channel(notify_socket,
276 session->objd,
277 chan->objd,
278 nr_fields,
279 fields,
280 &chan_id,
281 &chan->header_type);
282 if (ret) {
283 DBG("Error (%d) registering channel to sessiond", ret);
284 return ret;
285 }
286 if (chan_id != chan->id) {
287 DBG("Error: channel registration id (%u) does not match id assigned at creation (%u)",
288 chan_id, chan->id);
289 return -EINVAL;
290 }
291 }
292
293 /* Set atomically the state to "active" */
294 CMM_ACCESS_ONCE(session->active) = 1;
295 CMM_ACCESS_ONCE(session->been_active) = 1;
296 end:
297 return ret;
298 }
299
300 int lttng_session_disable(struct lttng_session *session)
301 {
302 int ret = 0;
303
304 if (!session->active) {
305 ret = -EBUSY;
306 goto end;
307 }
308 /* Set atomically the state to "inactive" */
309 CMM_ACCESS_ONCE(session->active) = 0;
310
311 /* Set transient enabler state to "disabled" */
312 session->tstate = 0;
313 lttng_session_sync_enablers(session);
314 end:
315 return ret;
316 }
317
318 int lttng_channel_enable(struct lttng_channel *channel)
319 {
320 int ret = 0;
321
322 if (channel->enabled) {
323 ret = -EBUSY;
324 goto end;
325 }
326 /* Set transient enabler state to "enabled" */
327 channel->tstate = 1;
328 lttng_session_sync_enablers(channel->session);
329 /* Set atomically the state to "enabled" */
330 CMM_ACCESS_ONCE(channel->enabled) = 1;
331 end:
332 return ret;
333 }
334
335 int lttng_channel_disable(struct lttng_channel *channel)
336 {
337 int ret = 0;
338
339 if (!channel->enabled) {
340 ret = -EBUSY;
341 goto end;
342 }
343 /* Set atomically the state to "disabled" */
344 CMM_ACCESS_ONCE(channel->enabled) = 0;
345 /* Set transient enabler state to "enabled" */
346 channel->tstate = 0;
347 lttng_session_sync_enablers(channel->session);
348 end:
349 return ret;
350 }
351
352 /*
353 * Supports event creation while tracing session is active.
354 */
355 static
356 int lttng_event_create(const struct lttng_event_desc *desc,
357 struct lttng_channel *chan)
358 {
359 const char *event_name = desc->name;
360 struct lttng_event *event;
361 struct lttng_session *session = chan->session;
362 struct cds_hlist_head *head;
363 struct cds_hlist_node *node;
364 int ret = 0;
365 size_t name_len = strlen(event_name);
366 uint32_t hash;
367 int notify_socket, loglevel;
368 const char *uri;
369
370 hash = jhash(event_name, name_len, 0);
371 head = &chan->session->events_ht.table[hash & (LTTNG_UST_EVENT_HT_SIZE - 1)];
372 cds_hlist_for_each_entry(event, node, head, hlist) {
373 assert(event->desc);
374 if (!strncmp(event->desc->name,
375 desc->name,
376 LTTNG_UST_SYM_NAME_LEN - 1)) {
377 ret = -EEXIST;
378 goto exist;
379 }
380 }
381
382 notify_socket = lttng_get_notify_socket(session->owner);
383 if (notify_socket < 0) {
384 ret = notify_socket;
385 goto socket_error;
386 }
387
388 /*
389 * Check if loglevel match. Refuse to connect event if not.
390 */
391 event = zmalloc(sizeof(struct lttng_event));
392 if (!event) {
393 ret = -ENOMEM;
394 goto cache_error;
395 }
396 event->chan = chan;
397
398 /* Event will be enabled by enabler sync. */
399 event->enabled = 0;
400 event->registered = 0;
401 CDS_INIT_LIST_HEAD(&event->bytecode_runtime_head);
402 CDS_INIT_LIST_HEAD(&event->enablers_ref_head);
403 event->desc = desc;
404
405 if (desc->loglevel)
406 loglevel = *(*event->desc->loglevel);
407 else
408 loglevel = TRACE_DEFAULT;
409 if (desc->u.ext.model_emf_uri)
410 uri = *(desc->u.ext.model_emf_uri);
411 else
412 uri = NULL;
413
414 /* Fetch event ID from sessiond */
415 ret = ustcomm_register_event(notify_socket,
416 session->objd,
417 chan->objd,
418 event_name,
419 loglevel,
420 desc->signature,
421 desc->nr_fields,
422 desc->fields,
423 uri,
424 &event->id);
425 if (ret < 0) {
426 DBG("Error (%d) registering event to sessiond", ret);
427 goto sessiond_register_error;
428 }
429
430 /* Populate lttng_event structure before tracepoint registration. */
431 cmm_smp_wmb();
432 cds_list_add(&event->node, &chan->session->events_head);
433 cds_hlist_add_head(&event->hlist, head);
434 return 0;
435
436 sessiond_register_error:
437 free(event);
438 cache_error:
439 socket_error:
440 exist:
441 return ret;
442 }
443
444 static
445 int lttng_desc_match_wildcard_enabler(const struct lttng_event_desc *desc,
446 struct lttng_enabler *enabler)
447 {
448 int loglevel = 0;
449 unsigned int has_loglevel = 0;
450
451 assert(enabler->type == LTTNG_ENABLER_WILDCARD);
452 /* Compare excluding final '*' */
453 if (strncmp(desc->name, enabler->event_param.name,
454 strlen(enabler->event_param.name) - 1))
455 return 0;
456 if (desc->loglevel) {
457 loglevel = *(*desc->loglevel);
458 has_loglevel = 1;
459 }
460 if (!lttng_loglevel_match(loglevel,
461 has_loglevel,
462 enabler->event_param.loglevel_type,
463 enabler->event_param.loglevel))
464 return 0;
465 return 1;
466 }
467
468 static
469 int lttng_desc_match_event_enabler(const struct lttng_event_desc *desc,
470 struct lttng_enabler *enabler)
471 {
472 int loglevel = 0;
473 unsigned int has_loglevel = 0;
474
475 assert(enabler->type == LTTNG_ENABLER_EVENT);
476 if (strcmp(desc->name, enabler->event_param.name))
477 return 0;
478 if (desc->loglevel) {
479 loglevel = *(*desc->loglevel);
480 has_loglevel = 1;
481 }
482 if (!lttng_loglevel_match(loglevel,
483 has_loglevel,
484 enabler->event_param.loglevel_type,
485 enabler->event_param.loglevel))
486 return 0;
487 return 1;
488 }
489
490 static
491 int lttng_desc_match_enabler(const struct lttng_event_desc *desc,
492 struct lttng_enabler *enabler)
493 {
494 switch (enabler->type) {
495 case LTTNG_ENABLER_WILDCARD:
496 return lttng_desc_match_wildcard_enabler(desc, enabler);
497 case LTTNG_ENABLER_EVENT:
498 return lttng_desc_match_event_enabler(desc, enabler);
499 default:
500 return -EINVAL;
501 }
502 }
503
504 static
505 int lttng_event_match_enabler(struct lttng_event *event,
506 struct lttng_enabler *enabler)
507 {
508 return lttng_desc_match_enabler(event->desc, enabler);
509 }
510
511 static
512 struct lttng_enabler_ref * lttng_event_enabler_ref(struct lttng_event *event,
513 struct lttng_enabler *enabler)
514 {
515 struct lttng_enabler_ref *enabler_ref;
516
517 cds_list_for_each_entry(enabler_ref,
518 &event->enablers_ref_head, node) {
519 if (enabler_ref->ref == enabler)
520 return enabler_ref;
521 }
522 return NULL;
523 }
524
525 /*
526 * Create struct lttng_event if it is missing and present in the list of
527 * tracepoint probes.
528 */
529 static
530 void lttng_create_event_if_missing(struct lttng_enabler *enabler)
531 {
532 struct lttng_session *session = enabler->chan->session;
533 struct lttng_probe_desc *probe_desc;
534 const struct lttng_event_desc *desc;
535 struct lttng_event *event;
536 int i;
537 struct cds_list_head *probe_list;
538
539 probe_list = lttng_get_probe_list_head();
540 /*
541 * For each probe event, if we find that a probe event matches
542 * our enabler, create an associated lttng_event if not
543 * already present.
544 */
545 cds_list_for_each_entry(probe_desc, probe_list, head) {
546 for (i = 0; i < probe_desc->nr_events; i++) {
547 int found = 0, ret;
548 struct cds_hlist_head *head;
549 struct cds_hlist_node *node;
550 const char *event_name;
551 size_t name_len;
552 uint32_t hash;
553
554 desc = probe_desc->event_desc[i];
555 if (!lttng_desc_match_enabler(desc, enabler))
556 continue;
557 event_name = desc->name;
558 name_len = strlen(event_name);
559
560 /*
561 * Check if already created.
562 */
563 hash = jhash(event_name, name_len, 0);
564 head = &session->events_ht.table[hash & (LTTNG_UST_EVENT_HT_SIZE - 1)];
565 cds_hlist_for_each_entry(event, node, head, hlist) {
566 if (event->desc == desc)
567 found = 1;
568 }
569 if (found)
570 continue;
571
572 /*
573 * We need to create an event for this
574 * event probe.
575 */
576 ret = lttng_event_create(probe_desc->event_desc[i],
577 enabler->chan);
578 if (ret) {
579 DBG("Unable to create event %s, error %d\n",
580 probe_desc->event_desc[i]->name, ret);
581 }
582 }
583 }
584 }
585
586 /*
587 * Create events associated with an enabler (if not already present),
588 * and add backward reference from the event to the enabler.
589 */
590 static
591 int lttng_enabler_ref_events(struct lttng_enabler *enabler)
592 {
593 struct lttng_session *session = enabler->chan->session;
594 struct lttng_event *event;
595
596 /* First ensure that probe events are created for this enabler. */
597 lttng_create_event_if_missing(enabler);
598
599 /* For each event matching enabler in session event list. */
600 cds_list_for_each_entry(event, &session->events_head, node) {
601 struct lttng_enabler_ref *enabler_ref;
602
603 if (!lttng_event_match_enabler(event, enabler))
604 continue;
605
606 enabler_ref = lttng_event_enabler_ref(event, enabler);
607 if (!enabler_ref) {
608 /*
609 * If no backward ref, create it.
610 * Add backward ref from event to enabler.
611 */
612 enabler_ref = zmalloc(sizeof(*enabler_ref));
613 if (!enabler_ref)
614 return -ENOMEM;
615 enabler_ref->ref = enabler;
616 cds_list_add(&enabler_ref->node,
617 &event->enablers_ref_head);
618 }
619
620 /*
621 * Link filter bytecodes if not linked yet.
622 */
623 lttng_enabler_event_link_bytecode(event, enabler);
624
625 /* TODO: merge event context. */
626 }
627 return 0;
628 }
629
630 /*
631 * Called at library load: connect the probe on all enablers matching
632 * this event.
633 * called with session mutex held.
634 * TODO: currently, for each desc added, we iterate on all event desc
635 * (inefficient). We should create specific code that only target the
636 * added desc.
637 */
638 int lttng_fix_pending_event_desc(const struct lttng_event_desc *desc)
639 {
640 struct lttng_session *session;
641
642 cds_list_for_each_entry(session, &sessions, node) {
643 lttng_session_lazy_sync_enablers(session);
644 }
645 return 0;
646 }
647
648 /*
649 * Only used internally at session destruction.
650 */
651 static
652 void _lttng_event_destroy(struct lttng_event *event)
653 {
654 struct lttng_enabler_ref *enabler_ref, *tmp_enabler_ref;
655
656 cds_list_del(&event->node);
657 lttng_destroy_context(event->ctx);
658 lttng_free_event_filter_runtime(event);
659 /* Free event enabler refs */
660 cds_list_for_each_entry_safe(enabler_ref, tmp_enabler_ref,
661 &event->enablers_ref_head, node)
662 free(enabler_ref);
663 free(event);
664 }
665
666 void lttng_ust_events_exit(void)
667 {
668 struct lttng_session *session, *tmpsession;
669
670 cds_list_for_each_entry_safe(session, tmpsession, &sessions, node)
671 lttng_session_destroy(session);
672 }
673
674 /*
675 * Enabler management.
676 */
677 struct lttng_enabler *lttng_enabler_create(enum lttng_enabler_type type,
678 struct lttng_ust_event *event_param,
679 struct lttng_channel *chan)
680 {
681 struct lttng_enabler *enabler;
682
683 enabler = zmalloc(sizeof(*enabler));
684 if (!enabler)
685 return NULL;
686 enabler->type = type;
687 CDS_INIT_LIST_HEAD(&enabler->filter_bytecode_head);
688 memcpy(&enabler->event_param, event_param,
689 sizeof(enabler->event_param));
690 enabler->chan = chan;
691 /* ctx left NULL */
692 enabler->enabled = 1;
693 cds_list_add(&enabler->node, &enabler->chan->session->enablers_head);
694 lttng_session_lazy_sync_enablers(enabler->chan->session);
695 return enabler;
696 }
697
698 int lttng_enabler_enable(struct lttng_enabler *enabler)
699 {
700 enabler->enabled = 1;
701 lttng_session_lazy_sync_enablers(enabler->chan->session);
702 return 0;
703 }
704
705 int lttng_enabler_disable(struct lttng_enabler *enabler)
706 {
707 enabler->enabled = 0;
708 lttng_session_lazy_sync_enablers(enabler->chan->session);
709 return 0;
710 }
711
712 int lttng_enabler_attach_bytecode(struct lttng_enabler *enabler,
713 struct lttng_ust_filter_bytecode_node *bytecode)
714 {
715 bytecode->enabler = enabler;
716 cds_list_add_tail(&bytecode->node, &enabler->filter_bytecode_head);
717 lttng_session_lazy_sync_enablers(enabler->chan->session);
718 return 0;
719 }
720
721 int lttng_attach_context(struct lttng_ust_context *context_param,
722 struct lttng_ctx **ctx, struct lttng_session *session)
723 {
724 /*
725 * We cannot attach a context after trace has been started for a
726 * session because the metadata does not allow expressing this
727 * information outside of the original channel scope.
728 */
729 if (session->been_active)
730 return -EPERM;
731
732 switch (context_param->ctx) {
733 case LTTNG_UST_CONTEXT_PTHREAD_ID:
734 return lttng_add_pthread_id_to_ctx(ctx);
735 case LTTNG_UST_CONTEXT_VTID:
736 return lttng_add_vtid_to_ctx(ctx);
737 case LTTNG_UST_CONTEXT_VPID:
738 return lttng_add_vpid_to_ctx(ctx);
739 case LTTNG_UST_CONTEXT_PROCNAME:
740 return lttng_add_procname_to_ctx(ctx);
741 default:
742 return -EINVAL;
743 }
744 }
745
746 int lttng_enabler_attach_context(struct lttng_enabler *enabler,
747 struct lttng_ust_context *context_param)
748 {
749 #if 0 // disabled for now.
750 struct lttng_session *session = enabler->chan->session;
751 int ret;
752
753 ret = lttng_attach_context(context_param, &enabler->ctx,
754 session);
755 if (ret)
756 return ret;
757 lttng_session_lazy_sync_enablers(enabler->chan->session);
758 #endif
759 return -ENOSYS;
760 }
761
762 static
763 void lttng_enabler_destroy(struct lttng_enabler *enabler)
764 {
765 struct lttng_ust_filter_bytecode_node *filter_node, *tmp_filter_node;
766
767 /* Destroy filter bytecode */
768 cds_list_for_each_entry_safe(filter_node, tmp_filter_node,
769 &enabler->filter_bytecode_head, node) {
770 free(filter_node);
771 }
772
773 /* Destroy contexts */
774 lttng_destroy_context(enabler->ctx);
775
776 cds_list_del(&enabler->node);
777 free(enabler);
778 }
779
780 /*
781 * lttng_session_sync_enablers should be called just before starting a
782 * session.
783 */
784 static
785 void lttng_session_sync_enablers(struct lttng_session *session)
786 {
787 struct lttng_enabler *enabler;
788 struct lttng_event *event;
789
790 cds_list_for_each_entry(enabler, &session->enablers_head, node)
791 lttng_enabler_ref_events(enabler);
792 /*
793 * For each event, if at least one of its enablers is enabled,
794 * and its channel and session transient states are enabled, we
795 * enable the event, else we disable it.
796 */
797 cds_list_for_each_entry(event, &session->events_head, node) {
798 struct lttng_enabler_ref *enabler_ref;
799 struct lttng_bytecode_runtime *runtime;
800 int enabled = 0, has_enablers_without_bytecode = 0;
801
802 /* Enable events */
803 cds_list_for_each_entry(enabler_ref,
804 &event->enablers_ref_head, node) {
805 if (enabler_ref->ref->enabled) {
806 enabled = 1;
807 break;
808 }
809 }
810 /*
811 * Enabled state is based on union of enablers, with
812 * intesection of session and channel transient enable
813 * states.
814 */
815 enabled = enabled && session->tstate && event->chan->tstate;
816
817 CMM_STORE_SHARED(event->enabled, enabled);
818 /*
819 * Sync tracepoint registration with event enabled
820 * state.
821 */
822 if (enabled) {
823 if (!event->registered)
824 register_event(event);
825 } else {
826 if (event->registered)
827 unregister_event(event);
828 }
829
830 /* Check if has enablers without bytecode enabled */
831 cds_list_for_each_entry(enabler_ref,
832 &event->enablers_ref_head, node) {
833 if (enabler_ref->ref->enabled
834 && cds_list_empty(&enabler_ref->ref->filter_bytecode_head)) {
835 has_enablers_without_bytecode = 1;
836 break;
837 }
838 }
839 event->has_enablers_without_bytecode =
840 has_enablers_without_bytecode;
841
842 /* Enable filters */
843 cds_list_for_each_entry(runtime,
844 &event->bytecode_runtime_head, node) {
845 lttng_filter_sync_state(runtime);
846 }
847 }
848 }
849
850 /*
851 * Apply enablers to session events, adding events to session if need
852 * be. It is required after each modification applied to an active
853 * session, and right before session "start".
854 * "lazy" sync means we only sync if required.
855 */
856 static
857 void lttng_session_lazy_sync_enablers(struct lttng_session *session)
858 {
859 /* We can skip if session is not active */
860 if (!session->active)
861 return;
862 lttng_session_sync_enablers(session);
863 }
This page took 0.048881 seconds and 5 git commands to generate.