SoW-2020-0002: Trace Hit Counters: Implement key-addressed counters in shared memory...
[deliverable/lttng-ust.git] / include / lttng / ust-abi.h
1 #ifndef _LTTNG_UST_ABI_H
2 #define _LTTNG_UST_ABI_H
3
4 /*
5 * lttng/ust-abi.h
6 *
7 * LTTng-UST ABI header
8 *
9 * Copyright 2010-2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * SOFTWARE.
28 */
29
30 #include <stdint.h>
31 #include <lttng/ust-compiler.h>
32
33 #ifndef LTTNG_PACKED
34 #error "LTTNG_PACKED should be defined"
35 #endif
36
37 #ifndef __ust_stringify
38 #define __ust_stringify1(x) #x
39 #define __ust_stringify(x) __ust_stringify1(x)
40 #endif /* __ust_stringify */
41
42 #define LTTNG_UST_SYM_NAME_LEN 256
43 #define LTTNG_UST_ABI_PROCNAME_LEN 16
44
45 /* UST comm magic number, used to validate protocol and endianness. */
46 #define LTTNG_UST_COMM_MAGIC 0xC57C57C5
47
48 /* Version for ABI between liblttng-ust, sessiond, consumerd */
49 #define LTTNG_UST_ABI_MAJOR_VERSION 9
50 #define LTTNG_UST_ABI_MAJOR_VERSION_OLDEST_COMPATIBLE 8
51 #define LTTNG_UST_ABI_MINOR_VERSION 0
52
53 enum lttng_ust_instrumentation {
54 LTTNG_UST_TRACEPOINT = 0,
55 LTTNG_UST_PROBE = 1,
56 LTTNG_UST_FUNCTION = 2,
57 };
58
59 enum lttng_ust_loglevel_type {
60 LTTNG_UST_LOGLEVEL_ALL = 0,
61 LTTNG_UST_LOGLEVEL_RANGE = 1,
62 LTTNG_UST_LOGLEVEL_SINGLE = 2,
63 };
64
65 enum lttng_ust_output {
66 LTTNG_UST_MMAP = 0,
67 };
68
69 enum lttng_ust_chan_type {
70 LTTNG_UST_CHAN_PER_CPU = 0,
71 LTTNG_UST_CHAN_METADATA = 1,
72 };
73
74 struct lttng_ust_tracer_version {
75 uint32_t major;
76 uint32_t minor;
77 uint32_t patchlevel;
78 } LTTNG_PACKED;
79
80 #define LTTNG_UST_CHANNEL_PADDING (LTTNG_UST_SYM_NAME_LEN + 32)
81 /*
82 * Given that the consumerd is limited to 64k file descriptors, we
83 * cannot expect much more than 1MB channel structure size. This size is
84 * depends on the number of streams within a channel, which depends on
85 * the number of possible CPUs on the system.
86 */
87 #define LTTNG_UST_CHANNEL_DATA_MAX_LEN 1048576U
88 struct lttng_ust_channel {
89 uint64_t len;
90 enum lttng_ust_chan_type type;
91 char padding[LTTNG_UST_CHANNEL_PADDING];
92 char data[]; /* variable sized data */
93 } LTTNG_PACKED;
94
95 #define LTTNG_UST_STREAM_PADDING1 (LTTNG_UST_SYM_NAME_LEN + 32)
96 struct lttng_ust_stream {
97 uint64_t len; /* shm len */
98 uint32_t stream_nr; /* stream number */
99 char padding[LTTNG_UST_STREAM_PADDING1];
100 /*
101 * shm_fd and wakeup_fd are send over unix socket as file
102 * descriptors after this structure.
103 */
104 } LTTNG_PACKED;
105
106 #define LTTNG_UST_TRIGGER_PADDING1 16
107 #define LTTNG_UST_TRIGGER_PADDING2 (LTTNG_UST_SYM_NAME_LEN + 32)
108 struct lttng_ust_trigger {
109 uint64_t id;
110 uint64_t error_counter_index;
111 enum lttng_ust_instrumentation instrumentation;
112 char name[LTTNG_UST_SYM_NAME_LEN]; /* event name */
113
114 enum lttng_ust_loglevel_type loglevel_type;
115 int loglevel; /* value, -1: all */
116 char padding[LTTNG_UST_TRIGGER_PADDING1];
117
118 /* Per instrumentation type configuration */
119 union {
120 char padding[LTTNG_UST_TRIGGER_PADDING2];
121 } u;
122 } LTTNG_PACKED;
123
124 enum lttng_ust_counter_arithmetic {
125 LTTNG_UST_COUNTER_ARITHMETIC_MODULAR = 0,
126 LTTNG_UST_COUNTER_ARITHMETIC_SATURATION = 1,
127 };
128
129 enum lttng_ust_counter_bitness {
130 LTTNG_UST_COUNTER_BITNESS_32BITS = 4,
131 LTTNG_UST_COUNTER_BITNESS_64BITS = 8,
132 };
133
134 struct lttng_ust_counter_dimension {
135 uint64_t size;
136 uint64_t underflow_index;
137 uint64_t overflow_index;
138 uint8_t has_underflow;
139 uint8_t has_overflow;
140 } LTTNG_PACKED;
141
142 #define LTTNG_UST_COUNTER_DIMENSION_MAX 8
143 struct lttng_ust_counter_conf {
144 uint32_t arithmetic; /* enum lttng_ust_counter_arithmetic */
145 uint32_t bitness; /* enum lttng_ust_counter_bitness */
146 uint32_t number_dimensions;
147 int64_t global_sum_step;
148 struct lttng_ust_counter_dimension dimensions[LTTNG_UST_COUNTER_DIMENSION_MAX];
149 } LTTNG_PACKED;
150
151 struct lttng_ust_counter_value {
152 uint32_t number_dimensions;
153 uint64_t dimension_indexes[LTTNG_UST_COUNTER_DIMENSION_MAX];
154 int64_t value;
155 } LTTNG_PACKED;
156
157 #define LTTNG_TRIGGER_NOTIFICATION_PADDING 32
158 struct lttng_ust_trigger_notification {
159 uint64_t id;
160 uint16_t capture_buf_size;
161 char padding[LTTNG_TRIGGER_NOTIFICATION_PADDING];
162 } LTTNG_PACKED;
163
164 #define LTTNG_UST_EVENT_PADDING1 16
165 #define LTTNG_UST_EVENT_PADDING2 (LTTNG_UST_SYM_NAME_LEN + 32)
166 struct lttng_ust_event {
167 enum lttng_ust_instrumentation instrumentation;
168 char name[LTTNG_UST_SYM_NAME_LEN]; /* event name */
169
170 enum lttng_ust_loglevel_type loglevel_type;
171 int loglevel; /* value, -1: all */
172 char padding[LTTNG_UST_EVENT_PADDING1];
173
174 /* Per instrumentation type configuration */
175 union {
176 char padding[LTTNG_UST_EVENT_PADDING2];
177 } u;
178 } LTTNG_PACKED;
179
180 #define LTTNG_UST_COUNTER_PADDING1 (LTTNG_UST_SYM_NAME_LEN + 32)
181 #define LTTNG_UST_COUNTER_DATA_MAX_LEN 4096U
182 struct lttng_ust_counter {
183 uint64_t len;
184 char padding[LTTNG_UST_COUNTER_PADDING1];
185 char data[]; /* variable sized data */
186 } LTTNG_PACKED;
187
188 #define LTTNG_UST_COUNTER_GLOBAL_PADDING1 (LTTNG_UST_SYM_NAME_LEN + 32)
189 struct lttng_ust_counter_global {
190 uint64_t len; /* shm len */
191 char padding[LTTNG_UST_COUNTER_GLOBAL_PADDING1];
192 } LTTNG_PACKED;
193
194 #define LTTNG_UST_COUNTER_CPU_PADDING1 (LTTNG_UST_SYM_NAME_LEN + 32)
195 struct lttng_ust_counter_cpu {
196 uint64_t len; /* shm len */
197 uint32_t cpu_nr;
198 char padding[LTTNG_UST_COUNTER_CPU_PADDING1];
199 } LTTNG_PACKED;
200
201 enum lttng_ust_field_type {
202 LTTNG_UST_FIELD_OTHER = 0,
203 LTTNG_UST_FIELD_INTEGER = 1,
204 LTTNG_UST_FIELD_ENUM = 2,
205 LTTNG_UST_FIELD_FLOAT = 3,
206 LTTNG_UST_FIELD_STRING = 4,
207 };
208
209 #define LTTNG_UST_FIELD_ITER_PADDING (LTTNG_UST_SYM_NAME_LEN + 28)
210 struct lttng_ust_field_iter {
211 char event_name[LTTNG_UST_SYM_NAME_LEN];
212 char field_name[LTTNG_UST_SYM_NAME_LEN];
213 enum lttng_ust_field_type type;
214 int loglevel; /* event loglevel */
215 int nowrite;
216 char padding[LTTNG_UST_FIELD_ITER_PADDING];
217 } LTTNG_PACKED;
218
219 enum lttng_ust_context_type {
220 LTTNG_UST_CONTEXT_VTID = 0,
221 LTTNG_UST_CONTEXT_VPID = 1,
222 LTTNG_UST_CONTEXT_PTHREAD_ID = 2,
223 LTTNG_UST_CONTEXT_PROCNAME = 3,
224 LTTNG_UST_CONTEXT_IP = 4,
225 LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER = 5,
226 LTTNG_UST_CONTEXT_CPU_ID = 6,
227 LTTNG_UST_CONTEXT_APP_CONTEXT = 7,
228 LTTNG_UST_CONTEXT_CGROUP_NS = 8,
229 LTTNG_UST_CONTEXT_IPC_NS = 9,
230 LTTNG_UST_CONTEXT_MNT_NS = 10,
231 LTTNG_UST_CONTEXT_NET_NS = 11,
232 LTTNG_UST_CONTEXT_PID_NS = 12,
233 LTTNG_UST_CONTEXT_USER_NS = 13,
234 LTTNG_UST_CONTEXT_UTS_NS = 14,
235 LTTNG_UST_CONTEXT_VUID = 15,
236 LTTNG_UST_CONTEXT_VEUID = 16,
237 LTTNG_UST_CONTEXT_VSUID = 17,
238 LTTNG_UST_CONTEXT_VGID = 18,
239 LTTNG_UST_CONTEXT_VEGID = 19,
240 LTTNG_UST_CONTEXT_VSGID = 20,
241 LTTNG_UST_CONTEXT_TIME_NS = 21,
242 };
243
244 struct lttng_ust_perf_counter_ctx {
245 uint32_t type;
246 uint64_t config;
247 char name[LTTNG_UST_SYM_NAME_LEN];
248 } LTTNG_PACKED;
249
250 #define LTTNG_UST_CONTEXT_PADDING1 16
251 #define LTTNG_UST_CONTEXT_PADDING2 (LTTNG_UST_SYM_NAME_LEN + 32)
252 struct lttng_ust_context {
253 enum lttng_ust_context_type ctx;
254 char padding[LTTNG_UST_CONTEXT_PADDING1];
255
256 union {
257 struct lttng_ust_perf_counter_ctx perf_counter;
258 struct {
259 /* Includes trailing '\0'. */
260 uint32_t provider_name_len;
261 uint32_t ctx_name_len;
262 } app_ctx;
263 char padding[LTTNG_UST_CONTEXT_PADDING2];
264 } u;
265 } LTTNG_PACKED;
266
267 /*
268 * Tracer channel attributes.
269 */
270 #define LTTNG_UST_CHANNEL_ATTR_PADDING (LTTNG_UST_SYM_NAME_LEN + 32)
271 struct lttng_ust_channel_attr {
272 uint64_t subbuf_size; /* bytes */
273 uint64_t num_subbuf; /* power of 2 */
274 int overwrite; /* 1: overwrite, 0: discard */
275 unsigned int switch_timer_interval; /* usec */
276 unsigned int read_timer_interval; /* usec */
277 enum lttng_ust_output output; /* splice, mmap */
278 union {
279 struct {
280 int64_t blocking_timeout; /* Blocking timeout (usec) */
281 } s;
282 char padding[LTTNG_UST_CHANNEL_ATTR_PADDING];
283 } u;
284 } LTTNG_PACKED;
285
286 #define LTTNG_UST_TRACEPOINT_ITER_PADDING 16
287 struct lttng_ust_tracepoint_iter {
288 char name[LTTNG_UST_SYM_NAME_LEN]; /* provider:name */
289 int loglevel;
290 char padding[LTTNG_UST_TRACEPOINT_ITER_PADDING];
291 } LTTNG_PACKED;
292
293 enum lttng_ust_object_type {
294 LTTNG_UST_OBJECT_TYPE_UNKNOWN = -1,
295 LTTNG_UST_OBJECT_TYPE_CHANNEL = 0,
296 LTTNG_UST_OBJECT_TYPE_STREAM = 1,
297 LTTNG_UST_OBJECT_TYPE_EVENT = 2,
298 LTTNG_UST_OBJECT_TYPE_CONTEXT = 3,
299 LTTNG_UST_OBJECT_TYPE_TRIGGER_GROUP = 4,
300 LTTNG_UST_OBJECT_TYPE_TRIGGER = 5,
301 LTTNG_UST_OBJECT_TYPE_COUNTER = 6,
302 LTTNG_UST_OBJECT_TYPE_COUNTER_GLOBAL = 7,
303 LTTNG_UST_OBJECT_TYPE_COUNTER_CPU = 8,
304 };
305
306 #define LTTNG_UST_OBJECT_DATA_PADDING1 32
307 #define LTTNG_UST_OBJECT_DATA_PADDING2 (LTTNG_UST_SYM_NAME_LEN + 32)
308
309 struct lttng_ust_object_data {
310 enum lttng_ust_object_type type;
311 int handle;
312 uint64_t size;
313 char padding1[LTTNG_UST_OBJECT_DATA_PADDING1];
314 union {
315 struct {
316 void *data;
317 enum lttng_ust_chan_type type;
318 int wakeup_fd;
319 } channel;
320 struct {
321 int shm_fd;
322 int wakeup_fd;
323 uint32_t stream_nr;
324 } stream;
325 struct {
326 void *data;
327 } counter;
328 struct {
329 int shm_fd;
330 } counter_global;
331 struct {
332 int shm_fd;
333 uint32_t cpu_nr;
334 } counter_cpu;
335 char padding2[LTTNG_UST_OBJECT_DATA_PADDING2];
336 } u;
337 } LTTNG_PACKED;
338
339 enum lttng_ust_calibrate_type {
340 LTTNG_UST_CALIBRATE_TRACEPOINT,
341 };
342
343 #define LTTNG_UST_CALIBRATE_PADDING1 16
344 #define LTTNG_UST_CALIBRATE_PADDING2 (LTTNG_UST_SYM_NAME_LEN + 32)
345 struct lttng_ust_calibrate {
346 enum lttng_ust_calibrate_type type; /* type (input) */
347 char padding[LTTNG_UST_CALIBRATE_PADDING1];
348
349 union {
350 char padding[LTTNG_UST_CALIBRATE_PADDING2];
351 } u;
352 } LTTNG_PACKED;
353
354 #define FILTER_BYTECODE_MAX_LEN 65536
355 #define LTTNG_UST_FILTER_PADDING 32
356 struct lttng_ust_filter_bytecode {
357 uint32_t len;
358 uint32_t reloc_offset;
359 uint64_t seqnum;
360 char padding[LTTNG_UST_FILTER_PADDING];
361 char data[0];
362 } LTTNG_PACKED;
363
364 #define CAPTURE_BYTECODE_MAX_LEN 65536
365 #define LTTNG_UST_CAPTURE_PADDING 32
366 struct lttng_ust_capture_bytecode {
367 uint32_t len;
368 uint32_t reloc_offset;
369 uint64_t seqnum;
370 char padding[LTTNG_UST_CAPTURE_PADDING];
371 char data[0];
372 } LTTNG_PACKED;
373
374 #define LTTNG_UST_EXCLUSION_PADDING 32
375 struct lttng_ust_event_exclusion {
376 uint32_t count;
377 char padding[LTTNG_UST_EXCLUSION_PADDING];
378 char names[LTTNG_UST_SYM_NAME_LEN][0];
379 } LTTNG_PACKED;
380
381 #define _UST_CMD(minor) (minor)
382 #define _UST_CMDR(minor, type) (minor)
383 #define _UST_CMDW(minor, type) (minor)
384
385 /* Handled by object descriptor */
386 #define LTTNG_UST_RELEASE _UST_CMD(0x1)
387
388 /* Handled by object cmd */
389
390 /* LTTng-UST commands */
391 #define LTTNG_UST_SESSION _UST_CMD(0x40)
392 #define LTTNG_UST_TRACER_VERSION \
393 _UST_CMDR(0x41, struct lttng_ust_tracer_version)
394 #define LTTNG_UST_TRACEPOINT_LIST _UST_CMD(0x42)
395 #define LTTNG_UST_WAIT_QUIESCENT _UST_CMD(0x43)
396 #define LTTNG_UST_REGISTER_DONE _UST_CMD(0x44)
397 #define LTTNG_UST_TRACEPOINT_FIELD_LIST _UST_CMD(0x45)
398
399 /* Session FD commands */
400 #define LTTNG_UST_CHANNEL \
401 _UST_CMDW(0x51, struct lttng_ust_channel)
402 #define LTTNG_UST_SESSION_START _UST_CMD(0x52)
403 #define LTTNG_UST_SESSION_STOP _UST_CMD(0x53)
404 #define LTTNG_UST_SESSION_STATEDUMP _UST_CMD(0x54)
405
406 /* Channel FD commands */
407 #define LTTNG_UST_STREAM _UST_CMD(0x60)
408 #define LTTNG_UST_EVENT \
409 _UST_CMDW(0x61, struct lttng_ust_event)
410
411 /* Event and Channel FD commands */
412 #define LTTNG_UST_CONTEXT \
413 _UST_CMDW(0x70, struct lttng_ust_context)
414 #define LTTNG_UST_FLUSH_BUFFER \
415 _UST_CMD(0x71)
416
417 /* Event, Channel and Session commands */
418 #define LTTNG_UST_ENABLE _UST_CMD(0x80)
419 #define LTTNG_UST_DISABLE _UST_CMD(0x81)
420
421 /* Tracepoint list commands */
422 #define LTTNG_UST_TRACEPOINT_LIST_GET _UST_CMD(0x90)
423 #define LTTNG_UST_TRACEPOINT_FIELD_LIST_GET _UST_CMD(0x91)
424
425 /* Event FD commands */
426 #define LTTNG_UST_FILTER _UST_CMD(0xA0)
427 #define LTTNG_UST_EXCLUSION _UST_CMD(0xA1)
428
429 /* Trigger commands */
430 #define LTTNG_UST_TRIGGER_GROUP_CREATE _UST_CMD(0xB0)
431 #define LTTNG_UST_TRIGGER_CREATE \
432 _UST_CMDW(0xB1, struct lttng_ust_trigger)
433 #define LTTNG_UST_CAPTURE _UST_CMD(0xB2)
434
435 /* Session and Trigger group FD commands */
436 #define LTTNG_UST_COUNTER \
437 _UST_CMDW(0xB3, struct lttng_ust_counter)
438 #define LTTNG_UST_COUNTER_GLOBAL \
439 _UST_CMDW(0xB4, struct lttng_ust_counter_global)
440 #define LTTNG_UST_COUNTER_CPU \
441 _UST_CMDW(0xB5, struct lttng_ust_counter_cpu)
442
443 #define LTTNG_UST_ROOT_HANDLE 0
444
445 struct lttng_ust_obj;
446
447 union ust_args {
448 struct {
449 void *chan_data;
450 int wakeup_fd;
451 } channel;
452 struct {
453 int shm_fd;
454 int wakeup_fd;
455 } stream;
456 struct {
457 struct lttng_ust_field_iter entry;
458 } field_list;
459 struct {
460 char *ctxname;
461 } app_context;
462 struct {
463 int trigger_notif_fd;
464 } trigger_handle;
465 struct {
466 void *counter_data;
467 } counter;
468 struct {
469 int shm_fd;
470 } counter_shm;
471 };
472
473 struct lttng_ust_objd_ops {
474 long (*cmd)(int objd, unsigned int cmd, unsigned long arg,
475 union ust_args *args, void *owner);
476 int (*release)(int objd);
477 };
478
479 /* Create root handle. Always ID 0. */
480 int lttng_abi_create_root_handle(void);
481
482 const struct lttng_ust_objd_ops *objd_ops(int id);
483 int lttng_ust_objd_unref(int id, int is_owner);
484
485 void lttng_ust_abi_exit(void);
486 void lttng_ust_events_exit(void);
487 void lttng_ust_objd_table_owner_cleanup(void *owner);
488
489 #endif /* _LTTNG_UST_ABI_H */
This page took 0.043028 seconds and 5 git commands to generate.