1500f74aa54b885c6cd9401f8797e06e9c0e3316
[lttng-tools.git] / src / bin / lttng-sessiond / ust-registry.h
1 /*
2 * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com>
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License, version 2 only, as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 51
15 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18 #ifndef LTTNG_UST_REGISTRY_H
19 #define LTTNG_UST_REGISTRY_H
20
21 #include <pthread.h>
22 #include <stdint.h>
23
24 #include <common/hashtable/hashtable.h>
25 #include <common/compat/uuid.h>
26
27 #include "ust-ctl.h"
28
29 #define CTF_SPEC_MAJOR 1
30 #define CTF_SPEC_MINOR 8
31
32 struct ust_app;
33
34 struct ust_registry_session {
35 /*
36 * With multiple writers and readers, use this lock to access the registry.
37 * Can nest within the ust app session lock.
38 */
39 pthread_mutex_t lock;
40 /* Next channel ID available for a newly registered channel. */
41 uint32_t next_channel_id;
42 /* Once this value reaches UINT32_MAX, no more id can be allocated. */
43 uint32_t used_channel_id;
44 /* Universal unique identifier used by the tracer. */
45 unsigned char uuid[UUID_LEN];
46
47 /* session ABI description */
48
49 /* Size of long, in bits */
50 unsigned int bits_per_long;
51 /* Alignment, in bits */
52 unsigned int uint8_t_alignment,
53 uint16_t_alignment,
54 uint32_t_alignment,
55 uint64_t_alignment,
56 long_alignment;
57 /* endianness */
58 int byte_order; /* BIG_ENDIAN or LITTLE_ENDIAN */
59
60 /* Generated metadata. */
61 char *metadata; /* NOT null-terminated ! Use memcpy. */
62 size_t metadata_len, metadata_alloc_len;
63 /* Length of bytes sent to the consumer. */
64 size_t metadata_len_sent;
65 /*
66 * Hash table containing channels sent by the UST tracer. MUST be accessed
67 * with a RCU read side lock acquired.
68 */
69 struct lttng_ht *channels;
70 /* Unique key to identify the metadata on the consumer side. */
71 uint64_t metadata_key;
72 /*
73 * Indicates if the metadata is closed on the consumer side. This is to
74 * avoid double close of metadata when an application unregisters AND
75 * deletes its sessions.
76 */
77 unsigned int metadata_closed;
78 };
79
80 struct ust_registry_channel {
81 uint64_t key;
82 /* Id set when replying to a register channel. */
83 uint32_t chan_id;
84 enum ustctl_channel_header header_type;
85
86 /*
87 * Flag for this channel if the metadata was dumped once during
88 * registration. 0 means no, 1 yes.
89 */
90 unsigned int metadata_dumped;
91 /* Indicates if this channel registry has already been registered. */
92 unsigned int register_done;
93
94 /*
95 * Hash table containing events sent by the UST tracer. MUST be accessed
96 * with a RCU read side lock acquired.
97 */
98 struct lttng_ht *ht;
99 /* Next event ID available for a newly registered event. */
100 uint32_t next_event_id;
101 /* Once this value reaches UINT32_MAX, no more id can be allocated. */
102 uint32_t used_event_id;
103 /*
104 * Context fields of the registry. Context are per channel. Allocated by a
105 * register channel notification from the UST tracer.
106 */
107 size_t nr_ctx_fields;
108 struct ustctl_field *ctx_fields;
109 struct lttng_ht_node_u64 node;
110 };
111
112 /*
113 * Event registered from a UST tracer sent to the session daemon. This is
114 * indexed and matched by <event_name/signature>.
115 */
116 struct ust_registry_event {
117 int id;
118 /* Both objd are set by the tracer. */
119 int session_objd;
120 int channel_objd;
121 /* Name of the event returned by the tracer. */
122 char name[LTTNG_UST_SYM_NAME_LEN];
123 char *signature;
124 int loglevel;
125 size_t nr_fields;
126 struct ustctl_field *fields;
127 char *model_emf_uri;
128 struct lttng_ust_object_data *obj;
129 /*
130 * Flag for this channel if the metadata was dumped once during
131 * registration. 0 means no, 1 yes.
132 */
133 unsigned int metadata_dumped;
134 /*
135 * Node in the ust-registry hash table. The event name is used to
136 * initialize the node and the event_name/signature for the match function.
137 */
138 struct lttng_ht_node_u64 node;
139 };
140
141 /*
142 * Validate that the id has reached the maximum allowed or not.
143 *
144 * Return 0 if NOT else 1.
145 */
146 static inline int ust_registry_is_max_id(uint32_t id)
147 {
148 return (id == UINT32_MAX) ? 1 : 0;
149 }
150
151 /*
152 * Return next available event id and increment the used counter. The
153 * ust_registry_is_max_id function MUST be called before in order to validate
154 * if the maximum number of IDs have been reached. If not, it is safe to call
155 * this function.
156 *
157 * Return a unique channel ID. If max is reached, the used_event_id counter is
158 * returned.
159 */
160 static inline uint32_t ust_registry_get_next_event_id(
161 struct ust_registry_channel *r)
162 {
163 if (ust_registry_is_max_id(r->used_event_id)) {
164 return r->used_event_id;
165 }
166
167 r->used_event_id++;
168 return r->next_event_id++;
169 }
170
171 /*
172 * Return next available channel id and increment the used counter. The
173 * ust_registry_is_max_id function MUST be called before in order to validate
174 * if the maximum number of IDs have been reached. If not, it is safe to call
175 * this function.
176 *
177 * Return a unique channel ID. If max is reached, the used_channel_id counter
178 * is returned.
179 */
180 static inline uint32_t ust_registry_get_next_chan_id(
181 struct ust_registry_session *r)
182 {
183 if (ust_registry_is_max_id(r->used_channel_id)) {
184 return r->used_channel_id;
185 }
186
187 r->used_channel_id++;
188 return r->next_channel_id++;
189 }
190
191 /*
192 * Return registry event count. This is read atomically.
193 */
194 static inline uint32_t ust_registry_get_event_count(
195 struct ust_registry_channel *r)
196 {
197 return (uint32_t) uatomic_read(&r->used_event_id);
198 }
199
200 #ifdef HAVE_LIBLTTNG_UST_CTL
201
202 void ust_registry_channel_destroy(struct ust_registry_session *session,
203 struct ust_registry_channel *chan);
204 struct ust_registry_channel *ust_registry_channel_find(
205 struct ust_registry_session *session, uint64_t key);
206 int ust_registry_channel_add(struct ust_registry_session *session,
207 uint64_t key);
208 void ust_registry_channel_del_free(struct ust_registry_session *session,
209 uint64_t key);
210
211 int ust_registry_session_init(struct ust_registry_session **sessionp,
212 struct ust_app *app,
213 uint32_t bits_per_long,
214 uint32_t uint8_t_alignment,
215 uint32_t uint16_t_alignment,
216 uint32_t uint32_t_alignment,
217 uint32_t uint64_t_alignment,
218 uint32_t long_alignment,
219 int byte_order);
220 void ust_registry_session_destroy(struct ust_registry_session *session);
221
222 int ust_registry_create_event(struct ust_registry_session *session,
223 uint64_t chan_key, int session_objd, int channel_objd, char *name,
224 char *sig, size_t nr_fields, struct ustctl_field *fields, int loglevel,
225 char *model_emf_uri, int buffer_type, uint32_t *event_id_p);
226 struct ust_registry_event *ust_registry_find_event(
227 struct ust_registry_channel *chan, char *name, char *sig);
228 void ust_registry_destroy_event(struct ust_registry_channel *chan,
229 struct ust_registry_event *event);
230
231 /* app can be NULL for registry shared across applications. */
232 int ust_metadata_session_statedump(struct ust_registry_session *session,
233 struct ust_app *app);
234 int ust_metadata_channel_statedump(struct ust_registry_session *session,
235 struct ust_registry_channel *chan);
236 int ust_metadata_event_statedump(struct ust_registry_session *session,
237 struct ust_registry_channel *chan,
238 struct ust_registry_event *event);
239
240 #else /* HAVE_LIBLTTNG_UST_CTL */
241
242 static inline
243 void ust_registry_channel_destroy(struct ust_registry_session *session,
244 struct ust_registry_channel *chan)
245 {}
246 static inline
247 struct ust_registry_channel *ust_registry_channel_find(
248 struct ust_registry_session *session, uint64_t key)
249 {
250 return NULL;
251 }
252 static inline
253 int ust_registry_channel_add(struct ust_registry_session *session,
254 uint64_t key)
255 {
256 return 0;
257 }
258 static inline
259 void ust_registry_channel_del_free(struct ust_registry_session *session,
260 uint64_t key)
261 {}
262 static inline
263 int ust_registry_session_init(struct ust_registry_session **sessionp,
264 struct ust_app *app,
265 uint32_t bits_per_long,
266 uint32_t uint8_t_alignment,
267 uint32_t uint16_t_alignment,
268 uint32_t uint32_t_alignment,
269 uint32_t uint64_t_alignment,
270 uint32_t long_alignment,
271 int byte_order)
272 {
273 return 0;
274 }
275 static inline
276 void ust_registry_session_destroy(struct ust_registry_session *session)
277 {}
278 static inline
279 int ust_registry_create_event(struct ust_registry_session *session,
280 uint64_t chan_key, int session_objd, int channel_objd, char *name,
281 char *sig, size_t nr_fields, struct ustctl_field *fields, int loglevel,
282 char *model_emf_uri, int buffer_type, uint32_t *event_id_p)
283 {
284 return 0;
285 }
286 static inline
287 struct ust_registry_event *ust_registry_find_event(
288 struct ust_registry_channel *chan, char *name, char *sig)
289 {
290 return NULL;
291 }
292 static inline
293 void ust_registry_destroy_event(struct ust_registry_channel *chan,
294 struct ust_registry_event *event)
295 {}
296
297 /* The app object can be NULL for registry shared across applications. */
298 static inline
299 int ust_metadata_session_statedump(struct ust_registry_session *session,
300 struct ust_app *app)
301 {
302 return 0;
303 }
304 static inline
305 int ust_metadata_channel_statedump(struct ust_registry_session *session,
306 struct ust_registry_channel *chan)
307 {
308 return 0;
309 }
310 static inline
311 int ust_metadata_event_statedump(struct ust_registry_session *session,
312 struct ust_registry_channel *chan,
313 struct ust_registry_event *event)
314 {
315 return 0;
316 }
317
318 #endif /* HAVE_LIBLTTNG_UST_CTL */
319
320 #endif /* LTTNG_UST_REGISTRY_H */
This page took 0.036814 seconds and 4 git commands to generate.