Add context management infrastructure
[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.
10 */
11
12#include <linux/list.h>
d793d5e1 13#include <linux/uuid.h>
d6d808f3 14#include <linux/kprobes.h>
11b5a3c2 15#include "ltt-debugfs-abi.h"
4e3c1b9b
MD
16
17struct ltt_channel;
18struct ltt_session;
1c25284c 19struct lib_ring_buffer_ctx;
ba1f5986 20struct perf_event;
833ad6a0 21struct perf_event_attr;
4e3c1b9b 22
c0edae1d
MD
23/* Type description */
24
25/* Update the astract_types name table in lttng-types.c along with this enum */
26enum abstract_types {
27 atype_integer,
28 atype_enum,
29 atype_array,
30 atype_sequence,
31 atype_string,
32 NR_ABSTRACT_TYPES,
33};
34
35/* Update the string_encodings name table in lttng-types.c along with this enum */
36enum lttng_string_encodings {
e0a7a7c4
MD
37 lttng_encode_none = 0,
38 lttng_encode_UTF8 = 1,
39 lttng_encode_ASCII = 2,
c0edae1d
MD
40 NR_STRING_ENCODINGS,
41};
42
43struct lttng_enum_entry {
44 unsigned long long start, end; /* start and end are inclusive */
45 const char *string;
46};
47
64c796d8 48#define __type_integer(_type, _byte_order, _base, _encoding) \
c099397a
MD
49 { \
50 .atype = atype_integer, \
51 .u.basic.integer = \
52 { \
30bdb6e4 53 .size = sizeof(_type) * CHAR_BIT, \
d793d5e1 54 .alignment = ltt_alignof(_type) * CHAR_BIT, \
c099397a
MD
55 .signedness = is_signed_type(_type), \
56 .reverse_byte_order = _byte_order != __BYTE_ORDER, \
e0a7a7c4 57 .base = _base, \
64c796d8 58 .encoding = lttng_encode_##_encoding, \
c099397a
MD
59 }, \
60 } \
61
62struct lttng_integer_type {
63 unsigned int size; /* in bits */
64 unsigned short alignment; /* in bits */
65 unsigned int signedness:1;
66 unsigned int reverse_byte_order:1;
e0a7a7c4
MD
67 unsigned int base; /* 2, 8, 10, 16, for pretty print */
68 enum lttng_string_encodings encoding;
c099397a
MD
69};
70
71union _lttng_basic_type {
72 struct lttng_integer_type integer;
73 struct {
74 const char *name;
75 } enumeration;
76 struct {
77 enum lttng_string_encodings encoding;
78 } string;
79};
80
81struct lttng_basic_type {
82 enum abstract_types atype;
83 union {
84 union _lttng_basic_type basic;
85 } u;
c0edae1d
MD
86};
87
88struct lttng_type {
89 enum abstract_types atype;
c0edae1d 90 union {
c099397a 91 union _lttng_basic_type basic;
c0edae1d 92 struct {
c099397a 93 struct lttng_basic_type elem_type;
c0edae1d
MD
94 unsigned int length; /* num. elems. */
95 } array;
96 struct {
c099397a
MD
97 struct lttng_basic_type length_type;
98 struct lttng_basic_type elem_type;
c0edae1d 99 } sequence;
c0edae1d 100 } u;
c099397a
MD
101};
102
103struct lttng_enum {
104 const char *name;
105 struct lttng_type container_type;
106 const struct lttng_enum_entry *entries;
107 unsigned int len;
108};
c0edae1d
MD
109
110/* Event field description */
111
112struct lttng_event_field {
113 const char *name;
f17701fb 114 struct lttng_type type;
c0edae1d
MD
115};
116
ba1f5986
MD
117struct lttng_ctx_field {
118 const char *name;
119 struct lttng_type type;
833ad6a0 120 void *callback;
ba1f5986
MD
121 union {
122 struct {
123 struct perf_event **e; /* per-cpu array */
833ad6a0
MD
124 struct list_head head;
125 struct perf_event_attr *attr;
ba1f5986
MD
126 } perf_counter;
127 } u;
2dccf128 128 void (*destroy)(struct lttng_ctx_field *field);
ba1f5986
MD
129};
130
131struct lttng_ctx {
833ad6a0 132 struct lttng_ctx_field *fields;
0d1a681e 133 unsigned int nr_fields;
ba1f5986 134 unsigned int allocated_fields;
0d1a681e
MD
135};
136
137struct lttng_event_desc {
c0edae1d
MD
138 const char *name;
139 void *probe_callback;
0d1a681e
MD
140 const struct lttng_event_ctx *ctx; /* context */
141 const struct lttng_event_field *fields; /* event payload */
c0edae1d 142 unsigned int nr_fields;
dc7f600a 143 struct module *owner;
c0edae1d
MD
144};
145
85a9ca7f
MD
146struct lttng_probe_desc {
147 const struct lttng_event_desc *event_desc;
148 unsigned int nr_events;
149 struct list_head head; /* chain registered probes */
150};
151
152/*
153 * ltt_event structure is referred to by the tracing fast path. It must be
154 * kept small.
155 */
156struct ltt_event {
157 unsigned int id;
158 struct ltt_channel *chan;
d3dbe23c 159 const struct lttng_event_desc *desc;
85a9ca7f 160 void *filter;
38d024ae 161 enum lttng_kernel_instrumentation instrumentation;
d6d808f3
MD
162 union {
163 struct {
164 struct kprobe kp;
165 char *symbol_name;
166 } kprobe;
e0a7a7c4
MD
167 struct {
168 char *symbol_name;
169 } ftrace;
d6d808f3 170 } u;
85a9ca7f 171 struct list_head list; /* Event list */
c099397a 172 int metadata_dumped:1;
85a9ca7f
MD
173};
174
175struct ltt_channel_ops {
176 struct channel *(*channel_create)(const char *name,
9115fbdc 177 struct ltt_channel *ltt_chan,
85a9ca7f
MD
178 void *buf_addr,
179 size_t subbuf_size, size_t num_subbuf,
180 unsigned int switch_timer_interval,
181 unsigned int read_timer_interval);
182 void (*channel_destroy)(struct channel *chan);
183 struct lib_ring_buffer *(*buffer_read_open)(struct channel *chan);
184 void (*buffer_read_close)(struct lib_ring_buffer *buf);
4e1f08f4 185 int (*event_reserve)(struct lib_ring_buffer_ctx *ctx,
64c796d8 186 uint32_t event_id);
85a9ca7f
MD
187 void (*event_commit)(struct lib_ring_buffer_ctx *ctx);
188 void (*event_write)(struct lib_ring_buffer_ctx *ctx, const void *src,
189 size_t len);
1ec3f75a
MD
190 /*
191 * packet_avail_size returns the available size in the current
192 * packet. Note that the size returned is only a hint, since it
193 * may change due to concurrent writes.
194 */
195 size_t (*packet_avail_size)(struct channel *chan);
c099397a 196 wait_queue_head_t *(*get_reader_wait_queue)(struct ltt_channel *chan);
85a9ca7f
MD
197};
198
199struct ltt_channel {
c099397a 200 unsigned int id;
85a9ca7f
MD
201 struct channel *chan; /* Channel buffers */
202 /* Event ID management */
203 struct ltt_session *session;
204 struct file *file; /* File associated to channel */
205 unsigned int free_event_id; /* Next event ID to allocate */
206 struct list_head list; /* Channel list */
207 wait_queue_head_t notify_wait; /* Channel addition notif. waitqueue */
208 struct ltt_channel_ops *ops;
9115fbdc 209 int header_type; /* 0: unset, 1: compact, 2: large */
c099397a 210 int metadata_dumped:1;
85a9ca7f
MD
211};
212
213struct ltt_session {
214 int active; /* Is trace session active ? */
215 struct file *file; /* File associated to session */
c099397a 216 struct ltt_channel *metadata; /* Metadata channel */
85a9ca7f
MD
217 struct list_head chan; /* Channel list head */
218 struct list_head events; /* Event list head */
219 struct list_head list; /* Session list */
c099397a 220 unsigned int free_chan_id; /* Next chan ID to allocate */
d793d5e1 221 uuid_le uuid; /* Trace session unique ID */
c099397a 222 int metadata_dumped:1;
85a9ca7f
MD
223};
224
225struct ltt_transport {
226 char *name;
227 struct module *owner;
228 struct list_head node;
229 struct ltt_channel_ops ops;
230};
231
baf20995 232struct ltt_session *ltt_session_create(void);
c0e31d2e
MD
233int ltt_session_start(struct ltt_session *session);
234int ltt_session_stop(struct ltt_session *session);
11b5a3c2 235void ltt_session_destroy(struct ltt_session *session);
4e3c1b9b 236
baf20995 237struct ltt_channel *ltt_channel_create(struct ltt_session *session,
5dbbdb43
MD
238 const char *transport_name,
239 void *buf_addr,
240 size_t subbuf_size, size_t num_subbuf,
241 unsigned int switch_timer_interval,
242 unsigned int read_timer_interval);
243struct ltt_channel *ltt_global_channel_create(struct ltt_session *session,
4e3c1b9b
MD
244 int overwrite, void *buf_addr,
245 size_t subbuf_size, size_t num_subbuf,
246 unsigned int switch_timer_interval,
247 unsigned int read_timer_interval);
4e3c1b9b 248
653fe716 249struct ltt_event *ltt_event_create(struct ltt_channel *chan,
d6d808f3 250 struct lttng_kernel_event *event_param,
85a9ca7f 251 void *filter);
c0e31d2e
MD
252
253void ltt_transport_register(struct ltt_transport *transport);
254void ltt_transport_unregister(struct ltt_transport *transport);
11b5a3c2 255
1c25284c
MD
256int ltt_debugfs_abi_init(void);
257void ltt_debugfs_abi_exit(void);
258
85a9ca7f
MD
259int ltt_probe_register(struct lttng_probe_desc *desc);
260void ltt_probe_unregister(struct lttng_probe_desc *desc);
261const struct lttng_event_desc *ltt_event_get(const char *name);
262void ltt_event_put(const struct lttng_event_desc *desc);
cd4bd11f
MD
263int ltt_probes_init(void);
264void ltt_probes_exit(void);
2dccf128
MD
265struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx);
266void lttng_destroy_context(struct lttng_ctx *ctx);
02119ee5 267
acd614cc 268#ifdef CONFIG_KPROBES
f17701fb
MD
269int lttng_kprobes_register(const char *name,
270 const char *symbol_name,
271 uint64_t offset,
272 uint64_t addr,
273 struct ltt_event *event);
274void lttng_kprobes_unregister(struct ltt_event *event);
edeb3137 275void lttng_kprobes_destroy_private(struct ltt_event *event);
acd614cc
MD
276#else
277static inline
278int lttng_kprobes_register(const char *name,
279 const char *symbol_name,
280 uint64_t offset,
281 uint64_t addr,
282 struct ltt_event *event)
283{
284 return -ENOSYS;
285}
286
25f53c39 287static inline
acd614cc
MD
288void lttng_kprobes_unregister(struct ltt_event *event)
289{
290}
edeb3137
MD
291
292static inline
293void lttng_kprobes_destroy_private(struct ltt_event *event)
294{
295}
acd614cc 296#endif
d6d808f3 297
e0a7a7c4
MD
298#ifdef CONFIG_DYNAMIC_FTRACE
299int lttng_ftrace_register(const char *name,
300 const char *symbol_name,
301 struct ltt_event *event);
302void lttng_ftrace_unregister(struct ltt_event *event);
edeb3137 303void lttng_ftrace_destroy_private(struct ltt_event *event);
e0a7a7c4
MD
304#else
305static inline
306int lttng_ftrace_register(const char *name,
307 const char *symbol_name,
308 struct ltt_event *event)
309{
acd614cc 310 return -ENOSYS;
e0a7a7c4
MD
311}
312
313static inline
314void lttng_ftrace_unregister(struct ltt_event *event)
315{
316}
edeb3137
MD
317
318static inline
319void lttng_ftrace_destroy_private(struct ltt_event *event)
320{
321}
e0a7a7c4 322#endif
271b6681
MD
323
324extern const struct file_operations lttng_tracepoint_list_fops;
325
11b5a3c2 326#endif /* _LTT_EVENTS_H */
This page took 0.041098 seconds and 4 git commands to generate.