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