| 1 | #ifndef _LTTNG_EVENTS_H |
| 2 | #define _LTTNG_EVENTS_H |
| 3 | |
| 4 | /* |
| 5 | * lttng-events.h |
| 6 | * |
| 7 | * Holds LTTng per-session event registry. |
| 8 | * |
| 9 | * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 10 | * |
| 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. |
| 15 | * |
| 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. |
| 20 | * |
| 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 |
| 24 | */ |
| 25 | |
| 26 | #include <linux/list.h> |
| 27 | #include <linux/kprobes.h> |
| 28 | #include "wrapper/uuid.h" |
| 29 | #include "lttng-abi.h" |
| 30 | |
| 31 | #undef is_signed_type |
| 32 | #define is_signed_type(type) (((type)(-1)) < 0) |
| 33 | |
| 34 | struct lttng_channel; |
| 35 | struct lttng_session; |
| 36 | struct lib_ring_buffer_ctx; |
| 37 | struct perf_event; |
| 38 | struct perf_event_attr; |
| 39 | |
| 40 | /* Type description */ |
| 41 | |
| 42 | /* Update the astract_types name table in lttng-types.c along with this enum */ |
| 43 | enum abstract_types { |
| 44 | atype_integer, |
| 45 | atype_enum, |
| 46 | atype_array, |
| 47 | atype_sequence, |
| 48 | atype_string, |
| 49 | NR_ABSTRACT_TYPES, |
| 50 | }; |
| 51 | |
| 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, |
| 57 | NR_STRING_ENCODINGS, |
| 58 | }; |
| 59 | |
| 60 | struct lttng_enum_entry { |
| 61 | unsigned long long start, end; /* start and end are inclusive */ |
| 62 | const char *string; |
| 63 | }; |
| 64 | |
| 65 | #define __type_integer(_type, _byte_order, _base, _encoding) \ |
| 66 | { \ |
| 67 | .atype = atype_integer, \ |
| 68 | .u.basic.integer = \ |
| 69 | { \ |
| 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, \ |
| 74 | .base = _base, \ |
| 75 | .encoding = lttng_encode_##_encoding, \ |
| 76 | }, \ |
| 77 | } \ |
| 78 | |
| 79 | struct lttng_integer_type { |
| 80 | unsigned int size; /* in bits */ |
| 81 | unsigned short alignment; /* in bits */ |
| 82 | unsigned int signedness:1, |
| 83 | reverse_byte_order:1; |
| 84 | unsigned int base; /* 2, 8, 10, 16, for pretty print */ |
| 85 | enum lttng_string_encodings encoding; |
| 86 | }; |
| 87 | |
| 88 | union _lttng_basic_type { |
| 89 | struct lttng_integer_type integer; |
| 90 | struct { |
| 91 | const char *name; |
| 92 | } enumeration; |
| 93 | struct { |
| 94 | enum lttng_string_encodings encoding; |
| 95 | } string; |
| 96 | }; |
| 97 | |
| 98 | struct lttng_basic_type { |
| 99 | enum abstract_types atype; |
| 100 | union { |
| 101 | union _lttng_basic_type basic; |
| 102 | } u; |
| 103 | }; |
| 104 | |
| 105 | struct lttng_type { |
| 106 | enum abstract_types atype; |
| 107 | union { |
| 108 | union _lttng_basic_type basic; |
| 109 | struct { |
| 110 | struct lttng_basic_type elem_type; |
| 111 | unsigned int length; /* num. elems. */ |
| 112 | } array; |
| 113 | struct { |
| 114 | struct lttng_basic_type length_type; |
| 115 | struct lttng_basic_type elem_type; |
| 116 | } sequence; |
| 117 | } u; |
| 118 | }; |
| 119 | |
| 120 | struct lttng_enum { |
| 121 | const char *name; |
| 122 | struct lttng_type container_type; |
| 123 | const struct lttng_enum_entry *entries; |
| 124 | unsigned int len; |
| 125 | }; |
| 126 | |
| 127 | /* Event field description */ |
| 128 | |
| 129 | struct lttng_event_field { |
| 130 | const char *name; |
| 131 | struct lttng_type type; |
| 132 | }; |
| 133 | |
| 134 | /* |
| 135 | * We need to keep this perf counter field separately from struct |
| 136 | * lttng_ctx_field because cpu hotplug needs fixed-location addresses. |
| 137 | */ |
| 138 | struct lttng_perf_counter_field { |
| 139 | struct notifier_block nb; |
| 140 | int hp_enable; |
| 141 | struct perf_event_attr *attr; |
| 142 | struct perf_event **e; /* per-cpu array */ |
| 143 | }; |
| 144 | |
| 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); |
| 151 | union { |
| 152 | struct lttng_perf_counter_field *perf_counter; |
| 153 | } u; |
| 154 | void (*destroy)(struct lttng_ctx_field *field); |
| 155 | }; |
| 156 | |
| 157 | struct lttng_ctx { |
| 158 | struct lttng_ctx_field *fields; |
| 159 | unsigned int nr_fields; |
| 160 | unsigned int allocated_fields; |
| 161 | }; |
| 162 | |
| 163 | struct lttng_event_desc { |
| 164 | const char *name; |
| 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; |
| 170 | }; |
| 171 | |
| 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 */ |
| 176 | }; |
| 177 | |
| 178 | struct lttng_krp; /* Kretprobe handling */ |
| 179 | |
| 180 | /* |
| 181 | * lttng_event structure is referred to by the tracing fast path. It must be |
| 182 | * kept small. |
| 183 | */ |
| 184 | struct lttng_event { |
| 185 | unsigned int id; |
| 186 | struct lttng_channel *chan; |
| 187 | int enabled; |
| 188 | const struct lttng_event_desc *desc; |
| 189 | void *filter; |
| 190 | struct lttng_ctx *ctx; |
| 191 | enum lttng_kernel_instrumentation instrumentation; |
| 192 | union { |
| 193 | struct { |
| 194 | struct kprobe kp; |
| 195 | char *symbol_name; |
| 196 | } kprobe; |
| 197 | struct { |
| 198 | struct lttng_krp *lttng_krp; |
| 199 | char *symbol_name; |
| 200 | } kretprobe; |
| 201 | struct { |
| 202 | char *symbol_name; |
| 203 | } ftrace; |
| 204 | } u; |
| 205 | struct list_head list; /* Event list */ |
| 206 | unsigned int metadata_dumped:1; |
| 207 | }; |
| 208 | |
| 209 | struct lttng_channel_ops { |
| 210 | struct channel *(*channel_create)(const char *name, |
| 211 | struct lttng_channel *lttng_chan, |
| 212 | void *buf_addr, |
| 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, |
| 221 | uint32_t event_id); |
| 222 | void (*event_commit)(struct lib_ring_buffer_ctx *ctx); |
| 223 | void (*event_write)(struct lib_ring_buffer_ctx *ctx, const void *src, |
| 224 | size_t len); |
| 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, |
| 228 | int c, size_t len); |
| 229 | /* |
| 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. |
| 233 | */ |
| 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); |
| 239 | }; |
| 240 | |
| 241 | struct lttng_transport { |
| 242 | char *name; |
| 243 | struct module *owner; |
| 244 | struct list_head node; |
| 245 | struct lttng_channel_ops ops; |
| 246 | }; |
| 247 | |
| 248 | struct lttng_channel { |
| 249 | unsigned int id; |
| 250 | struct channel *chan; /* Channel buffers */ |
| 251 | int enabled; |
| 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; |
| 267 | }; |
| 268 | |
| 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; |
| 280 | }; |
| 281 | |
| 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); |
| 286 | |
| 287 | struct lttng_channel *lttng_channel_create(struct lttng_session *session, |
| 288 | const char *transport_name, |
| 289 | void *buf_addr, |
| 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); |
| 298 | |
| 299 | struct lttng_event *lttng_event_create(struct lttng_channel *chan, |
| 300 | struct lttng_kernel_event *event_param, |
| 301 | void *filter, |
| 302 | const struct lttng_event_desc *internal_desc); |
| 303 | |
| 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); |
| 308 | |
| 309 | void lttng_transport_register(struct lttng_transport *transport); |
| 310 | void lttng_transport_unregister(struct lttng_transport *transport); |
| 311 | |
| 312 | void synchronize_trace(void); |
| 313 | int lttng_abi_init(void); |
| 314 | void lttng_abi_exit(void); |
| 315 | |
| 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); |
| 322 | |
| 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); |
| 326 | #else |
| 327 | static inline int lttng_syscalls_register(struct lttng_channel *chan, void *filter) |
| 328 | { |
| 329 | return -ENOSYS; |
| 330 | } |
| 331 | |
| 332 | static inline int lttng_syscalls_unregister(struct lttng_channel *chan) |
| 333 | { |
| 334 | return 0; |
| 335 | } |
| 336 | #endif |
| 337 | |
| 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 | int lttng_add_hostname_to_ctx(struct lttng_ctx **ctx); |
| 353 | #if defined(CONFIG_PERF_EVENTS) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33)) |
| 354 | int lttng_add_perf_counter_to_ctx(uint32_t type, |
| 355 | uint64_t config, |
| 356 | const char *name, |
| 357 | struct lttng_ctx **ctx); |
| 358 | #else |
| 359 | static inline |
| 360 | int lttng_add_perf_counter_to_ctx(uint32_t type, |
| 361 | uint64_t config, |
| 362 | const char *name, |
| 363 | struct lttng_ctx **ctx) |
| 364 | { |
| 365 | return -ENOSYS; |
| 366 | } |
| 367 | #endif |
| 368 | |
| 369 | extern int lttng_statedump_start(struct lttng_session *session); |
| 370 | |
| 371 | #ifdef CONFIG_KPROBES |
| 372 | int lttng_kprobes_register(const char *name, |
| 373 | const char *symbol_name, |
| 374 | uint64_t offset, |
| 375 | uint64_t addr, |
| 376 | struct lttng_event *event); |
| 377 | void lttng_kprobes_unregister(struct lttng_event *event); |
| 378 | void lttng_kprobes_destroy_private(struct lttng_event *event); |
| 379 | #else |
| 380 | static inline |
| 381 | int lttng_kprobes_register(const char *name, |
| 382 | const char *symbol_name, |
| 383 | uint64_t offset, |
| 384 | uint64_t addr, |
| 385 | struct lttng_event *event) |
| 386 | { |
| 387 | return -ENOSYS; |
| 388 | } |
| 389 | |
| 390 | static inline |
| 391 | void lttng_kprobes_unregister(struct lttng_event *event) |
| 392 | { |
| 393 | } |
| 394 | |
| 395 | static inline |
| 396 | void lttng_kprobes_destroy_private(struct lttng_event *event) |
| 397 | { |
| 398 | } |
| 399 | #endif |
| 400 | |
| 401 | #ifdef CONFIG_KRETPROBES |
| 402 | int lttng_kretprobes_register(const char *name, |
| 403 | const char *symbol_name, |
| 404 | uint64_t offset, |
| 405 | uint64_t addr, |
| 406 | struct lttng_event *event_entry, |
| 407 | struct lttng_event *event_exit); |
| 408 | void lttng_kretprobes_unregister(struct lttng_event *event); |
| 409 | void lttng_kretprobes_destroy_private(struct lttng_event *event); |
| 410 | #else |
| 411 | static inline |
| 412 | int lttng_kretprobes_register(const char *name, |
| 413 | const char *symbol_name, |
| 414 | uint64_t offset, |
| 415 | uint64_t addr, |
| 416 | struct lttng_event *event_entry, |
| 417 | struct lttng_event *event_exit) |
| 418 | { |
| 419 | return -ENOSYS; |
| 420 | } |
| 421 | |
| 422 | static inline |
| 423 | void lttng_kretprobes_unregister(struct lttng_event *event) |
| 424 | { |
| 425 | } |
| 426 | |
| 427 | static inline |
| 428 | void lttng_kretprobes_destroy_private(struct lttng_event *event) |
| 429 | { |
| 430 | } |
| 431 | #endif |
| 432 | |
| 433 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 434 | int lttng_ftrace_register(const char *name, |
| 435 | const char *symbol_name, |
| 436 | struct lttng_event *event); |
| 437 | void lttng_ftrace_unregister(struct lttng_event *event); |
| 438 | void lttng_ftrace_destroy_private(struct lttng_event *event); |
| 439 | #else |
| 440 | static inline |
| 441 | int lttng_ftrace_register(const char *name, |
| 442 | const char *symbol_name, |
| 443 | struct lttng_event *event) |
| 444 | { |
| 445 | return -ENOSYS; |
| 446 | } |
| 447 | |
| 448 | static inline |
| 449 | void lttng_ftrace_unregister(struct lttng_event *event) |
| 450 | { |
| 451 | } |
| 452 | |
| 453 | static inline |
| 454 | void lttng_ftrace_destroy_private(struct lttng_event *event) |
| 455 | { |
| 456 | } |
| 457 | #endif |
| 458 | |
| 459 | int lttng_calibrate(struct lttng_kernel_calibrate *calibrate); |
| 460 | |
| 461 | extern const struct file_operations lttng_tracepoint_list_fops; |
| 462 | |
| 463 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) |
| 464 | #define TRACEPOINT_HAS_DATA_ARG |
| 465 | #endif |
| 466 | |
| 467 | #endif /* _LTTNG_EVENTS_H */ |