Handle newer 3.1+ perf API
[lttng-modules.git] / ltt-events.h
CommitLineData
11b5a3c2
MD
1#ifndef _LTT_EVENTS_H
2#define _LTT_EVENTS_H
3
4e3c1b9b
MD
4/*
5 * ltt-events.h
6 *
7 * Copyright 2010 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 *
9 * Holds LTTng per-session event registry.
17baffe2
MD
10 *
11 * Dual LGPL v2.1/GPL v2 license.
4e3c1b9b
MD
12 */
13
14#include <linux/list.h>
d6d808f3 15#include <linux/kprobes.h>
a864fb02 16#include "wrapper/uuid.h"
11b5a3c2 17#include "ltt-debugfs-abi.h"
4e3c1b9b 18
9e7e4892
MD
19#undef is_signed_type
20#define is_signed_type(type) (((type)(-1)) < 0)
21
4e3c1b9b
MD
22struct ltt_channel;
23struct ltt_session;
1c25284c 24struct lib_ring_buffer_ctx;
ba1f5986 25struct perf_event;
833ad6a0 26struct perf_event_attr;
4e3c1b9b 27
c0edae1d
MD
28/* Type description */
29
30/* Update the astract_types name table in lttng-types.c along with this enum */
31enum abstract_types {
32 atype_integer,
33 atype_enum,
34 atype_array,
35 atype_sequence,
36 atype_string,
37 NR_ABSTRACT_TYPES,
38};
39
40/* Update the string_encodings name table in lttng-types.c along with this enum */
41enum lttng_string_encodings {
e0a7a7c4
MD
42 lttng_encode_none = 0,
43 lttng_encode_UTF8 = 1,
44 lttng_encode_ASCII = 2,
c0edae1d
MD
45 NR_STRING_ENCODINGS,
46};
47
48struct lttng_enum_entry {
49 unsigned long long start, end; /* start and end are inclusive */
50 const char *string;
51};
52
64c796d8 53#define __type_integer(_type, _byte_order, _base, _encoding) \
c099397a
MD
54 { \
55 .atype = atype_integer, \
56 .u.basic.integer = \
57 { \
30bdb6e4 58 .size = sizeof(_type) * CHAR_BIT, \
d793d5e1 59 .alignment = ltt_alignof(_type) * CHAR_BIT, \
c099397a
MD
60 .signedness = is_signed_type(_type), \
61 .reverse_byte_order = _byte_order != __BYTE_ORDER, \
e0a7a7c4 62 .base = _base, \
64c796d8 63 .encoding = lttng_encode_##_encoding, \
c099397a
MD
64 }, \
65 } \
66
67struct lttng_integer_type {
68 unsigned int size; /* in bits */
69 unsigned short alignment; /* in bits */
70 unsigned int signedness:1;
71 unsigned int reverse_byte_order:1;
e0a7a7c4
MD
72 unsigned int base; /* 2, 8, 10, 16, for pretty print */
73 enum lttng_string_encodings encoding;
c099397a
MD
74};
75
76union _lttng_basic_type {
77 struct lttng_integer_type integer;
78 struct {
79 const char *name;
80 } enumeration;
81 struct {
82 enum lttng_string_encodings encoding;
83 } string;
84};
85
86struct lttng_basic_type {
87 enum abstract_types atype;
88 union {
89 union _lttng_basic_type basic;
90 } u;
c0edae1d
MD
91};
92
93struct lttng_type {
94 enum abstract_types atype;
c0edae1d 95 union {
c099397a 96 union _lttng_basic_type basic;
c0edae1d 97 struct {
c099397a 98 struct lttng_basic_type elem_type;
c0edae1d
MD
99 unsigned int length; /* num. elems. */
100 } array;
101 struct {
c099397a
MD
102 struct lttng_basic_type length_type;
103 struct lttng_basic_type elem_type;
c0edae1d 104 } sequence;
c0edae1d 105 } u;
c099397a
MD
106};
107
108struct lttng_enum {
109 const char *name;
110 struct lttng_type container_type;
111 const struct lttng_enum_entry *entries;
112 unsigned int len;
113};
c0edae1d
MD
114
115/* Event field description */
116
117struct lttng_event_field {
118 const char *name;
f17701fb 119 struct lttng_type type;
c0edae1d
MD
120};
121
2001023e
MD
122/*
123 * We need to keep this perf counter field separately from struct
124 * lttng_ctx_field because cpu hotplug needs fixed-location addresses.
125 */
126struct lttng_perf_counter_field {
127 struct notifier_block nb;
128 int hp_enable;
129 struct perf_event_attr *attr;
130 struct perf_event **e; /* per-cpu array */
131};
132
ba1f5986 133struct lttng_ctx_field {
8070f5c0 134 struct lttng_event_field event_field;
f1676205
MD
135 size_t (*get_size)(size_t offset);
136 void (*record)(struct lttng_ctx_field *field,
137 struct lib_ring_buffer_ctx *ctx,
138 struct ltt_channel *chan);
ba1f5986 139 union {
2001023e 140 struct lttng_perf_counter_field *perf_counter;
ba1f5986 141 } u;
2dccf128 142 void (*destroy)(struct lttng_ctx_field *field);
ba1f5986
MD
143};
144
145struct lttng_ctx {
833ad6a0 146 struct lttng_ctx_field *fields;
0d1a681e 147 unsigned int nr_fields;
ba1f5986 148 unsigned int allocated_fields;
0d1a681e
MD
149};
150
151struct lttng_event_desc {
c0edae1d
MD
152 const char *name;
153 void *probe_callback;
0d1a681e
MD
154 const struct lttng_event_ctx *ctx; /* context */
155 const struct lttng_event_field *fields; /* event payload */
c0edae1d 156 unsigned int nr_fields;
dc7f600a 157 struct module *owner;
c0edae1d
MD
158};
159
85a9ca7f 160struct lttng_probe_desc {
f7bdf4db 161 const struct lttng_event_desc **event_desc;
85a9ca7f
MD
162 unsigned int nr_events;
163 struct list_head head; /* chain registered probes */
164};
165
7371f44c
MD
166struct lttng_krp; /* Kretprobe handling */
167
85a9ca7f
MD
168/*
169 * ltt_event structure is referred to by the tracing fast path. It must be
170 * kept small.
171 */
172struct ltt_event {
173 unsigned int id;
174 struct ltt_channel *chan;
e64957da 175 int enabled;
d3dbe23c 176 const struct lttng_event_desc *desc;
85a9ca7f 177 void *filter;
f1676205 178 struct lttng_ctx *ctx;
38d024ae 179 enum lttng_kernel_instrumentation instrumentation;
d6d808f3
MD
180 union {
181 struct {
182 struct kprobe kp;
183 char *symbol_name;
184 } kprobe;
7371f44c
MD
185 struct {
186 struct lttng_krp *lttng_krp;
187 char *symbol_name;
188 } kretprobe;
e0a7a7c4
MD
189 struct {
190 char *symbol_name;
191 } ftrace;
d6d808f3 192 } u;
85a9ca7f 193 struct list_head list; /* Event list */
c099397a 194 int metadata_dumped:1;
85a9ca7f
MD
195};
196
197struct ltt_channel_ops {
198 struct channel *(*channel_create)(const char *name,
9115fbdc 199 struct ltt_channel *ltt_chan,
85a9ca7f
MD
200 void *buf_addr,
201 size_t subbuf_size, size_t num_subbuf,
202 unsigned int switch_timer_interval,
203 unsigned int read_timer_interval);
204 void (*channel_destroy)(struct channel *chan);
205 struct lib_ring_buffer *(*buffer_read_open)(struct channel *chan);
f71ecafa 206 int (*buffer_has_read_closed_stream)(struct channel *chan);
85a9ca7f 207 void (*buffer_read_close)(struct lib_ring_buffer *buf);
4e1f08f4 208 int (*event_reserve)(struct lib_ring_buffer_ctx *ctx,
64c796d8 209 uint32_t event_id);
85a9ca7f
MD
210 void (*event_commit)(struct lib_ring_buffer_ctx *ctx);
211 void (*event_write)(struct lib_ring_buffer_ctx *ctx, const void *src,
212 size_t len);
4ea00e4f
JD
213 void (*event_write_from_user)(struct lib_ring_buffer_ctx *ctx,
214 const void *src, size_t len);
58aa5d24
MD
215 void (*event_memset)(struct lib_ring_buffer_ctx *ctx,
216 int c, size_t len);
1ec3f75a
MD
217 /*
218 * packet_avail_size returns the available size in the current
219 * packet. Note that the size returned is only a hint, since it
220 * may change due to concurrent writes.
221 */
222 size_t (*packet_avail_size)(struct channel *chan);
71c1d843 223 wait_queue_head_t *(*get_writer_buf_wait_queue)(struct channel *chan, int cpu);
24cedcfe
MD
224 wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan);
225 int (*is_finalized)(struct channel *chan);
254ec7bc 226 int (*is_disabled)(struct channel *chan);
85a9ca7f
MD
227};
228
a33c9927
MD
229struct ltt_transport {
230 char *name;
231 struct module *owner;
232 struct list_head node;
233 struct ltt_channel_ops ops;
234};
235
85a9ca7f 236struct ltt_channel {
c099397a 237 unsigned int id;
85a9ca7f 238 struct channel *chan; /* Channel buffers */
e64957da 239 int enabled;
f1676205 240 struct lttng_ctx *ctx;
85a9ca7f
MD
241 /* Event ID management */
242 struct ltt_session *session;
243 struct file *file; /* File associated to channel */
244 unsigned int free_event_id; /* Next event ID to allocate */
245 struct list_head list; /* Channel list */
85a9ca7f 246 struct ltt_channel_ops *ops;
a33c9927 247 struct ltt_transport *transport;
1ec65de1 248 struct ltt_event **sc_table; /* for syscall tracing */
f405cfce 249 struct ltt_event *sc_unknown; /* for unknown syscalls */
b76dc1a0 250 struct ltt_event *sc_compat_unknown;
2f804c0a 251 struct ltt_event *sc_exit; /* for syscall exit */
9115fbdc 252 int header_type; /* 0: unset, 1: compact, 2: large */
c099397a 253 int metadata_dumped:1;
85a9ca7f
MD
254};
255
256struct ltt_session {
257 int active; /* Is trace session active ? */
8070f5c0 258 int been_active; /* Has trace session been active ? */
85a9ca7f 259 struct file *file; /* File associated to session */
c099397a 260 struct ltt_channel *metadata; /* Metadata channel */
85a9ca7f
MD
261 struct list_head chan; /* Channel list head */
262 struct list_head events; /* Event list head */
263 struct list_head list; /* Session list */
c099397a 264 unsigned int free_chan_id; /* Next chan ID to allocate */
d793d5e1 265 uuid_le uuid; /* Trace session unique ID */
c099397a 266 int metadata_dumped:1;
85a9ca7f
MD
267};
268
baf20995 269struct ltt_session *ltt_session_create(void);
e64957da
MD
270int ltt_session_enable(struct ltt_session *session);
271int ltt_session_disable(struct ltt_session *session);
11b5a3c2 272void ltt_session_destroy(struct ltt_session *session);
4e3c1b9b 273
baf20995 274struct ltt_channel *ltt_channel_create(struct ltt_session *session,
5dbbdb43
MD
275 const char *transport_name,
276 void *buf_addr,
277 size_t subbuf_size, size_t num_subbuf,
278 unsigned int switch_timer_interval,
279 unsigned int read_timer_interval);
280struct ltt_channel *ltt_global_channel_create(struct ltt_session *session,
4e3c1b9b
MD
281 int overwrite, void *buf_addr,
282 size_t subbuf_size, size_t num_subbuf,
283 unsigned int switch_timer_interval,
284 unsigned int read_timer_interval);
4e3c1b9b 285
653fe716 286struct ltt_event *ltt_event_create(struct ltt_channel *chan,
d6d808f3 287 struct lttng_kernel_event *event_param,
259b6cb3
MD
288 void *filter,
289 const struct lttng_event_desc *internal_desc);
c0e31d2e 290
e64957da
MD
291int ltt_channel_enable(struct ltt_channel *channel);
292int ltt_channel_disable(struct ltt_channel *channel);
293int ltt_event_enable(struct ltt_event *event);
294int ltt_event_disable(struct ltt_event *event);
295
c0e31d2e
MD
296void ltt_transport_register(struct ltt_transport *transport);
297void ltt_transport_unregister(struct ltt_transport *transport);
11b5a3c2 298
360f38ea 299void synchronize_trace(void);
1c25284c
MD
300int ltt_debugfs_abi_init(void);
301void ltt_debugfs_abi_exit(void);
302
85a9ca7f
MD
303int ltt_probe_register(struct lttng_probe_desc *desc);
304void ltt_probe_unregister(struct lttng_probe_desc *desc);
305const struct lttng_event_desc *ltt_event_get(const char *name);
306void ltt_event_put(const struct lttng_event_desc *desc);
cd4bd11f
MD
307int ltt_probes_init(void);
308void ltt_probes_exit(void);
1ec65de1 309
63728b02 310#ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
1ec65de1
MD
311int lttng_syscalls_register(struct ltt_channel *chan, void *filter);
312int lttng_syscalls_unregister(struct ltt_channel *chan);
313#else
314static inline int lttng_syscalls_register(struct ltt_channel *chan, void *filter)
315{
316 return -ENOSYS;
317}
318
319static inline int lttng_syscalls_unregister(struct ltt_channel *chan)
320{
321 return 0;
322}
323#endif
324
2dccf128 325struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx);
44252f0f 326int lttng_find_context(struct lttng_ctx *ctx, const char *name);
8289661d
MD
327void lttng_remove_context_field(struct lttng_ctx **ctx,
328 struct lttng_ctx_field *field);
2dccf128 329void lttng_destroy_context(struct lttng_ctx *ctx);
8070f5c0 330int lttng_add_pid_to_ctx(struct lttng_ctx **ctx);
25b2f99a 331int lttng_add_comm_to_ctx(struct lttng_ctx **ctx);
a8ad3613 332int lttng_add_prio_to_ctx(struct lttng_ctx **ctx);
53f1f0ca 333int lttng_add_nice_to_ctx(struct lttng_ctx **ctx);
b64bc438
MD
334int lttng_add_vpid_to_ctx(struct lttng_ctx **ctx);
335int lttng_add_tid_to_ctx(struct lttng_ctx **ctx);
336int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx);
337int lttng_add_ppid_to_ctx(struct lttng_ctx **ctx);
338int lttng_add_vppid_to_ctx(struct lttng_ctx **ctx);
41c3c24e 339#if defined(CONFIG_PERF_EVENTS) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33))
c24a0d71
MD
340int lttng_add_perf_counter_to_ctx(uint32_t type,
341 uint64_t config,
342 const char *name,
343 struct lttng_ctx **ctx);
1d443b34
MD
344#else
345static inline
346int lttng_add_perf_counter_to_ctx(uint32_t type,
347 uint64_t config,
348 const char *name,
349 struct lttng_ctx **ctx)
350{
351 return -ENOSYS;
352}
353#endif
02119ee5 354
acd614cc 355#ifdef CONFIG_KPROBES
f17701fb
MD
356int lttng_kprobes_register(const char *name,
357 const char *symbol_name,
358 uint64_t offset,
359 uint64_t addr,
360 struct ltt_event *event);
361void lttng_kprobes_unregister(struct ltt_event *event);
edeb3137 362void lttng_kprobes_destroy_private(struct ltt_event *event);
acd614cc
MD
363#else
364static inline
365int lttng_kprobes_register(const char *name,
366 const char *symbol_name,
367 uint64_t offset,
368 uint64_t addr,
369 struct ltt_event *event)
370{
371 return -ENOSYS;
372}
373
25f53c39 374static inline
acd614cc
MD
375void lttng_kprobes_unregister(struct ltt_event *event)
376{
377}
edeb3137
MD
378
379static inline
380void lttng_kprobes_destroy_private(struct ltt_event *event)
381{
382}
acd614cc 383#endif
d6d808f3 384
7371f44c
MD
385#ifdef CONFIG_KRETPROBES
386int lttng_kretprobes_register(const char *name,
387 const char *symbol_name,
388 uint64_t offset,
389 uint64_t addr,
390 struct ltt_event *event_entry,
391 struct ltt_event *event_exit);
392void lttng_kretprobes_unregister(struct ltt_event *event);
393void lttng_kretprobes_destroy_private(struct ltt_event *event);
394#else
395static inline
396int lttng_kretprobes_register(const char *name,
397 const char *symbol_name,
398 uint64_t offset,
399 uint64_t addr,
400 struct ltt_event *event_entry,
401 struct ltt_event *event_exit)
402{
403 return -ENOSYS;
404}
405
406static inline
407void lttng_kretprobes_unregister(struct ltt_event *event)
408{
409}
410
411static inline
412void lttng_kretprobes_destroy_private(struct ltt_event *event)
413{
414}
415#endif
416
e0a7a7c4
MD
417#ifdef CONFIG_DYNAMIC_FTRACE
418int lttng_ftrace_register(const char *name,
419 const char *symbol_name,
420 struct ltt_event *event);
421void lttng_ftrace_unregister(struct ltt_event *event);
edeb3137 422void lttng_ftrace_destroy_private(struct ltt_event *event);
e0a7a7c4
MD
423#else
424static inline
425int lttng_ftrace_register(const char *name,
426 const char *symbol_name,
427 struct ltt_event *event)
428{
acd614cc 429 return -ENOSYS;
e0a7a7c4
MD
430}
431
432static inline
433void lttng_ftrace_unregister(struct ltt_event *event)
434{
435}
edeb3137
MD
436
437static inline
438void lttng_ftrace_destroy_private(struct ltt_event *event)
439{
440}
e0a7a7c4 441#endif
271b6681 442
3db41b2c 443int lttng_calibrate(struct lttng_kernel_calibrate *calibrate);
57105fc2 444
271b6681
MD
445extern const struct file_operations lttng_tracepoint_list_fops;
446
ef200626
MD
447#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
448#define TRACEPOINT_HAS_DATA_ARG
449#endif
450
11b5a3c2 451#endif /* _LTT_EVENTS_H */
This page took 0.046118 seconds and 4 git commands to generate.