1 #ifndef _LTTNG_EVENTS_H
2 #define _LTTNG_EVENTS_H
7 * Holds LTTng per-session event registry.
9 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; only
14 * version 2.1 of the License.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 #include <linux/list.h>
27 #include <linux/kprobes.h>
28 #include "wrapper/uuid.h"
29 #include "lttng-abi.h"
32 #define is_signed_type(type) (((type)(-1)) < 0)
36 struct lib_ring_buffer_ctx
;
38 struct perf_event_attr
;
40 /* Type description */
42 /* Update the astract_types name table in lttng-types.c along with this enum */
52 /* Update the string_encodings name table in lttng-types.c along with this enum */
53 enum lttng_string_encodings
{
54 lttng_encode_none
= 0,
55 lttng_encode_UTF8
= 1,
56 lttng_encode_ASCII
= 2,
60 struct lttng_enum_entry
{
61 unsigned long long start
, end
; /* start and end are inclusive */
65 #define __type_integer(_type, _byte_order, _base, _encoding) \
67 .atype = atype_integer, \
70 .size = sizeof(_type) * CHAR_BIT, \
71 .alignment = lttng_alignof(_type) * CHAR_BIT, \
72 .signedness = is_signed_type(_type), \
73 .reverse_byte_order = _byte_order != __BYTE_ORDER, \
75 .encoding = lttng_encode_##_encoding, \
79 struct lttng_integer_type {
80 unsigned int size
; /* in bits */
81 unsigned short alignment
; /* in bits */
82 unsigned int signedness
:1,
84 unsigned int base
; /* 2, 8, 10, 16, for pretty print */
85 enum lttng_string_encodings encoding
;
88 union _lttng_basic_type
{
89 struct lttng_integer_type integer
;
94 enum lttng_string_encodings encoding
;
98 struct lttng_basic_type
{
99 enum abstract_types atype
;
101 union _lttng_basic_type basic
;
106 enum abstract_types atype
;
108 union _lttng_basic_type basic
;
110 struct lttng_basic_type elem_type
;
111 unsigned int length
; /* num. elems. */
114 struct lttng_basic_type length_type
;
115 struct lttng_basic_type elem_type
;
122 struct lttng_type container_type
;
123 const struct lttng_enum_entry
*entries
;
127 /* Event field description */
129 struct lttng_event_field
{
131 struct lttng_type type
;
135 * We need to keep this perf counter field separately from struct
136 * lttng_ctx_field because cpu hotplug needs fixed-location addresses.
138 struct lttng_perf_counter_field
{
139 struct notifier_block nb
;
141 struct perf_event_attr
*attr
;
142 struct perf_event
**e
; /* per-cpu array */
145 struct lttng_ctx_field
{
146 struct lttng_event_field event_field
;
147 size_t (*get_size
)(size_t offset
);
148 void (*record
)(struct lttng_ctx_field
*field
,
149 struct lib_ring_buffer_ctx
*ctx
,
150 struct lttng_channel
*chan
);
152 struct lttng_perf_counter_field
*perf_counter
;
154 void (*destroy
)(struct lttng_ctx_field
*field
);
158 struct lttng_ctx_field
*fields
;
159 unsigned int nr_fields
;
160 unsigned int allocated_fields
;
163 struct lttng_event_desc
{
165 void *probe_callback
;
166 const struct lttng_event_ctx
*ctx
; /* context */
167 const struct lttng_event_field
*fields
; /* event payload */
168 unsigned int nr_fields
;
169 struct module
*owner
;
172 struct lttng_probe_desc
{
173 const struct lttng_event_desc
**event_desc
;
174 unsigned int nr_events
;
175 struct list_head head
; /* chain registered probes */
178 struct lttng_krp
; /* Kretprobe handling */
181 * lttng_event structure is referred to by the tracing fast path. It must be
186 struct lttng_channel
*chan
;
188 const struct lttng_event_desc
*desc
;
190 struct lttng_ctx
*ctx
;
191 enum lttng_kernel_instrumentation instrumentation
;
198 struct lttng_krp
*lttng_krp
;
205 struct list_head list
; /* Event list */
206 unsigned int metadata_dumped
:1;
209 struct lttng_channel_ops
{
210 struct channel
*(*channel_create
)(const char *name
,
211 struct lttng_channel
*lttng_chan
,
213 size_t subbuf_size
, size_t num_subbuf
,
214 unsigned int switch_timer_interval
,
215 unsigned int read_timer_interval
);
216 void (*channel_destroy
)(struct channel
*chan
);
217 struct lib_ring_buffer
*(*buffer_read_open
)(struct channel
*chan
);
218 int (*buffer_has_read_closed_stream
)(struct channel
*chan
);
219 void (*buffer_read_close
)(struct lib_ring_buffer
*buf
);
220 int (*event_reserve
)(struct lib_ring_buffer_ctx
*ctx
,
222 void (*event_commit
)(struct lib_ring_buffer_ctx
*ctx
);
223 void (*event_write
)(struct lib_ring_buffer_ctx
*ctx
, const void *src
,
225 void (*event_write_from_user
)(struct lib_ring_buffer_ctx
*ctx
,
226 const void *src
, size_t len
);
227 void (*event_memset
)(struct lib_ring_buffer_ctx
*ctx
,
230 * packet_avail_size returns the available size in the current
231 * packet. Note that the size returned is only a hint, since it
232 * may change due to concurrent writes.
234 size_t (*packet_avail_size
)(struct channel
*chan
);
235 wait_queue_head_t
*(*get_writer_buf_wait_queue
)(struct channel
*chan
, int cpu
);
236 wait_queue_head_t
*(*get_hp_wait_queue
)(struct channel
*chan
);
237 int (*is_finalized
)(struct channel
*chan
);
238 int (*is_disabled
)(struct channel
*chan
);
241 struct lttng_transport
{
243 struct module
*owner
;
244 struct list_head node
;
245 struct lttng_channel_ops ops
;
248 struct lttng_channel
{
250 struct channel
*chan
; /* Channel buffers */
252 struct lttng_ctx
*ctx
;
253 /* Event ID management */
254 struct lttng_session
*session
;
255 struct file
*file
; /* File associated to channel */
256 unsigned int free_event_id
; /* Next event ID to allocate */
257 struct list_head list
; /* Channel list */
258 struct lttng_channel_ops
*ops
;
259 struct lttng_transport
*transport
;
260 struct lttng_event
**sc_table
; /* for syscall tracing */
261 struct lttng_event
**compat_sc_table
;
262 struct lttng_event
*sc_unknown
; /* for unknown syscalls */
263 struct lttng_event
*sc_compat_unknown
;
264 struct lttng_event
*sc_exit
; /* for syscall exit */
265 int header_type
; /* 0: unset, 1: compact, 2: large */
266 unsigned int metadata_dumped
:1;
269 struct lttng_session
{
270 int active
; /* Is trace session active ? */
271 int been_active
; /* Has trace session been active ? */
272 struct file
*file
; /* File associated to session */
273 struct lttng_channel
*metadata
; /* Metadata channel */
274 struct list_head chan
; /* Channel list head */
275 struct list_head events
; /* Event list head */
276 struct list_head list
; /* Session list */
277 unsigned int free_chan_id
; /* Next chan ID to allocate */
278 uuid_le uuid
; /* Trace session unique ID */
279 unsigned int metadata_dumped
:1;
282 struct lttng_session
*lttng_session_create(void);
283 int lttng_session_enable(struct lttng_session
*session
);
284 int lttng_session_disable(struct lttng_session
*session
);
285 void lttng_session_destroy(struct lttng_session
*session
);
287 struct lttng_channel
*lttng_channel_create(struct lttng_session
*session
,
288 const char *transport_name
,
290 size_t subbuf_size
, size_t num_subbuf
,
291 unsigned int switch_timer_interval
,
292 unsigned int read_timer_interval
);
293 struct lttng_channel
*lttng_global_channel_create(struct lttng_session
*session
,
294 int overwrite
, void *buf_addr
,
295 size_t subbuf_size
, size_t num_subbuf
,
296 unsigned int switch_timer_interval
,
297 unsigned int read_timer_interval
);
299 struct lttng_event
*lttng_event_create(struct lttng_channel
*chan
,
300 struct lttng_kernel_event
*event_param
,
302 const struct lttng_event_desc
*internal_desc
);
304 int lttng_channel_enable(struct lttng_channel
*channel
);
305 int lttng_channel_disable(struct lttng_channel
*channel
);
306 int lttng_event_enable(struct lttng_event
*event
);
307 int lttng_event_disable(struct lttng_event
*event
);
309 void lttng_transport_register(struct lttng_transport
*transport
);
310 void lttng_transport_unregister(struct lttng_transport
*transport
);
312 void synchronize_trace(void);
313 int lttng_abi_init(void);
314 void lttng_abi_exit(void);
316 int lttng_probe_register(struct lttng_probe_desc
*desc
);
317 void lttng_probe_unregister(struct lttng_probe_desc
*desc
);
318 const struct lttng_event_desc
*lttng_event_get(const char *name
);
319 void lttng_event_put(const struct lttng_event_desc
*desc
);
320 int lttng_probes_init(void);
321 void lttng_probes_exit(void);
323 #ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
324 int lttng_syscalls_register(struct lttng_channel
*chan
, void *filter
);
325 int lttng_syscalls_unregister(struct lttng_channel
*chan
);
327 static inline int lttng_syscalls_register(struct lttng_channel
*chan
, void *filter
)
332 static inline int lttng_syscalls_unregister(struct lttng_channel
*chan
)
338 struct lttng_ctx_field
*lttng_append_context(struct lttng_ctx
**ctx
);
339 int lttng_find_context(struct lttng_ctx
*ctx
, const char *name
);
340 void lttng_remove_context_field(struct lttng_ctx
**ctx
,
341 struct lttng_ctx_field
*field
);
342 void lttng_destroy_context(struct lttng_ctx
*ctx
);
343 int lttng_add_pid_to_ctx(struct lttng_ctx
**ctx
);
344 int lttng_add_procname_to_ctx(struct lttng_ctx
**ctx
);
345 int lttng_add_prio_to_ctx(struct lttng_ctx
**ctx
);
346 int lttng_add_nice_to_ctx(struct lttng_ctx
**ctx
);
347 int lttng_add_vpid_to_ctx(struct lttng_ctx
**ctx
);
348 int lttng_add_tid_to_ctx(struct lttng_ctx
**ctx
);
349 int lttng_add_vtid_to_ctx(struct lttng_ctx
**ctx
);
350 int lttng_add_ppid_to_ctx(struct lttng_ctx
**ctx
);
351 int lttng_add_vppid_to_ctx(struct lttng_ctx
**ctx
);
352 #if defined(CONFIG_PERF_EVENTS) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33))
353 int lttng_add_perf_counter_to_ctx(uint32_t type
,
356 struct lttng_ctx
**ctx
);
359 int lttng_add_perf_counter_to_ctx(uint32_t type
,
362 struct lttng_ctx
**ctx
)
368 extern int lttng_statedump_start(struct lttng_session
*session
);
370 #ifdef CONFIG_KPROBES
371 int lttng_kprobes_register(const char *name
,
372 const char *symbol_name
,
375 struct lttng_event
*event
);
376 void lttng_kprobes_unregister(struct lttng_event
*event
);
377 void lttng_kprobes_destroy_private(struct lttng_event
*event
);
380 int lttng_kprobes_register(const char *name
,
381 const char *symbol_name
,
384 struct lttng_event
*event
)
390 void lttng_kprobes_unregister(struct lttng_event
*event
)
395 void lttng_kprobes_destroy_private(struct lttng_event
*event
)
400 #ifdef CONFIG_KRETPROBES
401 int lttng_kretprobes_register(const char *name
,
402 const char *symbol_name
,
405 struct lttng_event
*event_entry
,
406 struct lttng_event
*event_exit
);
407 void lttng_kretprobes_unregister(struct lttng_event
*event
);
408 void lttng_kretprobes_destroy_private(struct lttng_event
*event
);
411 int lttng_kretprobes_register(const char *name
,
412 const char *symbol_name
,
415 struct lttng_event
*event_entry
,
416 struct lttng_event
*event_exit
)
422 void lttng_kretprobes_unregister(struct lttng_event
*event
)
427 void lttng_kretprobes_destroy_private(struct lttng_event
*event
)
432 #ifdef CONFIG_DYNAMIC_FTRACE
433 int lttng_ftrace_register(const char *name
,
434 const char *symbol_name
,
435 struct lttng_event
*event
);
436 void lttng_ftrace_unregister(struct lttng_event
*event
);
437 void lttng_ftrace_destroy_private(struct lttng_event
*event
);
440 int lttng_ftrace_register(const char *name
,
441 const char *symbol_name
,
442 struct lttng_event
*event
)
448 void lttng_ftrace_unregister(struct lttng_event
*event
)
453 void lttng_ftrace_destroy_private(struct lttng_event
*event
)
458 int lttng_calibrate(struct lttng_kernel_calibrate
*calibrate
);
460 extern const struct file_operations lttng_tracepoint_list_fops
;
462 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
463 #define TRACEPOINT_HAS_DATA_ARG
466 #endif /* _LTTNG_EVENTS_H */