66c76d9819c42106ae456718627cfe7f0de3e17d
[lttng-modules.git] / include / lttng / events.h
1 /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
2 *
3 * lttng/events.h
4 *
5 * Holds LTTng per-session event registry.
6 *
7 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 */
9
10 #ifndef _LTTNG_EVENTS_H
11 #define _LTTNG_EVENTS_H
12
13 #include <lttng/kernel-version.h>
14 #include <linux/list.h>
15 #include <linux/kprobes.h>
16 #include <linux/kref.h>
17 #include <linux/uuid.h>
18 #include <linux/irq_work.h>
19 #include <wrapper/uprobes.h>
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>
25
26 #define lttng_is_signed_type(type) (((type) -1) < (type) 1)
27
28 struct lttng_channel;
29 struct lttng_session;
30 struct lttng_metadata_cache;
31 struct lib_ring_buffer_ctx;
32 struct perf_event;
33 struct perf_event_attr;
34 struct lib_ring_buffer_config;
35
36 /* Type description */
37
38 enum lttng_kernel_type {
39 lttng_kernel_type_integer,
40 lttng_kernel_type_string,
41 lttng_kernel_type_enum,
42 lttng_kernel_type_array,
43 lttng_kernel_type_sequence,
44 lttng_kernel_type_struct,
45 lttng_kernel_type_variant,
46 NR_LTTNG_KERNEL_TYPES,
47 };
48
49 enum lttng_kernel_string_encoding {
50 lttng_kernel_string_encoding_none = 0,
51 lttng_kernel_string_encoding_UTF8 = 1,
52 lttng_kernel_string_encoding_ASCII = 2,
53 NR_LTTNG_KERNEL_STRING_ENCODING,
54 };
55
56 enum channel_type {
57 PER_CPU_CHANNEL,
58 METADATA_CHANNEL,
59 };
60
61 struct lttng_kernel_enum_value {
62 unsigned long long value;
63 unsigned int signedness:1;
64 };
65
66 struct lttng_kernel_enum_entry {
67 struct lttng_kernel_enum_value start, end; /* start and end are inclusive */
68 const char *string;
69 struct {
70 unsigned int is_auto:1;
71 } options;
72 };
73
74 /*
75 * struct lttng_kernel_type_common is fixed-size. Its children inherits
76 * from it by embedding struct lttng_kernel_type_common as its first field.
77 */
78 struct lttng_kernel_type_common {
79 enum lttng_kernel_type type;
80 };
81
82 struct lttng_kernel_type_integer {
83 struct lttng_kernel_type_common parent;
84 unsigned int size; /* in bits */
85 unsigned short alignment; /* in bits */
86 unsigned int signedness:1,
87 reverse_byte_order:1;
88 unsigned int base; /* 2, 8, 10, 16, for pretty print */
89 };
90
91 struct lttng_kernel_type_string {
92 struct lttng_kernel_type_common parent;
93 enum lttng_kernel_string_encoding encoding;
94 };
95
96 struct lttng_kernel_type_enum {
97 struct lttng_kernel_type_common parent;
98 const struct lttng_kernel_enum_desc *desc; /* Enumeration mapping */
99 const struct lttng_kernel_type_common *container_type;
100 };
101
102 struct lttng_kernel_type_array {
103 struct lttng_kernel_type_common parent;
104 const struct lttng_kernel_type_common *elem_type;
105 unsigned int length; /* Num. elems. */
106 unsigned int alignment;
107 enum lttng_kernel_string_encoding encoding;
108 };
109
110 struct lttng_kernel_type_sequence {
111 struct lttng_kernel_type_common parent;
112 const char *length_name; /* Length field name. If NULL, use previous field. */
113 const struct lttng_kernel_type_common *elem_type;
114 unsigned int alignment; /* Alignment before elements. */
115 enum lttng_kernel_string_encoding encoding;
116 };
117
118 struct lttng_kernel_type_struct {
119 struct lttng_kernel_type_common parent;
120 unsigned int nr_fields;
121 const struct lttng_kernel_event_field **fields; /* Array of pointers to fields. */
122 unsigned int alignment;
123 };
124
125 struct lttng_kernel_type_variant {
126 struct lttng_kernel_type_common parent;
127 const char *tag_name; /* Tag field name. If NULL, use previous field. */
128 const struct lttng_kernel_event_field **choices; /* Array of pointers to fields. */
129 unsigned int nr_choices;
130 unsigned int alignment;
131 };
132
133 struct lttng_kernel_enum_desc {
134 const char *name;
135 const struct lttng_kernel_enum_entry **entries;
136 unsigned int nr_entries;
137 };
138
139 /* Event field description */
140
141 struct lttng_kernel_event_field {
142 const char *name;
143 const struct lttng_kernel_type_common *type;
144 unsigned int nowrite:1, /* do not write into trace */
145 user:1, /* fetch from user-space */
146 nofilter:1; /* do not consider for filter */
147 };
148
149 #define lttng_kernel_static_type_integer(_size, _alignment, _signedness, _byte_order, _base) \
150 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_integer, { \
151 .parent = { \
152 .type = lttng_kernel_type_integer, \
153 }, \
154 .size = (_size), \
155 .alignment = (_alignment), \
156 .signedness = (_signedness), \
157 .reverse_byte_order = (_byte_order) != __BYTE_ORDER, \
158 .base = (_base), \
159 }))
160
161 #define lttng_kernel_static_type_integer_from_type(_type, _byte_order, _base) \
162 lttng_kernel_static_type_integer(sizeof(_type) * CHAR_BIT, \
163 lttng_alignof(_type) * CHAR_BIT, \
164 lttng_is_signed_type(_type), \
165 _byte_order, \
166 _base)
167
168 #define lttng_kernel_static_type_enum(_desc, _container_type) \
169 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_enum, { \
170 .parent = { \
171 .type = lttng_kernel_type_enum, \
172 }, \
173 .desc = (_desc), \
174 .container_type = (_container_type), \
175 }))
176
177 #define lttng_kernel_static_type_array(_length, _elem_type, _alignment, _encoding) \
178 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_array, { \
179 .parent = { \
180 .type = lttng_kernel_type_array, \
181 }, \
182 .length = (_length), \
183 .alignment = (_alignment), \
184 .encoding = lttng_kernel_string_encoding_##_encoding, \
185 .elem_type = (_elem_type), \
186 }))
187
188 #define lttng_kernel_static_type_array_text(_length) \
189 lttng_kernel_static_type_array(_length, \
190 lttng_kernel_static_type_integer(sizeof(char) * CHAR_BIT, \
191 lttng_alignof(char) * CHAR_BIT, lttng_is_signed_type(char), \
192 __BYTE_ORDER, 10), \
193 0, UTF8)
194
195 #define lttng_kernel_static_type_sequence(_length_name, _elem_type, _alignment, _encoding) \
196 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_sequence, { \
197 .parent = { \
198 .type = lttng_kernel_type_sequence, \
199 }, \
200 .length_name = (_length_name), \
201 .alignment = (_alignment), \
202 .encoding = lttng_kernel_string_encoding_##_encoding, \
203 .elem_type = (_elem_type), \
204 }))
205
206 #define lttng_kernel_static_type_string(_encoding) \
207 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_string, { \
208 .parent = { \
209 .type = lttng_kernel_type_string, \
210 }, \
211 .encoding = lttng_kernel_string_encoding_##_encoding, \
212 }))
213
214 #define lttng_kernel_static_type_struct(_nr_fields, _fields, _alignment) \
215 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_struct, { \
216 .parent = { \
217 .type = lttng_kernel_type_struct, \
218 }, \
219 .nr_fields = (_nr_fields), \
220 .fields = _fields, \
221 .alignment = (_alignment), \
222 }))
223
224 #define lttng_kernel_static_type_variant(_nr_choices, _choices, _tag_name, _alignment) \
225 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_variant, { \
226 .parent = { \
227 .type = lttng_kernel_type_variant, \
228 }, \
229 .tag_name = (_tag_name), \
230 .choices = _choices, \
231 .nr_choices = (_nr_choices), \
232 .alignment = (_alignment), \
233 }))
234
235 #define lttng_kernel_static_event_field(_name, _type, _nowrite, _user, _nofilter) \
236 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_event_field, { \
237 .name = (_name), \
238 .type = (_type), \
239 .nowrite = (_nowrite), \
240 .user = (_user), \
241 .nofilter = (_nofilter), \
242 })
243
244 #define lttng_kernel_static_event_field_array(_fields...) \
245 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_event_field *, \
246 _fields \
247 )
248
249 #define lttng_kernel_static_enum_entry_value(_string, _value) \
250 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_enum_entry, { \
251 .start = { \
252 .signedness = lttng_is_signed_type(__typeof__(_value)), \
253 .value = lttng_is_signed_type(__typeof__(_value)) ? \
254 (long long) (_value) : (_value), \
255 }, \
256 .end = { \
257 .signedness = lttng_is_signed_type(__typeof__(_value)), \
258 .value = lttng_is_signed_type(__typeof__(_value)) ? \
259 (long long) (_value) : (_value), \
260 }, \
261 .string = (_string), \
262 }),
263
264 #define lttng_kernel_static_enum_entry_range(_string, _range_start, _range_end) \
265 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_enum_entry, { \
266 .start = { \
267 .signedness = lttng_is_signed_type(__typeof__(_range_start)), \
268 .value = lttng_is_signed_type(__typeof__(_range_start)) ? \
269 (long long) (_range_start) : (_range_start), \
270 }, \
271 .end = { \
272 .signedness = lttng_is_signed_type(__typeof__(_range_end)), \
273 .value = lttng_is_signed_type(__typeof__(_range_end)) ? \
274 (long long) (_range_end) : (_range_end), \
275 }, \
276 .string = (_string), \
277 }),
278
279 #define lttng_kernel_static_enum_entry_auto(_string) \
280 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_enum_entry, { \
281 .start = { \
282 .signedness = -1, \
283 .value = -1, \
284 }, \
285 .end = { \
286 .signedness = -1, \
287 .value = -1, \
288 }, \
289 .string = (_string), \
290 .options = { \
291 .is_auto = 1, \
292 } \
293 }),
294
295 struct lttng_kernel_probe_ctx {
296 struct lttng_kernel_event_common *event;
297 uint8_t interruptible;
298 };
299
300 struct lttng_kernel_event_desc {
301 const char *event_name; /* lttng-modules name */
302 const char *event_kname; /* Linux kernel name (tracepoints) */
303 const struct lttng_kernel_probe_desc *probe_desc;
304 void (*probe_callback)(void);
305 const struct lttng_kernel_event_field **fields; /* event payload */
306 unsigned int nr_fields;
307 struct module *owner;
308 };
309
310 struct lttng_kernel_probe_desc {
311 const char *provider_name;
312 const struct lttng_kernel_event_desc **event_desc;
313 unsigned int nr_events;
314 struct list_head head; /* chain registered probes */
315 struct list_head lazy_init_head;
316 int lazy; /* lazy registration */
317 };
318
319 struct lttng_krp; /* Kretprobe handling */
320
321 struct lttng_uprobe_handler {
322 struct lttng_kernel_event_common *event;
323 loff_t offset;
324 struct uprobe_consumer up_consumer;
325 struct list_head node;
326 };
327
328 struct lttng_kprobe {
329 struct kprobe kp;
330 char *symbol_name;
331 };
332
333 struct lttng_uprobe {
334 struct inode *inode;
335 struct list_head head;
336 };
337
338 enum lttng_syscall_entryexit {
339 LTTNG_SYSCALL_ENTRY,
340 LTTNG_SYSCALL_EXIT,
341 };
342
343 enum lttng_syscall_abi {
344 LTTNG_SYSCALL_ABI_NATIVE,
345 LTTNG_SYSCALL_ABI_COMPAT,
346 };
347
348 /*
349 * Result of the run_filter() callback.
350 */
351 enum lttng_kernel_event_filter_result {
352 LTTNG_KERNEL_EVENT_FILTER_ACCEPT = 0,
353 LTTNG_KERNEL_EVENT_FILTER_REJECT = 1,
354 };
355
356 struct lttng_kernel_event_common_private;
357
358 enum lttng_kernel_event_type {
359 LTTNG_KERNEL_EVENT_TYPE_RECORDER = 0,
360 LTTNG_KERNEL_EVENT_TYPE_NOTIFIER = 1,
361 };
362
363 struct lttng_kernel_event_common {
364 struct lttng_kernel_event_common_private *priv; /* Private event interface */
365
366 enum lttng_kernel_event_type type;
367 /* Get child with container_of(). */
368
369 int enabled;
370 int eval_filter; /* Need to evaluate filters */
371 int (*run_filter)(const struct lttng_kernel_event_common *event,
372 const char *stack_data,
373 struct lttng_kernel_probe_ctx *probe_ctx,
374 void *filter_ctx);
375 };
376
377 struct lttng_kernel_event_recorder_private;
378
379 struct lttng_kernel_event_recorder {
380 struct lttng_kernel_event_common parent;
381 struct lttng_kernel_event_recorder_private *priv; /* Private event record interface */
382
383 struct lttng_channel *chan;
384 };
385
386 struct lttng_kernel_notification_ctx {
387 int eval_capture; /* Capture evaluation available. */
388 };
389
390 struct lttng_kernel_event_notifier_private;
391
392 struct lttng_kernel_event_notifier {
393 struct lttng_kernel_event_common parent;
394 struct lttng_kernel_event_notifier_private *priv; /* Private event notifier interface */
395
396 int eval_capture; /* Need to evaluate capture */
397 void (*notification_send)(struct lttng_kernel_event_notifier *event_notifier,
398 const char *stack_data,
399 struct lttng_kernel_probe_ctx *probe_ctx,
400 struct lttng_kernel_notification_ctx *notif_ctx);
401 };
402
403 struct lttng_channel_ops {
404 struct channel *(*channel_create)(const char *name,
405 void *priv,
406 void *buf_addr,
407 size_t subbuf_size, size_t num_subbuf,
408 unsigned int switch_timer_interval,
409 unsigned int read_timer_interval);
410 void (*channel_destroy)(struct channel *chan);
411 struct lib_ring_buffer *(*buffer_read_open)(struct channel *chan);
412 int (*buffer_has_read_closed_stream)(struct channel *chan);
413 void (*buffer_read_close)(struct lib_ring_buffer *buf);
414 int (*event_reserve)(struct lib_ring_buffer_ctx *ctx);
415 void (*event_commit)(struct lib_ring_buffer_ctx *ctx);
416 void (*event_write)(struct lib_ring_buffer_ctx *ctx, const void *src,
417 size_t len);
418 void (*event_write_from_user)(struct lib_ring_buffer_ctx *ctx,
419 const void *src, size_t len);
420 void (*event_memset)(struct lib_ring_buffer_ctx *ctx,
421 int c, size_t len);
422 void (*event_strcpy)(struct lib_ring_buffer_ctx *ctx, const char *src,
423 size_t len);
424 void (*event_strcpy_from_user)(struct lib_ring_buffer_ctx *ctx,
425 const char __user *src, size_t len);
426 /*
427 * packet_avail_size returns the available size in the current
428 * packet. Note that the size returned is only a hint, since it
429 * may change due to concurrent writes.
430 */
431 size_t (*packet_avail_size)(struct channel *chan);
432 wait_queue_head_t *(*get_writer_buf_wait_queue)(struct channel *chan, int cpu);
433 wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan);
434 int (*is_finalized)(struct channel *chan);
435 int (*is_disabled)(struct channel *chan);
436 int (*timestamp_begin) (const struct lib_ring_buffer_config *config,
437 struct lib_ring_buffer *bufb,
438 uint64_t *timestamp_begin);
439 int (*timestamp_end) (const struct lib_ring_buffer_config *config,
440 struct lib_ring_buffer *bufb,
441 uint64_t *timestamp_end);
442 int (*events_discarded) (const struct lib_ring_buffer_config *config,
443 struct lib_ring_buffer *bufb,
444 uint64_t *events_discarded);
445 int (*content_size) (const struct lib_ring_buffer_config *config,
446 struct lib_ring_buffer *bufb,
447 uint64_t *content_size);
448 int (*packet_size) (const struct lib_ring_buffer_config *config,
449 struct lib_ring_buffer *bufb,
450 uint64_t *packet_size);
451 int (*stream_id) (const struct lib_ring_buffer_config *config,
452 struct lib_ring_buffer *bufb,
453 uint64_t *stream_id);
454 int (*current_timestamp) (const struct lib_ring_buffer_config *config,
455 struct lib_ring_buffer *bufb,
456 uint64_t *ts);
457 int (*sequence_number) (const struct lib_ring_buffer_config *config,
458 struct lib_ring_buffer *bufb,
459 uint64_t *seq);
460 int (*instance_id) (const struct lib_ring_buffer_config *config,
461 struct lib_ring_buffer *bufb,
462 uint64_t *id);
463 };
464
465 struct lttng_counter_ops {
466 struct lib_counter *(*counter_create)(size_t nr_dimensions,
467 const size_t *max_nr_elem, /* for each dimension */
468 int64_t global_sum_step);
469 void (*counter_destroy)(struct lib_counter *counter);
470 int (*counter_add)(struct lib_counter *counter, const size_t *dimension_indexes,
471 int64_t v);
472 /*
473 * counter_read reads a specific cpu's counter if @cpu >= 0, or
474 * the global aggregation counter if @cpu == -1.
475 */
476 int (*counter_read)(struct lib_counter *counter, const size_t *dimension_indexes, int cpu,
477 int64_t *value, bool *overflow, bool *underflow);
478 /*
479 * counter_aggregate returns the total sum of all per-cpu counters and
480 * the global aggregation counter.
481 */
482 int (*counter_aggregate)(struct lib_counter *counter, const size_t *dimension_indexes,
483 int64_t *value, bool *overflow, bool *underflow);
484 int (*counter_clear)(struct lib_counter *counter, const size_t *dimension_indexes);
485 };
486
487 struct lttng_transport {
488 char *name;
489 struct module *owner;
490 struct list_head node;
491 struct lttng_channel_ops ops;
492 };
493
494 struct lttng_counter_transport {
495 char *name;
496 struct module *owner;
497 struct list_head node;
498 struct lttng_counter_ops ops;
499 };
500
501 struct lttng_syscall_filter;
502
503 #define LTTNG_EVENT_HT_BITS 12
504 #define LTTNG_EVENT_HT_SIZE (1U << LTTNG_EVENT_HT_BITS)
505
506 struct lttng_event_ht {
507 struct hlist_head table[LTTNG_EVENT_HT_SIZE];
508 };
509
510 #define LTTNG_EVENT_NOTIFIER_HT_BITS 12
511 #define LTTNG_EVENT_NOTIFIER_HT_SIZE (1U << LTTNG_EVENT_NOTIFIER_HT_BITS)
512
513 struct lttng_event_notifier_ht {
514 struct hlist_head table[LTTNG_EVENT_NOTIFIER_HT_SIZE];
515 };
516
517 struct lttng_channel {
518 unsigned int id;
519 struct channel *chan; /* Channel buffers */
520 int enabled;
521 struct lttng_kernel_ctx *ctx;
522 /* Event ID management */
523 struct lttng_session *session;
524 struct file *file; /* File associated to channel */
525 unsigned int free_event_id; /* Next event ID to allocate */
526 struct list_head list; /* Channel list */
527 struct lttng_channel_ops *ops;
528 struct lttng_transport *transport;
529 struct hlist_head *sc_table; /* for syscall tracing */
530 struct hlist_head *compat_sc_table;
531 struct hlist_head *sc_exit_table; /* for syscall exit tracing */
532 struct hlist_head *compat_sc_exit_table;
533 struct hlist_head sc_unknown; /* for unknown syscalls */
534 struct hlist_head sc_compat_unknown;
535 struct hlist_head sc_exit_unknown;
536 struct hlist_head compat_sc_exit_unknown;
537 struct lttng_syscall_filter *sc_filter;
538 int header_type; /* 0: unset, 1: compact, 2: large */
539 enum channel_type channel_type;
540 int syscall_all_entry;
541 int syscall_all_exit;
542 unsigned int metadata_dumped:1,
543 sys_enter_registered:1,
544 sys_exit_registered:1,
545 tstate:1; /* Transient enable state */
546 };
547
548 struct lttng_metadata_stream {
549 void *priv; /* Ring buffer private data */
550 struct lttng_metadata_cache *metadata_cache;
551 unsigned int metadata_in; /* Bytes read from the cache */
552 unsigned int metadata_out; /* Bytes consumed from stream */
553 int finalized; /* Has channel been finalized */
554 wait_queue_head_t read_wait; /* Reader buffer-level wait queue */
555 struct list_head list; /* Stream list */
556 struct lttng_transport *transport;
557 uint64_t version; /* Current version of the metadata cache */
558 bool coherent; /* Stream in a coherent state */
559 };
560
561 #define LTTNG_DYNAMIC_LEN_STACK_SIZE 128
562
563 struct lttng_dynamic_len_stack {
564 size_t stack[LTTNG_DYNAMIC_LEN_STACK_SIZE];
565 size_t offset;
566 };
567
568 DECLARE_PER_CPU(struct lttng_dynamic_len_stack, lttng_dynamic_len_stack);
569
570 /*
571 * struct lttng_id_tracker declared in header due to deferencing of *v
572 * in RCU_INITIALIZER(v).
573 */
574 #define LTTNG_ID_HASH_BITS 6
575 #define LTTNG_ID_TABLE_SIZE (1 << LTTNG_ID_HASH_BITS)
576
577 enum tracker_type {
578 TRACKER_PID,
579 TRACKER_VPID,
580 TRACKER_UID,
581 TRACKER_VUID,
582 TRACKER_GID,
583 TRACKER_VGID,
584
585 TRACKER_UNKNOWN,
586 };
587
588 struct lttng_id_tracker_rcu {
589 struct hlist_head id_hash[LTTNG_ID_TABLE_SIZE];
590 };
591
592 struct lttng_id_tracker {
593 struct lttng_session *session;
594 enum tracker_type tracker_type;
595 struct lttng_id_tracker_rcu *p; /* RCU dereferenced. */
596 };
597
598 struct lttng_id_hash_node {
599 struct hlist_node hlist;
600 int id;
601 };
602
603 struct lttng_session {
604 int active; /* Is trace session active ? */
605 int been_active; /* Has trace session been active ? */
606 struct file *file; /* File associated to session */
607 struct list_head chan; /* Channel list head */
608 struct list_head events; /* Event list head */
609 struct list_head list; /* Session list */
610 unsigned int free_chan_id; /* Next chan ID to allocate */
611 uuid_le uuid; /* Trace session unique ID */
612 struct lttng_metadata_cache *metadata_cache;
613 struct lttng_id_tracker pid_tracker;
614 struct lttng_id_tracker vpid_tracker;
615 struct lttng_id_tracker uid_tracker;
616 struct lttng_id_tracker vuid_tracker;
617 struct lttng_id_tracker gid_tracker;
618 struct lttng_id_tracker vgid_tracker;
619 unsigned int metadata_dumped:1,
620 tstate:1; /* Transient enable state */
621 /* List of event enablers */
622 struct list_head enablers_head;
623 /* Hash table of events */
624 struct lttng_event_ht events_ht;
625 char name[LTTNG_KERNEL_ABI_SESSION_NAME_LEN];
626 char creation_time[LTTNG_KERNEL_ABI_SESSION_CREATION_TIME_ISO8601_LEN];
627 };
628
629 struct lttng_counter {
630 struct file *file; /* File associated to counter. */
631 struct file *owner;
632 struct lttng_counter_transport *transport;
633 struct lib_counter *counter;
634 struct lttng_counter_ops *ops;
635 };
636
637 struct lttng_event_notifier_group {
638 struct file *file; /* File associated to event notifier group */
639 struct file *notif_file; /* File used to expose notifications to userspace. */
640 struct list_head node; /* event notifier group list */
641 struct list_head enablers_head; /* List of enablers */
642 struct list_head event_notifiers_head; /* List of event notifier */
643 struct lttng_event_notifier_ht event_notifiers_ht; /* Hash table of event notifiers */
644 struct lttng_channel_ops *ops;
645 struct lttng_transport *transport;
646 struct channel *chan; /* Ring buffer channel for event notifier group. */
647 struct lib_ring_buffer *buf; /* Ring buffer for event notifier group. */
648 wait_queue_head_t read_wait;
649 struct irq_work wakeup_pending; /* Pending wakeup irq work. */
650 struct lttng_kernel_event_notifier *sc_unknown; /* for unknown syscalls */
651 struct lttng_kernel_event_notifier *sc_compat_unknown;
652
653 struct lttng_syscall_filter *sc_filter;
654
655 struct hlist_head *event_notifier_syscall_dispatch;
656 struct hlist_head *event_notifier_compat_syscall_dispatch;
657 struct hlist_head *event_notifier_exit_syscall_dispatch;
658 struct hlist_head *event_notifier_exit_compat_syscall_dispatch;
659
660 struct hlist_head event_notifier_unknown_syscall_dispatch;
661 struct hlist_head event_notifier_compat_unknown_syscall_dispatch;
662 struct hlist_head event_notifier_exit_unknown_syscall_dispatch;
663 struct hlist_head event_notifier_exit_compat_unknown_syscall_dispatch;
664
665 int syscall_all_entry;
666 int syscall_all_exit;
667
668 unsigned int sys_enter_registered:1, sys_exit_registered:1;
669
670 struct lttng_counter *error_counter;
671 size_t error_counter_len;
672 };
673
674 struct lttng_metadata_cache {
675 char *data; /* Metadata cache */
676 unsigned int cache_alloc; /* Metadata allocated size (bytes) */
677 unsigned int metadata_written; /* Number of bytes written in metadata cache */
678 atomic_t producing; /* Metadata being produced (incomplete) */
679 struct kref refcount; /* Metadata cache usage */
680 struct list_head metadata_stream; /* Metadata stream list */
681 uuid_le uuid; /* Trace session unique ID (copy) */
682 struct mutex lock; /* Produce/consume lock */
683 uint64_t version; /* Current version of the metadata */
684 };
685
686 void lttng_lock_sessions(void);
687 void lttng_unlock_sessions(void);
688
689 struct list_head *lttng_get_probe_list_head(void);
690
691 int lttng_fix_pending_events(void);
692 int lttng_fix_pending_event_notifiers(void);
693 int lttng_session_active(void);
694 bool lttng_event_notifier_active(void);
695
696 struct lttng_session *lttng_session_create(void);
697 int lttng_session_enable(struct lttng_session *session);
698 int lttng_session_disable(struct lttng_session *session);
699 void lttng_session_destroy(struct lttng_session *session);
700 int lttng_session_metadata_regenerate(struct lttng_session *session);
701 int lttng_session_statedump(struct lttng_session *session);
702 void metadata_cache_destroy(struct kref *kref);
703
704 struct lttng_counter *lttng_kernel_counter_create(
705 const char *counter_transport_name, size_t number_dimensions,
706 const size_t *dimensions_sizes);
707 int lttng_kernel_counter_read(struct lttng_counter *counter,
708 const size_t *dimension_indexes, int32_t cpu,
709 int64_t *val, bool *overflow, bool *underflow);
710 int lttng_kernel_counter_aggregate(struct lttng_counter *counter,
711 const size_t *dimension_indexes, int64_t *val,
712 bool *overflow, bool *underflow);
713 int lttng_kernel_counter_clear(struct lttng_counter *counter,
714 const size_t *dimension_indexes);
715
716
717 struct lttng_event_notifier_group *lttng_event_notifier_group_create(void);
718 int lttng_event_notifier_group_create_error_counter(
719 struct file *event_notifier_group_file,
720 const struct lttng_kernel_abi_counter_conf *error_counter_conf);
721 void lttng_event_notifier_group_destroy(
722 struct lttng_event_notifier_group *event_notifier_group);
723
724 struct lttng_channel *lttng_channel_create(struct lttng_session *session,
725 const char *transport_name,
726 void *buf_addr,
727 size_t subbuf_size, size_t num_subbuf,
728 unsigned int switch_timer_interval,
729 unsigned int read_timer_interval,
730 enum channel_type channel_type);
731 struct lttng_channel *lttng_global_channel_create(struct lttng_session *session,
732 int overwrite, void *buf_addr,
733 size_t subbuf_size, size_t num_subbuf,
734 unsigned int switch_timer_interval,
735 unsigned int read_timer_interval);
736
737 void lttng_metadata_channel_destroy(struct lttng_channel *chan);
738 struct lttng_kernel_event_recorder *lttng_kernel_event_recorder_create(struct lttng_channel *chan,
739 struct lttng_kernel_abi_event *event_param,
740 const struct lttng_kernel_event_desc *event_desc,
741 enum lttng_kernel_abi_instrumentation itype);
742 struct lttng_kernel_event_recorder *_lttng_kernel_event_recorder_create(struct lttng_channel *chan,
743 struct lttng_kernel_abi_event *event_param,
744 const struct lttng_kernel_event_desc *event_desc,
745 enum lttng_kernel_abi_instrumentation itype);
746 struct lttng_kernel_event_recorder *lttng_event_compat_old_create(struct lttng_channel *chan,
747 struct lttng_kernel_abi_old_event *old_event_param,
748 const struct lttng_kernel_event_desc *internal_desc);
749
750 struct lttng_kernel_event_notifier *lttng_event_notifier_create(
751 const struct lttng_kernel_event_desc *event_notifier_desc,
752 uint64_t id,
753 uint64_t error_counter_idx,
754 struct lttng_event_notifier_group *event_notifier_group,
755 struct lttng_kernel_abi_event_notifier *event_notifier_param,
756 enum lttng_kernel_abi_instrumentation itype);
757 struct lttng_kernel_event_notifier *_lttng_event_notifier_create(
758 const struct lttng_kernel_event_desc *event_notifier_desc,
759 uint64_t id,
760 uint64_t error_counter_idx,
761 struct lttng_event_notifier_group *event_notifier_group,
762 struct lttng_kernel_abi_event_notifier *event_notifier_param,
763 enum lttng_kernel_abi_instrumentation itype);
764
765 int lttng_channel_enable(struct lttng_channel *channel);
766 int lttng_channel_disable(struct lttng_channel *channel);
767 int lttng_event_enable(struct lttng_kernel_event_common *event);
768 int lttng_event_disable(struct lttng_kernel_event_common *event);
769
770 void lttng_transport_register(struct lttng_transport *transport);
771 void lttng_transport_unregister(struct lttng_transport *transport);
772
773 void lttng_counter_transport_register(struct lttng_counter_transport *transport);
774 void lttng_counter_transport_unregister(struct lttng_counter_transport *transport);
775
776 void synchronize_trace(void);
777 int lttng_abi_init(void);
778 int lttng_abi_compat_old_init(void);
779 void lttng_abi_exit(void);
780 void lttng_abi_compat_old_exit(void);
781
782 int lttng_probe_register(struct lttng_kernel_probe_desc *desc);
783 void lttng_probe_unregister(struct lttng_kernel_probe_desc *desc);
784 const struct lttng_kernel_event_desc *lttng_event_desc_get(const char *name);
785 void lttng_event_desc_put(const struct lttng_kernel_event_desc *desc);
786 int lttng_probes_init(void);
787 void lttng_probes_exit(void);
788
789 int lttng_metadata_output_channel(struct lttng_metadata_stream *stream,
790 struct channel *chan, bool *coherent);
791
792 int lttng_id_tracker_get_node_id(const struct lttng_id_hash_node *node);
793 int lttng_id_tracker_empty_set(struct lttng_id_tracker *lf);
794 void lttng_id_tracker_destroy(struct lttng_id_tracker *lf, bool rcu);
795 bool lttng_id_tracker_lookup(struct lttng_id_tracker_rcu *p, int id);
796 int lttng_id_tracker_add(struct lttng_id_tracker *lf, int id);
797 int lttng_id_tracker_del(struct lttng_id_tracker *lf, int id);
798
799 int lttng_session_track_id(struct lttng_session *session,
800 enum tracker_type tracker_type, int id);
801 int lttng_session_untrack_id(struct lttng_session *session,
802 enum tracker_type tracker_type, int id);
803
804 int lttng_session_list_tracker_ids(struct lttng_session *session,
805 enum tracker_type tracker_type);
806
807 void lttng_clock_ref(void);
808 void lttng_clock_unref(void);
809
810 void lttng_free_event_filter_runtime(struct lttng_kernel_event_common *event);
811
812 int lttng_probes_init(void);
813
814 int lttng_logger_init(void);
815 void lttng_logger_exit(void);
816
817 extern int lttng_statedump_start(struct lttng_session *session);
818
819 #ifdef CONFIG_KPROBES
820 int lttng_kprobes_register_event(const char *name,
821 const char *symbol_name,
822 uint64_t offset,
823 uint64_t addr,
824 struct lttng_kernel_event_recorder *event);
825 void lttng_kprobes_unregister_event(struct lttng_kernel_event_recorder *event);
826 void lttng_kprobes_destroy_event_private(struct lttng_kernel_event_recorder *event);
827 int lttng_kprobes_register_event_notifier(const char *symbol_name,
828 uint64_t offset,
829 uint64_t addr,
830 struct lttng_kernel_event_notifier *event_notifier);
831 void lttng_kprobes_unregister_event_notifier(struct lttng_kernel_event_notifier *event_notifier);
832 void lttng_kprobes_destroy_event_notifier_private(struct lttng_kernel_event_notifier *event_notifier);
833 #else
834 static inline
835 int lttng_kprobes_register_event(const char *name,
836 const char *symbol_name,
837 uint64_t offset,
838 uint64_t addr,
839 struct lttng_kernel_event_recorder *event)
840 {
841 return -ENOSYS;
842 }
843
844 static inline
845 void lttng_kprobes_unregister_event(struct lttng_kernel_event_recorder *event)
846 {
847 }
848
849 static inline
850 void lttng_kprobes_destroy_event_private(struct lttng_kernel_event_recorder *event)
851 {
852 }
853
854 static inline
855 int lttng_kprobes_register_event_notifier(const char *symbol_name,
856 uint64_t offset,
857 uint64_t addr,
858 struct lttng_kernel_event_notifier *event_notifier)
859 {
860 return -ENOSYS;
861 }
862
863 static inline
864 void lttng_kprobes_unregister_event_notifier(struct lttng_kernel_event_notifier *event_notifier)
865 {
866 }
867
868 static inline
869 void lttng_kprobes_destroy_event_notifier_private(struct lttng_kernel_event_notifier *event_notifier)
870 {
871 }
872 #endif
873
874 int lttng_event_add_callsite(struct lttng_kernel_event_common *event,
875 struct lttng_kernel_abi_event_callsite __user *callsite);
876
877 #ifdef CONFIG_UPROBES
878 int lttng_uprobes_register_event(const char *name,
879 int fd, struct lttng_kernel_event_recorder *event);
880 int lttng_uprobes_event_add_callsite(struct lttng_kernel_event_common *event,
881 struct lttng_kernel_abi_event_callsite __user *callsite);
882 void lttng_uprobes_unregister_event(struct lttng_kernel_event_recorder *event);
883 void lttng_uprobes_destroy_event_private(struct lttng_kernel_event_recorder *event);
884 int lttng_uprobes_register_event_notifier(const char *name,
885 int fd, struct lttng_kernel_event_notifier *event_notifier);
886 void lttng_uprobes_unregister_event_notifier(struct lttng_kernel_event_notifier *event_notifier);
887 void lttng_uprobes_destroy_event_notifier_private(struct lttng_kernel_event_notifier *event_notifier);
888 #else
889 static inline
890 int lttng_uprobes_register_event(const char *name,
891 int fd, struct lttng_kernel_event_recorder *event)
892 {
893 return -ENOSYS;
894 }
895
896 static inline
897 int lttng_uprobes_event_add_callsite(struct lttng_kernel_event_common *event,
898 struct lttng_kernel_abi_event_callsite __user *callsite)
899 {
900 return -ENOSYS;
901 }
902
903 static inline
904 void lttng_uprobes_unregister_event(struct lttng_kernel_event_recorder *event)
905 {
906 }
907
908 static inline
909 void lttng_uprobes_destroy_event_private(struct lttng_kernel_event_recorder *event)
910 {
911 }
912
913 static inline
914 int lttng_uprobes_register_event_notifier(const char *name,
915 int fd, struct lttng_kernel_event_notifier *event_notifier)
916 {
917 return -ENOSYS;
918 }
919
920 static inline
921 void lttng_uprobes_unregister_event_notifier(struct lttng_kernel_event_notifier *event_notifier)
922 {
923 }
924
925 static inline
926 void lttng_uprobes_destroy_event_notifier_private(struct lttng_kernel_event_notifier *event_notifier)
927 {
928 }
929 #endif
930
931 #ifdef CONFIG_KRETPROBES
932 int lttng_kretprobes_register(const char *name,
933 const char *symbol_name,
934 uint64_t offset,
935 uint64_t addr,
936 struct lttng_kernel_event_recorder *event_entry,
937 struct lttng_kernel_event_recorder *event_exit);
938 void lttng_kretprobes_unregister(struct lttng_kernel_event_recorder *event);
939 void lttng_kretprobes_destroy_private(struct lttng_kernel_event_recorder *event);
940 int lttng_kretprobes_event_enable_state(struct lttng_kernel_event_common *event,
941 int enable);
942 #else
943 static inline
944 int lttng_kretprobes_register(const char *name,
945 const char *symbol_name,
946 uint64_t offset,
947 uint64_t addr,
948 struct lttng_kernel_event_recorder *event_entry,
949 struct lttng_kernel_event_recorder *event_exit)
950 {
951 return -ENOSYS;
952 }
953
954 static inline
955 void lttng_kretprobes_unregister(struct lttng_kernel_event_recorder *event)
956 {
957 }
958
959 static inline
960 void lttng_kretprobes_destroy_private(struct lttng_kernel_event_recorder *event)
961 {
962 }
963
964 static inline
965 int lttng_kretprobes_event_enable_state(struct lttng_kernel_event_common *event,
966 int enable)
967 {
968 return -ENOSYS;
969 }
970 #endif
971
972 int lttng_calibrate(struct lttng_kernel_abi_calibrate *calibrate);
973
974 extern const struct file_operations lttng_tracepoint_list_fops;
975 extern const struct file_operations lttng_syscall_list_fops;
976
977 #define TRACEPOINT_HAS_DATA_ARG
978
979 #endif /* _LTTNG_EVENTS_H */
This page took 0.045844 seconds and 3 git commands to generate.