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 "ltt-events.h"
15 static LIST_HEAD(sessions
);
16 static LIST_HEAD(ltt_transport_list
);
17 static DEFINE_MUTEX(sessions_mutex
);
18 static struct kmem_cache
*event_cache
;
20 static void synchronize_trace(void)
23 #ifdef CONFIG_PREEMPT_RT
28 struct ltt_session
*ltt_session_create(void)
30 struct ltt_session
*session
;
32 mutex_lock(&sessions_mutex
);
33 session
= kmalloc(sizeof(struct ltt_session
));
36 INIT_LIST_HEAD(&session
->chan
);
37 list_add(&session
->list
, &sessions
);
38 mutex_unlock(&sessions_mutex
);
42 mutex_unlock(&sessions_mutex
);
46 int ltt_session_destroy(struct ltt_session
*session
)
48 struct ltt_channel
*chan
, *tmpchan
;
49 struct ltt_event
*event
, *tmpevent
;
51 mutex_lock(&sessions_mutex
);
53 synchronize_trace(); /* Wait for in-flight events to complete */
54 list_for_each_entry_safe(event
, tmpevent
, &session
->events
, list
)
55 _ltt_event_destroy(event
);
56 list_for_each_entry_safe(chan
, tmpchan
, &session
->chan
, list
)
57 _ltt_channel_destroy(chan
);
58 list_del(&session
->list
);
59 mutex_unlock(&sessions_mutex
);
63 int ltt_session_start(struct ltt_session
*session
)
67 mutex_lock(&sessions_mutex
);
68 if (session
->active
) {
73 synchronize_trace(); /* Wait for in-flight events to complete */
75 mutex_unlock(&sessions_mutex
);
79 int ltt_session_stop(struct ltt_session
*session
)
83 mutex_lock(&sessions_mutex
);
84 if (!session
->active
) {
89 synchronize_trace(); /* Wait for in-flight events to complete */
91 mutex_unlock(&sessions_mutex
);
95 struct ltt_channel
*ltt_channel_create(struct ltt_session
*session
,
96 int overwrite
, void *buf_addr
,
97 size_t subbuf_size
, size_t num_subbuf
,
98 unsigned int switch_timer_interval
,
99 unsigned int read_timer_interval
)
101 struct ltt_channel
*chan
;
102 struct ltt_transport
*transport
= NULL
, *tran_iter
;
103 char *transport_name
;
105 mutex_lock(&sessions_mutex
);
107 goto active
; /* Refuse to add channel to active session */
108 transport_name
= overwrite
? "relay-overwrite" : "relay-discard";
109 list_for_each_entry(tran_iter
, <t_transport_list
, node
) {
110 if (!strcmp(tran_iter
->name
, transport_name
)) {
111 transport
= tran_iter
;
117 chan
= kmalloc(sizeof(struct ltt_channel
), GFP_KERNEL
);
120 chan
->session
= session
;
121 init_waitqueue_head(&chan
->notify_wait
);
122 transport
->ops
.channel_create(session
, buf_addr
, subbuf_size
,
123 num_subbuf
, switch_timer_interval
,
124 read_timer_interval
);
125 list_add(&chan
->list
, &session
->chan
);
126 mutex_unlock(&sessions_mutex
);
132 mutex_unlock(&sessions_mutex
);
137 * Only used internally at session destruction.
139 int _ltt_channel_destroy(struct ltt_channel
*chan
)
141 transport
->ops
.channel_destroy(chan
);
142 list_del(&chan
->list
);
147 * Supports event creation while tracing session is active.
149 struct ltt_event
*ltt_event_create(struct ltt_channel
*chan
, char *name
,
150 enum instrum_type itype
,
151 void *probe
, void *filter
)
153 struct ltt_event
*event
;
156 mutex_lock(&sessions_mutex
);
157 if (chan
->free_event_id
== -1UL)
160 * This is O(n^2) (for each event loop called at event creation).
161 * Might require a hash if we have lots of events.
163 list_for_each_entry(event
, &chan
->session
->events
, list
)
164 if (!strcmp(event
->name
, name
))
166 event
= kmem_cache_zalloc(events_cache
, GFP_KERNEL
);
169 event
->name
= kmalloc(strlen(name
) + 1, GFP_KERNEL
);
172 strcpy(event
->name
, name
);
174 event
->probe
= probe
;
175 event
->filter
= filter
;
176 event
->id
= chan
->free_event_id
++;
177 event
->itype
= itype
;
178 mutex_unlock(&sessions_mutex
);
179 /* Populate ltt_event structure before tracepoint registration. */
182 case INSTRUM_TRACEPOINTS
:
183 ret
= tracepoint_probe_register(name
, probe
, event
);
191 kmem_cache_free(event
);
195 mutex_unlock(&sessions_mutex
);
200 * Only used internally at session destruction.
202 int _ltt_event_destroy(struct ltt_event
*event
)
204 switch (event
->itype
) {
205 case INSTRUM_TRACEPOINTS
:
206 ret
= tracepoint_probe_unregister(name
, event
->probe
, event
);
212 kmem_cache_free(event
);
216 * ltt_transport_register - LTT transport registration
217 * @transport: transport structure
219 * Registers a transport which can be used as output to extract the data out of
220 * LTTng. The module calling this registration function must ensure that no
221 * trap-inducing code will be executed by the transport functions. E.g.
222 * vmalloc_sync_all() must be called between a vmalloc and the moment the memory
223 * is made visible to the transport function. This registration acts as a
224 * vmalloc_sync_all. Therefore, only if the module allocates virtual memory
225 * after its registration must it synchronize the TLBs.
227 void ltt_transport_register(struct ltt_transport
*transport
)
230 * Make sure no page fault can be triggered by the module about to be
231 * registered. We deal with this here so we don't have to call
232 * vmalloc_sync_all() in each module's init.
236 mutex_lock(&sessions_mutex
);
237 list_add_tail(&transport
->node
, <t_transport_list
);
238 mutex_unlock(&sessions_mutex
);
240 EXPORT_SYMBOL_GPL(ltt_transport_register
);
243 * ltt_transport_unregister - LTT transport unregistration
244 * @transport: transport structure
246 void ltt_transport_unregister(struct ltt_transport
*transport
)
248 mutex_lock(&sessions_mutex
);
249 list_del(&transport
->node
);
250 mutex_unlock(&sessions_mutex
);
252 EXPORT_SYMBOL_GPL(ltt_transport_unregister
);
255 static int __init
ltt_events_init(void)
259 events_cache
= KMEM_CACHE(ltt_event
, 0);
265 static void __exit
ltt_events_exit(void)
267 struct ltt_session
*session
, *tmpsession
;
269 list_for_each_entry_safe(session
, tmpsession
, &sessions
, list
)
270 ltt_session_destroy(session
);
271 kmem_cache_destroy(events_cache
);
274 MODULE_LICENSE("GPL and additional rights");
275 MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
276 MODULE_DESCRIPTION("LTTng Events");
This page took 0.045383 seconds and 4 git commands to generate.