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/kprobes.h>
16 #include "wrapper/uuid.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
;
123 * We need to keep this perf counter field separately from struct
124 * lttng_ctx_field because cpu hotplug needs fixed-location addresses.
126 struct lttng_perf_counter_field
{
127 struct notifier_block nb
;
129 struct perf_event_attr
*attr
;
130 struct perf_event
**e
; /* per-cpu array */
133 struct lttng_ctx_field
{
134 struct lttng_event_field event_field
;
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
);
140 struct lttng_perf_counter_field
*perf_counter
;
142 void (*destroy
)(struct lttng_ctx_field
*field
);
146 struct lttng_ctx_field
*fields
;
147 unsigned int nr_fields
;
148 unsigned int allocated_fields
;
151 struct lttng_event_desc
{
153 void *probe_callback
;
154 const struct lttng_event_ctx
*ctx
; /* context */
155 const struct lttng_event_field
*fields
; /* event payload */
156 unsigned int nr_fields
;
157 struct module
*owner
;
160 struct lttng_probe_desc
{
161 const struct lttng_event_desc
**event_desc
;
162 unsigned int nr_events
;
163 struct list_head head
; /* chain registered probes */
166 struct lttng_krp
; /* Kretprobe handling */
169 * ltt_event structure is referred to by the tracing fast path. It must be
174 struct ltt_channel
*chan
;
176 const struct lttng_event_desc
*desc
;
178 struct lttng_ctx
*ctx
;
179 enum lttng_kernel_instrumentation instrumentation
;
186 struct lttng_krp
*lttng_krp
;
193 struct list_head list
; /* Event list */
194 int metadata_dumped
:1;
197 struct ltt_channel_ops
{
198 struct channel
*(*channel_create
)(const char *name
,
199 struct ltt_channel
*ltt_chan
,
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
);
206 int (*buffer_has_read_closed_stream
)(struct channel
*chan
);
207 void (*buffer_read_close
)(struct lib_ring_buffer
*buf
);
208 int (*event_reserve
)(struct lib_ring_buffer_ctx
*ctx
,
210 void (*event_commit
)(struct lib_ring_buffer_ctx
*ctx
);
211 void (*event_write
)(struct lib_ring_buffer_ctx
*ctx
, const void *src
,
213 void (*event_write_from_user
)(struct lib_ring_buffer_ctx
*ctx
,
214 const void *src
, size_t len
);
215 void (*event_memset
)(struct lib_ring_buffer_ctx
*ctx
,
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.
222 size_t (*packet_avail_size
)(struct channel
*chan
);
223 wait_queue_head_t
*(*get_writer_buf_wait_queue
)(struct channel
*chan
, int cpu
);
224 wait_queue_head_t
*(*get_hp_wait_queue
)(struct channel
*chan
);
225 int (*is_finalized
)(struct channel
*chan
);
226 int (*is_disabled
)(struct channel
*chan
);
229 struct ltt_transport
{
231 struct module
*owner
;
232 struct list_head node
;
233 struct ltt_channel_ops ops
;
238 struct channel
*chan
; /* Channel buffers */
240 struct lttng_ctx
*ctx
;
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 */
246 struct ltt_channel_ops
*ops
;
247 struct ltt_transport
*transport
;
248 struct ltt_event
**sc_table
; /* for syscall tracing */
249 struct ltt_event
*sc_unknown
; /* for unknown syscalls */
250 struct ltt_event
*sc_compat_unknown
;
251 struct ltt_event
*sc_exit
; /* for syscall exit */
252 int header_type
; /* 0: unset, 1: compact, 2: large */
253 int metadata_dumped
:1;
257 int active
; /* Is trace session active ? */
258 int been_active
; /* Has trace session been active ? */
259 struct file
*file
; /* File associated to session */
260 struct ltt_channel
*metadata
; /* Metadata channel */
261 struct list_head chan
; /* Channel list head */
262 struct list_head events
; /* Event list head */
263 struct list_head list
; /* Session list */
264 unsigned int free_chan_id
; /* Next chan ID to allocate */
265 uuid_le uuid
; /* Trace session unique ID */
266 int metadata_dumped
:1;
269 struct ltt_session
*ltt_session_create(void);
270 int ltt_session_enable(struct ltt_session
*session
);
271 int ltt_session_disable(struct ltt_session
*session
);
272 void ltt_session_destroy(struct ltt_session
*session
);
274 struct ltt_channel
*ltt_channel_create(struct ltt_session
*session
,
275 const char *transport_name
,
277 size_t subbuf_size
, size_t num_subbuf
,
278 unsigned int switch_timer_interval
,
279 unsigned int read_timer_interval
);
280 struct ltt_channel
*ltt_global_channel_create(struct ltt_session
*session
,
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
);
286 struct ltt_event
*ltt_event_create(struct ltt_channel
*chan
,
287 struct lttng_kernel_event
*event_param
,
289 const struct lttng_event_desc
*internal_desc
);
291 int ltt_channel_enable(struct ltt_channel
*channel
);
292 int ltt_channel_disable(struct ltt_channel
*channel
);
293 int ltt_event_enable(struct ltt_event
*event
);
294 int ltt_event_disable(struct ltt_event
*event
);
296 void ltt_transport_register(struct ltt_transport
*transport
);
297 void ltt_transport_unregister(struct ltt_transport
*transport
);
299 void synchronize_trace(void);
300 int ltt_debugfs_abi_init(void);
301 void ltt_debugfs_abi_exit(void);
303 int ltt_probe_register(struct lttng_probe_desc
*desc
);
304 void ltt_probe_unregister(struct lttng_probe_desc
*desc
);
305 const struct lttng_event_desc
*ltt_event_get(const char *name
);
306 void ltt_event_put(const struct lttng_event_desc
*desc
);
307 int ltt_probes_init(void);
308 void ltt_probes_exit(void);
310 #ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
311 int lttng_syscalls_register(struct ltt_channel
*chan
, void *filter
);
312 int lttng_syscalls_unregister(struct ltt_channel
*chan
);
314 static inline int lttng_syscalls_register(struct ltt_channel
*chan
, void *filter
)
319 static inline int lttng_syscalls_unregister(struct ltt_channel
*chan
)
325 struct lttng_ctx_field
*lttng_append_context(struct lttng_ctx
**ctx
);
326 int lttng_find_context(struct lttng_ctx
*ctx
, const char *name
);
327 void lttng_remove_context_field(struct lttng_ctx
**ctx
,
328 struct lttng_ctx_field
*field
);
329 void lttng_destroy_context(struct lttng_ctx
*ctx
);
330 int lttng_add_pid_to_ctx(struct lttng_ctx
**ctx
);
331 int lttng_add_comm_to_ctx(struct lttng_ctx
**ctx
);
332 int lttng_add_prio_to_ctx(struct lttng_ctx
**ctx
);
333 int lttng_add_nice_to_ctx(struct lttng_ctx
**ctx
);
334 int lttng_add_vpid_to_ctx(struct lttng_ctx
**ctx
);
335 int lttng_add_tid_to_ctx(struct lttng_ctx
**ctx
);
336 int lttng_add_vtid_to_ctx(struct lttng_ctx
**ctx
);
337 int lttng_add_ppid_to_ctx(struct lttng_ctx
**ctx
);
338 int lttng_add_vppid_to_ctx(struct lttng_ctx
**ctx
);
339 #if defined(CONFIG_PERF_EVENTS) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33))
340 int lttng_add_perf_counter_to_ctx(uint32_t type
,
343 struct lttng_ctx
**ctx
);
346 int lttng_add_perf_counter_to_ctx(uint32_t type
,
349 struct lttng_ctx
**ctx
)
355 #ifdef CONFIG_KPROBES
356 int lttng_kprobes_register(const char *name
,
357 const char *symbol_name
,
360 struct ltt_event
*event
);
361 void lttng_kprobes_unregister(struct ltt_event
*event
);
362 void lttng_kprobes_destroy_private(struct ltt_event
*event
);
365 int lttng_kprobes_register(const char *name
,
366 const char *symbol_name
,
369 struct ltt_event
*event
)
375 void lttng_kprobes_unregister(struct ltt_event
*event
)
380 void lttng_kprobes_destroy_private(struct ltt_event
*event
)
385 #ifdef CONFIG_KRETPROBES
386 int lttng_kretprobes_register(const char *name
,
387 const char *symbol_name
,
390 struct ltt_event
*event_entry
,
391 struct ltt_event
*event_exit
);
392 void lttng_kretprobes_unregister(struct ltt_event
*event
);
393 void lttng_kretprobes_destroy_private(struct ltt_event
*event
);
396 int lttng_kretprobes_register(const char *name
,
397 const char *symbol_name
,
400 struct ltt_event
*event_entry
,
401 struct ltt_event
*event_exit
)
407 void lttng_kretprobes_unregister(struct ltt_event
*event
)
412 void lttng_kretprobes_destroy_private(struct ltt_event
*event
)
417 #ifdef CONFIG_DYNAMIC_FTRACE
418 int lttng_ftrace_register(const char *name
,
419 const char *symbol_name
,
420 struct ltt_event
*event
);
421 void lttng_ftrace_unregister(struct ltt_event
*event
);
422 void lttng_ftrace_destroy_private(struct ltt_event
*event
);
425 int lttng_ftrace_register(const char *name
,
426 const char *symbol_name
,
427 struct ltt_event
*event
)
433 void lttng_ftrace_unregister(struct ltt_event
*event
)
438 void lttng_ftrace_destroy_private(struct ltt_event
*event
)
443 int lttng_calibrate(struct lttng_kernel_calibrate
*calibrate
);
445 extern const struct file_operations lttng_tracepoint_list_fops
;
447 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
448 #define TRACEPOINT_HAS_DATA_ARG
451 #endif /* _LTT_EVENTS_H */