7 * Copyright 2010 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * Holds LTTng per-session event registry.
12 #include <linux/list.h>
13 #include <linux/uuid.h>
14 #include <linux/kprobes.h>
15 #include "ltt-debugfs-abi.h"
18 #define is_signed_type(type) (((type)(-1)) < 0)
22 struct lib_ring_buffer_ctx
;
24 struct perf_event_attr
;
26 /* Type description */
28 /* Update the astract_types name table in lttng-types.c along with this enum */
38 /* Update the string_encodings name table in lttng-types.c along with this enum */
39 enum lttng_string_encodings
{
40 lttng_encode_none
= 0,
41 lttng_encode_UTF8
= 1,
42 lttng_encode_ASCII
= 2,
46 struct lttng_enum_entry
{
47 unsigned long long start
, end
; /* start and end are inclusive */
51 #define __type_integer(_type, _byte_order, _base, _encoding) \
53 .atype = atype_integer, \
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, \
61 .encoding = lttng_encode_##_encoding, \
65 struct 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
;
74 union _lttng_basic_type
{
75 struct lttng_integer_type integer
;
80 enum lttng_string_encodings encoding
;
84 struct lttng_basic_type
{
85 enum abstract_types atype
;
87 union _lttng_basic_type basic
;
92 enum abstract_types atype
;
94 union _lttng_basic_type basic
;
96 struct lttng_basic_type elem_type
;
97 unsigned int length
; /* num. elems. */
100 struct lttng_basic_type length_type
;
101 struct lttng_basic_type elem_type
;
108 struct lttng_type container_type
;
109 const struct lttng_enum_entry
*entries
;
113 /* Event field description */
115 struct lttng_event_field
{
117 struct lttng_type type
;
120 struct lttng_ctx_field
{
122 struct lttng_type type
;
126 struct perf_event
**e
; /* per-cpu array */
127 struct list_head head
;
128 struct perf_event_attr
*attr
;
131 void (*destroy
)(struct lttng_ctx_field
*field
);
135 struct lttng_ctx_field
*fields
;
136 unsigned int nr_fields
;
137 unsigned int allocated_fields
;
140 struct lttng_event_desc
{
142 void *probe_callback
;
143 const struct lttng_event_ctx
*ctx
; /* context */
144 const struct lttng_event_field
*fields
; /* event payload */
145 unsigned int nr_fields
;
146 struct module
*owner
;
149 struct lttng_probe_desc
{
150 const struct lttng_event_desc
*event_desc
;
151 unsigned int nr_events
;
152 struct list_head head
; /* chain registered probes */
156 * ltt_event structure is referred to by the tracing fast path. It must be
161 struct ltt_channel
*chan
;
162 const struct lttng_event_desc
*desc
;
164 enum lttng_kernel_instrumentation instrumentation
;
174 struct list_head list
; /* Event list */
175 int metadata_dumped
:1;
178 struct ltt_channel_ops
{
179 struct channel
*(*channel_create
)(const char *name
,
180 struct ltt_channel
*ltt_chan
,
182 size_t subbuf_size
, size_t num_subbuf
,
183 unsigned int switch_timer_interval
,
184 unsigned int read_timer_interval
);
185 void (*channel_destroy
)(struct channel
*chan
);
186 struct lib_ring_buffer
*(*buffer_read_open
)(struct channel
*chan
);
187 void (*buffer_read_close
)(struct lib_ring_buffer
*buf
);
188 int (*event_reserve
)(struct lib_ring_buffer_ctx
*ctx
,
190 void (*event_commit
)(struct lib_ring_buffer_ctx
*ctx
);
191 void (*event_write
)(struct lib_ring_buffer_ctx
*ctx
, const void *src
,
194 * packet_avail_size returns the available size in the current
195 * packet. Note that the size returned is only a hint, since it
196 * may change due to concurrent writes.
198 size_t (*packet_avail_size
)(struct channel
*chan
);
199 wait_queue_head_t
*(*get_reader_wait_queue
)(struct ltt_channel
*chan
);
204 struct channel
*chan
; /* Channel buffers */
205 /* Event ID management */
206 struct ltt_session
*session
;
207 struct file
*file
; /* File associated to channel */
208 unsigned int free_event_id
; /* Next event ID to allocate */
209 struct list_head list
; /* Channel list */
210 wait_queue_head_t notify_wait
; /* Channel addition notif. waitqueue */
211 struct ltt_channel_ops
*ops
;
212 int header_type
; /* 0: unset, 1: compact, 2: large */
213 int metadata_dumped
:1;
217 int active
; /* Is trace session active ? */
218 struct file
*file
; /* File associated to session */
219 struct ltt_channel
*metadata
; /* Metadata channel */
220 struct list_head chan
; /* Channel list head */
221 struct list_head events
; /* Event list head */
222 struct list_head list
; /* Session list */
223 unsigned int free_chan_id
; /* Next chan ID to allocate */
224 uuid_le uuid
; /* Trace session unique ID */
225 int metadata_dumped
:1;
228 struct ltt_transport
{
230 struct module
*owner
;
231 struct list_head node
;
232 struct ltt_channel_ops ops
;
235 struct ltt_session
*ltt_session_create(void);
236 int ltt_session_start(struct ltt_session
*session
);
237 int ltt_session_stop(struct ltt_session
*session
);
238 void ltt_session_destroy(struct ltt_session
*session
);
240 struct ltt_channel
*ltt_channel_create(struct ltt_session
*session
,
241 const char *transport_name
,
243 size_t subbuf_size
, size_t num_subbuf
,
244 unsigned int switch_timer_interval
,
245 unsigned int read_timer_interval
);
246 struct ltt_channel
*ltt_global_channel_create(struct ltt_session
*session
,
247 int overwrite
, void *buf_addr
,
248 size_t subbuf_size
, size_t num_subbuf
,
249 unsigned int switch_timer_interval
,
250 unsigned int read_timer_interval
);
252 struct ltt_event
*ltt_event_create(struct ltt_channel
*chan
,
253 struct lttng_kernel_event
*event_param
,
256 void ltt_transport_register(struct ltt_transport
*transport
);
257 void ltt_transport_unregister(struct ltt_transport
*transport
);
259 int ltt_debugfs_abi_init(void);
260 void ltt_debugfs_abi_exit(void);
262 int ltt_probe_register(struct lttng_probe_desc
*desc
);
263 void ltt_probe_unregister(struct lttng_probe_desc
*desc
);
264 const struct lttng_event_desc
*ltt_event_get(const char *name
);
265 void ltt_event_put(const struct lttng_event_desc
*desc
);
266 int ltt_probes_init(void);
267 void ltt_probes_exit(void);
268 struct lttng_ctx_field
*lttng_append_context(struct lttng_ctx
**ctx
);
269 void lttng_destroy_context(struct lttng_ctx
*ctx
);
271 #ifdef CONFIG_KPROBES
272 int lttng_kprobes_register(const char *name
,
273 const char *symbol_name
,
276 struct ltt_event
*event
);
277 void lttng_kprobes_unregister(struct ltt_event
*event
);
278 void lttng_kprobes_destroy_private(struct ltt_event
*event
);
281 int lttng_kprobes_register(const char *name
,
282 const char *symbol_name
,
285 struct ltt_event
*event
)
291 void lttng_kprobes_unregister(struct ltt_event
*event
)
296 void lttng_kprobes_destroy_private(struct ltt_event
*event
)
301 #ifdef CONFIG_DYNAMIC_FTRACE
302 int lttng_ftrace_register(const char *name
,
303 const char *symbol_name
,
304 struct ltt_event
*event
);
305 void lttng_ftrace_unregister(struct ltt_event
*event
);
306 void lttng_ftrace_destroy_private(struct ltt_event
*event
);
309 int lttng_ftrace_register(const char *name
,
310 const char *symbol_name
,
311 struct ltt_event
*event
)
317 void lttng_ftrace_unregister(struct ltt_event
*event
)
322 void lttng_ftrace_destroy_private(struct ltt_event
*event
)
327 extern const struct file_operations lttng_tracepoint_list_fops
;
329 #endif /* _LTT_EVENTS_H */