Cleanup: remove logically dead code
[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 <lttng/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 (!has_loglevel)
110 loglevel = TRACE_DEFAULT;
111 switch (req_type) {
112 case LTTNG_UST_LOGLEVEL_RANGE:
113 if (loglevel <= req_loglevel || req_loglevel == -1)
114 return 1;
115 else
116 return 0;
117 case LTTNG_UST_LOGLEVEL_SINGLE:
118 if (loglevel == req_loglevel || req_loglevel == -1)
119 return 1;
120 else
121 return 0;
122 case LTTNG_UST_LOGLEVEL_ALL:
123 default:
124 return 1;
125 }
126 }
127
128 void synchronize_trace(void)
129 {
130 synchronize_rcu();
131 }
132
133 struct lttng_session *lttng_session_create(void)
134 {
135 struct lttng_session *session;
136 int i;
137
138 session = zmalloc(sizeof(struct lttng_session));
139 if (!session)
140 return NULL;
141 CDS_INIT_LIST_HEAD(&session->chan_head);
142 CDS_INIT_LIST_HEAD(&session->events_head);
143 CDS_INIT_LIST_HEAD(&session->enablers_head);
144 for (i = 0; i < LTTNG_UST_EVENT_HT_SIZE; i++)
145 CDS_INIT_HLIST_HEAD(&session->events_ht.table[i]);
146 cds_list_add(&session->node, &sessions);
147 return session;
148 }
149
150 /*
151 * Only used internally at session destruction.
152 */
153 static
154 void _lttng_channel_unmap(struct lttng_channel *lttng_chan)
155 {
156 struct channel *chan;
157 struct lttng_ust_shm_handle *handle;
158
159 cds_list_del(&lttng_chan->node);
160 lttng_destroy_context(lttng_chan->ctx);
161 chan = lttng_chan->chan;
162 handle = lttng_chan->handle;
163 /*
164 * note: lttng_chan is private data contained within handle. It
165 * will be freed along with the handle.
166 */
167 channel_destroy(chan, handle, 0);
168 }
169
170 static
171 void register_event(struct lttng_event *event)
172 {
173 int ret;
174 const struct lttng_event_desc *desc;
175
176 assert(event->registered == 0);
177 desc = event->desc;
178 ret = __tracepoint_probe_register(desc->name,
179 desc->probe_callback,
180 event, desc->signature);
181 WARN_ON_ONCE(ret);
182 if (!ret)
183 event->registered = 1;
184 }
185
186 static
187 void unregister_event(struct lttng_event *event)
188 {
189 int ret;
190 const struct lttng_event_desc *desc;
191
192 assert(event->registered == 1);
193 desc = event->desc;
194 ret = __tracepoint_probe_unregister(desc->name,
195 desc->probe_callback,
196 event);
197 WARN_ON_ONCE(ret);
198 if (!ret)
199 event->registered = 0;
200 }
201
202 /*
203 * Only used internally at session destruction.
204 */
205 static
206 void _lttng_event_unregister(struct lttng_event *event)
207 {
208 if (event->registered)
209 unregister_event(event);
210 }
211
212 void lttng_session_destroy(struct lttng_session *session)
213 {
214 struct lttng_channel *chan, *tmpchan;
215 struct lttng_event *event, *tmpevent;
216 struct lttng_enabler *enabler, *tmpenabler;
217
218 CMM_ACCESS_ONCE(session->active) = 0;
219 cds_list_for_each_entry(event, &session->events_head, node) {
220 _lttng_event_unregister(event);
221 }
222 synchronize_trace(); /* Wait for in-flight events to complete */
223 cds_list_for_each_entry_safe(enabler, tmpenabler,
224 &session->enablers_head, node)
225 lttng_enabler_destroy(enabler);
226 cds_list_for_each_entry_safe(event, tmpevent,
227 &session->events_head, node)
228 _lttng_event_destroy(event);
229 cds_list_for_each_entry_safe(chan, tmpchan, &session->chan_head, node)
230 _lttng_channel_unmap(chan);
231 cds_list_del(&session->node);
232 free(session);
233 }
234
235 int lttng_session_enable(struct lttng_session *session)
236 {
237 int ret = 0;
238 struct lttng_channel *chan;
239 int notify_socket;
240
241 if (session->active) {
242 ret = -EBUSY;
243 goto end;
244 }
245
246 notify_socket = lttng_get_notify_socket(session->owner);
247 if (notify_socket < 0)
248 return notify_socket;
249
250 /* Set transient enabler state to "enabled" */
251 session->tstate = 1;
252 /* We need to sync enablers with session before activation. */
253 lttng_session_sync_enablers(session);
254
255 /*
256 * Snapshot the number of events per channel to know the type of header
257 * we need to use.
258 */
259 cds_list_for_each_entry(chan, &session->chan_head, node) {
260 const struct lttng_ctx *ctx;
261 const struct lttng_ctx_field *fields = NULL;
262 size_t nr_fields = 0;
263 uint32_t chan_id;
264
265 /* don't change it if session stop/restart */
266 if (chan->header_type)
267 continue;
268 ctx = chan->ctx;
269 if (ctx) {
270 nr_fields = ctx->nr_fields;
271 fields = ctx->fields;
272 }
273 ret = ustcomm_register_channel(notify_socket,
274 session->objd,
275 chan->objd,
276 nr_fields,
277 fields,
278 &chan_id,
279 &chan->header_type);
280 if (ret) {
281 DBG("Error (%d) registering channel to sessiond", ret);
282 return ret;
283 }
284 if (chan_id != chan->id) {
285 DBG("Error: channel registration id (%u) does not match id assigned at creation (%u)",
286 chan_id, chan->id);
287 return -EINVAL;
288 }
289 }
290
291 /* Set atomically the state to "active" */
292 CMM_ACCESS_ONCE(session->active) = 1;
293 CMM_ACCESS_ONCE(session->been_active) = 1;
294 end:
295 return ret;
296 }
297
298 int lttng_session_disable(struct lttng_session *session)
299 {
300 int ret = 0;
301
302 if (!session->active) {
303 ret = -EBUSY;
304 goto end;
305 }
306 /* Set atomically the state to "inactive" */
307 CMM_ACCESS_ONCE(session->active) = 0;
308
309 /* Set transient enabler state to "disabled" */
310 session->tstate = 0;
311 lttng_session_sync_enablers(session);
312 end:
313 return ret;
314 }
315
316 int lttng_channel_enable(struct lttng_channel *channel)
317 {
318 int ret = 0;
319
320 if (channel->enabled) {
321 ret = -EBUSY;
322 goto end;
323 }
324 /* Set transient enabler state to "enabled" */
325 channel->tstate = 1;
326 lttng_session_sync_enablers(channel->session);
327 /* Set atomically the state to "enabled" */
328 CMM_ACCESS_ONCE(channel->enabled) = 1;
329 end:
330 return ret;
331 }
332
333 int lttng_channel_disable(struct lttng_channel *channel)
334 {
335 int ret = 0;
336
337 if (!channel->enabled) {
338 ret = -EBUSY;
339 goto end;
340 }
341 /* Set atomically the state to "disabled" */
342 CMM_ACCESS_ONCE(channel->enabled) = 0;
343 /* Set transient enabler state to "enabled" */
344 channel->tstate = 0;
345 lttng_session_sync_enablers(channel->session);
346 end:
347 return ret;
348 }
349
350 /*
351 * Supports event creation while tracing session is active.
352 */
353 static
354 int lttng_event_create(const struct lttng_event_desc *desc,
355 struct lttng_channel *chan)
356 {
357 const char *event_name = desc->name;
358 struct lttng_event *event;
359 struct lttng_session *session = chan->session;
360 struct cds_hlist_head *head;
361 struct cds_hlist_node *node;
362 int ret = 0;
363 size_t name_len = strlen(event_name);
364 uint32_t hash;
365 int notify_socket, loglevel;
366 const char *uri;
367
368 hash = jhash(event_name, name_len, 0);
369 head = &chan->session->events_ht.table[hash & (LTTNG_UST_EVENT_HT_SIZE - 1)];
370 cds_hlist_for_each_entry(event, node, head, hlist) {
371 assert(event->desc);
372 if (!strncmp(event->desc->name, desc->name,
373 LTTNG_UST_SYM_NAME_LEN - 1)
374 && chan == event->chan) {
375 ret = -EEXIST;
376 goto exist;
377 }
378 }
379
380 notify_socket = lttng_get_notify_socket(session->owner);
381 if (notify_socket < 0) {
382 ret = notify_socket;
383 goto socket_error;
384 }
385
386 /*
387 * Check if loglevel match. Refuse to connect event if not.
388 */
389 event = zmalloc(sizeof(struct lttng_event));
390 if (!event) {
391 ret = -ENOMEM;
392 goto cache_error;
393 }
394 event->chan = chan;
395
396 /* Event will be enabled by enabler sync. */
397 event->enabled = 0;
398 event->registered = 0;
399 CDS_INIT_LIST_HEAD(&event->bytecode_runtime_head);
400 CDS_INIT_LIST_HEAD(&event->enablers_ref_head);
401 event->desc = desc;
402
403 if (desc->loglevel)
404 loglevel = *(*event->desc->loglevel);
405 else
406 loglevel = TRACE_DEFAULT;
407 if (desc->u.ext.model_emf_uri)
408 uri = *(desc->u.ext.model_emf_uri);
409 else
410 uri = NULL;
411
412 /* Fetch event ID from sessiond */
413 ret = ustcomm_register_event(notify_socket,
414 session->objd,
415 chan->objd,
416 event_name,
417 loglevel,
418 desc->signature,
419 desc->nr_fields,
420 desc->fields,
421 uri,
422 &event->id);
423 if (ret < 0) {
424 DBG("Error (%d) registering event to sessiond", ret);
425 goto sessiond_register_error;
426 }
427
428 /* Populate lttng_event structure before tracepoint registration. */
429 cmm_smp_wmb();
430 cds_list_add(&event->node, &chan->session->events_head);
431 cds_hlist_add_head(&event->hlist, head);
432 return 0;
433
434 sessiond_register_error:
435 free(event);
436 cache_error:
437 socket_error:
438 exist:
439 return ret;
440 }
441
442 static
443 int lttng_desc_match_wildcard_enabler(const struct lttng_event_desc *desc,
444 struct lttng_enabler *enabler)
445 {
446 int loglevel = 0;
447 unsigned int has_loglevel = 0;
448
449 assert(enabler->type == LTTNG_ENABLER_WILDCARD);
450 /* Compare excluding final '*' */
451 if (strncmp(desc->name, enabler->event_param.name,
452 strlen(enabler->event_param.name) - 1))
453 return 0;
454 if (desc->loglevel) {
455 loglevel = *(*desc->loglevel);
456 has_loglevel = 1;
457 }
458 if (!lttng_loglevel_match(loglevel,
459 has_loglevel,
460 enabler->event_param.loglevel_type,
461 enabler->event_param.loglevel))
462 return 0;
463 return 1;
464 }
465
466 static
467 int lttng_desc_match_event_enabler(const struct lttng_event_desc *desc,
468 struct lttng_enabler *enabler)
469 {
470 int loglevel = 0;
471 unsigned int has_loglevel = 0;
472
473 assert(enabler->type == LTTNG_ENABLER_EVENT);
474 if (strcmp(desc->name, enabler->event_param.name))
475 return 0;
476 if (desc->loglevel) {
477 loglevel = *(*desc->loglevel);
478 has_loglevel = 1;
479 }
480 if (!lttng_loglevel_match(loglevel,
481 has_loglevel,
482 enabler->event_param.loglevel_type,
483 enabler->event_param.loglevel))
484 return 0;
485 return 1;
486 }
487
488 static
489 int lttng_desc_match_enabler(const struct lttng_event_desc *desc,
490 struct lttng_enabler *enabler)
491 {
492 switch (enabler->type) {
493 case LTTNG_ENABLER_WILDCARD:
494 return lttng_desc_match_wildcard_enabler(desc, enabler);
495 case LTTNG_ENABLER_EVENT:
496 return lttng_desc_match_event_enabler(desc, enabler);
497 default:
498 return -EINVAL;
499 }
500 }
501
502 static
503 int lttng_event_match_enabler(struct lttng_event *event,
504 struct lttng_enabler *enabler)
505 {
506 if (lttng_desc_match_enabler(event->desc, enabler)
507 && event->chan == enabler->chan)
508 return 1;
509 else
510 return 0;
511 }
512
513 static
514 struct lttng_enabler_ref * lttng_event_enabler_ref(struct lttng_event *event,
515 struct lttng_enabler *enabler)
516 {
517 struct lttng_enabler_ref *enabler_ref;
518
519 cds_list_for_each_entry(enabler_ref,
520 &event->enablers_ref_head, node) {
521 if (enabler_ref->ref == enabler)
522 return enabler_ref;
523 }
524 return NULL;
525 }
526
527 /*
528 * Create struct lttng_event if it is missing and present in the list of
529 * tracepoint probes.
530 */
531 static
532 void lttng_create_event_if_missing(struct lttng_enabler *enabler)
533 {
534 struct lttng_session *session = enabler->chan->session;
535 struct lttng_probe_desc *probe_desc;
536 const struct lttng_event_desc *desc;
537 struct lttng_event *event;
538 int i;
539 struct cds_list_head *probe_list;
540
541 probe_list = lttng_get_probe_list_head();
542 /*
543 * For each probe event, if we find that a probe event matches
544 * our enabler, create an associated lttng_event if not
545 * already present.
546 */
547 cds_list_for_each_entry(probe_desc, probe_list, head) {
548 for (i = 0; i < probe_desc->nr_events; i++) {
549 int found = 0, ret;
550 struct cds_hlist_head *head;
551 struct cds_hlist_node *node;
552 const char *event_name;
553 size_t name_len;
554 uint32_t hash;
555
556 desc = probe_desc->event_desc[i];
557 if (!lttng_desc_match_enabler(desc, enabler))
558 continue;
559 event_name = desc->name;
560 name_len = strlen(event_name);
561
562 /*
563 * Check if already created.
564 */
565 hash = jhash(event_name, name_len, 0);
566 head = &session->events_ht.table[hash & (LTTNG_UST_EVENT_HT_SIZE - 1)];
567 cds_hlist_for_each_entry(event, node, head, hlist) {
568 if (event->desc == desc
569 && event->chan == enabler->chan)
570 found = 1;
571 }
572 if (found)
573 continue;
574
575 /*
576 * We need to create an event for this
577 * event probe.
578 */
579 ret = lttng_event_create(probe_desc->event_desc[i],
580 enabler->chan);
581 if (ret) {
582 DBG("Unable to create event %s, error %d\n",
583 probe_desc->event_desc[i]->name, ret);
584 }
585 }
586 }
587 }
588
589 /*
590 * Create events associated with an enabler (if not already present),
591 * and add backward reference from the event to the enabler.
592 */
593 static
594 int lttng_enabler_ref_events(struct lttng_enabler *enabler)
595 {
596 struct lttng_session *session = enabler->chan->session;
597 struct lttng_event *event;
598
599 /* First ensure that probe events are created for this enabler. */
600 lttng_create_event_if_missing(enabler);
601
602 /* For each event matching enabler in session event list. */
603 cds_list_for_each_entry(event, &session->events_head, node) {
604 struct lttng_enabler_ref *enabler_ref;
605
606 if (!lttng_event_match_enabler(event, enabler))
607 continue;
608
609 enabler_ref = lttng_event_enabler_ref(event, enabler);
610 if (!enabler_ref) {
611 /*
612 * If no backward ref, create it.
613 * Add backward ref from event to enabler.
614 */
615 enabler_ref = zmalloc(sizeof(*enabler_ref));
616 if (!enabler_ref)
617 return -ENOMEM;
618 enabler_ref->ref = enabler;
619 cds_list_add(&enabler_ref->node,
620 &event->enablers_ref_head);
621 }
622
623 /*
624 * Link filter bytecodes if not linked yet.
625 */
626 lttng_enabler_event_link_bytecode(event, enabler);
627
628 /* TODO: merge event context. */
629 }
630 return 0;
631 }
632
633 /*
634 * Called at library load: connect the probe on all enablers matching
635 * this event.
636 * Called with session mutex held.
637 */
638 int lttng_fix_pending_events(void)
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 case LTTNG_UST_CONTEXT_IP:
742 return lttng_add_ip_to_ctx(ctx);
743 default:
744 return -EINVAL;
745 }
746 }
747
748 int lttng_enabler_attach_context(struct lttng_enabler *enabler,
749 struct lttng_ust_context *context_param)
750 {
751 #if 0 // disabled for now.
752 struct lttng_session *session = enabler->chan->session;
753 int ret;
754
755 ret = lttng_attach_context(context_param, &enabler->ctx,
756 session);
757 if (ret)
758 return ret;
759 lttng_session_lazy_sync_enablers(enabler->chan->session);
760 #endif
761 return -ENOSYS;
762 }
763
764 static
765 void lttng_enabler_destroy(struct lttng_enabler *enabler)
766 {
767 struct lttng_ust_filter_bytecode_node *filter_node, *tmp_filter_node;
768
769 /* Destroy filter bytecode */
770 cds_list_for_each_entry_safe(filter_node, tmp_filter_node,
771 &enabler->filter_bytecode_head, node) {
772 free(filter_node);
773 }
774
775 /* Destroy contexts */
776 lttng_destroy_context(enabler->ctx);
777
778 cds_list_del(&enabler->node);
779 free(enabler);
780 }
781
782 /*
783 * lttng_session_sync_enablers should be called just before starting a
784 * session.
785 */
786 static
787 void lttng_session_sync_enablers(struct lttng_session *session)
788 {
789 struct lttng_enabler *enabler;
790 struct lttng_event *event;
791
792 cds_list_for_each_entry(enabler, &session->enablers_head, node)
793 lttng_enabler_ref_events(enabler);
794 /*
795 * For each event, if at least one of its enablers is enabled,
796 * and its channel and session transient states are enabled, we
797 * enable the event, else we disable it.
798 */
799 cds_list_for_each_entry(event, &session->events_head, node) {
800 struct lttng_enabler_ref *enabler_ref;
801 struct lttng_bytecode_runtime *runtime;
802 int enabled = 0, has_enablers_without_bytecode = 0;
803
804 /* Enable events */
805 cds_list_for_each_entry(enabler_ref,
806 &event->enablers_ref_head, node) {
807 if (enabler_ref->ref->enabled) {
808 enabled = 1;
809 break;
810 }
811 }
812 /*
813 * Enabled state is based on union of enablers, with
814 * intesection of session and channel transient enable
815 * states.
816 */
817 enabled = enabled && session->tstate && event->chan->tstate;
818
819 CMM_STORE_SHARED(event->enabled, enabled);
820 /*
821 * Sync tracepoint registration with event enabled
822 * state.
823 */
824 if (enabled) {
825 if (!event->registered)
826 register_event(event);
827 } else {
828 if (event->registered)
829 unregister_event(event);
830 }
831
832 /* Check if has enablers without bytecode enabled */
833 cds_list_for_each_entry(enabler_ref,
834 &event->enablers_ref_head, node) {
835 if (enabler_ref->ref->enabled
836 && cds_list_empty(&enabler_ref->ref->filter_bytecode_head)) {
837 has_enablers_without_bytecode = 1;
838 break;
839 }
840 }
841 event->has_enablers_without_bytecode =
842 has_enablers_without_bytecode;
843
844 /* Enable filters */
845 cds_list_for_each_entry(runtime,
846 &event->bytecode_runtime_head, node) {
847 lttng_filter_sync_state(runtime);
848 }
849 }
850 }
851
852 /*
853 * Apply enablers to session events, adding events to session if need
854 * be. It is required after each modification applied to an active
855 * session, and right before session "start".
856 * "lazy" sync means we only sync if required.
857 */
858 static
859 void lttng_session_lazy_sync_enablers(struct lttng_session *session)
860 {
861 /* We can skip if session is not active */
862 if (!session->active)
863 return;
864 lttng_session_sync_enablers(session);
865 }
This page took 0.047615 seconds and 4 git commands to generate.