Commit | Line | Data |
---|---|---|
d0b96690 DG |
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> | |
d0b96690 DG |
23 | |
24 | #include <common/hashtable/hashtable.h> | |
25 | #include <common/compat/uuid.h> | |
26 | ||
7972aab2 DG |
27 | #include "ust-ctl.h" |
28 | ||
d0b96690 DG |
29 | #define CTF_SPEC_MAJOR 1 |
30 | #define CTF_SPEC_MINOR 8 | |
31 | ||
32 | struct ust_app; | |
33 | ||
34 | struct ust_registry_session { | |
35 | /* | |
7972aab2 | 36 | * With multiple writers and readers, use this lock to access the registry. |
d0b96690 DG |
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; | |
d88aee68 DG |
63 | /* Length of bytes sent to the consumer. */ |
64 | size_t metadata_len_sent; | |
45893984 DG |
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; | |
7972aab2 DG |
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; | |
d0b96690 DG |
78 | }; |
79 | ||
80 | struct ust_registry_channel { | |
45893984 | 81 | uint64_t key; |
d0b96690 DG |
82 | /* Id set when replying to a register channel. */ |
83 | uint32_t chan_id; | |
84 | enum ustctl_channel_header header_type; | |
85 | ||
7972aab2 DG |
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 | ||
d0b96690 DG |
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; | |
45893984 | 109 | struct lttng_ht_node_u64 node; |
36b588ed MD |
110 | /* For delayed reclaim */ |
111 | struct rcu_head rcu_head; | |
d0b96690 DG |
112 | }; |
113 | ||
114 | /* | |
115 | * Event registered from a UST tracer sent to the session daemon. This is | |
116 | * indexed and matched by <event_name/signature>. | |
117 | */ | |
118 | struct ust_registry_event { | |
119 | int id; | |
120 | /* Both objd are set by the tracer. */ | |
121 | int session_objd; | |
122 | int channel_objd; | |
123 | /* Name of the event returned by the tracer. */ | |
124 | char name[LTTNG_UST_SYM_NAME_LEN]; | |
125 | char *signature; | |
126 | int loglevel; | |
127 | size_t nr_fields; | |
128 | struct ustctl_field *fields; | |
129 | char *model_emf_uri; | |
7972aab2 DG |
130 | /* |
131 | * Flag for this channel if the metadata was dumped once during | |
132 | * registration. 0 means no, 1 yes. | |
133 | */ | |
134 | unsigned int metadata_dumped; | |
d0b96690 DG |
135 | /* |
136 | * Node in the ust-registry hash table. The event name is used to | |
137 | * initialize the node and the event_name/signature for the match function. | |
138 | */ | |
7972aab2 | 139 | struct lttng_ht_node_u64 node; |
d0b96690 DG |
140 | }; |
141 | ||
142 | /* | |
143 | * Validate that the id has reached the maximum allowed or not. | |
144 | * | |
145 | * Return 0 if NOT else 1. | |
146 | */ | |
147 | static inline int ust_registry_is_max_id(uint32_t id) | |
148 | { | |
149 | return (id == UINT32_MAX) ? 1 : 0; | |
150 | } | |
151 | ||
152 | /* | |
153 | * Return next available event id and increment the used counter. The | |
154 | * ust_registry_is_max_id function MUST be called before in order to validate | |
155 | * if the maximum number of IDs have been reached. If not, it is safe to call | |
156 | * this function. | |
157 | * | |
158 | * Return a unique channel ID. If max is reached, the used_event_id counter is | |
159 | * returned. | |
160 | */ | |
161 | static inline uint32_t ust_registry_get_next_event_id( | |
162 | struct ust_registry_channel *r) | |
163 | { | |
164 | if (ust_registry_is_max_id(r->used_event_id)) { | |
165 | return r->used_event_id; | |
166 | } | |
167 | ||
168 | r->used_event_id++; | |
169 | return r->next_event_id++; | |
170 | } | |
171 | ||
172 | /* | |
173 | * Return next available channel id and increment the used counter. The | |
174 | * ust_registry_is_max_id function MUST be called before in order to validate | |
175 | * if the maximum number of IDs have been reached. If not, it is safe to call | |
176 | * this function. | |
177 | * | |
178 | * Return a unique channel ID. If max is reached, the used_channel_id counter | |
179 | * is returned. | |
180 | */ | |
181 | static inline uint32_t ust_registry_get_next_chan_id( | |
182 | struct ust_registry_session *r) | |
183 | { | |
184 | if (ust_registry_is_max_id(r->used_channel_id)) { | |
185 | return r->used_channel_id; | |
186 | } | |
187 | ||
188 | r->used_channel_id++; | |
189 | return r->next_channel_id++; | |
190 | } | |
191 | ||
192 | /* | |
193 | * Return registry event count. This is read atomically. | |
194 | */ | |
195 | static inline uint32_t ust_registry_get_event_count( | |
196 | struct ust_registry_channel *r) | |
197 | { | |
198 | return (uint32_t) uatomic_read(&r->used_event_id); | |
199 | } | |
200 | ||
7972aab2 DG |
201 | #ifdef HAVE_LIBLTTNG_UST_CTL |
202 | ||
d0b96690 DG |
203 | void ust_registry_channel_destroy(struct ust_registry_session *session, |
204 | struct ust_registry_channel *chan); | |
45893984 DG |
205 | struct ust_registry_channel *ust_registry_channel_find( |
206 | struct ust_registry_session *session, uint64_t key); | |
207 | int ust_registry_channel_add(struct ust_registry_session *session, | |
208 | uint64_t key); | |
209 | void ust_registry_channel_del_free(struct ust_registry_session *session, | |
210 | uint64_t key); | |
211 | ||
212 | int ust_registry_session_init(struct ust_registry_session **sessionp, | |
d0b96690 DG |
213 | struct ust_app *app, |
214 | uint32_t bits_per_long, | |
215 | uint32_t uint8_t_alignment, | |
216 | uint32_t uint16_t_alignment, | |
217 | uint32_t uint32_t_alignment, | |
218 | uint32_t uint64_t_alignment, | |
219 | uint32_t long_alignment, | |
af6142cf MD |
220 | int byte_order, |
221 | uint32_t major, | |
222 | uint32_t minor); | |
d0b96690 DG |
223 | void ust_registry_session_destroy(struct ust_registry_session *session); |
224 | ||
225 | int ust_registry_create_event(struct ust_registry_session *session, | |
45893984 DG |
226 | uint64_t chan_key, int session_objd, int channel_objd, char *name, |
227 | char *sig, size_t nr_fields, struct ustctl_field *fields, int loglevel, | |
8494bda5 MD |
228 | char *model_emf_uri, int buffer_type, uint32_t *event_id_p, |
229 | struct ust_app *app); | |
d0b96690 DG |
230 | struct ust_registry_event *ust_registry_find_event( |
231 | struct ust_registry_channel *chan, char *name, char *sig); | |
232 | void ust_registry_destroy_event(struct ust_registry_channel *chan, | |
233 | struct ust_registry_event *event); | |
234 | ||
235 | /* app can be NULL for registry shared across applications. */ | |
236 | int ust_metadata_session_statedump(struct ust_registry_session *session, | |
af6142cf | 237 | struct ust_app *app, uint32_t major, uint32_t minor); |
d0b96690 DG |
238 | int ust_metadata_channel_statedump(struct ust_registry_session *session, |
239 | struct ust_registry_channel *chan); | |
240 | int ust_metadata_event_statedump(struct ust_registry_session *session, | |
241 | struct ust_registry_channel *chan, | |
242 | struct ust_registry_event *event); | |
243 | ||
7972aab2 DG |
244 | #else /* HAVE_LIBLTTNG_UST_CTL */ |
245 | ||
246 | static inline | |
247 | void ust_registry_channel_destroy(struct ust_registry_session *session, | |
248 | struct ust_registry_channel *chan) | |
249 | {} | |
250 | static inline | |
251 | struct ust_registry_channel *ust_registry_channel_find( | |
252 | struct ust_registry_session *session, uint64_t key) | |
253 | { | |
254 | return NULL; | |
255 | } | |
256 | static inline | |
257 | int ust_registry_channel_add(struct ust_registry_session *session, | |
258 | uint64_t key) | |
259 | { | |
260 | return 0; | |
261 | } | |
262 | static inline | |
263 | void ust_registry_channel_del_free(struct ust_registry_session *session, | |
264 | uint64_t key) | |
265 | {} | |
266 | static inline | |
267 | int ust_registry_session_init(struct ust_registry_session **sessionp, | |
268 | struct ust_app *app, | |
269 | uint32_t bits_per_long, | |
270 | uint32_t uint8_t_alignment, | |
271 | uint32_t uint16_t_alignment, | |
272 | uint32_t uint32_t_alignment, | |
273 | uint32_t uint64_t_alignment, | |
274 | uint32_t long_alignment, | |
275 | int byte_order) | |
276 | { | |
277 | return 0; | |
278 | } | |
279 | static inline | |
280 | void ust_registry_session_destroy(struct ust_registry_session *session) | |
281 | {} | |
282 | static inline | |
283 | int ust_registry_create_event(struct ust_registry_session *session, | |
284 | uint64_t chan_key, int session_objd, int channel_objd, char *name, | |
285 | char *sig, size_t nr_fields, struct ustctl_field *fields, int loglevel, | |
286 | char *model_emf_uri, int buffer_type, uint32_t *event_id_p) | |
287 | { | |
288 | return 0; | |
289 | } | |
290 | static inline | |
291 | struct ust_registry_event *ust_registry_find_event( | |
292 | struct ust_registry_channel *chan, char *name, char *sig) | |
293 | { | |
294 | return NULL; | |
295 | } | |
296 | static inline | |
297 | void ust_registry_destroy_event(struct ust_registry_channel *chan, | |
298 | struct ust_registry_event *event) | |
299 | {} | |
300 | ||
301 | /* The app object can be NULL for registry shared across applications. */ | |
302 | static inline | |
303 | int ust_metadata_session_statedump(struct ust_registry_session *session, | |
304 | struct ust_app *app) | |
305 | { | |
306 | return 0; | |
307 | } | |
308 | static inline | |
309 | int ust_metadata_channel_statedump(struct ust_registry_session *session, | |
310 | struct ust_registry_channel *chan) | |
311 | { | |
312 | return 0; | |
313 | } | |
314 | static inline | |
315 | int ust_metadata_event_statedump(struct ust_registry_session *session, | |
316 | struct ust_registry_channel *chan, | |
317 | struct ust_registry_event *event) | |
318 | { | |
319 | return 0; | |
320 | } | |
321 | ||
322 | #endif /* HAVE_LIBLTTNG_UST_CTL */ | |
323 | ||
d0b96690 | 324 | #endif /* LTTNG_UST_REGISTRY_H */ |