Commit | Line | Data |
---|---|---|
d871c65b | 1 | /* |
c0c0989a | 2 | * SPDX-License-Identifier: MIT |
d871c65b | 3 | * |
c0c0989a | 4 | * Copyright 2019 (c) Francis Deslauriers <francis.deslauriers@efficios.com> |
d871c65b FD |
5 | */ |
6 | ||
c0c0989a MJ |
7 | #ifndef _LTTNG_UST_EVENTS_INTERNAL_H |
8 | #define _LTTNG_UST_EVENTS_INTERNAL_H | |
9 | ||
d871c65b FD |
10 | #include <stdint.h> |
11 | ||
12 | #include <urcu/list.h> | |
13 | #include <urcu/hlist.h> | |
14 | ||
864a1eda | 15 | #include <ust-helper.h> |
d871c65b FD |
16 | #include <lttng/ust-events.h> |
17 | ||
8665f6a4 MJ |
18 | enum lttng_enabler_format_type { |
19 | LTTNG_ENABLER_FORMAT_STAR_GLOB, | |
20 | LTTNG_ENABLER_FORMAT_EVENT, | |
21 | }; | |
22 | ||
23 | /* | |
24 | * Enabler field, within whatever object is enabling an event. Target of | |
25 | * backward reference. | |
26 | */ | |
27 | struct lttng_enabler { | |
28 | enum lttng_enabler_format_type format_type; | |
29 | ||
30 | /* head list of struct lttng_ust_filter_bytecode_node */ | |
31 | struct cds_list_head filter_bytecode_head; | |
32 | /* head list of struct lttng_ust_excluder_node */ | |
33 | struct cds_list_head excluder_head; | |
34 | ||
35 | struct lttng_ust_event event_param; | |
36 | unsigned int enabled:1; | |
37 | }; | |
38 | ||
d871c65b FD |
39 | struct lttng_event_enabler { |
40 | struct lttng_enabler base; | |
41 | struct cds_list_head node; /* per-session list of enablers */ | |
42 | struct lttng_channel *chan; | |
43 | /* | |
44 | * Unused, but kept around to make it explicit that the tracer can do | |
45 | * it. | |
46 | */ | |
47 | struct lttng_ctx *ctx; | |
48 | }; | |
49 | ||
d8d2416d FD |
50 | struct lttng_event_notifier_enabler { |
51 | struct lttng_enabler base; | |
6566528b | 52 | uint64_t error_counter_index; |
d37ecb3f FD |
53 | struct cds_list_head node; /* per-app list of event_notifier enablers */ |
54 | struct cds_list_head capture_bytecode_head; | |
d8d2416d FD |
55 | struct lttng_event_notifier_group *group; /* weak ref */ |
56 | uint64_t user_token; /* User-provided token */ | |
d37ecb3f | 57 | uint64_t num_captures; |
d8d2416d FD |
58 | }; |
59 | ||
ab249ecf FD |
60 | enum lttng_ust_bytecode_node_type { |
61 | LTTNG_UST_BYTECODE_NODE_TYPE_FILTER, | |
d37ecb3f | 62 | LTTNG_UST_BYTECODE_NODE_TYPE_CAPTURE, |
ab249ecf FD |
63 | }; |
64 | ||
65 | struct lttng_ust_bytecode_node { | |
66 | enum lttng_ust_bytecode_node_type type; | |
92495593 FD |
67 | struct cds_list_head node; |
68 | struct lttng_enabler *enabler; | |
ab249ecf FD |
69 | struct { |
70 | uint32_t len; | |
71 | uint32_t reloc_offset; | |
72 | uint64_t seqnum; | |
73 | char data[]; | |
74 | } bc; | |
92495593 FD |
75 | }; |
76 | ||
77 | struct lttng_ust_excluder_node { | |
78 | struct cds_list_head node; | |
79 | struct lttng_enabler *enabler; | |
80 | /* | |
81 | * struct lttng_ust_event_exclusion had variable sized array, | |
82 | * must be last field. | |
83 | */ | |
84 | struct lttng_ust_event_exclusion excluder; | |
85 | }; | |
86 | ||
d871c65b FD |
87 | static inline |
88 | struct lttng_enabler *lttng_event_enabler_as_enabler( | |
89 | struct lttng_event_enabler *event_enabler) | |
90 | { | |
91 | return &event_enabler->base; | |
92 | } | |
93 | ||
d8d2416d FD |
94 | static inline |
95 | struct lttng_enabler *lttng_event_notifier_enabler_as_enabler( | |
96 | struct lttng_event_notifier_enabler *event_notifier_enabler) | |
97 | { | |
98 | return &event_notifier_enabler->base; | |
99 | } | |
d871c65b FD |
100 | |
101 | /* | |
102 | * Allocate and initialize a `struct lttng_event_enabler` object. | |
103 | * | |
104 | * On success, returns a `struct lttng_event_enabler`, | |
105 | * On memory error, returns NULL. | |
106 | */ | |
107 | LTTNG_HIDDEN | |
108 | struct lttng_event_enabler *lttng_event_enabler_create( | |
109 | enum lttng_enabler_format_type format_type, | |
110 | struct lttng_ust_event *event_param, | |
111 | struct lttng_channel *chan); | |
112 | ||
113 | /* | |
114 | * Destroy a `struct lttng_event_enabler` object. | |
115 | */ | |
116 | LTTNG_HIDDEN | |
117 | void lttng_event_enabler_destroy(struct lttng_event_enabler *enabler); | |
118 | ||
119 | /* | |
120 | * Enable a `struct lttng_event_enabler` object and all events related to this | |
121 | * enabler. | |
122 | */ | |
123 | LTTNG_HIDDEN | |
124 | int lttng_event_enabler_enable(struct lttng_event_enabler *enabler); | |
125 | ||
126 | /* | |
127 | * Disable a `struct lttng_event_enabler` object and all events related to this | |
128 | * enabler. | |
129 | */ | |
130 | LTTNG_HIDDEN | |
131 | int lttng_event_enabler_disable(struct lttng_event_enabler *enabler); | |
132 | ||
133 | /* | |
134 | * Attach filter bytecode program to `struct lttng_event_enabler` and all | |
135 | * events related to this enabler. | |
136 | */ | |
137 | LTTNG_HIDDEN | |
a56fd376 FD |
138 | int lttng_event_enabler_attach_filter_bytecode( |
139 | struct lttng_event_enabler *enabler, | |
ab89263e | 140 | struct lttng_ust_bytecode_node **bytecode); |
d871c65b FD |
141 | |
142 | /* | |
143 | * Attach an application context to an event enabler. | |
144 | * | |
145 | * Not implemented. | |
146 | */ | |
147 | LTTNG_HIDDEN | |
148 | int lttng_event_enabler_attach_context(struct lttng_event_enabler *enabler, | |
149 | struct lttng_ust_context *ctx); | |
150 | ||
151 | /* | |
152 | * Attach exclusion list to `struct lttng_event_enabler` and all | |
153 | * events related to this enabler. | |
154 | */ | |
155 | LTTNG_HIDDEN | |
156 | int lttng_event_enabler_attach_exclusion(struct lttng_event_enabler *enabler, | |
e9fe6aad | 157 | struct lttng_ust_excluder_node **excluder); |
d871c65b FD |
158 | |
159 | /* | |
d37ecb3f FD |
160 | * Synchronize bytecodes for the enabler and the instance (event or |
161 | * event_notifier). | |
d871c65b | 162 | * |
621c07fc | 163 | * This function goes over all bytecode programs of the enabler (event or |
d37ecb3f | 164 | * event_notifier enabler) to ensure each is linked to the provided instance. |
d871c65b FD |
165 | */ |
166 | LTTNG_HIDDEN | |
53b9d7db FD |
167 | void lttng_enabler_link_bytecode(const struct lttng_event_desc *event_desc, |
168 | struct lttng_ctx **ctx, | |
621c07fc FD |
169 | struct cds_list_head *instance_bytecode_runtime_head, |
170 | struct cds_list_head *enabler_bytecode_runtime_head); | |
d871c65b | 171 | |
d8d2416d FD |
172 | /* |
173 | * Allocate and initialize a `struct lttng_event_notifier_group` object. | |
174 | * | |
175 | * On success, returns a `struct lttng_triggre_group`, | |
176 | * on memory error, returns NULL. | |
177 | */ | |
178 | LTTNG_HIDDEN | |
179 | struct lttng_event_notifier_group *lttng_event_notifier_group_create(void); | |
180 | ||
181 | /* | |
182 | * Destroy a `struct lttng_event_notifier_group` object. | |
183 | */ | |
184 | LTTNG_HIDDEN | |
185 | void lttng_event_notifier_group_destroy( | |
186 | struct lttng_event_notifier_group *event_notifier_group); | |
187 | ||
188 | /* | |
189 | * Allocate and initialize a `struct lttng_event_notifier_enabler` object. | |
190 | * | |
191 | * On success, returns a `struct lttng_event_notifier_enabler`, | |
192 | * On memory error, returns NULL. | |
193 | */ | |
194 | LTTNG_HIDDEN | |
195 | struct lttng_event_notifier_enabler *lttng_event_notifier_enabler_create( | |
196 | struct lttng_event_notifier_group *event_notifier_group, | |
197 | enum lttng_enabler_format_type format_type, | |
198 | struct lttng_ust_event_notifier *event_notifier_param); | |
199 | ||
200 | /* | |
201 | * Destroy a `struct lttng_event_notifier_enabler` object. | |
202 | */ | |
203 | LTTNG_HIDDEN | |
204 | void lttng_event_notifier_enabler_destroy( | |
205 | struct lttng_event_notifier_enabler *event_notifier_enabler); | |
206 | ||
207 | /* | |
208 | * Enable a `struct lttng_event_notifier_enabler` object and all event | |
209 | * notifiers related to this enabler. | |
210 | */ | |
211 | LTTNG_HIDDEN | |
212 | int lttng_event_notifier_enabler_enable( | |
213 | struct lttng_event_notifier_enabler *event_notifier_enabler); | |
214 | ||
215 | /* | |
216 | * Disable a `struct lttng_event_notifier_enabler` object and all event | |
217 | * notifiers related to this enabler. | |
218 | */ | |
219 | LTTNG_HIDDEN | |
220 | int lttng_event_notifier_enabler_disable( | |
221 | struct lttng_event_notifier_enabler *event_notifier_enabler); | |
222 | ||
223 | /* | |
224 | * Attach filter bytecode program to `struct lttng_event_notifier_enabler` and | |
225 | * all event notifiers related to this enabler. | |
226 | */ | |
227 | LTTNG_HIDDEN | |
a56fd376 | 228 | int lttng_event_notifier_enabler_attach_filter_bytecode( |
d8d2416d | 229 | struct lttng_event_notifier_enabler *event_notifier_enabler, |
ab89263e | 230 | struct lttng_ust_bytecode_node **bytecode); |
d8d2416d | 231 | |
d37ecb3f FD |
232 | /* |
233 | * Attach capture bytecode program to `struct lttng_event_notifier_enabler` and | |
234 | * all event_notifiers related to this enabler. | |
235 | */ | |
236 | LTTNG_HIDDEN | |
237 | int lttng_event_notifier_enabler_attach_capture_bytecode( | |
238 | struct lttng_event_notifier_enabler *event_notifier_enabler, | |
49cde654 | 239 | struct lttng_ust_bytecode_node **bytecode); |
d37ecb3f | 240 | |
d8d2416d FD |
241 | /* |
242 | * Attach exclusion list to `struct lttng_event_notifier_enabler` and all | |
243 | * event notifiers related to this enabler. | |
244 | */ | |
245 | LTTNG_HIDDEN | |
246 | int lttng_event_notifier_enabler_attach_exclusion( | |
247 | struct lttng_event_notifier_enabler *event_notifier_enabler, | |
e9fe6aad | 248 | struct lttng_ust_excluder_node **excluder); |
d8d2416d FD |
249 | |
250 | LTTNG_HIDDEN | |
251 | void lttng_free_event_notifier_filter_runtime( | |
252 | struct lttng_event_notifier *event_notifier); | |
253 | ||
254 | /* | |
255 | * Connect the probe on all enablers matching this event description. | |
256 | * Called on library load. | |
257 | */ | |
258 | LTTNG_HIDDEN | |
259 | int lttng_fix_pending_event_notifiers(void); | |
260 | ||
67d4e8f5 MJ |
261 | LTTNG_HIDDEN |
262 | struct lttng_counter *lttng_ust_counter_create( | |
263 | const char *counter_transport_name, | |
264 | size_t number_dimensions, const struct lttng_counter_dimension *dimensions); | |
265 | ||
bd8c1787 MJ |
266 | #ifdef HAVE_PERF_EVENT |
267 | ||
268 | LTTNG_HIDDEN | |
269 | int lttng_add_perf_counter_to_ctx(uint32_t type, | |
270 | uint64_t config, | |
271 | const char *name, | |
272 | struct lttng_ctx **ctx); | |
273 | LTTNG_HIDDEN | |
274 | int lttng_perf_counter_init(void); | |
275 | LTTNG_HIDDEN | |
276 | void lttng_perf_counter_exit(void); | |
277 | ||
278 | #else /* #ifdef HAVE_PERF_EVENT */ | |
279 | ||
280 | static inline | |
281 | int lttng_add_perf_counter_to_ctx(uint32_t type, | |
282 | uint64_t config, | |
283 | const char *name, | |
284 | struct lttng_ctx **ctx) | |
285 | { | |
286 | return -ENOSYS; | |
287 | } | |
288 | static inline | |
289 | int lttng_perf_counter_init(void) | |
290 | { | |
291 | return 0; | |
292 | } | |
293 | static inline | |
294 | void lttng_perf_counter_exit(void) | |
295 | { | |
296 | } | |
297 | #endif /* #else #ifdef HAVE_PERF_EVENT */ | |
298 | ||
d871c65b | 299 | #endif /* _LTTNG_UST_EVENTS_INTERNAL_H */ |