Move forward declarations to private header
[lttng-modules.git] / include / lttng / events.h
CommitLineData
b7cdc182 1/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
9f36eaed 2 *
2df37e95 3 * lttng/events.h
4e3c1b9b 4 *
4e3c1b9b 5 * Holds LTTng per-session event registry.
17baffe2 6 *
886d51a3 7 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4e3c1b9b
MD
8 */
9
9f36eaed
MJ
10#ifndef _LTTNG_EVENTS_H
11#define _LTTNG_EVENTS_H
12
5f4c791e 13#include <lttng/kernel-version.h>
4e3c1b9b 14#include <linux/list.h>
d6d808f3 15#include <linux/kprobes.h>
d83004aa 16#include <linux/kref.h>
41f229dc 17#include <linux/uuid.h>
754d534a 18#include <linux/irq_work.h>
149b9a9d 19#include <wrapper/uprobes.h>
2df37e95
MD
20#include <lttng/cpuhotplug.h>
21#include <lttng/tracer.h>
22#include <lttng/abi.h>
23#include <lttng/abi-old.h>
24#include <lttng/endian.h>
4e3c1b9b 25
e97dc605 26#define lttng_is_signed_type(type) (((type) -1) < (type) 1)
9e7e4892 27
a90917c3 28struct lttng_channel;
8cdc1a81 29struct lttng_kernel_session;
8a57ec02 30struct lttng_kernel_ring_buffer_ctx;
4e3c1b9b 31
c0edae1d
MD
32/* Type description */
33
12bb2edb
MD
34enum lttng_kernel_type {
35 lttng_kernel_type_integer,
36 lttng_kernel_type_string,
437d5aa5
MD
37 lttng_kernel_type_enum,
38 lttng_kernel_type_array,
39 lttng_kernel_type_sequence,
40 lttng_kernel_type_struct,
41 lttng_kernel_type_variant,
12bb2edb 42 NR_LTTNG_KERNEL_TYPES,
c0edae1d
MD
43};
44
28cbcb59
MD
45enum lttng_kernel_string_encoding {
46 lttng_kernel_string_encoding_none = 0,
47 lttng_kernel_string_encoding_UTF8 = 1,
48 lttng_kernel_string_encoding_ASCII = 2,
49 NR_LTTNG_KERNEL_STRING_ENCODING,
c0edae1d
MD
50};
51
d83004aa
JD
52enum channel_type {
53 PER_CPU_CHANNEL,
54 METADATA_CHANNEL,
55};
56
a28cc520 57struct lttng_kernel_enum_value {
141ddf28
MD
58 unsigned long long value;
59 unsigned int signedness:1;
60};
61
a28cc520
MD
62struct lttng_kernel_enum_entry {
63 struct lttng_kernel_enum_value start, end; /* start and end are inclusive */
c0edae1d 64 const char *string;
08ad1061
PP
65 struct {
66 unsigned int is_auto:1;
67 } options;
c0edae1d
MD
68};
69
437d5aa5
MD
70/*
71 * struct lttng_kernel_type_common is fixed-size. Its children inherits
72 * from it by embedding struct lttng_kernel_type_common as its first field.
73 */
74struct lttng_kernel_type_common {
75 enum lttng_kernel_type type;
76};
77
78struct lttng_kernel_type_integer {
79 struct lttng_kernel_type_common parent;
c099397a
MD
80 unsigned int size; /* in bits */
81 unsigned short alignment; /* in bits */
9cccf98a
MD
82 unsigned int signedness:1,
83 reverse_byte_order:1;
e0a7a7c4 84 unsigned int base; /* 2, 8, 10, 16, for pretty print */
437d5aa5
MD
85};
86
87struct lttng_kernel_type_string {
88 struct lttng_kernel_type_common parent;
28cbcb59 89 enum lttng_kernel_string_encoding encoding;
c099397a
MD
90};
91
437d5aa5
MD
92struct lttng_kernel_type_enum {
93 struct lttng_kernel_type_common parent;
94 const struct lttng_kernel_enum_desc *desc; /* Enumeration mapping */
95 const struct lttng_kernel_type_common *container_type;
96};
97
98struct lttng_kernel_type_array {
99 struct lttng_kernel_type_common parent;
100 const struct lttng_kernel_type_common *elem_type;
101 unsigned int length; /* Num. elems. */
102 unsigned int alignment;
103 enum lttng_kernel_string_encoding encoding;
104};
105
106struct lttng_kernel_type_sequence {
107 struct lttng_kernel_type_common parent;
51ef4536 108 const char *length_name; /* Length field name. If NULL, use previous field. */
437d5aa5
MD
109 const struct lttng_kernel_type_common *elem_type;
110 unsigned int alignment; /* Alignment before elements. */
111 enum lttng_kernel_string_encoding encoding;
112};
113
114struct lttng_kernel_type_struct {
115 struct lttng_kernel_type_common parent;
116 unsigned int nr_fields;
117 const struct lttng_kernel_event_field **fields; /* Array of pointers to fields. */
118 unsigned int alignment;
119};
120
121struct lttng_kernel_type_variant {
122 struct lttng_kernel_type_common parent;
51ef4536 123 const char *tag_name; /* Tag field name. If NULL, use previous field. */
437d5aa5
MD
124 const struct lttng_kernel_event_field **choices; /* Array of pointers to fields. */
125 unsigned int nr_choices;
126 unsigned int alignment;
c099397a
MD
127};
128
d96a4a7a 129struct lttng_kernel_enum_desc {
c099397a 130 const char *name;
437d5aa5 131 const struct lttng_kernel_enum_entry **entries;
141ddf28 132 unsigned int nr_entries;
c099397a 133};
c0edae1d
MD
134
135/* Event field description */
136
437d5aa5 137struct lttng_kernel_event_field {
c0edae1d 138 const char *name;
437d5aa5 139 const struct lttng_kernel_type_common *type;
f127e61e 140 unsigned int nowrite:1, /* do not write into trace */
ceabb767
MD
141 user:1, /* fetch from user-space */
142 nofilter:1; /* do not consider for filter */
c0edae1d
MD
143};
144
437d5aa5
MD
145#define lttng_kernel_static_type_integer(_size, _alignment, _signedness, _byte_order, _base) \
146 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_integer, { \
147 .parent = { \
148 .type = lttng_kernel_type_integer, \
149 }, \
150 .size = (_size), \
151 .alignment = (_alignment), \
152 .signedness = (_signedness), \
153 .reverse_byte_order = (_byte_order) != __BYTE_ORDER, \
154 .base = (_base), \
155 }))
156
157#define lttng_kernel_static_type_integer_from_type(_type, _byte_order, _base) \
158 lttng_kernel_static_type_integer(sizeof(_type) * CHAR_BIT, \
159 lttng_alignof(_type) * CHAR_BIT, \
160 lttng_is_signed_type(_type), \
161 _byte_order, \
162 _base)
163
164#define lttng_kernel_static_type_enum(_desc, _container_type) \
165 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_enum, { \
166 .parent = { \
167 .type = lttng_kernel_type_enum, \
168 }, \
169 .desc = (_desc), \
170 .container_type = (_container_type), \
171 }))
172
173#define lttng_kernel_static_type_array(_length, _elem_type, _alignment, _encoding) \
174 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_array, { \
175 .parent = { \
176 .type = lttng_kernel_type_array, \
177 }, \
178 .length = (_length), \
179 .alignment = (_alignment), \
180 .encoding = lttng_kernel_string_encoding_##_encoding, \
181 .elem_type = (_elem_type), \
182 }))
183
184#define lttng_kernel_static_type_array_text(_length) \
185 lttng_kernel_static_type_array(_length, \
186 lttng_kernel_static_type_integer(sizeof(char) * CHAR_BIT, \
187 lttng_alignof(char) * CHAR_BIT, lttng_is_signed_type(char), \
188 __BYTE_ORDER, 10), \
189 0, UTF8)
190
191#define lttng_kernel_static_type_sequence(_length_name, _elem_type, _alignment, _encoding) \
192 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_sequence, { \
193 .parent = { \
194 .type = lttng_kernel_type_sequence, \
195 }, \
196 .length_name = (_length_name), \
197 .alignment = (_alignment), \
198 .encoding = lttng_kernel_string_encoding_##_encoding, \
199 .elem_type = (_elem_type), \
200 }))
201
202#define lttng_kernel_static_type_string(_encoding) \
203 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_string, { \
204 .parent = { \
205 .type = lttng_kernel_type_string, \
206 }, \
207 .encoding = lttng_kernel_string_encoding_##_encoding, \
208 }))
209
210#define lttng_kernel_static_type_struct(_nr_fields, _fields, _alignment) \
211 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_struct, { \
212 .parent = { \
213 .type = lttng_kernel_type_struct, \
214 }, \
215 .nr_fields = (_nr_fields), \
216 .fields = _fields, \
217 .alignment = (_alignment), \
218 }))
219
220#define lttng_kernel_static_type_variant(_nr_choices, _choices, _tag_name, _alignment) \
221 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_variant, { \
222 .parent = { \
223 .type = lttng_kernel_type_variant, \
224 }, \
225 .tag_name = (_tag_name), \
226 .choices = _choices, \
227 .nr_choices = (_nr_choices), \
228 .alignment = (_alignment), \
229 }))
230
231#define lttng_kernel_static_event_field(_name, _type, _nowrite, _user, _nofilter) \
232 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_event_field, { \
233 .name = (_name), \
234 .type = (_type), \
235 .nowrite = (_nowrite), \
236 .user = (_user), \
237 .nofilter = (_nofilter), \
238 })
239
240#define lttng_kernel_static_event_field_array(_fields...) \
241 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_event_field *, \
242 _fields \
243 )
244
437d5aa5
MD
245#define lttng_kernel_static_enum_entry_value(_string, _value) \
246 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_enum_entry, { \
247 .start = { \
248 .signedness = lttng_is_signed_type(__typeof__(_value)), \
249 .value = lttng_is_signed_type(__typeof__(_value)) ? \
250 (long long) (_value) : (_value), \
251 }, \
252 .end = { \
253 .signedness = lttng_is_signed_type(__typeof__(_value)), \
254 .value = lttng_is_signed_type(__typeof__(_value)) ? \
255 (long long) (_value) : (_value), \
256 }, \
257 .string = (_string), \
258 }),
259
260#define lttng_kernel_static_enum_entry_range(_string, _range_start, _range_end) \
261 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_enum_entry, { \
262 .start = { \
263 .signedness = lttng_is_signed_type(__typeof__(_range_start)), \
264 .value = lttng_is_signed_type(__typeof__(_range_start)) ? \
265 (long long) (_range_start) : (_range_start), \
266 }, \
267 .end = { \
268 .signedness = lttng_is_signed_type(__typeof__(_range_end)), \
269 .value = lttng_is_signed_type(__typeof__(_range_end)) ? \
270 (long long) (_range_end) : (_range_end), \
271 }, \
272 .string = (_string), \
273 }),
274
275#define lttng_kernel_static_enum_entry_auto(_string) \
276 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_enum_entry, { \
277 .start = { \
278 .signedness = -1, \
279 .value = -1, \
280 }, \
281 .end = { \
282 .signedness = -1, \
283 .value = -1, \
284 }, \
285 .string = (_string), \
286 .options = { \
287 .is_auto = 1, \
288 } \
289 }),
290
a92e844e 291struct lttng_kernel_probe_ctx {
e2d5dbc7 292 struct lttng_kernel_event_common *event;
79150a49
JD
293 uint8_t interruptible;
294};
295
437d5aa5
MD
296struct lttng_kernel_event_desc {
297 const char *event_name; /* lttng-modules name */
298 const char *event_kname; /* Linux kernel name (tracepoints) */
299 const struct lttng_kernel_probe_desc *probe_desc;
300 void (*probe_callback)(void);
301 const struct lttng_kernel_event_field **fields; /* event payload */
c0edae1d 302 unsigned int nr_fields;
dc7f600a 303 struct module *owner;
c0edae1d
MD
304};
305
437d5aa5
MD
306struct lttng_kernel_probe_desc {
307 const char *provider_name;
308 const struct lttng_kernel_event_desc **event_desc;
85a9ca7f
MD
309 unsigned int nr_events;
310 struct list_head head; /* chain registered probes */
3c997079
MD
311 struct list_head lazy_init_head;
312 int lazy; /* lazy registration */
85a9ca7f
MD
313};
314
8a445457
MD
315/*
316 * Result of the run_filter() callback.
317 */
318enum lttng_kernel_event_filter_result {
319 LTTNG_KERNEL_EVENT_FILTER_ACCEPT = 0,
320 LTTNG_KERNEL_EVENT_FILTER_REJECT = 1,
321};
322
a67ba386
MD
323struct lttng_kernel_event_common_private;
324
325enum lttng_kernel_event_type {
326 LTTNG_KERNEL_EVENT_TYPE_RECORDER = 0,
327 LTTNG_KERNEL_EVENT_TYPE_NOTIFIER = 1,
328};
329
330struct lttng_kernel_event_common {
331 struct lttng_kernel_event_common_private *priv; /* Private event interface */
332
333 enum lttng_kernel_event_type type;
334 /* Get child with container_of(). */
335
e64957da 336 int enabled;
a67ba386 337 int eval_filter; /* Need to evaluate filters */
8a445457 338 int (*run_filter)(const struct lttng_kernel_event_common *event,
a67ba386 339 const char *stack_data,
a92e844e 340 struct lttng_kernel_probe_ctx *probe_ctx,
a67ba386 341 void *filter_ctx);
3c997079
MD
342};
343
a67ba386
MD
344struct lttng_kernel_event_recorder_private;
345
346struct lttng_kernel_event_recorder {
347 struct lttng_kernel_event_common parent;
348 struct lttng_kernel_event_recorder_private *priv; /* Private event record interface */
349
350 struct lttng_channel *chan;
c3eddb2e
MD
351};
352
a67ba386
MD
353struct lttng_kernel_notification_ctx {
354 int eval_capture; /* Capture evaluation available. */
355};
dffef45d 356
a67ba386 357struct lttng_kernel_event_notifier_private;
8a8ac9a8 358
a67ba386
MD
359struct lttng_kernel_event_notifier {
360 struct lttng_kernel_event_common parent;
361 struct lttng_kernel_event_notifier_private *priv; /* Private event notifier interface */
dffef45d 362
a67ba386
MD
363 int eval_capture; /* Need to evaluate capture */
364 void (*notification_send)(struct lttng_kernel_event_notifier *event_notifier,
a67ba386 365 const char *stack_data,
a92e844e 366 struct lttng_kernel_probe_ctx *probe_ctx,
a67ba386 367 struct lttng_kernel_notification_ctx *notif_ctx);
dffef45d
FD
368};
369
4a399b76
MD
370struct lttng_kernel_channel_buffer_ops {
371 struct lttng_kernel_channel_buffer_ops_private *priv; /* Private channel buffer ops interface. */
372
8a57ec02
MD
373 int (*event_reserve)(struct lttng_kernel_ring_buffer_ctx *ctx);
374 void (*event_commit)(struct lttng_kernel_ring_buffer_ctx *ctx);
375 void (*event_write)(struct lttng_kernel_ring_buffer_ctx *ctx, const void *src,
85a9ca7f 376 size_t len);
8a57ec02 377 void (*event_write_from_user)(struct lttng_kernel_ring_buffer_ctx *ctx,
4ea00e4f 378 const void *src, size_t len);
8a57ec02 379 void (*event_memset)(struct lttng_kernel_ring_buffer_ctx *ctx,
58aa5d24 380 int c, size_t len);
8a57ec02 381 void (*event_strcpy)(struct lttng_kernel_ring_buffer_ctx *ctx, const char *src,
16f78f3a 382 size_t len);
8a57ec02 383 void (*event_strcpy_from_user)(struct lttng_kernel_ring_buffer_ctx *ctx,
16f78f3a 384 const char __user *src, size_t len);
85a9ca7f
MD
385};
386
3c997079
MD
387#define LTTNG_EVENT_HT_BITS 12
388#define LTTNG_EVENT_HT_SIZE (1U << LTTNG_EVENT_HT_BITS)
389
390struct lttng_event_ht {
391 struct hlist_head table[LTTNG_EVENT_HT_SIZE];
392};
393
dffef45d
FD
394#define LTTNG_EVENT_NOTIFIER_HT_BITS 12
395#define LTTNG_EVENT_NOTIFIER_HT_SIZE (1U << LTTNG_EVENT_NOTIFIER_HT_BITS)
396
397struct lttng_event_notifier_ht {
398 struct hlist_head table[LTTNG_EVENT_NOTIFIER_HT_SIZE];
399};
400
a90917c3 401struct lttng_channel {
c099397a 402 unsigned int id;
85a9ca7f 403 struct channel *chan; /* Channel buffers */
e64957da 404 int enabled;
437d5aa5 405 struct lttng_kernel_ctx *ctx;
85a9ca7f 406 /* Event ID management */
8cdc1a81 407 struct lttng_kernel_session *session;
85a9ca7f
MD
408 struct file *file; /* File associated to channel */
409 unsigned int free_event_id; /* Next event ID to allocate */
410 struct list_head list; /* Channel list */
4a399b76 411 struct lttng_kernel_channel_buffer_ops *ops;
a90917c3 412 struct lttng_transport *transport;
3b82c4e1
MD
413 struct hlist_head *sc_table; /* for syscall tracing */
414 struct hlist_head *compat_sc_table;
415 struct hlist_head *sc_exit_table; /* for syscall exit tracing */
416 struct hlist_head *compat_sc_exit_table;
417 struct hlist_head sc_unknown; /* for unknown syscalls */
418 struct hlist_head sc_compat_unknown;
419 struct hlist_head sc_exit_unknown;
420 struct hlist_head compat_sc_exit_unknown;
80f87dd2 421 struct lttng_syscall_filter *sc_filter;
9115fbdc 422 int header_type; /* 0: unset, 1: compact, 2: large */
d83004aa 423 enum channel_type channel_type;
3b82c4e1
MD
424 int syscall_all_entry;
425 int syscall_all_exit;
80f87dd2
MD
426 unsigned int metadata_dumped:1,
427 sys_enter_registered:1,
428 sys_exit_registered:1,
3c997079 429 tstate:1; /* Transient enable state */
85a9ca7f
MD
430};
431
114667d5
MD
432#define LTTNG_DYNAMIC_LEN_STACK_SIZE 128
433
434struct lttng_dynamic_len_stack {
435 size_t stack[LTTNG_DYNAMIC_LEN_STACK_SIZE];
436 size_t offset;
437};
438
439DECLARE_PER_CPU(struct lttng_dynamic_len_stack, lttng_dynamic_len_stack);
e0130fab
MD
440
441/*
8c0393c3 442 * struct lttng_kernel_id_tracker declared in header due to deferencing of *v
e0130fab
MD
443 * in RCU_INITIALIZER(v).
444 */
d1f652f8
MD
445#define LTTNG_ID_HASH_BITS 6
446#define LTTNG_ID_TABLE_SIZE (1 << LTTNG_ID_HASH_BITS)
e0130fab 447
8c0393c3 448struct lttng_kernel_id_tracker_rcu {
d1f652f8
MD
449 struct hlist_head id_hash[LTTNG_ID_TABLE_SIZE];
450};
451
8c0393c3
MD
452struct lttng_kernel_id_tracker {
453 struct lttng_kernel_id_tracker_private *priv; /* Private API */
454
455 struct lttng_kernel_id_tracker_rcu *p; /* RCU dereferenced. */
e0130fab
MD
456};
457
8cdc1a81
MD
458struct lttng_kernel_session_private;
459
460struct lttng_kernel_session {
461 struct lttng_kernel_session_private *priv; /* Private session interface */
462
85a9ca7f 463 int active; /* Is trace session active ? */
8cdc1a81 464
8c0393c3
MD
465 struct lttng_kernel_id_tracker pid_tracker;
466 struct lttng_kernel_id_tracker vpid_tracker;
467 struct lttng_kernel_id_tracker uid_tracker;
468 struct lttng_kernel_id_tracker vuid_tracker;
469 struct lttng_kernel_id_tracker gid_tracker;
470 struct lttng_kernel_id_tracker vgid_tracker;
85a9ca7f
MD
471};
472
d1769981
MD
473int lttng_kernel_probe_register(struct lttng_kernel_probe_desc *desc);
474void lttng_kernel_probe_unregister(struct lttng_kernel_probe_desc *desc);
d83004aa 475
8c0393c3 476bool lttng_id_tracker_lookup(struct lttng_kernel_id_tracker_rcu *p, int id);
271b6681 477
a90917c3 478#endif /* _LTTNG_EVENTS_H */
This page took 0.083726 seconds and 4 git commands to generate.