Commit | Line | Data |
---|---|---|
11b5a3c2 MD |
1 | #ifndef _LTT_EVENTS_H |
2 | #define _LTT_EVENTS_H | |
3 | ||
4e3c1b9b MD |
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> | |
d793d5e1 | 13 | #include <linux/uuid.h> |
d6d808f3 | 14 | #include <linux/kprobes.h> |
11b5a3c2 | 15 | #include "ltt-debugfs-abi.h" |
4e3c1b9b MD |
16 | |
17 | struct ltt_channel; | |
18 | struct ltt_session; | |
1c25284c | 19 | struct lib_ring_buffer_ctx; |
4e3c1b9b | 20 | |
c0edae1d MD |
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_UTF8 = 0, | |
36 | lttng_encode_ASCII = 1, | |
37 | NR_STRING_ENCODINGS, | |
38 | }; | |
39 | ||
40 | struct lttng_enum_entry { | |
41 | unsigned long long start, end; /* start and end are inclusive */ | |
42 | const char *string; | |
43 | }; | |
44 | ||
c099397a MD |
45 | #define __type_integer(_type, _byte_order) \ |
46 | { \ | |
47 | .atype = atype_integer, \ | |
48 | .u.basic.integer = \ | |
49 | { \ | |
50 | .size = sizeof(_type), \ | |
d793d5e1 | 51 | .alignment = ltt_alignof(_type) * CHAR_BIT, \ |
c099397a MD |
52 | .signedness = is_signed_type(_type), \ |
53 | .reverse_byte_order = _byte_order != __BYTE_ORDER, \ | |
54 | }, \ | |
55 | } \ | |
56 | ||
57 | struct lttng_integer_type { | |
58 | unsigned int size; /* in bits */ | |
59 | unsigned short alignment; /* in bits */ | |
60 | unsigned int signedness:1; | |
61 | unsigned int reverse_byte_order:1; | |
62 | }; | |
63 | ||
64 | union _lttng_basic_type { | |
65 | struct lttng_integer_type integer; | |
66 | struct { | |
67 | const char *name; | |
68 | } enumeration; | |
69 | struct { | |
70 | enum lttng_string_encodings encoding; | |
71 | } string; | |
72 | }; | |
73 | ||
74 | struct lttng_basic_type { | |
75 | enum abstract_types atype; | |
76 | union { | |
77 | union _lttng_basic_type basic; | |
78 | } u; | |
c0edae1d MD |
79 | }; |
80 | ||
81 | struct lttng_type { | |
82 | enum abstract_types atype; | |
c0edae1d | 83 | union { |
c099397a | 84 | union _lttng_basic_type basic; |
c0edae1d | 85 | struct { |
c099397a | 86 | struct lttng_basic_type elem_type; |
c0edae1d MD |
87 | unsigned int length; /* num. elems. */ |
88 | } array; | |
89 | struct { | |
c099397a MD |
90 | struct lttng_basic_type length_type; |
91 | struct lttng_basic_type elem_type; | |
c0edae1d | 92 | } sequence; |
c0edae1d | 93 | } u; |
c099397a MD |
94 | }; |
95 | ||
96 | struct lttng_enum { | |
97 | const char *name; | |
98 | struct lttng_type container_type; | |
99 | const struct lttng_enum_entry *entries; | |
100 | unsigned int len; | |
101 | }; | |
c0edae1d MD |
102 | |
103 | /* Event field description */ | |
104 | ||
105 | struct lttng_event_field { | |
106 | const char *name; | |
107 | const struct lttng_type type; | |
108 | }; | |
109 | ||
110 | struct lttng_event_desc { | |
111 | const struct lttng_event_field *fields; | |
112 | const char *name; | |
113 | void *probe_callback; | |
114 | unsigned int nr_fields; | |
115 | }; | |
116 | ||
85a9ca7f MD |
117 | struct lttng_probe_desc { |
118 | const struct lttng_event_desc *event_desc; | |
119 | unsigned int nr_events; | |
120 | struct list_head head; /* chain registered probes */ | |
121 | }; | |
122 | ||
123 | /* | |
124 | * ltt_event structure is referred to by the tracing fast path. It must be | |
125 | * kept small. | |
126 | */ | |
127 | struct ltt_event { | |
128 | unsigned int id; | |
129 | struct ltt_channel *chan; | |
130 | const struct lttng_event_desc *desc; | |
131 | void *filter; | |
38d024ae | 132 | enum lttng_kernel_instrumentation instrumentation; |
d6d808f3 MD |
133 | union { |
134 | struct { | |
135 | struct kprobe kp; | |
136 | char *symbol_name; | |
137 | } kprobe; | |
138 | } u; | |
85a9ca7f | 139 | struct list_head list; /* Event list */ |
c099397a | 140 | int metadata_dumped:1; |
85a9ca7f MD |
141 | }; |
142 | ||
143 | struct ltt_channel_ops { | |
144 | struct channel *(*channel_create)(const char *name, | |
9115fbdc | 145 | struct ltt_channel *ltt_chan, |
85a9ca7f MD |
146 | void *buf_addr, |
147 | size_t subbuf_size, size_t num_subbuf, | |
148 | unsigned int switch_timer_interval, | |
149 | unsigned int read_timer_interval); | |
150 | void (*channel_destroy)(struct channel *chan); | |
151 | struct lib_ring_buffer *(*buffer_read_open)(struct channel *chan); | |
152 | void (*buffer_read_close)(struct lib_ring_buffer *buf); | |
153 | int (*event_reserve)(struct lib_ring_buffer_ctx *ctx); | |
154 | void (*event_commit)(struct lib_ring_buffer_ctx *ctx); | |
155 | void (*event_write)(struct lib_ring_buffer_ctx *ctx, const void *src, | |
156 | size_t len); | |
1ec3f75a MD |
157 | /* |
158 | * packet_avail_size returns the available size in the current | |
159 | * packet. Note that the size returned is only a hint, since it | |
160 | * may change due to concurrent writes. | |
161 | */ | |
162 | size_t (*packet_avail_size)(struct channel *chan); | |
c099397a | 163 | wait_queue_head_t *(*get_reader_wait_queue)(struct ltt_channel *chan); |
85a9ca7f MD |
164 | }; |
165 | ||
166 | struct ltt_channel { | |
c099397a | 167 | unsigned int id; |
85a9ca7f MD |
168 | struct channel *chan; /* Channel buffers */ |
169 | /* Event ID management */ | |
170 | struct ltt_session *session; | |
171 | struct file *file; /* File associated to channel */ | |
172 | unsigned int free_event_id; /* Next event ID to allocate */ | |
173 | struct list_head list; /* Channel list */ | |
174 | wait_queue_head_t notify_wait; /* Channel addition notif. waitqueue */ | |
175 | struct ltt_channel_ops *ops; | |
9115fbdc | 176 | int header_type; /* 0: unset, 1: compact, 2: large */ |
c099397a | 177 | int metadata_dumped:1; |
85a9ca7f MD |
178 | }; |
179 | ||
180 | struct ltt_session { | |
181 | int active; /* Is trace session active ? */ | |
182 | struct file *file; /* File associated to session */ | |
c099397a | 183 | struct ltt_channel *metadata; /* Metadata channel */ |
85a9ca7f MD |
184 | struct list_head chan; /* Channel list head */ |
185 | struct list_head events; /* Event list head */ | |
186 | struct list_head list; /* Session list */ | |
c099397a | 187 | unsigned int free_chan_id; /* Next chan ID to allocate */ |
d793d5e1 | 188 | uuid_le uuid; /* Trace session unique ID */ |
c099397a | 189 | int metadata_dumped:1; |
85a9ca7f MD |
190 | }; |
191 | ||
192 | struct ltt_transport { | |
193 | char *name; | |
194 | struct module *owner; | |
195 | struct list_head node; | |
196 | struct ltt_channel_ops ops; | |
197 | }; | |
198 | ||
baf20995 | 199 | struct ltt_session *ltt_session_create(void); |
c0e31d2e MD |
200 | int ltt_session_start(struct ltt_session *session); |
201 | int ltt_session_stop(struct ltt_session *session); | |
11b5a3c2 | 202 | void ltt_session_destroy(struct ltt_session *session); |
4e3c1b9b | 203 | |
baf20995 | 204 | struct ltt_channel *ltt_channel_create(struct ltt_session *session, |
5dbbdb43 MD |
205 | const char *transport_name, |
206 | void *buf_addr, | |
207 | size_t subbuf_size, size_t num_subbuf, | |
208 | unsigned int switch_timer_interval, | |
209 | unsigned int read_timer_interval); | |
210 | struct ltt_channel *ltt_global_channel_create(struct ltt_session *session, | |
4e3c1b9b MD |
211 | int overwrite, void *buf_addr, |
212 | size_t subbuf_size, size_t num_subbuf, | |
213 | unsigned int switch_timer_interval, | |
214 | unsigned int read_timer_interval); | |
11b5a3c2 | 215 | void _ltt_channel_destroy(struct ltt_channel *chan); |
4e3c1b9b | 216 | |
653fe716 | 217 | struct ltt_event *ltt_event_create(struct ltt_channel *chan, |
653fe716 | 218 | char *name, |
d6d808f3 | 219 | struct lttng_kernel_event *event_param, |
85a9ca7f MD |
220 | const struct lttng_event_desc *event_desc, |
221 | void *filter); | |
be066e6c | 222 | int ltt_event_unregister(struct ltt_event *event); |
c0e31d2e MD |
223 | |
224 | void ltt_transport_register(struct ltt_transport *transport); | |
225 | void ltt_transport_unregister(struct ltt_transport *transport); | |
11b5a3c2 | 226 | |
1c25284c MD |
227 | int ltt_debugfs_abi_init(void); |
228 | void ltt_debugfs_abi_exit(void); | |
229 | ||
85a9ca7f MD |
230 | int ltt_probe_register(struct lttng_probe_desc *desc); |
231 | void ltt_probe_unregister(struct lttng_probe_desc *desc); | |
232 | const struct lttng_event_desc *ltt_event_get(const char *name); | |
233 | void ltt_event_put(const struct lttng_event_desc *desc); | |
cd4bd11f MD |
234 | int ltt_probes_init(void); |
235 | void ltt_probes_exit(void); | |
02119ee5 | 236 | |
d6d808f3 MD |
237 | void lttng_kprobes_handler_pre(struct kprobe *p, struct pt_regs *regs); |
238 | ||
11b5a3c2 | 239 | #endif /* _LTT_EVENTS_H */ |