96c90c4cc674eb967482d1963f50772e8912ae09
4 * Copyright 2010 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 * Holds LTTng per-session event registry.
9 #include <linux/module.h>
10 #include "ltt-events.h"
12 static LIST_HEAD(sessions
);
13 static DEFINE_MUTEX(sessions_mutex
);
14 static struct kmem_cache
*event_cache
;
16 struct ltt_session
*ltt_session_create(char *name
)
18 struct ltt_session
*session
;
20 mutex_lock(&sessions_mutex
);
21 list_for_each_entry(session
, &sessions
, list
)
22 if (!strcmp(session
->name
, name
))
24 session
= kmalloc(sizeof(struct ltt_session
) + strlen(name
) + 1);
27 strcpy(session
->name
, name
);
28 INIT_LIST_HEAD(&session
->chan
);
29 list_add(&session
->list
, &sessions
);
30 mutex_unlock(&sessions_mutex
);
34 mutex_unlock(&sessions_mutex
);
38 int ltt_session_destroy(struct ltt_session
*session
)
40 struct ltt_channel
*chan
, *tmpchan
;
41 struct ltt_event
*event
, *tmpevent
;
43 mutex_lock(&sessions_mutex
);
44 list_for_each_entry_safe(event
, tmpevent
, &session
->events
, list
)
45 _ltt_event_destroy(event
);
46 list_for_each_entry_safe(chan
, tmpchan
, &session
->chan
, list
)
47 _ltt_channel_destroy(chan
);
48 list_del(&session
->list
);
49 mutex_unlock(&sessions_mutex
);
53 struct ltt_channel
*ltt_channel_create(struct ltt_session
*session
, char *name
,
54 int overwrite
, void *buf_addr
,
55 size_t subbuf_size
, size_t num_subbuf
,
56 unsigned int switch_timer_interval
,
57 unsigned int read_timer_interval
)
59 struct ltt_channel
*chan
;
61 mutex_lock(&sessions_mutex
);
63 goto active
; /* Refuse to add channel to active session */
64 list_for_each_entry(chan
, &session
->chan
, list
)
65 if (!strcmp(chan
->name
, name
))
67 chan
= kmalloc(sizeof(struct ltt_channel
) + strlen(name
) + 1, GFP_KERNEL
);
70 strcpy(chan
->name
, name
);
71 chan
->session
= session
;
73 /* TODO: create rb channel */
74 list_add(&chan
->list
, &session
->chan
);
75 mutex_unlock(&sessions_mutex
);
80 mutex_unlock(&sessions_mutex
);
85 * Only used internally at session destruction.
87 int _ltt_channel_destroy(struct ltt_channel
*chan
)
89 list_del(&chan
->list
);
94 * Supports event creation while tracing session is active.
96 struct ltt_event
*ltt_event_create(struct ltt_channel
*chan
, char *name
,
99 struct ltt_event
*event
;
101 mutex_lock(&sessions_mutex
);
102 if (chan
->free_event_id
== -1UL)
105 * This is O(n^2) (for each event loop called at event creation).
106 * Might require a hash if we have lots of events.
108 list_for_each_entry(event
, &chan
->session
->events
, list
)
109 if (!strcmp(event
->name
, name
))
111 event
= kmem_cache_zalloc(events_cache
, GFP_KERNEL
);
114 event
->name
= kmalloc(strlen(name
) + 1, GFP_KERNEL
);
117 strcpy(event
->name
, name
);
119 event
->filter
= filter
;
120 event
->id
= chan
->free_event_id
++;
121 mutex_unlock(&sessions_mutex
);
122 /* Populate ltt_event structure before tracepoint registration. */
124 /* TODO register to tracepoint */
128 kmem_cache_free(event
);
132 mutex_unlock(&sessions_mutex
);
137 * Only used internally at session destruction.
139 int _ltt_event_destroy(struct ltt_event
*event
)
141 /* TODO unregister from tracepoint */
143 kmem_cache_free(event
);
146 static int __init
ltt_events_init(void)
150 events_cache
= KMEM_CACHE(ltt_event
, 0);
154 /* TODO: show ABI to userspace */
159 static void __exit
ltt_events_exit(void)
161 struct ltt_session
*session
, *tmpsession
;
163 /* TODO: hide ABI from userspace, wait for callers to release refs. */
165 list_for_each_entry_safe(session
, tmpsession
, &sessions
, list
)
166 ltt_session_destroy(session
);
167 kmem_cache_destroy(events_cache
);
170 MODULE_LICENSE("GPL and additional rights");
171 MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
172 MODULE_DESCRIPTION("LTTng Events");
This page took 0.037447 seconds and 4 git commands to generate.