| 1 | #ifndef _LTTNG_EVENTS_H |
| 2 | #define _LTTNG_EVENTS_H |
| 3 | |
| 4 | /* |
| 5 | * lttng-events.h |
| 6 | * |
| 7 | * Copyright 2010-2011 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 8 | * |
| 9 | * Holds LTTng per-session event registry. |
| 10 | * |
| 11 | * Dual LGPL v2.1/GPL v2 license. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/list.h> |
| 15 | #include <linux/kprobes.h> |
| 16 | #include "wrapper/uuid.h" |
| 17 | #include "lttng-abi.h" |
| 18 | |
| 19 | #undef is_signed_type |
| 20 | #define is_signed_type(type) (((type)(-1)) < 0) |
| 21 | |
| 22 | struct lttng_channel; |
| 23 | struct lttng_session; |
| 24 | struct lib_ring_buffer_ctx; |
| 25 | struct perf_event; |
| 26 | struct perf_event_attr; |
| 27 | |
| 28 | /* Type description */ |
| 29 | |
| 30 | /* Update the astract_types name table in lttng-types.c along with this enum */ |
| 31 | enum abstract_types { |
| 32 | atype_integer, |
| 33 | atype_enum, |
| 34 | atype_array, |
| 35 | atype_sequence, |
| 36 | atype_string, |
| 37 | NR_ABSTRACT_TYPES, |
| 38 | }; |
| 39 | |
| 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, |
| 45 | NR_STRING_ENCODINGS, |
| 46 | }; |
| 47 | |
| 48 | struct lttng_enum_entry { |
| 49 | unsigned long long start, end; /* start and end are inclusive */ |
| 50 | const char *string; |
| 51 | }; |
| 52 | |
| 53 | #define __type_integer(_type, _byte_order, _base, _encoding) \ |
| 54 | { \ |
| 55 | .atype = atype_integer, \ |
| 56 | .u.basic.integer = \ |
| 57 | { \ |
| 58 | .size = sizeof(_type) * CHAR_BIT, \ |
| 59 | .alignment = lttng_alignof(_type) * CHAR_BIT, \ |
| 60 | .signedness = is_signed_type(_type), \ |
| 61 | .reverse_byte_order = _byte_order != __BYTE_ORDER, \ |
| 62 | .base = _base, \ |
| 63 | .encoding = lttng_encode_##_encoding, \ |
| 64 | }, \ |
| 65 | } \ |
| 66 | |
| 67 | struct lttng_integer_type { |
| 68 | unsigned int size; /* in bits */ |
| 69 | unsigned short alignment; /* in bits */ |
| 70 | unsigned int signedness:1, |
| 71 | reverse_byte_order:1; |
| 72 | unsigned int base; /* 2, 8, 10, 16, for pretty print */ |
| 73 | enum lttng_string_encodings encoding; |
| 74 | }; |
| 75 | |
| 76 | union _lttng_basic_type { |
| 77 | struct lttng_integer_type integer; |
| 78 | struct { |
| 79 | const char *name; |
| 80 | } enumeration; |
| 81 | struct { |
| 82 | enum lttng_string_encodings encoding; |
| 83 | } string; |
| 84 | }; |
| 85 | |
| 86 | struct lttng_basic_type { |
| 87 | enum abstract_types atype; |
| 88 | union { |
| 89 | union _lttng_basic_type basic; |
| 90 | } u; |
| 91 | }; |
| 92 | |
| 93 | struct lttng_type { |
| 94 | enum abstract_types atype; |
| 95 | union { |
| 96 | union _lttng_basic_type basic; |
| 97 | struct { |
| 98 | struct lttng_basic_type elem_type; |
| 99 | unsigned int length; /* num. elems. */ |
| 100 | } array; |
| 101 | struct { |
| 102 | struct lttng_basic_type length_type; |
| 103 | struct lttng_basic_type elem_type; |
| 104 | } sequence; |
| 105 | } u; |
| 106 | }; |
| 107 | |
| 108 | struct lttng_enum { |
| 109 | const char *name; |
| 110 | struct lttng_type container_type; |
| 111 | const struct lttng_enum_entry *entries; |
| 112 | unsigned int len; |
| 113 | }; |
| 114 | |
| 115 | /* Event field description */ |
| 116 | |
| 117 | struct lttng_event_field { |
| 118 | const char *name; |
| 119 | struct lttng_type type; |
| 120 | }; |
| 121 | |
| 122 | /* |
| 123 | * We need to keep this perf counter field separately from struct |
| 124 | * lttng_ctx_field because cpu hotplug needs fixed-location addresses. |
| 125 | */ |
| 126 | struct lttng_perf_counter_field { |
| 127 | struct notifier_block nb; |
| 128 | int hp_enable; |
| 129 | struct perf_event_attr *attr; |
| 130 | struct perf_event **e; /* per-cpu array */ |
| 131 | }; |
| 132 | |
| 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 lttng_channel *chan); |
| 139 | union { |
| 140 | struct lttng_perf_counter_field *perf_counter; |
| 141 | } u; |
| 142 | void (*destroy)(struct lttng_ctx_field *field); |
| 143 | }; |
| 144 | |
| 145 | struct lttng_ctx { |
| 146 | struct lttng_ctx_field *fields; |
| 147 | unsigned int nr_fields; |
| 148 | unsigned int allocated_fields; |
| 149 | }; |
| 150 | |
| 151 | struct lttng_event_desc { |
| 152 | const char *name; |
| 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; |
| 158 | }; |
| 159 | |
| 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 */ |
| 164 | }; |
| 165 | |
| 166 | struct lttng_krp; /* Kretprobe handling */ |
| 167 | |
| 168 | /* |
| 169 | * lttng_event structure is referred to by the tracing fast path. It must be |
| 170 | * kept small. |
| 171 | */ |
| 172 | struct lttng_event { |
| 173 | unsigned int id; |
| 174 | struct lttng_channel *chan; |
| 175 | int enabled; |
| 176 | const struct lttng_event_desc *desc; |
| 177 | void *filter; |
| 178 | struct lttng_ctx *ctx; |
| 179 | enum lttng_kernel_instrumentation instrumentation; |
| 180 | union { |
| 181 | struct { |
| 182 | struct kprobe kp; |
| 183 | char *symbol_name; |
| 184 | } kprobe; |
| 185 | struct { |
| 186 | struct lttng_krp *lttng_krp; |
| 187 | char *symbol_name; |
| 188 | } kretprobe; |
| 189 | struct { |
| 190 | char *symbol_name; |
| 191 | } ftrace; |
| 192 | } u; |
| 193 | struct list_head list; /* Event list */ |
| 194 | unsigned int metadata_dumped:1; |
| 195 | }; |
| 196 | |
| 197 | struct lttng_channel_ops { |
| 198 | struct channel *(*channel_create)(const char *name, |
| 199 | struct lttng_channel *lttng_chan, |
| 200 | void *buf_addr, |
| 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, |
| 209 | uint32_t event_id); |
| 210 | void (*event_commit)(struct lib_ring_buffer_ctx *ctx); |
| 211 | void (*event_write)(struct lib_ring_buffer_ctx *ctx, const void *src, |
| 212 | size_t len); |
| 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, |
| 216 | int c, size_t len); |
| 217 | /* |
| 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. |
| 221 | */ |
| 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); |
| 227 | }; |
| 228 | |
| 229 | struct lttng_transport { |
| 230 | char *name; |
| 231 | struct module *owner; |
| 232 | struct list_head node; |
| 233 | struct lttng_channel_ops ops; |
| 234 | }; |
| 235 | |
| 236 | struct lttng_channel { |
| 237 | unsigned int id; |
| 238 | struct channel *chan; /* Channel buffers */ |
| 239 | int enabled; |
| 240 | struct lttng_ctx *ctx; |
| 241 | /* Event ID management */ |
| 242 | struct lttng_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 lttng_channel_ops *ops; |
| 247 | struct lttng_transport *transport; |
| 248 | struct lttng_event **sc_table; /* for syscall tracing */ |
| 249 | struct lttng_event **compat_sc_table; |
| 250 | struct lttng_event *sc_unknown; /* for unknown syscalls */ |
| 251 | struct lttng_event *sc_compat_unknown; |
| 252 | struct lttng_event *sc_exit; /* for syscall exit */ |
| 253 | int header_type; /* 0: unset, 1: compact, 2: large */ |
| 254 | unsigned int metadata_dumped:1; |
| 255 | }; |
| 256 | |
| 257 | struct lttng_session { |
| 258 | int active; /* Is trace session active ? */ |
| 259 | int been_active; /* Has trace session been active ? */ |
| 260 | struct file *file; /* File associated to session */ |
| 261 | struct lttng_channel *metadata; /* Metadata channel */ |
| 262 | struct list_head chan; /* Channel list head */ |
| 263 | struct list_head events; /* Event list head */ |
| 264 | struct list_head list; /* Session list */ |
| 265 | unsigned int free_chan_id; /* Next chan ID to allocate */ |
| 266 | uuid_le uuid; /* Trace session unique ID */ |
| 267 | unsigned int metadata_dumped:1; |
| 268 | }; |
| 269 | |
| 270 | struct lttng_session *lttng_session_create(void); |
| 271 | int lttng_session_enable(struct lttng_session *session); |
| 272 | int lttng_session_disable(struct lttng_session *session); |
| 273 | void lttng_session_destroy(struct lttng_session *session); |
| 274 | |
| 275 | struct lttng_channel *lttng_channel_create(struct lttng_session *session, |
| 276 | const char *transport_name, |
| 277 | void *buf_addr, |
| 278 | size_t subbuf_size, size_t num_subbuf, |
| 279 | unsigned int switch_timer_interval, |
| 280 | unsigned int read_timer_interval); |
| 281 | struct lttng_channel *lttng_global_channel_create(struct lttng_session *session, |
| 282 | int overwrite, void *buf_addr, |
| 283 | size_t subbuf_size, size_t num_subbuf, |
| 284 | unsigned int switch_timer_interval, |
| 285 | unsigned int read_timer_interval); |
| 286 | |
| 287 | struct lttng_event *lttng_event_create(struct lttng_channel *chan, |
| 288 | struct lttng_kernel_event *event_param, |
| 289 | void *filter, |
| 290 | const struct lttng_event_desc *internal_desc); |
| 291 | |
| 292 | int lttng_channel_enable(struct lttng_channel *channel); |
| 293 | int lttng_channel_disable(struct lttng_channel *channel); |
| 294 | int lttng_event_enable(struct lttng_event *event); |
| 295 | int lttng_event_disable(struct lttng_event *event); |
| 296 | |
| 297 | void lttng_transport_register(struct lttng_transport *transport); |
| 298 | void lttng_transport_unregister(struct lttng_transport *transport); |
| 299 | |
| 300 | void synchronize_trace(void); |
| 301 | int lttng_abi_init(void); |
| 302 | void lttng_abi_exit(void); |
| 303 | |
| 304 | int lttng_probe_register(struct lttng_probe_desc *desc); |
| 305 | void lttng_probe_unregister(struct lttng_probe_desc *desc); |
| 306 | const struct lttng_event_desc *lttng_event_get(const char *name); |
| 307 | void lttng_event_put(const struct lttng_event_desc *desc); |
| 308 | int lttng_probes_init(void); |
| 309 | void lttng_probes_exit(void); |
| 310 | |
| 311 | #ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS |
| 312 | int lttng_syscalls_register(struct lttng_channel *chan, void *filter); |
| 313 | int lttng_syscalls_unregister(struct lttng_channel *chan); |
| 314 | #else |
| 315 | static inline int lttng_syscalls_register(struct lttng_channel *chan, void *filter) |
| 316 | { |
| 317 | return -ENOSYS; |
| 318 | } |
| 319 | |
| 320 | static inline int lttng_syscalls_unregister(struct lttng_channel *chan) |
| 321 | { |
| 322 | return 0; |
| 323 | } |
| 324 | #endif |
| 325 | |
| 326 | struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx); |
| 327 | int lttng_find_context(struct lttng_ctx *ctx, const char *name); |
| 328 | void lttng_remove_context_field(struct lttng_ctx **ctx, |
| 329 | struct lttng_ctx_field *field); |
| 330 | void lttng_destroy_context(struct lttng_ctx *ctx); |
| 331 | int lttng_add_pid_to_ctx(struct lttng_ctx **ctx); |
| 332 | int lttng_add_procname_to_ctx(struct lttng_ctx **ctx); |
| 333 | int lttng_add_prio_to_ctx(struct lttng_ctx **ctx); |
| 334 | int lttng_add_nice_to_ctx(struct lttng_ctx **ctx); |
| 335 | int lttng_add_vpid_to_ctx(struct lttng_ctx **ctx); |
| 336 | int lttng_add_tid_to_ctx(struct lttng_ctx **ctx); |
| 337 | int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx); |
| 338 | int lttng_add_ppid_to_ctx(struct lttng_ctx **ctx); |
| 339 | int lttng_add_vppid_to_ctx(struct lttng_ctx **ctx); |
| 340 | #if defined(CONFIG_PERF_EVENTS) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33)) |
| 341 | int lttng_add_perf_counter_to_ctx(uint32_t type, |
| 342 | uint64_t config, |
| 343 | const char *name, |
| 344 | struct lttng_ctx **ctx); |
| 345 | #else |
| 346 | static inline |
| 347 | int lttng_add_perf_counter_to_ctx(uint32_t type, |
| 348 | uint64_t config, |
| 349 | const char *name, |
| 350 | struct lttng_ctx **ctx) |
| 351 | { |
| 352 | return -ENOSYS; |
| 353 | } |
| 354 | #endif |
| 355 | |
| 356 | #ifdef CONFIG_KPROBES |
| 357 | int lttng_kprobes_register(const char *name, |
| 358 | const char *symbol_name, |
| 359 | uint64_t offset, |
| 360 | uint64_t addr, |
| 361 | struct lttng_event *event); |
| 362 | void lttng_kprobes_unregister(struct lttng_event *event); |
| 363 | void lttng_kprobes_destroy_private(struct lttng_event *event); |
| 364 | #else |
| 365 | static inline |
| 366 | int lttng_kprobes_register(const char *name, |
| 367 | const char *symbol_name, |
| 368 | uint64_t offset, |
| 369 | uint64_t addr, |
| 370 | struct lttng_event *event) |
| 371 | { |
| 372 | return -ENOSYS; |
| 373 | } |
| 374 | |
| 375 | static inline |
| 376 | void lttng_kprobes_unregister(struct lttng_event *event) |
| 377 | { |
| 378 | } |
| 379 | |
| 380 | static inline |
| 381 | void lttng_kprobes_destroy_private(struct lttng_event *event) |
| 382 | { |
| 383 | } |
| 384 | #endif |
| 385 | |
| 386 | #ifdef CONFIG_KRETPROBES |
| 387 | int lttng_kretprobes_register(const char *name, |
| 388 | const char *symbol_name, |
| 389 | uint64_t offset, |
| 390 | uint64_t addr, |
| 391 | struct lttng_event *event_entry, |
| 392 | struct lttng_event *event_exit); |
| 393 | void lttng_kretprobes_unregister(struct lttng_event *event); |
| 394 | void lttng_kretprobes_destroy_private(struct lttng_event *event); |
| 395 | #else |
| 396 | static inline |
| 397 | int lttng_kretprobes_register(const char *name, |
| 398 | const char *symbol_name, |
| 399 | uint64_t offset, |
| 400 | uint64_t addr, |
| 401 | struct lttng_event *event_entry, |
| 402 | struct lttng_event *event_exit) |
| 403 | { |
| 404 | return -ENOSYS; |
| 405 | } |
| 406 | |
| 407 | static inline |
| 408 | void lttng_kretprobes_unregister(struct lttng_event *event) |
| 409 | { |
| 410 | } |
| 411 | |
| 412 | static inline |
| 413 | void lttng_kretprobes_destroy_private(struct lttng_event *event) |
| 414 | { |
| 415 | } |
| 416 | #endif |
| 417 | |
| 418 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 419 | int lttng_ftrace_register(const char *name, |
| 420 | const char *symbol_name, |
| 421 | struct lttng_event *event); |
| 422 | void lttng_ftrace_unregister(struct lttng_event *event); |
| 423 | void lttng_ftrace_destroy_private(struct lttng_event *event); |
| 424 | #else |
| 425 | static inline |
| 426 | int lttng_ftrace_register(const char *name, |
| 427 | const char *symbol_name, |
| 428 | struct lttng_event *event) |
| 429 | { |
| 430 | return -ENOSYS; |
| 431 | } |
| 432 | |
| 433 | static inline |
| 434 | void lttng_ftrace_unregister(struct lttng_event *event) |
| 435 | { |
| 436 | } |
| 437 | |
| 438 | static inline |
| 439 | void lttng_ftrace_destroy_private(struct lttng_event *event) |
| 440 | { |
| 441 | } |
| 442 | #endif |
| 443 | |
| 444 | int lttng_calibrate(struct lttng_kernel_calibrate *calibrate); |
| 445 | |
| 446 | extern const struct file_operations lttng_tracepoint_list_fops; |
| 447 | |
| 448 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) |
| 449 | #define TRACEPOINT_HAS_DATA_ARG |
| 450 | #endif |
| 451 | |
| 452 | #endif /* _LTTNG_EVENTS_H */ |