2 * Copyright (C) 2007 Mathieu Desnoyers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 * LTT marker control module over /proc
27 #define DEFAULT_CHANNEL "cpu"
28 #define DEFAULT_PROBE "default"
30 LIST_HEAD(probes_list
);
33 * Mutex protecting the probe slab cache.
34 * Nests inside the traces mutex.
36 DEFINE_MUTEX(probes_mutex
);
38 struct ltt_available_probe default_probe
= {
41 .probe_func
= ltt_vtrace
,
42 .callbacks
[0] = ltt_serialize_data
,
45 //ust//static struct kmem_cache *markers_loaded_cachep;
46 static LIST_HEAD(markers_loaded_list
);
48 * List sorted by name strcmp order.
50 static LIST_HEAD(probes_registered_list
);
52 //ust// static struct proc_dir_entry *pentry;
54 //ust// static struct file_operations ltt_fops;
56 static struct ltt_available_probe
*get_probe_from_name(const char *pname
)
58 struct ltt_available_probe
*iter
;
59 int comparison
, found
= 0;
62 pname
= DEFAULT_PROBE
;
63 list_for_each_entry(iter
, &probes_registered_list
, node
) {
64 comparison
= strcmp(pname
, iter
->name
);
77 static char *skip_spaces(char *buf)
79 while (*buf != '\0' && isspace(*buf))
84 static char *skip_nonspaces(char *buf)
86 while (*buf != '\0' && !isspace(*buf))
91 static void get_marker_string(char *buf, char **start,
94 *start = skip_spaces(buf);
95 *end = skip_nonspaces(*start);
100 int ltt_probe_register(struct ltt_available_probe
*pdata
)
104 struct ltt_available_probe
*iter
;
106 mutex_lock(&probes_mutex
);
107 list_for_each_entry_reverse(iter
, &probes_registered_list
, node
) {
108 comparison
= strcmp(pdata
->name
, iter
->name
);
112 } else if (comparison
> 0) {
113 /* We belong to the location right after iter. */
114 list_add(&pdata
->node
, &iter
->node
);
118 /* Should be added at the head of the list */
119 list_add(&pdata
->node
, &probes_registered_list
);
121 mutex_unlock(&probes_mutex
);
126 * Called when a probe does not want to be called anymore.
128 int ltt_probe_unregister(struct ltt_available_probe
*pdata
)
131 struct ltt_active_marker
*amark
, *tmp
;
133 mutex_lock(&probes_mutex
);
134 list_for_each_entry_safe(amark
, tmp
, &markers_loaded_list
, node
) {
135 if (amark
->probe
== pdata
) {
136 ret
= marker_probe_unregister_private_data(
137 pdata
->probe_func
, amark
);
140 list_del(&amark
->node
);
144 list_del(&pdata
->node
);
146 mutex_unlock(&probes_mutex
);
151 * Connect marker "mname" to probe "pname".
152 * Only allow _only_ probe instance to be connected to a marker.
154 int ltt_marker_connect(const char *channel
, const char *mname
,
159 struct ltt_active_marker
*pdata
;
160 struct ltt_available_probe
*probe
;
163 mutex_lock(&probes_mutex
);
164 probe
= get_probe_from_name(pname
);
169 pdata
= marker_get_private_data(channel
, mname
, probe
->probe_func
, 0);
170 if (pdata
&& !IS_ERR(pdata
)) {
174 pdata
= zmalloc(sizeof(struct ltt_active_marker
));
179 pdata
->probe
= probe
;
181 * ID has priority over channel in case of conflict.
183 ret
= marker_probe_register(channel
, mname
, NULL
,
184 probe
->probe_func
, pdata
);
188 list_add(&pdata
->node
, &markers_loaded_list
);
190 mutex_unlock(&probes_mutex
);
196 * Disconnect marker "mname", probe "pname".
198 int ltt_marker_disconnect(const char *channel
, const char *mname
,
201 struct ltt_active_marker
*pdata
;
202 struct ltt_available_probe
*probe
;
205 mutex_lock(&probes_mutex
);
206 probe
= get_probe_from_name(pname
);
211 pdata
= marker_get_private_data(channel
, mname
, probe
->probe_func
, 0);
213 ret
= PTR_ERR(pdata
);
217 * Not registered by us.
222 ret
= marker_probe_unregister(channel
, mname
, probe
->probe_func
, pdata
);
226 list_del(&pdata
->node
);
230 mutex_unlock(&probes_mutex
);
235 * function handling proc entry write.
237 * connect <channel name> <marker name> [<probe name>]]
238 * disconnect <channel name> <marker name> [<probe name>]
240 //ust// static ssize_t ltt_write(struct file *file, const char __user *buffer,
241 //ust// size_t count, loff_t *offset)
244 //ust// char *iter, *marker_action, *arg[4];
249 //ust// return -EINVAL;
251 //ust// kbuf = vmalloc(count + 1);
252 //ust// kbuf[count] = '\0'; /* Transform into a string */
253 //ust// ret = copy_from_user(kbuf, buffer, count);
255 //ust// ret = -EINVAL;
258 //ust// get_marker_string(kbuf, &marker_action, &iter);
259 //ust// if (!marker_action || marker_action == iter) {
260 //ust// ret = -EINVAL;
263 //ust// for (i = 0; i < 4; i++) {
264 //ust// arg[i] = NULL;
265 //ust// if (iter < kbuf + count) {
266 //ust// iter++; /* skip the added '\0' */
267 //ust// get_marker_string(iter, &arg[i], &iter);
268 //ust// if (arg[i] == iter)
269 //ust// arg[i] = NULL;
273 //ust// if (!arg[0] || !arg[1]) {
274 //ust// ret = -EINVAL;
278 //ust// if (!strcmp(marker_action, "connect")) {
279 //ust// ret = ltt_marker_connect(arg[0], arg[1], arg[2]);
282 //ust// } else if (!strcmp(marker_action, "disconnect")) {
283 //ust// ret = ltt_marker_disconnect(arg[0], arg[1], arg[2]);
293 //ust// static void *s_next(struct seq_file *m, void *p, loff_t *pos)
295 //ust// struct marker_iter *iter = m->private;
297 //ust// marker_iter_next(iter);
298 //ust// if (!iter->marker) {
300 //ust// * Setting the iter module to -1UL will make sure
301 //ust// * that no module can possibly hold the current marker.
303 //ust// iter->module = (void *)-1UL;
306 //ust// return iter->marker;
309 //ust// static void *s_start(struct seq_file *m, loff_t *pos)
311 //ust// struct marker_iter *iter = m->private;
314 //ust// marker_iter_reset(iter);
315 //ust// marker_iter_start(iter);
316 //ust// if (!iter->marker) {
318 //ust// * Setting the iter module to -1UL will make sure
319 //ust// * that no module can possibly hold the current marker.
321 //ust// iter->module = (void *)-1UL;
324 //ust// return iter->marker;
327 //ust// static void s_stop(struct seq_file *m, void *p)
329 //ust// marker_iter_stop(m->private);
332 //ust// static int s_show(struct seq_file *m, void *p)
334 //ust// struct marker_iter *iter = m->private;
336 //ust// seq_printf(m, "channel: %s marker: %s format: \"%s\" state: %d "
337 //ust// "event_id: %hu call: 0x%p probe %s : 0x%p\n",
338 //ust// iter->marker->channel,
339 //ust// iter->marker->name, iter->marker->format,
340 //ust// _imv_read(iter->marker->state),
341 //ust// iter->marker->event_id,
342 //ust// iter->marker->call,
343 //ust// iter->marker->ptype ? "multi" : "single",
344 //ust// iter->marker->ptype ?
345 //ust// (void*)iter->marker->multi : (void*)iter->marker->single.func);
349 //ust// static const struct seq_operations ltt_seq_op = {
350 //ust// .start = s_start,
351 //ust// .next = s_next,
352 //ust// .stop = s_stop,
353 //ust// .show = s_show,
356 //ust// static int ltt_open(struct inode *inode, struct file *file)
359 //ust// * Iterator kept in m->private.
360 //ust// * Restart iteration on all modules between reads because we do not lock
361 //ust// * the module mutex between those.
364 //ust// struct marker_iter *iter;
366 //ust// iter = kzalloc(sizeof(*iter), GFP_KERNEL);
368 //ust// return -ENOMEM;
370 //ust// ret = seq_open(file, <t_seq_op);
371 //ust// if (ret == 0)
372 //ust// ((struct seq_file *)file->private_data)->private = iter;
378 //ust// static struct file_operations ltt_fops = {
379 //ust// .write = ltt_write,
380 //ust// .open = ltt_open,
381 //ust// .read = seq_read,
382 //ust// .llseek = seq_lseek,
383 //ust// .release = seq_release_private,
386 static void disconnect_all_markers(void)
388 struct ltt_active_marker
*pdata
, *tmp
;
390 list_for_each_entry_safe(pdata
, tmp
, &markers_loaded_list
, node
) {
391 marker_probe_unregister_private_data(pdata
->probe
->probe_func
,
393 list_del(&pdata
->node
);
398 static char initialized
= 0;
400 void __attribute__((constructor
)) init_marker_control(void)
405 //ust// pentry = create_proc_entry("ltt", S_IRUSR|S_IWUSR, NULL);
407 //ust// return -EBUSY;
408 //ust// markers_loaded_cachep = KMEM_CACHE(ltt_active_marker, 0);
410 ret
= ltt_probe_register(&default_probe
);
412 ret
= ltt_marker_connect("metadata", "core_marker_format",
415 ret
= ltt_marker_connect("metadata", "core_marker_id", DEFAULT_PROBE
);
417 //ust// pentry->proc_fops = <t_fops;
422 //ust// module_init(marker_control_init);
424 static void __attribute__((destructor
)) marker_control_exit(void)
428 //ust// remove_proc_entry("ltt", NULL);
429 ret
= ltt_marker_disconnect("metadata", "core_marker_format",
432 ret
= ltt_marker_disconnect("metadata", "core_marker_id",
435 ret
= ltt_probe_unregister(&default_probe
);
437 disconnect_all_markers();
438 //ust// kmem_cache_destroy(markers_loaded_cachep);
439 //ust// marker_synchronize_unregister();
441 //ust// module_exit(marker_control_exit);
443 //ust// MODULE_LICENSE("GPL");
444 //ust// MODULE_AUTHOR("Mathieu Desnoyers");
445 //ust// MODULE_DESCRIPTION("Linux Trace Toolkit Marker Control");