7 * Copyright 2010 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * Holds LTTng per-session event registry.
11 * Dual LGPL v2.1/GPL v2 license.
14 #include <linux/list.h>
15 #include <linux/uuid.h>
16 #include <linux/kprobes.h>
17 #include "ltt-debugfs-abi.h"
20 #define is_signed_type(type) (((type)(-1)) < 0)
24 struct lib_ring_buffer_ctx
;
26 struct perf_event_attr
;
28 /* Type description */
30 /* Update the astract_types name table in lttng-types.c along with this enum */
40 /* Update the string_encodings name table in lttng-types.c along with this enum */
41 enum lttng_string_encodings
{
42 lttng_encode_none
= 0,
43 lttng_encode_UTF8
= 1,
44 lttng_encode_ASCII
= 2,
48 struct lttng_enum_entry
{
49 unsigned long long start
, end
; /* start and end are inclusive */
53 #define __type_integer(_type, _byte_order, _base, _encoding) \
55 .atype = atype_integer, \
58 .size = sizeof(_type) * CHAR_BIT, \
59 .alignment = ltt_alignof(_type) * CHAR_BIT, \
60 .signedness = is_signed_type(_type), \
61 .reverse_byte_order = _byte_order != __BYTE_ORDER, \
63 .encoding = lttng_encode_##_encoding, \
67 struct 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;
72 unsigned int base
; /* 2, 8, 10, 16, for pretty print */
73 enum lttng_string_encodings encoding
;
76 union _lttng_basic_type
{
77 struct lttng_integer_type integer
;
82 enum lttng_string_encodings encoding
;
86 struct lttng_basic_type
{
87 enum abstract_types atype
;
89 union _lttng_basic_type basic
;
94 enum abstract_types atype
;
96 union _lttng_basic_type basic
;
98 struct lttng_basic_type elem_type
;
99 unsigned int length
; /* num. elems. */
102 struct lttng_basic_type length_type
;
103 struct lttng_basic_type elem_type
;
110 struct lttng_type container_type
;
111 const struct lttng_enum_entry
*entries
;
115 /* Event field description */
117 struct lttng_event_field
{
119 struct lttng_type type
;
122 struct lttng_ctx_field
{
123 struct lttng_event_field event_field
;
124 size_t (*get_size
)(size_t offset
);
125 void (*record
)(struct lttng_ctx_field
*field
,
126 struct lib_ring_buffer_ctx
*ctx
,
127 struct ltt_channel
*chan
);
130 struct perf_event
**e
; /* per-cpu array */
131 struct notifier_block nb
;
133 struct perf_event_attr
*attr
;
136 void (*destroy
)(struct lttng_ctx_field
*field
);
140 struct lttng_ctx_field
*fields
;
141 unsigned int nr_fields
;
142 unsigned int allocated_fields
;
145 struct lttng_event_desc
{
147 void *probe_callback
;
148 const struct lttng_event_ctx
*ctx
; /* context */
149 const struct lttng_event_field
*fields
; /* event payload */
150 unsigned int nr_fields
;
151 struct module
*owner
;
154 struct lttng_probe_desc
{
155 const struct lttng_event_desc
*event_desc
;
156 unsigned int nr_events
;
157 struct list_head head
; /* chain registered probes */
161 * ltt_event structure is referred to by the tracing fast path. It must be
166 struct ltt_channel
*chan
;
167 const struct lttng_event_desc
*desc
;
169 struct lttng_ctx
*ctx
;
170 enum lttng_kernel_instrumentation instrumentation
;
180 struct list_head list
; /* Event list */
181 int metadata_dumped
:1;
184 struct ltt_channel_ops
{
185 struct channel
*(*channel_create
)(const char *name
,
186 struct ltt_channel
*ltt_chan
,
188 size_t subbuf_size
, size_t num_subbuf
,
189 unsigned int switch_timer_interval
,
190 unsigned int read_timer_interval
);
191 void (*channel_destroy
)(struct channel
*chan
);
192 struct lib_ring_buffer
*(*buffer_read_open
)(struct channel
*chan
);
193 void (*buffer_read_close
)(struct lib_ring_buffer
*buf
);
194 int (*event_reserve
)(struct lib_ring_buffer_ctx
*ctx
,
196 void (*event_commit
)(struct lib_ring_buffer_ctx
*ctx
);
197 void (*event_write
)(struct lib_ring_buffer_ctx
*ctx
, const void *src
,
200 * packet_avail_size returns the available size in the current
201 * packet. Note that the size returned is only a hint, since it
202 * may change due to concurrent writes.
204 size_t (*packet_avail_size
)(struct channel
*chan
);
205 wait_queue_head_t
*(*get_reader_wait_queue
)(struct channel
*chan
);
206 wait_queue_head_t
*(*get_hp_wait_queue
)(struct channel
*chan
);
207 int (*is_finalized
)(struct channel
*chan
);
208 int (*is_disabled
)(struct channel
*chan
);
213 struct channel
*chan
; /* Channel buffers */
214 struct lttng_ctx
*ctx
;
215 /* Event ID management */
216 struct ltt_session
*session
;
217 struct file
*file
; /* File associated to channel */
218 unsigned int free_event_id
; /* Next event ID to allocate */
219 struct list_head list
; /* Channel list */
220 struct ltt_channel_ops
*ops
;
221 int header_type
; /* 0: unset, 1: compact, 2: large */
222 int metadata_dumped
:1;
226 int active
; /* Is trace session active ? */
227 int been_active
; /* Has trace session been active ? */
228 struct file
*file
; /* File associated to session */
229 struct ltt_channel
*metadata
; /* Metadata channel */
230 struct list_head chan
; /* Channel list head */
231 struct list_head events
; /* Event list head */
232 struct list_head list
; /* Session list */
233 unsigned int free_chan_id
; /* Next chan ID to allocate */
234 uuid_le uuid
; /* Trace session unique ID */
235 int metadata_dumped
:1;
238 struct ltt_transport
{
240 struct module
*owner
;
241 struct list_head node
;
242 struct ltt_channel_ops ops
;
245 struct ltt_session
*ltt_session_create(void);
246 int ltt_session_start(struct ltt_session
*session
);
247 int ltt_session_stop(struct ltt_session
*session
);
248 void ltt_session_destroy(struct ltt_session
*session
);
250 struct ltt_channel
*ltt_channel_create(struct ltt_session
*session
,
251 const char *transport_name
,
253 size_t subbuf_size
, size_t num_subbuf
,
254 unsigned int switch_timer_interval
,
255 unsigned int read_timer_interval
);
256 struct ltt_channel
*ltt_global_channel_create(struct ltt_session
*session
,
257 int overwrite
, void *buf_addr
,
258 size_t subbuf_size
, size_t num_subbuf
,
259 unsigned int switch_timer_interval
,
260 unsigned int read_timer_interval
);
262 struct ltt_event
*ltt_event_create(struct ltt_channel
*chan
,
263 struct lttng_kernel_event
*event_param
,
266 void ltt_transport_register(struct ltt_transport
*transport
);
267 void ltt_transport_unregister(struct ltt_transport
*transport
);
269 int ltt_debugfs_abi_init(void);
270 void ltt_debugfs_abi_exit(void);
272 int ltt_probe_register(struct lttng_probe_desc
*desc
);
273 void ltt_probe_unregister(struct lttng_probe_desc
*desc
);
274 const struct lttng_event_desc
*ltt_event_get(const char *name
);
275 void ltt_event_put(const struct lttng_event_desc
*desc
);
276 int ltt_probes_init(void);
277 void ltt_probes_exit(void);
278 struct lttng_ctx_field
*lttng_append_context(struct lttng_ctx
**ctx
);
279 void lttng_remove_context_field(struct lttng_ctx
**ctx
,
280 struct lttng_ctx_field
*field
);
281 void lttng_destroy_context(struct lttng_ctx
*ctx
);
282 int lttng_add_pid_to_ctx(struct lttng_ctx
**ctx
);
283 int lttng_add_comm_to_ctx(struct lttng_ctx
**ctx
);
284 int lttng_add_prio_to_ctx(struct lttng_ctx
**ctx
);
285 int lttng_add_nice_to_ctx(struct lttng_ctx
**ctx
);
286 int lttng_add_perf_counter_to_ctx(uint32_t type
,
289 struct lttng_ctx
**ctx
);
291 #ifdef CONFIG_KPROBES
292 int lttng_kprobes_register(const char *name
,
293 const char *symbol_name
,
296 struct ltt_event
*event
);
297 void lttng_kprobes_unregister(struct ltt_event
*event
);
298 void lttng_kprobes_destroy_private(struct ltt_event
*event
);
301 int lttng_kprobes_register(const char *name
,
302 const char *symbol_name
,
305 struct ltt_event
*event
)
311 void lttng_kprobes_unregister(struct ltt_event
*event
)
316 void lttng_kprobes_destroy_private(struct ltt_event
*event
)
321 #ifdef CONFIG_DYNAMIC_FTRACE
322 int lttng_ftrace_register(const char *name
,
323 const char *symbol_name
,
324 struct ltt_event
*event
);
325 void lttng_ftrace_unregister(struct ltt_event
*event
);
326 void lttng_ftrace_destroy_private(struct ltt_event
*event
);
329 int lttng_ftrace_register(const char *name
,
330 const char *symbol_name
,
331 struct ltt_event
*event
)
337 void lttng_ftrace_unregister(struct ltt_event
*event
)
342 void lttng_ftrace_destroy_private(struct ltt_event
*event
)
347 extern const struct file_operations lttng_tracepoint_list_fops
;
349 #endif /* _LTT_EVENTS_H */