a85b7932e38e42ffda5fba7fa501aa55b0282381
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
);
62 list_for_each_entry(chan
, &session
->chan
, list
)
63 if (!strcmp(chan
->name
, name
))
65 chan
= kmalloc(sizeof(struct ltt_channel
) + strlen(name
) + 1, GFP_KERNEL
);
68 strcpy(chan
->name
, name
);
69 chan
->session
= session
;
71 /* TODO: create rb channel */
72 list_add(&chan
->list
, &session
->chan
);
73 mutex_unlock(&sessions_mutex
);
77 mutex_unlock(&sessions_mutex
);
82 * Only used internally at session destruction.
84 int _ltt_channel_destroy(struct ltt_channel
*chan
)
86 list_del(&chan
->list
);
90 struct ltt_event
*ltt_event_create(struct ltt_channel
*chan
, char *name
,
93 struct ltt_event
*event
;
95 mutex_lock(&sessions_mutex
);
97 * This is O(n^2) (for each event loop called at event creation).
98 * Might require a hash if we have lots of events.
100 list_for_each_entry(event
, &chan
->session
->events
, list
)
101 if (!strcmp(event
->name
, name
))
103 event
= kmem_cache_zalloc(events_cache
, GFP_KERNEL
);
106 event
->name
= kmalloc(strlen(name
) + 1, GFP_KERNEL
);
109 strcpy(event
->name
, name
);
111 event
->filter
= filter
;
112 event
->id
= atomic_inc_return(&chan
->free_event_id
) - 1;
113 /* TODO register to tracepoint */
114 mutex_unlock(&sessions_mutex
);
118 kmem_cache_free(event
);
121 mutex_unlock(&sessions_mutex
);
126 * Only used internally at session destruction.
128 int _ltt_event_destroy(struct ltt_event
*event
)
130 /* TODO unregister from tracepoint */
132 kmem_cache_free(event
);
135 static int __init
ltt_events_init(void)
139 events_cache
= KMEM_CACHE(ltt_event
, 0);
145 static void __exit
ltt_events_exit(void)
147 kmem_cache_destroy(events_cache
);
This page took 0.031996 seconds and 4 git commands to generate.