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