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