Move ust channel registry inside session registry
[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 #include <lttng/ust-ctl.h>
24
25 #include <common/hashtable/hashtable.h>
26 #include <common/compat/uuid.h>
27
28 #define CTF_SPEC_MAJOR 1
29 #define CTF_SPEC_MINOR 8
30
31 struct ust_app;
32
33 struct ust_registry_session {
34 /*
35 * With multiple writers and readers, use this lock to access
36 * the registry. Use defined macros above to lock it.
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 };
71
72 struct ust_registry_channel {
73 uint64_t key;
74 /* Id set when replying to a register channel. */
75 uint32_t chan_id;
76 enum ustctl_channel_header header_type;
77
78 /*
79 * Hash table containing events sent by the UST tracer. MUST be accessed
80 * with a RCU read side lock acquired.
81 */
82 struct lttng_ht *ht;
83 /* Next event ID available for a newly registered event. */
84 uint32_t next_event_id;
85 /* Once this value reaches UINT32_MAX, no more id can be allocated. */
86 uint32_t used_event_id;
87 /*
88 * Context fields of the registry. Context are per channel. Allocated by a
89 * register channel notification from the UST tracer.
90 */
91 size_t nr_ctx_fields;
92 struct ustctl_field *ctx_fields;
93 /* Hash table node for the session ht indexed by key. */
94 struct lttng_ht_node_u64 node;
95 };
96
97 /*
98 * Event registered from a UST tracer sent to the session daemon. This is
99 * indexed and matched by <event_name/signature>.
100 */
101 struct ust_registry_event {
102 int id;
103 /* Both objd are set by the tracer. */
104 int session_objd;
105 int channel_objd;
106 /* Name of the event returned by the tracer. */
107 char name[LTTNG_UST_SYM_NAME_LEN];
108 char *signature;
109 int loglevel;
110 size_t nr_fields;
111 struct ustctl_field *fields;
112 char *model_emf_uri;
113 /*
114 * Node in the ust-registry hash table. The event name is used to
115 * initialize the node and the event_name/signature for the match function.
116 */
117 struct lttng_ht_node_str node;
118 };
119
120 /*
121 * Validate that the id has reached the maximum allowed or not.
122 *
123 * Return 0 if NOT else 1.
124 */
125 static inline int ust_registry_is_max_id(uint32_t id)
126 {
127 return (id == UINT32_MAX) ? 1 : 0;
128 }
129
130 /*
131 * Return next available event id and increment the used counter. The
132 * ust_registry_is_max_id function MUST be called before in order to validate
133 * if the maximum number of IDs have been reached. If not, it is safe to call
134 * this function.
135 *
136 * Return a unique channel ID. If max is reached, the used_event_id counter is
137 * returned.
138 */
139 static inline uint32_t ust_registry_get_next_event_id(
140 struct ust_registry_channel *r)
141 {
142 if (ust_registry_is_max_id(r->used_event_id)) {
143 return r->used_event_id;
144 }
145
146 r->used_event_id++;
147 return r->next_event_id++;
148 }
149
150 /*
151 * Return next available channel id and increment the used counter. The
152 * ust_registry_is_max_id function MUST be called before in order to validate
153 * if the maximum number of IDs have been reached. If not, it is safe to call
154 * this function.
155 *
156 * Return a unique channel ID. If max is reached, the used_channel_id counter
157 * is returned.
158 */
159 static inline uint32_t ust_registry_get_next_chan_id(
160 struct ust_registry_session *r)
161 {
162 if (ust_registry_is_max_id(r->used_channel_id)) {
163 return r->used_channel_id;
164 }
165
166 r->used_channel_id++;
167 return r->next_channel_id++;
168 }
169
170 /*
171 * Return registry event count. This is read atomically.
172 */
173 static inline uint32_t ust_registry_get_event_count(
174 struct ust_registry_channel *r)
175 {
176 return (uint32_t) uatomic_read(&r->used_event_id);
177 }
178
179 void ust_registry_channel_destroy(struct ust_registry_session *session,
180 struct ust_registry_channel *chan);
181 struct ust_registry_channel *ust_registry_channel_find(
182 struct ust_registry_session *session, uint64_t key);
183 int ust_registry_channel_add(struct ust_registry_session *session,
184 uint64_t key);
185 void ust_registry_channel_del_free(struct ust_registry_session *session,
186 uint64_t key);
187
188 int ust_registry_session_init(struct ust_registry_session **sessionp,
189 struct ust_app *app,
190 uint32_t bits_per_long,
191 uint32_t uint8_t_alignment,
192 uint32_t uint16_t_alignment,
193 uint32_t uint32_t_alignment,
194 uint32_t uint64_t_alignment,
195 uint32_t long_alignment,
196 int byte_order);
197 void ust_registry_session_destroy(struct ust_registry_session *session);
198
199 int ust_registry_create_event(struct ust_registry_session *session,
200 uint64_t chan_key, int session_objd, int channel_objd, char *name,
201 char *sig, size_t nr_fields, struct ustctl_field *fields, int loglevel,
202 char *model_emf_uri, uint32_t *event_id);
203 struct ust_registry_event *ust_registry_find_event(
204 struct ust_registry_channel *chan, char *name, char *sig);
205 void ust_registry_destroy_event(struct ust_registry_channel *chan,
206 struct ust_registry_event *event);
207
208 /* app can be NULL for registry shared across applications. */
209 int ust_metadata_session_statedump(struct ust_registry_session *session,
210 struct ust_app *app);
211 int ust_metadata_channel_statedump(struct ust_registry_session *session,
212 struct ust_registry_channel *chan);
213 int ust_metadata_event_statedump(struct ust_registry_session *session,
214 struct ust_registry_channel *chan,
215 struct ust_registry_event *event);
216
217 #endif /* LTTNG_UST_REGISTRY_H */
This page took 0.034642 seconds and 5 git commands to generate.