| 1 | #ifndef _LTT_EVENTS_H |
| 2 | #define _LTT_EVENTS_H |
| 3 | |
| 4 | /* |
| 5 | * ltt-events.h |
| 6 | * |
| 7 | * Copyright 2010 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 8 | * |
| 9 | * Holds LTTng per-session event registry. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/list.h> |
| 13 | #include <linux/uuid.h> |
| 14 | #include <linux/kprobes.h> |
| 15 | #include "ltt-debugfs-abi.h" |
| 16 | |
| 17 | struct ltt_channel; |
| 18 | struct ltt_session; |
| 19 | struct lib_ring_buffer_ctx; |
| 20 | |
| 21 | /* Type description */ |
| 22 | |
| 23 | /* Update the astract_types name table in lttng-types.c along with this enum */ |
| 24 | enum abstract_types { |
| 25 | atype_integer, |
| 26 | atype_enum, |
| 27 | atype_array, |
| 28 | atype_sequence, |
| 29 | atype_string, |
| 30 | NR_ABSTRACT_TYPES, |
| 31 | }; |
| 32 | |
| 33 | /* Update the string_encodings name table in lttng-types.c along with this enum */ |
| 34 | enum lttng_string_encodings { |
| 35 | lttng_encode_none = 0, |
| 36 | lttng_encode_UTF8 = 1, |
| 37 | lttng_encode_ASCII = 2, |
| 38 | NR_STRING_ENCODINGS, |
| 39 | }; |
| 40 | |
| 41 | struct lttng_enum_entry { |
| 42 | unsigned long long start, end; /* start and end are inclusive */ |
| 43 | const char *string; |
| 44 | }; |
| 45 | |
| 46 | #define __type_integer(_type, _byte_order, _base) \ |
| 47 | { \ |
| 48 | .atype = atype_integer, \ |
| 49 | .u.basic.integer = \ |
| 50 | { \ |
| 51 | .size = sizeof(_type), \ |
| 52 | .alignment = ltt_alignof(_type) * CHAR_BIT, \ |
| 53 | .signedness = is_signed_type(_type), \ |
| 54 | .reverse_byte_order = _byte_order != __BYTE_ORDER, \ |
| 55 | .base = _base, \ |
| 56 | .encoding = lttng_encode_none, \ |
| 57 | }, \ |
| 58 | } \ |
| 59 | |
| 60 | struct lttng_integer_type { |
| 61 | unsigned int size; /* in bits */ |
| 62 | unsigned short alignment; /* in bits */ |
| 63 | unsigned int signedness:1; |
| 64 | unsigned int reverse_byte_order:1; |
| 65 | unsigned int base; /* 2, 8, 10, 16, for pretty print */ |
| 66 | enum lttng_string_encodings encoding; |
| 67 | }; |
| 68 | |
| 69 | union _lttng_basic_type { |
| 70 | struct lttng_integer_type integer; |
| 71 | struct { |
| 72 | const char *name; |
| 73 | } enumeration; |
| 74 | struct { |
| 75 | enum lttng_string_encodings encoding; |
| 76 | } string; |
| 77 | }; |
| 78 | |
| 79 | struct lttng_basic_type { |
| 80 | enum abstract_types atype; |
| 81 | union { |
| 82 | union _lttng_basic_type basic; |
| 83 | } u; |
| 84 | }; |
| 85 | |
| 86 | struct lttng_type { |
| 87 | enum abstract_types atype; |
| 88 | union { |
| 89 | union _lttng_basic_type basic; |
| 90 | struct { |
| 91 | struct lttng_basic_type elem_type; |
| 92 | unsigned int length; /* num. elems. */ |
| 93 | } array; |
| 94 | struct { |
| 95 | struct lttng_basic_type length_type; |
| 96 | struct lttng_basic_type elem_type; |
| 97 | } sequence; |
| 98 | } u; |
| 99 | }; |
| 100 | |
| 101 | struct lttng_enum { |
| 102 | const char *name; |
| 103 | struct lttng_type container_type; |
| 104 | const struct lttng_enum_entry *entries; |
| 105 | unsigned int len; |
| 106 | }; |
| 107 | |
| 108 | /* Event field description */ |
| 109 | |
| 110 | struct lttng_event_field { |
| 111 | const char *name; |
| 112 | struct lttng_type type; |
| 113 | }; |
| 114 | |
| 115 | struct lttng_event_desc { |
| 116 | const struct lttng_event_field *fields; |
| 117 | const char *name; |
| 118 | void *probe_callback; |
| 119 | unsigned int nr_fields; |
| 120 | }; |
| 121 | |
| 122 | struct lttng_probe_desc { |
| 123 | const struct lttng_event_desc *event_desc; |
| 124 | unsigned int nr_events; |
| 125 | struct list_head head; /* chain registered probes */ |
| 126 | }; |
| 127 | |
| 128 | /* |
| 129 | * ltt_event structure is referred to by the tracing fast path. It must be |
| 130 | * kept small. |
| 131 | */ |
| 132 | struct ltt_event { |
| 133 | unsigned int id; |
| 134 | struct ltt_channel *chan; |
| 135 | const struct lttng_event_desc *desc; |
| 136 | void *filter; |
| 137 | enum lttng_kernel_instrumentation instrumentation; |
| 138 | union { |
| 139 | struct { |
| 140 | struct kprobe kp; |
| 141 | char *symbol_name; |
| 142 | } kprobe; |
| 143 | struct { |
| 144 | char *symbol_name; |
| 145 | } ftrace; |
| 146 | } u; |
| 147 | struct list_head list; /* Event list */ |
| 148 | int metadata_dumped:1; |
| 149 | }; |
| 150 | |
| 151 | struct ltt_channel_ops { |
| 152 | struct channel *(*channel_create)(const char *name, |
| 153 | struct ltt_channel *ltt_chan, |
| 154 | void *buf_addr, |
| 155 | size_t subbuf_size, size_t num_subbuf, |
| 156 | unsigned int switch_timer_interval, |
| 157 | unsigned int read_timer_interval); |
| 158 | void (*channel_destroy)(struct channel *chan); |
| 159 | struct lib_ring_buffer *(*buffer_read_open)(struct channel *chan); |
| 160 | void (*buffer_read_close)(struct lib_ring_buffer *buf); |
| 161 | int (*event_reserve)(struct lib_ring_buffer_ctx *ctx); |
| 162 | void (*event_commit)(struct lib_ring_buffer_ctx *ctx); |
| 163 | void (*event_write)(struct lib_ring_buffer_ctx *ctx, const void *src, |
| 164 | size_t len); |
| 165 | /* |
| 166 | * packet_avail_size returns the available size in the current |
| 167 | * packet. Note that the size returned is only a hint, since it |
| 168 | * may change due to concurrent writes. |
| 169 | */ |
| 170 | size_t (*packet_avail_size)(struct channel *chan); |
| 171 | wait_queue_head_t *(*get_reader_wait_queue)(struct ltt_channel *chan); |
| 172 | }; |
| 173 | |
| 174 | struct ltt_channel { |
| 175 | unsigned int id; |
| 176 | struct channel *chan; /* Channel buffers */ |
| 177 | /* Event ID management */ |
| 178 | struct ltt_session *session; |
| 179 | struct file *file; /* File associated to channel */ |
| 180 | unsigned int free_event_id; /* Next event ID to allocate */ |
| 181 | struct list_head list; /* Channel list */ |
| 182 | wait_queue_head_t notify_wait; /* Channel addition notif. waitqueue */ |
| 183 | struct ltt_channel_ops *ops; |
| 184 | int header_type; /* 0: unset, 1: compact, 2: large */ |
| 185 | int metadata_dumped:1; |
| 186 | }; |
| 187 | |
| 188 | struct ltt_session { |
| 189 | int active; /* Is trace session active ? */ |
| 190 | struct file *file; /* File associated to session */ |
| 191 | struct ltt_channel *metadata; /* Metadata channel */ |
| 192 | struct list_head chan; /* Channel list head */ |
| 193 | struct list_head events; /* Event list head */ |
| 194 | struct list_head list; /* Session list */ |
| 195 | unsigned int free_chan_id; /* Next chan ID to allocate */ |
| 196 | uuid_le uuid; /* Trace session unique ID */ |
| 197 | int metadata_dumped:1; |
| 198 | }; |
| 199 | |
| 200 | struct ltt_transport { |
| 201 | char *name; |
| 202 | struct module *owner; |
| 203 | struct list_head node; |
| 204 | struct ltt_channel_ops ops; |
| 205 | }; |
| 206 | |
| 207 | struct ltt_session *ltt_session_create(void); |
| 208 | int ltt_session_start(struct ltt_session *session); |
| 209 | int ltt_session_stop(struct ltt_session *session); |
| 210 | void ltt_session_destroy(struct ltt_session *session); |
| 211 | |
| 212 | struct ltt_channel *ltt_channel_create(struct ltt_session *session, |
| 213 | const char *transport_name, |
| 214 | void *buf_addr, |
| 215 | size_t subbuf_size, size_t num_subbuf, |
| 216 | unsigned int switch_timer_interval, |
| 217 | unsigned int read_timer_interval); |
| 218 | struct ltt_channel *ltt_global_channel_create(struct ltt_session *session, |
| 219 | int overwrite, void *buf_addr, |
| 220 | size_t subbuf_size, size_t num_subbuf, |
| 221 | unsigned int switch_timer_interval, |
| 222 | unsigned int read_timer_interval); |
| 223 | void _ltt_channel_destroy(struct ltt_channel *chan); |
| 224 | |
| 225 | struct ltt_event *ltt_event_create(struct ltt_channel *chan, |
| 226 | char *name, |
| 227 | struct lttng_kernel_event *event_param, |
| 228 | void *filter); |
| 229 | int ltt_event_unregister(struct ltt_event *event); |
| 230 | |
| 231 | void ltt_transport_register(struct ltt_transport *transport); |
| 232 | void ltt_transport_unregister(struct ltt_transport *transport); |
| 233 | |
| 234 | int ltt_debugfs_abi_init(void); |
| 235 | void ltt_debugfs_abi_exit(void); |
| 236 | |
| 237 | int ltt_probe_register(struct lttng_probe_desc *desc); |
| 238 | void ltt_probe_unregister(struct lttng_probe_desc *desc); |
| 239 | const struct lttng_event_desc *ltt_event_get(const char *name); |
| 240 | void ltt_event_put(const struct lttng_event_desc *desc); |
| 241 | int ltt_probes_init(void); |
| 242 | void ltt_probes_exit(void); |
| 243 | |
| 244 | int lttng_kprobes_register(const char *name, |
| 245 | const char *symbol_name, |
| 246 | uint64_t offset, |
| 247 | uint64_t addr, |
| 248 | struct ltt_event *event); |
| 249 | void lttng_kprobes_unregister(struct ltt_event *event); |
| 250 | |
| 251 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 252 | int lttng_ftrace_register(const char *name, |
| 253 | const char *symbol_name, |
| 254 | struct ltt_event *event); |
| 255 | void lttng_ftrace_unregister(struct ltt_event *event); |
| 256 | #else |
| 257 | static inline |
| 258 | int lttng_ftrace_register(const char *name, |
| 259 | const char *symbol_name, |
| 260 | struct ltt_event *event) |
| 261 | { |
| 262 | return 0; |
| 263 | } |
| 264 | |
| 265 | static inline |
| 266 | void lttng_ftrace_unregister(struct ltt_event *event) |
| 267 | { |
| 268 | } |
| 269 | #endif |
| 270 | #endif /* _LTT_EVENTS_H */ |