2 * Copyright (C) 2013 David Goulet <dgoulet@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
8 #ifndef LTTNG_BUFFER_REGISTRY_H
9 #define LTTNG_BUFFER_REGISTRY_H
12 #include <urcu/list.h>
14 #include <lttng/lttng.h>
15 #include <common/hashtable/hashtable.h>
18 #include "lttng-ust-ctl.h"
19 #include "ust-registry.h"
21 struct buffer_reg_stream
{
22 struct cds_list_head lnode
;
24 /* Original object data that MUST be copied over. */
25 struct lttng_ust_object_data
*ust
;
29 struct buffer_reg_map_counter
{
30 struct cds_list_head lnode
;
32 /* Original object data that MUST be copied over. */
33 struct lttng_ust_object_data
*ust
;
37 struct buffer_reg_channel
{
38 /* This key is the same as a tracing channel key. */
40 /* Key of the channel on the consumer side. */
41 uint64_t consumer_key
;
42 /* Stream registry object of this channel registry. */
43 struct cds_list_head streams
;
44 /* Total number of stream in the list. */
45 uint64_t stream_count
;
46 /* Used to ensure mutual exclusion to the stream's list. */
47 pthread_mutex_t stream_list_lock
;
48 /* Node for hash table usage. */
49 struct lttng_ht_node_u64 node
;
50 /* Size of subbuffers in this channel. */
52 /* Number of subbuffers per stream. */
55 /* Original object data that MUST be copied over. */
56 struct lttng_ust_object_data
*ust
;
60 struct buffer_reg_map
{
61 /* This key is the same as a tracing map key. */
63 /* Per cpu counter registry object of this map registry. */
64 struct cds_list_head counters
;
65 /* Total number of stream in the list. */
66 uint64_t counter_count
;
67 /* Used to ensure mutual exclusion to the counter's list. */
68 pthread_mutex_t counter_list_lock
;
69 /* Node for hash table usage. */
70 struct lttng_ht_node_u64 node
;
72 /* Original object data that MUST be copied over. */
73 struct lttng_ust_object_data
*ust
;
76 struct ustctl_daemon_counter
*daemon_counter
;
79 struct buffer_reg_session
{
80 /* Registry per domain. */
82 struct ust_registry_session
*ust
;
85 /* Contains buffer registry channel indexed by tracing channel key. */
86 struct lttng_ht
*channels
;
87 /* Contains buffer registry map indexed by tracing map key. */
88 struct lttng_ht
*maps
;
92 * Registry object for per UID buffers.
94 struct buffer_reg_uid
{
96 * Keys to match this object in a hash table. The following three variables
97 * identify a unique per UID buffer registry.
99 uint64_t session_id
; /* Unique tracing session id. */
100 int bits_per_long
; /* ABI */
101 uid_t uid
; /* Owner. */
103 enum lttng_domain_type domain
;
104 struct buffer_reg_session
*registry
;
106 /* Indexed by session id. */
107 struct lttng_ht_node_u64 node
;
108 /* Node of a linked list used to teardown object at a destroy session. */
109 struct cds_list_head lnode
;
111 char root_shm_path
[PATH_MAX
];
112 char shm_path
[PATH_MAX
];
116 * Registry object for per PID buffers.
118 struct buffer_reg_pid
{
121 struct buffer_reg_session
*registry
;
123 /* Indexed by session id. */
124 struct lttng_ht_node_u64 node
;
126 char root_shm_path
[PATH_MAX
];
127 char shm_path
[PATH_MAX
];
130 /* Buffer registry per UID. */
131 void buffer_reg_init_uid_registry(void);
132 int buffer_reg_uid_create(uint64_t session_id
, uint32_t bits_per_long
, uid_t uid
,
133 enum lttng_domain_type domain
, struct buffer_reg_uid
**regp
,
134 const char *root_shm_path
, const char *shm_path
);
135 void buffer_reg_uid_add(struct buffer_reg_uid
*reg
);
136 struct buffer_reg_uid
*buffer_reg_uid_find(uint64_t session_id
,
137 uint32_t bits_per_long
, uid_t uid
);
138 void buffer_reg_uid_remove(struct buffer_reg_uid
*regp
);
139 void buffer_reg_uid_destroy(struct buffer_reg_uid
*regp
,
140 struct consumer_output
*consumer
);
142 /* Buffer registry per PID. */
143 void buffer_reg_init_pid_registry(void);
144 int buffer_reg_pid_create(uint64_t session_id
, struct buffer_reg_pid
**regp
,
145 const char *root_shm_path
, const char *shm_path
);
146 void buffer_reg_pid_add(struct buffer_reg_pid
*reg
);
147 struct buffer_reg_pid
*buffer_reg_pid_find(uint64_t session_id
);
148 void buffer_reg_pid_remove(struct buffer_reg_pid
*regp
);
149 void buffer_reg_pid_destroy(struct buffer_reg_pid
*regp
);
152 int buffer_reg_channel_create(uint64_t key
, struct buffer_reg_channel
**regp
);
153 void buffer_reg_channel_add(struct buffer_reg_session
*session
,
154 struct buffer_reg_channel
*channel
);
155 struct buffer_reg_channel
*buffer_reg_channel_find(uint64_t key
,
156 struct buffer_reg_uid
*reg
);
157 void buffer_reg_channel_remove(struct buffer_reg_session
*session
,
158 struct buffer_reg_channel
*regp
);
159 void buffer_reg_channel_destroy(struct buffer_reg_channel
*regp
,
160 enum lttng_domain_type domain
);
163 int buffer_reg_map_create(uint64_t key
, struct buffer_reg_map
**regp
);
164 void buffer_reg_map_add(struct buffer_reg_session
*session
,
165 struct buffer_reg_map
*map
);
166 struct buffer_reg_map
*buffer_reg_map_find(uint64_t key
,
167 struct buffer_reg_uid
*reg
);
168 void buffer_reg_map_remove(struct buffer_reg_session
*session
,
169 struct buffer_reg_map
*regp
);
170 void buffer_reg_map_destroy(struct buffer_reg_map
*regp
,
171 enum lttng_domain_type domain
);
174 int buffer_reg_stream_create(struct buffer_reg_stream
**regp
);
175 void buffer_reg_stream_add(struct buffer_reg_stream
*stream
,
176 struct buffer_reg_channel
*channel
);
177 void buffer_reg_stream_destroy(struct buffer_reg_stream
*regp
,
178 enum lttng_domain_type domain
);
181 int buffer_reg_map_counter_create(struct buffer_reg_map_counter
**regp
);
182 void buffer_reg_map_counter_add(struct buffer_reg_map_counter
*map_counter
,
183 struct buffer_reg_map
*map
);
184 void buffer_reg_map_counter_destroy(struct buffer_reg_map_counter
*regp
,
185 enum lttng_domain_type domain
);
187 /* Global registry. */
188 void buffer_reg_destroy_registries(void);
190 int buffer_reg_uid_consumer_channel_key(
191 struct cds_list_head
*buffer_reg_uid_list
,
192 uint64_t chan_key
, uint64_t *consumer_chan_key
);
194 #endif /* LTTNG_BUFFER_REGISTRY_H */