2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <common/common.h>
26 #include <common/defaults.h>
28 #include "buffer-registry.h"
29 #include "trace-ust.h"
35 * Match function for the events hash table lookup.
37 * Matches by name only. Used by the disable command.
39 int trace_ust_ht_match_event_by_name(struct cds_lfht_node
*node
,
42 struct ltt_ust_event
*event
;
48 event
= caa_container_of(node
, struct ltt_ust_event
, node
.node
);
52 if (strncmp(event
->attr
.name
, name
, sizeof(event
->attr
.name
)) != 0) {
64 * Match function for the hash table lookup.
66 * It matches an ust event based on three attributes which are the event name,
67 * the filter bytecode and the loglevel.
69 int trace_ust_ht_match_event(struct cds_lfht_node
*node
, const void *_key
)
71 struct ltt_ust_event
*event
;
72 const struct ltt_ust_ht_key
*key
;
73 int ev_loglevel_value
;
79 event
= caa_container_of(node
, struct ltt_ust_event
, node
.node
);
81 ev_loglevel_value
= event
->attr
.loglevel
;
83 /* Match the 4 elements of the key: name, filter, loglevel, exclusions. */
86 if (strncmp(event
->attr
.name
, key
->name
, sizeof(event
->attr
.name
)) != 0) {
90 /* Event loglevel value and type. */
91 ll_match
= loglevels_match(event
->attr
.loglevel_type
,
92 ev_loglevel_value
, key
->loglevel_type
,
93 key
->loglevel_value
, LTTNG_UST_LOGLEVEL_ALL
);
99 /* Only one of the filters is NULL, fail. */
100 if ((key
->filter
&& !event
->filter
) || (!key
->filter
&& event
->filter
)) {
104 if (key
->filter
&& event
->filter
) {
105 /* Both filters exists, check length followed by the bytecode. */
106 if (event
->filter
->len
!= key
->filter
->len
||
107 memcmp(event
->filter
->data
, key
->filter
->data
,
108 event
->filter
->len
) != 0) {
113 /* If only one of the exclusions is NULL, fail. */
114 if ((key
->exclusion
&& !event
->exclusion
) || (!key
->exclusion
&& event
->exclusion
)) {
118 if (key
->exclusion
&& event
->exclusion
) {
121 /* Check exclusion counts first. */
122 if (event
->exclusion
->count
!= key
->exclusion
->count
) {
126 /* Compare names individually. */
127 for (i
= 0; i
< event
->exclusion
->count
; ++i
) {
130 const char *name_ev
=
131 LTTNG_EVENT_EXCLUSION_NAME_AT(
132 event
->exclusion
, i
);
135 * Compare this exclusion name to all the key's
138 for (j
= 0; j
< key
->exclusion
->count
; ++j
) {
139 const char *name_key
=
140 LTTNG_EVENT_EXCLUSION_NAME_AT(
143 if (!strncmp(name_ev
, name_key
,
144 LTTNG_SYMBOL_NAME_LEN
)) {
152 * If the current exclusion name was not found amongst
153 * the key's exclusion names, then there's no match.
168 * Find the channel in the hashtable and return channel pointer. RCU read side
169 * lock MUST be acquired before calling this.
171 struct ltt_ust_channel
*trace_ust_find_channel_by_name(struct lttng_ht
*ht
,
174 struct lttng_ht_node_str
*node
;
175 struct lttng_ht_iter iter
;
178 * If we receive an empty string for channel name, it means the
179 * default channel name is requested.
182 name
= DEFAULT_CHANNEL_NAME
;
184 lttng_ht_lookup(ht
, (void *)name
, &iter
);
185 node
= lttng_ht_iter_get_node_str(&iter
);
190 DBG2("Trace UST channel %s found by name", name
);
192 return caa_container_of(node
, struct ltt_ust_channel
, node
);
195 DBG2("Trace UST channel %s not found by name", name
);
200 * Find the event in the hashtable and return event pointer. RCU read side lock
201 * MUST be acquired before calling this.
203 struct ltt_ust_event
*trace_ust_find_event(struct lttng_ht
*ht
,
204 char *name
, struct lttng_filter_bytecode
*filter
,
205 enum lttng_ust_loglevel_type loglevel_type
, int loglevel_value
,
206 struct lttng_event_exclusion
*exclusion
)
208 struct lttng_ht_node_str
*node
;
209 struct lttng_ht_iter iter
;
210 struct ltt_ust_ht_key key
;
217 key
.loglevel_type
= loglevel_type
;
218 key
.loglevel_value
= loglevel_value
;
219 key
.exclusion
= exclusion
;
221 cds_lfht_lookup(ht
->ht
, ht
->hash_fct((void *) name
, lttng_ht_seed
),
222 trace_ust_ht_match_event
, &key
, &iter
.iter
);
223 node
= lttng_ht_iter_get_node_str(&iter
);
228 DBG2("Trace UST event %s found", key
.name
);
230 return caa_container_of(node
, struct ltt_ust_event
, node
);
233 DBG2("Trace UST event %s NOT found", key
.name
);
238 * Lookup an agent in the session agents hash table by domain type and return
239 * the object if found else NULL.
241 * RCU read side lock must be acquired before calling and only released
242 * once the agent is no longer in scope or being used.
244 struct agent
*trace_ust_find_agent(struct ltt_ust_session
*session
,
245 enum lttng_domain_type domain_type
)
247 struct agent
*agt
= NULL
;
248 struct lttng_ht_node_u64
*node
;
249 struct lttng_ht_iter iter
;
254 DBG3("Trace ust agent lookup for domain %d", domain_type
);
258 lttng_ht_lookup(session
->agents
, &key
, &iter
);
259 node
= lttng_ht_iter_get_node_u64(&iter
);
263 agt
= caa_container_of(node
, struct agent
, node
);
270 * Allocate and initialize a ust session data structure.
272 * Return pointer to structure or NULL.
274 struct ltt_ust_session
*trace_ust_create_session(uint64_t session_id
)
276 struct ltt_ust_session
*lus
;
278 /* Allocate a new ltt ust session */
279 lus
= zmalloc(sizeof(struct ltt_ust_session
));
281 PERROR("create ust session zmalloc");
285 /* Init data structure */
286 lus
->id
= session_id
;
289 /* Set default metadata channel attribute. */
290 lus
->metadata_attr
.overwrite
= DEFAULT_CHANNEL_OVERWRITE
;
291 lus
->metadata_attr
.subbuf_size
= default_get_metadata_subbuf_size();
292 lus
->metadata_attr
.num_subbuf
= DEFAULT_METADATA_SUBBUF_NUM
;
293 lus
->metadata_attr
.switch_timer_interval
= DEFAULT_METADATA_SWITCH_TIMER
;
294 lus
->metadata_attr
.read_timer_interval
= DEFAULT_METADATA_READ_TIMER
;
295 lus
->metadata_attr
.output
= LTTNG_UST_MMAP
;
298 * Default buffer type. This can be changed through an enable channel
299 * requesting a different type. Note that this can only be changed once
300 * during the session lifetime which is at the first enable channel and
301 * only before start. The flag buffer_type_changed indicates the status.
303 lus
->buffer_type
= LTTNG_BUFFER_PER_UID
;
304 /* Once set to 1, the buffer_type is immutable for the session. */
305 lus
->buffer_type_changed
= 0;
306 /* Init it in case it get used after allocation. */
307 CDS_INIT_LIST_HEAD(&lus
->buffer_reg_uid_list
);
309 /* Alloc UST global domain channels' HT */
310 lus
->domain_global
.channels
= lttng_ht_new(0, LTTNG_HT_TYPE_STRING
);
311 /* Alloc agent hash table. */
312 lus
->agents
= lttng_ht_new(0, LTTNG_HT_TYPE_U64
);
314 lus
->consumer
= consumer_create_output(CONSUMER_DST_LOCAL
);
315 if (lus
->consumer
== NULL
) {
319 DBG2("UST trace session create successful");
324 ht_cleanup_push(lus
->domain_global
.channels
);
325 ht_cleanup_push(lus
->agents
);
332 * Allocate and initialize a ust channel data structure.
334 * Return pointer to structure or NULL.
336 struct ltt_ust_channel
*trace_ust_create_channel(struct lttng_channel
*chan
,
337 enum lttng_domain_type domain
)
339 struct ltt_ust_channel
*luc
;
343 luc
= zmalloc(sizeof(struct ltt_ust_channel
));
345 PERROR("ltt_ust_channel zmalloc");
349 luc
->domain
= domain
;
351 /* Copy UST channel attributes */
352 luc
->attr
.overwrite
= chan
->attr
.overwrite
;
353 luc
->attr
.subbuf_size
= chan
->attr
.subbuf_size
;
354 luc
->attr
.num_subbuf
= chan
->attr
.num_subbuf
;
355 luc
->attr
.switch_timer_interval
= chan
->attr
.switch_timer_interval
;
356 luc
->attr
.read_timer_interval
= chan
->attr
.read_timer_interval
;
357 luc
->attr
.output
= (enum lttng_ust_output
) chan
->attr
.output
;
359 /* Translate to UST output enum */
360 switch (luc
->attr
.output
) {
362 luc
->attr
.output
= LTTNG_UST_MMAP
;
367 * If we receive an empty string for channel name, it means the
368 * default channel name is requested.
370 if (chan
->name
[0] == '\0') {
371 strncpy(luc
->name
, DEFAULT_CHANNEL_NAME
, sizeof(luc
->name
));
373 /* Copy channel name */
374 strncpy(luc
->name
, chan
->name
, sizeof(luc
->name
));
376 luc
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
379 lttng_ht_node_init_str(&luc
->node
, luc
->name
);
380 CDS_INIT_LIST_HEAD(&luc
->ctx_list
);
382 /* Alloc hash tables */
383 luc
->events
= lttng_ht_new(0, LTTNG_HT_TYPE_STRING
);
384 luc
->ctx
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
386 /* On-disk circular buffer parameters */
387 luc
->tracefile_size
= chan
->attr
.tracefile_size
;
388 luc
->tracefile_count
= chan
->attr
.tracefile_count
;
390 DBG2("Trace UST channel %s created", luc
->name
);
397 * Validates an exclusion list.
399 * Returns 0 if valid, negative value if invalid.
401 static int validate_exclusion(struct lttng_event_exclusion
*exclusion
)
408 for (i
= 0; i
< exclusion
->count
; ++i
) {
411 LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, i
);
413 for (j
= 0; j
< i
; ++j
) {
415 LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, j
);
417 if (!strncmp(name_a
, name_b
, LTTNG_SYMBOL_NAME_LEN
)) {
430 * Allocate and initialize a ust event. Set name and event type.
431 * We own filter_expression, filter, and exclusion.
433 * Return pointer to structure or NULL.
435 struct ltt_ust_event
*trace_ust_create_event(struct lttng_event
*ev
,
436 char *filter_expression
,
437 struct lttng_filter_bytecode
*filter
,
438 struct lttng_event_exclusion
*exclusion
,
441 struct ltt_ust_event
*lue
;
445 if (exclusion
&& validate_exclusion(exclusion
)) {
449 lue
= zmalloc(sizeof(struct ltt_ust_event
));
451 PERROR("ust event zmalloc");
455 lue
->internal
= internal_event
;
458 case LTTNG_EVENT_PROBE
:
459 lue
->attr
.instrumentation
= LTTNG_UST_PROBE
;
461 case LTTNG_EVENT_FUNCTION
:
462 lue
->attr
.instrumentation
= LTTNG_UST_FUNCTION
;
464 case LTTNG_EVENT_FUNCTION_ENTRY
:
465 lue
->attr
.instrumentation
= LTTNG_UST_FUNCTION
;
467 case LTTNG_EVENT_TRACEPOINT
:
468 lue
->attr
.instrumentation
= LTTNG_UST_TRACEPOINT
;
471 ERR("Unknown ust instrumentation type (%d)", ev
->type
);
472 goto error_free_event
;
475 /* Copy event name */
476 strncpy(lue
->attr
.name
, ev
->name
, LTTNG_UST_SYM_NAME_LEN
);
477 lue
->attr
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
479 switch (ev
->loglevel_type
) {
480 case LTTNG_EVENT_LOGLEVEL_ALL
:
481 lue
->attr
.loglevel_type
= LTTNG_UST_LOGLEVEL_ALL
;
482 lue
->attr
.loglevel
= -1; /* Force to -1 */
484 case LTTNG_EVENT_LOGLEVEL_RANGE
:
485 lue
->attr
.loglevel_type
= LTTNG_UST_LOGLEVEL_RANGE
;
486 lue
->attr
.loglevel
= ev
->loglevel
;
488 case LTTNG_EVENT_LOGLEVEL_SINGLE
:
489 lue
->attr
.loglevel_type
= LTTNG_UST_LOGLEVEL_SINGLE
;
490 lue
->attr
.loglevel
= ev
->loglevel
;
493 ERR("Unknown ust loglevel type (%d)", ev
->loglevel_type
);
494 goto error_free_event
;
498 lue
->filter_expression
= filter_expression
;
499 lue
->filter
= filter
;
500 lue
->exclusion
= exclusion
;
503 lttng_ht_node_init_str(&lue
->node
, lue
->attr
.name
);
505 DBG2("Trace UST event %s, loglevel (%d,%d) created",
506 lue
->attr
.name
, lue
->attr
.loglevel_type
,
514 free(filter_expression
);
521 int trace_ust_context_type_event_to_ust(
522 enum lttng_event_context_type type
)
527 case LTTNG_EVENT_CONTEXT_VTID
:
528 utype
= LTTNG_UST_CONTEXT_VTID
;
530 case LTTNG_EVENT_CONTEXT_VPID
:
531 utype
= LTTNG_UST_CONTEXT_VPID
;
533 case LTTNG_EVENT_CONTEXT_PTHREAD_ID
:
534 utype
= LTTNG_UST_CONTEXT_PTHREAD_ID
;
536 case LTTNG_EVENT_CONTEXT_PROCNAME
:
537 utype
= LTTNG_UST_CONTEXT_PROCNAME
;
539 case LTTNG_EVENT_CONTEXT_IP
:
540 utype
= LTTNG_UST_CONTEXT_IP
;
542 case LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER
:
543 if (!ustctl_has_perf_counters()) {
545 WARN("Perf counters not implemented in UST");
547 utype
= LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER
;
550 case LTTNG_EVENT_CONTEXT_APP_CONTEXT
:
551 utype
= LTTNG_UST_CONTEXT_APP_CONTEXT
;
561 * Return 1 if contexts match, 0 otherwise.
563 int trace_ust_match_context(struct ltt_ust_context
*uctx
,
564 struct lttng_event_context
*ctx
)
568 utype
= trace_ust_context_type_event_to_ust(ctx
->ctx
);
572 if (uctx
->ctx
.ctx
!= utype
) {
576 case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER
:
577 if (uctx
->ctx
.u
.perf_counter
.type
578 != ctx
->u
.perf_counter
.type
) {
581 if (uctx
->ctx
.u
.perf_counter
.config
582 != ctx
->u
.perf_counter
.config
) {
585 if (strncmp(uctx
->ctx
.u
.perf_counter
.name
,
586 ctx
->u
.perf_counter
.name
,
587 LTTNG_UST_SYM_NAME_LEN
)) {
599 * Allocate and initialize an UST context.
601 * Return pointer to structure or NULL.
603 struct ltt_ust_context
*trace_ust_create_context(
604 struct lttng_event_context
*ctx
)
606 struct ltt_ust_context
*uctx
= NULL
;
611 utype
= trace_ust_context_type_event_to_ust(ctx
->ctx
);
613 ERR("Invalid UST context");
617 uctx
= zmalloc(sizeof(struct ltt_ust_context
));
619 PERROR("zmalloc ltt_ust_context");
623 uctx
->ctx
.ctx
= (enum lttng_ust_context_type
) utype
;
625 case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER
:
626 uctx
->ctx
.u
.perf_counter
.type
= ctx
->u
.perf_counter
.type
;
627 uctx
->ctx
.u
.perf_counter
.config
= ctx
->u
.perf_counter
.config
;
628 strncpy(uctx
->ctx
.u
.perf_counter
.name
, ctx
->u
.perf_counter
.name
,
629 LTTNG_UST_SYM_NAME_LEN
);
630 uctx
->ctx
.u
.perf_counter
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] = '\0';
632 case LTTNG_UST_CONTEXT_APP_CONTEXT
:
634 char *provider_name
= NULL
, *ctx_name
= NULL
;
636 provider_name
= strdup(ctx
->u
.app_ctx
.provider_name
);
637 if (!provider_name
) {
640 uctx
->ctx
.u
.app_ctx
.provider_name
= provider_name
;
642 ctx_name
= strdup(ctx
->u
.app_ctx
.ctx_name
);
646 uctx
->ctx
.u
.app_ctx
.ctx_name
= ctx_name
;
652 lttng_ht_node_init_ulong(&uctx
->node
, (unsigned long) uctx
->ctx
.ctx
);
656 trace_ust_destroy_context(uctx
);
661 void destroy_pid_tracker_node_rcu(struct rcu_head
*head
)
663 struct ust_pid_tracker_node
*tracker_node
=
664 caa_container_of(head
, struct ust_pid_tracker_node
, node
.head
);
669 void destroy_pid_tracker_node(struct ust_pid_tracker_node
*tracker_node
)
672 call_rcu(&tracker_node
->node
.head
, destroy_pid_tracker_node_rcu
);
676 int init_pid_tracker(struct ust_pid_tracker
*pid_tracker
)
680 pid_tracker
->ht
= lttng_ht_new(0, LTTNG_HT_TYPE_ULONG
);
681 if (!pid_tracker
->ht
) {
691 * Teardown pid tracker content, but don't free pid_tracker object.
694 void fini_pid_tracker(struct ust_pid_tracker
*pid_tracker
)
696 struct ust_pid_tracker_node
*tracker_node
;
697 struct lttng_ht_iter iter
;
699 if (!pid_tracker
->ht
) {
703 cds_lfht_for_each_entry(pid_tracker
->ht
->ht
,
704 &iter
.iter
, tracker_node
, node
.node
) {
705 int ret
= lttng_ht_del(pid_tracker
->ht
, &iter
);
708 destroy_pid_tracker_node(tracker_node
);
711 ht_cleanup_push(pid_tracker
->ht
);
712 pid_tracker
->ht
= NULL
;
716 struct ust_pid_tracker_node
*pid_tracker_lookup(
717 struct ust_pid_tracker
*pid_tracker
, int pid
,
718 struct lttng_ht_iter
*iter
)
720 unsigned long _pid
= (unsigned long) pid
;
721 struct lttng_ht_node_ulong
*node
;
723 lttng_ht_lookup(pid_tracker
->ht
, (void *) _pid
, iter
);
724 node
= lttng_ht_iter_get_node_ulong(iter
);
726 return caa_container_of(node
, struct ust_pid_tracker_node
,
734 int pid_tracker_add_pid(struct ust_pid_tracker
*pid_tracker
, int pid
)
736 int retval
= LTTNG_OK
;
737 struct ust_pid_tracker_node
*tracker_node
;
738 struct lttng_ht_iter iter
;
741 retval
= LTTNG_ERR_INVALID
;
744 tracker_node
= pid_tracker_lookup(pid_tracker
, pid
, &iter
);
746 /* Already exists. */
747 retval
= LTTNG_ERR_PID_TRACKED
;
750 tracker_node
= zmalloc(sizeof(*tracker_node
));
752 retval
= LTTNG_ERR_NOMEM
;
755 lttng_ht_node_init_ulong(&tracker_node
->node
, (unsigned long) pid
);
756 lttng_ht_add_unique_ulong(pid_tracker
->ht
, &tracker_node
->node
);
762 int pid_tracker_del_pid(struct ust_pid_tracker
*pid_tracker
, int pid
)
764 int retval
= LTTNG_OK
, ret
;
765 struct ust_pid_tracker_node
*tracker_node
;
766 struct lttng_ht_iter iter
;
769 retval
= LTTNG_ERR_INVALID
;
772 tracker_node
= pid_tracker_lookup(pid_tracker
, pid
, &iter
);
775 retval
= LTTNG_ERR_PID_NOT_TRACKED
;
778 ret
= lttng_ht_del(pid_tracker
->ht
, &iter
);
781 destroy_pid_tracker_node(tracker_node
);
787 * The session lock is held when calling this function.
789 int trace_ust_pid_tracker_lookup(struct ltt_ust_session
*session
, int pid
)
791 struct lttng_ht_iter iter
;
793 if (!session
->pid_tracker
.ht
) {
796 if (pid_tracker_lookup(&session
->pid_tracker
, pid
, &iter
)) {
803 * Called with the session lock held.
805 int trace_ust_track_pid(struct ltt_ust_session
*session
, int pid
)
807 int retval
= LTTNG_OK
;
810 /* Track all pids: destroy tracker if exists. */
811 if (session
->pid_tracker
.ht
) {
812 fini_pid_tracker(&session
->pid_tracker
);
813 /* Ensure all apps have session. */
814 ust_app_global_update_all(session
);
819 if (!session
->pid_tracker
.ht
) {
820 /* Create tracker. */
821 if (init_pid_tracker(&session
->pid_tracker
)) {
822 ERR("Error initializing PID tracker");
823 retval
= LTTNG_ERR_NOMEM
;
826 ret
= pid_tracker_add_pid(&session
->pid_tracker
, pid
);
827 if (ret
!= LTTNG_OK
) {
829 fini_pid_tracker(&session
->pid_tracker
);
832 /* Remove all apps from session except pid. */
833 ust_app_global_update_all(session
);
837 ret
= pid_tracker_add_pid(&session
->pid_tracker
, pid
);
838 if (ret
!= LTTNG_OK
) {
842 /* Add session to application */
843 app
= ust_app_find_by_pid(pid
);
845 ust_app_global_update(session
, app
);
854 * Called with the session lock held.
856 int trace_ust_untrack_pid(struct ltt_ust_session
*session
, int pid
)
858 int retval
= LTTNG_OK
;
861 /* Create empty tracker, replace old tracker. */
862 struct ust_pid_tracker tmp_tracker
;
864 tmp_tracker
= session
->pid_tracker
;
865 if (init_pid_tracker(&session
->pid_tracker
)) {
866 ERR("Error initializing PID tracker");
867 retval
= LTTNG_ERR_NOMEM
;
868 /* Rollback operation. */
869 session
->pid_tracker
= tmp_tracker
;
872 fini_pid_tracker(&tmp_tracker
);
874 /* Remove session from all applications */
875 ust_app_global_update_all(session
);
880 if (!session
->pid_tracker
.ht
) {
881 /* No PID being tracked. */
882 retval
= LTTNG_ERR_PID_NOT_TRACKED
;
885 /* Remove PID from tracker */
886 ret
= pid_tracker_del_pid(&session
->pid_tracker
, pid
);
887 if (ret
!= LTTNG_OK
) {
891 /* Remove session from application. */
892 app
= ust_app_find_by_pid(pid
);
894 ust_app_global_update(session
, app
);
902 * Called with session lock held.
904 ssize_t
trace_ust_list_tracker_pids(struct ltt_ust_session
*session
,
907 struct ust_pid_tracker_node
*tracker_node
;
908 struct lttng_ht_iter iter
;
909 unsigned long count
, i
= 0;
914 if (!session
->pid_tracker
.ht
) {
915 /* Tracker disabled. Set first entry to -1. */
916 pids
= zmalloc(sizeof(*pids
));
927 cds_lfht_count_nodes(session
->pid_tracker
.ht
->ht
,
928 &approx
[0], &count
, &approx
[1]);
929 pids
= zmalloc(sizeof(*pids
) * count
);
934 cds_lfht_for_each_entry(session
->pid_tracker
.ht
->ht
,
935 &iter
.iter
, tracker_node
, node
.node
) {
936 pids
[i
++] = tracker_node
->node
.key
;
946 * RCU safe free context structure.
948 static void destroy_context_rcu(struct rcu_head
*head
)
950 struct lttng_ht_node_ulong
*node
=
951 caa_container_of(head
, struct lttng_ht_node_ulong
, head
);
952 struct ltt_ust_context
*ctx
=
953 caa_container_of(node
, struct ltt_ust_context
, node
);
955 trace_ust_destroy_context(ctx
);
959 * Cleanup UST context hash table.
961 static void destroy_contexts(struct lttng_ht
*ht
)
964 struct lttng_ht_node_ulong
*node
;
965 struct lttng_ht_iter iter
;
966 struct ltt_ust_context
*ctx
;
971 cds_lfht_for_each_entry(ht
->ht
, &iter
.iter
, node
, node
) {
972 /* Remove from ordered list. */
973 ctx
= caa_container_of(node
, struct ltt_ust_context
, node
);
974 cds_list_del(&ctx
->list
);
975 /* Remove from channel's hash table. */
976 ret
= lttng_ht_del(ht
, &iter
);
978 call_rcu(&node
->head
, destroy_context_rcu
);
987 * Cleanup ust event structure.
989 void trace_ust_destroy_event(struct ltt_ust_event
*event
)
993 DBG2("Trace destroy UST event %s", event
->attr
.name
);
994 free(event
->filter_expression
);
996 free(event
->exclusion
);
1001 * Cleanup ust context structure.
1003 void trace_ust_destroy_context(struct ltt_ust_context
*ctx
)
1007 if (ctx
->ctx
.ctx
== LTTNG_UST_CONTEXT_APP_CONTEXT
) {
1008 free(ctx
->ctx
.u
.app_ctx
.provider_name
);
1009 free(ctx
->ctx
.u
.app_ctx
.ctx_name
);
1015 * URCU intermediate call to complete destroy event.
1017 static void destroy_event_rcu(struct rcu_head
*head
)
1019 struct lttng_ht_node_str
*node
=
1020 caa_container_of(head
, struct lttng_ht_node_str
, head
);
1021 struct ltt_ust_event
*event
=
1022 caa_container_of(node
, struct ltt_ust_event
, node
);
1024 trace_ust_destroy_event(event
);
1028 * Cleanup UST events hashtable.
1030 static void destroy_events(struct lttng_ht
*events
)
1033 struct lttng_ht_node_str
*node
;
1034 struct lttng_ht_iter iter
;
1039 cds_lfht_for_each_entry(events
->ht
, &iter
.iter
, node
, node
) {
1040 ret
= lttng_ht_del(events
, &iter
);
1042 call_rcu(&node
->head
, destroy_event_rcu
);
1046 ht_cleanup_push(events
);
1050 * Cleanup ust channel structure.
1052 * Should _NOT_ be called with RCU read lock held.
1054 static void _trace_ust_destroy_channel(struct ltt_ust_channel
*channel
)
1058 DBG2("Trace destroy UST channel %s", channel
->name
);
1064 * URCU intermediate call to complete destroy channel.
1066 static void destroy_channel_rcu(struct rcu_head
*head
)
1068 struct lttng_ht_node_str
*node
=
1069 caa_container_of(head
, struct lttng_ht_node_str
, head
);
1070 struct ltt_ust_channel
*channel
=
1071 caa_container_of(node
, struct ltt_ust_channel
, node
);
1073 _trace_ust_destroy_channel(channel
);
1076 void trace_ust_destroy_channel(struct ltt_ust_channel
*channel
)
1078 /* Destroying all events of the channel */
1079 destroy_events(channel
->events
);
1080 /* Destroying all context of the channel */
1081 destroy_contexts(channel
->ctx
);
1083 call_rcu(&channel
->node
.head
, destroy_channel_rcu
);
1087 * Remove an UST channel from a channel HT.
1089 void trace_ust_delete_channel(struct lttng_ht
*ht
,
1090 struct ltt_ust_channel
*channel
)
1093 struct lttng_ht_iter iter
;
1098 iter
.iter
.node
= &channel
->node
.node
;
1099 ret
= lttng_ht_del(ht
, &iter
);
1104 * Iterate over a hash table containing channels and cleanup safely.
1106 static void destroy_channels(struct lttng_ht
*channels
)
1108 struct lttng_ht_node_str
*node
;
1109 struct lttng_ht_iter iter
;
1114 cds_lfht_for_each_entry(channels
->ht
, &iter
.iter
, node
, node
) {
1115 struct ltt_ust_channel
*chan
=
1116 caa_container_of(node
, struct ltt_ust_channel
, node
);
1118 trace_ust_delete_channel(channels
, chan
);
1119 trace_ust_destroy_channel(chan
);
1123 ht_cleanup_push(channels
);
1127 * Cleanup UST global domain.
1129 static void destroy_domain_global(struct ltt_ust_domain_global
*dom
)
1133 destroy_channels(dom
->channels
);
1137 * Cleanup ust session structure
1139 * Should *NOT* be called with RCU read-side lock held.
1141 void trace_ust_destroy_session(struct ltt_ust_session
*session
)
1144 struct buffer_reg_uid
*reg
, *sreg
;
1145 struct lttng_ht_iter iter
;
1149 DBG2("Trace UST destroy session %" PRIu64
, session
->id
);
1151 /* Cleaning up UST domain */
1152 destroy_domain_global(&session
->domain_global
);
1155 cds_lfht_for_each_entry(session
->agents
->ht
, &iter
.iter
, agt
, node
.node
) {
1156 int ret
= lttng_ht_del(session
->agents
, &iter
);
1163 ht_cleanup_push(session
->agents
);
1165 /* Cleanup UID buffer registry object(s). */
1166 cds_list_for_each_entry_safe(reg
, sreg
, &session
->buffer_reg_uid_list
,
1168 cds_list_del(®
->lnode
);
1169 buffer_reg_uid_remove(reg
);
1170 buffer_reg_uid_destroy(reg
, session
->consumer
);
1173 consumer_output_put(session
->consumer
);
1175 fini_pid_tracker(&session
->pid_tracker
);