4 * Copyright 2010 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 * Holds LTTng per-session event registry.
9 #include <linux/module.h>
10 #include <linux/list.h>
11 #include <linux/mutex.h>
12 #include <linux/sched.h>
13 #include <linux/slab.h>
14 #include <linux/vmalloc.h> /* For vmalloc_sync_all */
15 #include "ltt-events.h"
17 static LIST_HEAD(sessions
);
18 static LIST_HEAD(ltt_transport_list
);
19 static DEFINE_MUTEX(sessions_mutex
);
20 static struct kmem_cache
*event_cache
;
22 static void synchronize_trace(void)
25 #ifdef CONFIG_PREEMPT_RT
30 struct ltt_session
*ltt_session_create(void)
32 struct ltt_session
*session
;
34 mutex_lock(&sessions_mutex
);
35 session
= kzalloc(sizeof(struct ltt_session
), GFP_KERNEL
);
38 INIT_LIST_HEAD(&session
->chan
);
39 INIT_LIST_HEAD(&session
->events
);
40 list_add(&session
->list
, &sessions
);
41 mutex_unlock(&sessions_mutex
);
45 void ltt_session_destroy(struct ltt_session
*session
)
47 struct ltt_channel
*chan
, *tmpchan
;
48 struct ltt_event
*event
, *tmpevent
;
50 mutex_lock(&sessions_mutex
);
52 synchronize_trace(); /* Wait for in-flight events to complete */
53 list_for_each_entry_safe(event
, tmpevent
, &session
->events
, list
)
54 _ltt_event_destroy(event
);
55 list_for_each_entry_safe(chan
, tmpchan
, &session
->chan
, list
)
56 _ltt_channel_destroy(chan
);
57 list_del(&session
->list
);
58 mutex_unlock(&sessions_mutex
);
62 int ltt_session_start(struct ltt_session
*session
)
66 mutex_lock(&sessions_mutex
);
67 if (session
->active
) {
72 synchronize_trace(); /* Wait for in-flight events to complete */
74 mutex_unlock(&sessions_mutex
);
78 int ltt_session_stop(struct ltt_session
*session
)
82 mutex_lock(&sessions_mutex
);
83 if (!session
->active
) {
88 synchronize_trace(); /* Wait for in-flight events to complete */
90 mutex_unlock(&sessions_mutex
);
94 static struct ltt_transport
*ltt_transport_find(char *name
)
96 struct ltt_transport
*transport
;
98 list_for_each_entry(transport
, <t_transport_list
, node
) {
99 if (!strcmp(transport
->name
, name
))
105 struct ltt_channel
*ltt_channel_create(struct ltt_session
*session
,
106 int overwrite
, void *buf_addr
,
107 size_t subbuf_size
, size_t num_subbuf
,
108 unsigned int switch_timer_interval
,
109 unsigned int read_timer_interval
)
111 struct ltt_channel
*chan
;
112 struct ltt_transport
*transport
;
113 char *transport_name
;
115 mutex_lock(&sessions_mutex
);
116 if (session
->active
) {
117 printk(KERN_WARNING
"LTTng refusing to add channel to active session\n");
118 goto active
; /* Refuse to add channel to active session */
120 transport_name
= overwrite
? "relay-overwrite" : "relay-discard";
121 transport
= ltt_transport_find(transport_name
);
123 printk(KERN_WARNING
"LTTng transport %s not found\n",
127 chan
= kzalloc(sizeof(struct ltt_channel
), GFP_KERNEL
);
130 chan
->session
= session
;
131 init_waitqueue_head(&chan
->notify_wait
);
132 chan
->chan
= transport
->ops
.channel_create("[lttng]", session
, buf_addr
,
133 subbuf_size
, num_subbuf
, switch_timer_interval
,
134 read_timer_interval
);
137 chan
->ops
= &transport
->ops
;
138 list_add(&chan
->list
, &session
->chan
);
139 mutex_unlock(&sessions_mutex
);
147 mutex_unlock(&sessions_mutex
);
152 * Only used internally at session destruction.
154 void _ltt_channel_destroy(struct ltt_channel
*chan
)
156 chan
->ops
->channel_destroy(chan
->chan
);
157 list_del(&chan
->list
);
162 * Supports event creation while tracing session is active.
164 struct ltt_event
*ltt_event_create(struct ltt_channel
*chan
, char *name
,
165 enum instrum_type itype
,
166 void *probe
, void *filter
)
168 struct ltt_event
*event
;
171 mutex_lock(&sessions_mutex
);
172 if (chan
->free_event_id
== -1UL)
175 * This is O(n^2) (for each event loop called at event creation).
176 * Might require a hash if we have lots of events.
178 list_for_each_entry(event
, &chan
->session
->events
, list
)
179 if (!strcmp(event
->name
, name
))
181 event
= kmem_cache_zalloc(event_cache
, GFP_KERNEL
);
184 event
->name
= kmalloc(strlen(name
) + 1, GFP_KERNEL
);
187 strcpy(event
->name
, name
);
189 event
->probe
= probe
;
190 event
->filter
= filter
;
191 event
->id
= chan
->free_event_id
++;
192 event
->itype
= itype
;
193 /* Populate ltt_event structure before tracepoint registration. */
196 case INSTRUM_TRACEPOINTS
:
197 ret
= tracepoint_probe_register(name
, probe
, event
);
204 mutex_unlock(&sessions_mutex
);
210 kmem_cache_free(event_cache
, event
);
214 mutex_unlock(&sessions_mutex
);
219 * Only used internally at session destruction.
221 int _ltt_event_destroy(struct ltt_event
*event
)
225 switch (event
->itype
) {
226 case INSTRUM_TRACEPOINTS
:
227 ret
= tracepoint_probe_unregister(event
->name
, event
->probe
,
236 kmem_cache_free(event_cache
, event
);
241 * ltt_transport_register - LTT transport registration
242 * @transport: transport structure
244 * Registers a transport which can be used as output to extract the data out of
245 * LTTng. The module calling this registration function must ensure that no
246 * trap-inducing code will be executed by the transport functions. E.g.
247 * vmalloc_sync_all() must be called between a vmalloc and the moment the memory
248 * is made visible to the transport function. This registration acts as a
249 * vmalloc_sync_all. Therefore, only if the module allocates virtual memory
250 * after its registration must it synchronize the TLBs.
252 void ltt_transport_register(struct ltt_transport
*transport
)
255 * Make sure no page fault can be triggered by the module about to be
256 * registered. We deal with this here so we don't have to call
257 * vmalloc_sync_all() in each module's init.
261 mutex_lock(&sessions_mutex
);
262 list_add_tail(&transport
->node
, <t_transport_list
);
263 mutex_unlock(&sessions_mutex
);
265 EXPORT_SYMBOL_GPL(ltt_transport_register
);
268 * ltt_transport_unregister - LTT transport unregistration
269 * @transport: transport structure
271 void ltt_transport_unregister(struct ltt_transport
*transport
)
273 mutex_lock(&sessions_mutex
);
274 list_del(&transport
->node
);
275 mutex_unlock(&sessions_mutex
);
277 EXPORT_SYMBOL_GPL(ltt_transport_unregister
);
280 static int __init
ltt_events_init(void)
284 event_cache
= KMEM_CACHE(ltt_event
, 0);
287 ret
= ltt_probes_init();
290 ret
= ltt_debugfs_abi_init();
297 kmem_cache_destroy(event_cache
);
301 module_init(ltt_events_init
);
303 static void __exit
ltt_events_exit(void)
305 struct ltt_session
*session
, *tmpsession
;
307 ltt_debugfs_abi_exit();
309 list_for_each_entry_safe(session
, tmpsession
, &sessions
, list
)
310 ltt_session_destroy(session
);
311 kmem_cache_destroy(event_cache
);
314 module_exit(ltt_events_exit
);
316 MODULE_LICENSE("GPL and additional rights");
317 MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
318 MODULE_DESCRIPTION("LTTng Events");
This page took 0.037164 seconds and 5 git commands to generate.