2 * Copyright (C) 2007 Mathieu Desnoyers
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program 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
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 * LTT marker control module over /proc
21 //ust// #include <linux/proc_fs.h>
22 //ust// #include <linux/module.h>
23 //ust// #include <linux/stat.h>
24 //ust// #include <linux/vmalloc.h>
25 //ust// #include <linux/marker.h>
26 //ust// #include <linux/ltt-tracer.h>
27 //ust// #include <linux/uaccess.h>
28 //ust// #include <linux/string.h>
29 //ust// #include <linux/ctype.h>
30 //ust// #include <linux/list.h>
31 //ust// #include <linux/mutex.h>
32 //ust// #include <linux/seq_file.h>
33 //ust// #include <linux/slab.h>
34 #include "kernelcompat.h"
39 #define DEFAULT_CHANNEL "cpu"
40 #define DEFAULT_PROBE "default"
42 LIST_HEAD(probes_list
);
45 * Mutex protecting the probe slab cache.
46 * Nests inside the traces mutex.
48 DEFINE_MUTEX(probes_mutex
);
50 struct ltt_available_probe default_probe
= {
53 .probe_func
= ltt_vtrace
,
54 .callbacks
[0] = ltt_serialize_data
,
57 //ust//static struct kmem_cache *markers_loaded_cachep;
58 static LIST_HEAD(markers_loaded_list
);
60 * List sorted by name strcmp order.
62 static LIST_HEAD(probes_registered_list
);
64 //ust// static struct proc_dir_entry *pentry;
66 //ust// static struct file_operations ltt_fops;
68 static struct ltt_available_probe
*get_probe_from_name(const char *pname
)
70 struct ltt_available_probe
*iter
;
71 int comparison
, found
= 0;
74 pname
= DEFAULT_PROBE
;
75 list_for_each_entry(iter
, &probes_registered_list
, node
) {
76 comparison
= strcmp(pname
, iter
->name
);
88 static char *skip_spaces(char *buf
)
90 while (*buf
!= '\0' && isspace(*buf
))
95 static char *skip_nonspaces(char *buf
)
97 while (*buf
!= '\0' && !isspace(*buf
))
102 static void get_marker_string(char *buf
, char **start
,
105 *start
= skip_spaces(buf
);
106 *end
= skip_nonspaces(*start
);
110 int ltt_probe_register(struct ltt_available_probe
*pdata
)
114 struct ltt_available_probe
*iter
;
116 mutex_lock(&probes_mutex
);
117 list_for_each_entry_reverse(iter
, &probes_registered_list
, node
) {
118 comparison
= strcmp(pdata
->name
, iter
->name
);
122 } else if (comparison
> 0) {
123 /* We belong to the location right after iter. */
124 list_add(&pdata
->node
, &iter
->node
);
128 /* Should be added at the head of the list */
129 list_add(&pdata
->node
, &probes_registered_list
);
131 mutex_unlock(&probes_mutex
);
134 EXPORT_SYMBOL_GPL(ltt_probe_register
);
137 * Called when a probe does not want to be called anymore.
139 int ltt_probe_unregister(struct ltt_available_probe
*pdata
)
142 struct ltt_active_marker
*amark
, *tmp
;
144 mutex_lock(&probes_mutex
);
145 list_for_each_entry_safe(amark
, tmp
, &markers_loaded_list
, node
) {
146 if (amark
->probe
== pdata
) {
147 ret
= marker_probe_unregister_private_data(
148 pdata
->probe_func
, amark
);
151 list_del(&amark
->node
);
155 list_del(&pdata
->node
);
157 mutex_unlock(&probes_mutex
);
160 EXPORT_SYMBOL_GPL(ltt_probe_unregister
);
163 * Connect marker "mname" to probe "pname".
164 * Only allow _only_ probe instance to be connected to a marker.
166 int ltt_marker_connect(const char *channel
, const char *mname
,
171 struct ltt_active_marker
*pdata
;
172 struct ltt_available_probe
*probe
;
175 mutex_lock(&probes_mutex
);
176 probe
= get_probe_from_name(pname
);
181 pdata
= marker_get_private_data(channel
, mname
, probe
->probe_func
, 0);
182 if (pdata
&& !IS_ERR(pdata
)) {
186 pdata
= zmalloc(sizeof(struct ltt_active_marker
));
191 pdata
->probe
= probe
;
193 * ID has priority over channel in case of conflict.
195 ret
= marker_probe_register(channel
, mname
, NULL
,
196 probe
->probe_func
, pdata
);
200 list_add(&pdata
->node
, &markers_loaded_list
);
202 mutex_unlock(&probes_mutex
);
206 EXPORT_SYMBOL_GPL(ltt_marker_connect
);
209 * Disconnect marker "mname", probe "pname".
211 int ltt_marker_disconnect(const char *channel
, const char *mname
,
214 struct ltt_active_marker
*pdata
;
215 struct ltt_available_probe
*probe
;
218 mutex_lock(&probes_mutex
);
219 probe
= get_probe_from_name(pname
);
224 pdata
= marker_get_private_data(channel
, mname
, probe
->probe_func
, 0);
226 ret
= PTR_ERR(pdata
);
230 * Not registered by us.
235 ret
= marker_probe_unregister(channel
, mname
, probe
->probe_func
, pdata
);
239 list_del(&pdata
->node
);
243 mutex_unlock(&probes_mutex
);
246 EXPORT_SYMBOL_GPL(ltt_marker_disconnect
);
249 * function handling proc entry write.
251 * connect <channel name> <marker name> [<probe name>]]
252 * disconnect <channel name> <marker name> [<probe name>]
254 //ust// static ssize_t ltt_write(struct file *file, const char __user *buffer,
255 //ust// size_t count, loff_t *offset)
258 //ust// char *iter, *marker_action, *arg[4];
263 //ust// return -EINVAL;
265 //ust// kbuf = vmalloc(count + 1);
266 //ust// kbuf[count] = '\0'; /* Transform into a string */
267 //ust// ret = copy_from_user(kbuf, buffer, count);
269 //ust// ret = -EINVAL;
272 //ust// get_marker_string(kbuf, &marker_action, &iter);
273 //ust// if (!marker_action || marker_action == iter) {
274 //ust// ret = -EINVAL;
277 //ust// for (i = 0; i < 4; i++) {
278 //ust// arg[i] = NULL;
279 //ust// if (iter < kbuf + count) {
280 //ust// iter++; /* skip the added '\0' */
281 //ust// get_marker_string(iter, &arg[i], &iter);
282 //ust// if (arg[i] == iter)
283 //ust// arg[i] = NULL;
287 //ust// if (!arg[0] || !arg[1]) {
288 //ust// ret = -EINVAL;
292 //ust// if (!strcmp(marker_action, "connect")) {
293 //ust// ret = ltt_marker_connect(arg[0], arg[1], arg[2]);
296 //ust// } else if (!strcmp(marker_action, "disconnect")) {
297 //ust// ret = ltt_marker_disconnect(arg[0], arg[1], arg[2]);
307 //ust// static void *s_next(struct seq_file *m, void *p, loff_t *pos)
309 //ust// struct marker_iter *iter = m->private;
311 //ust// marker_iter_next(iter);
312 //ust// if (!iter->marker) {
314 //ust// * Setting the iter module to -1UL will make sure
315 //ust// * that no module can possibly hold the current marker.
317 //ust// iter->module = (void *)-1UL;
320 //ust// return iter->marker;
323 //ust// static void *s_start(struct seq_file *m, loff_t *pos)
325 //ust// struct marker_iter *iter = m->private;
328 //ust// marker_iter_reset(iter);
329 //ust// marker_iter_start(iter);
330 //ust// if (!iter->marker) {
332 //ust// * Setting the iter module to -1UL will make sure
333 //ust// * that no module can possibly hold the current marker.
335 //ust// iter->module = (void *)-1UL;
338 //ust// return iter->marker;
341 //ust// static void s_stop(struct seq_file *m, void *p)
343 //ust// marker_iter_stop(m->private);
346 //ust// static int s_show(struct seq_file *m, void *p)
348 //ust// struct marker_iter *iter = m->private;
350 //ust// seq_printf(m, "channel: %s marker: %s format: \"%s\" state: %d "
351 //ust// "event_id: %hu call: 0x%p probe %s : 0x%p\n",
352 //ust// iter->marker->channel,
353 //ust// iter->marker->name, iter->marker->format,
354 //ust// _imv_read(iter->marker->state),
355 //ust// iter->marker->event_id,
356 //ust// iter->marker->call,
357 //ust// iter->marker->ptype ? "multi" : "single",
358 //ust// iter->marker->ptype ?
359 //ust// (void*)iter->marker->multi : (void*)iter->marker->single.func);
363 //ust// static const struct seq_operations ltt_seq_op = {
364 //ust// .start = s_start,
365 //ust// .next = s_next,
366 //ust// .stop = s_stop,
367 //ust// .show = s_show,
370 //ust// static int ltt_open(struct inode *inode, struct file *file)
373 //ust// * Iterator kept in m->private.
374 //ust// * Restart iteration on all modules between reads because we do not lock
375 //ust// * the module mutex between those.
378 //ust// struct marker_iter *iter;
380 //ust// iter = kzalloc(sizeof(*iter), GFP_KERNEL);
382 //ust// return -ENOMEM;
384 //ust// ret = seq_open(file, <t_seq_op);
385 //ust// if (ret == 0)
386 //ust// ((struct seq_file *)file->private_data)->private = iter;
392 //ust// static struct file_operations ltt_fops = {
393 //ust// .write = ltt_write,
394 //ust// .open = ltt_open,
395 //ust// .read = seq_read,
396 //ust// .llseek = seq_lseek,
397 //ust// .release = seq_release_private,
400 static void disconnect_all_markers(void)
402 struct ltt_active_marker
*pdata
, *tmp
;
404 list_for_each_entry_safe(pdata
, tmp
, &markers_loaded_list
, node
) {
405 marker_probe_unregister_private_data(pdata
->probe
->probe_func
,
407 list_del(&pdata
->node
);
412 static char initialized
= 0;
414 void __attribute__((constructor
)) init_marker_control(void)
419 //ust// pentry = create_proc_entry("ltt", S_IRUSR|S_IWUSR, NULL);
421 //ust// return -EBUSY;
422 //ust// markers_loaded_cachep = KMEM_CACHE(ltt_active_marker, 0);
424 ret
= ltt_probe_register(&default_probe
);
426 ret
= ltt_marker_connect("metadata", "core_marker_format",
429 ret
= ltt_marker_connect("metadata", "core_marker_id", DEFAULT_PROBE
);
431 //ust// pentry->proc_fops = <t_fops;
436 //ust// module_init(marker_control_init);
438 static void __exit
marker_control_exit(void)
442 //ust// remove_proc_entry("ltt", NULL);
443 ret
= ltt_marker_disconnect("metadata", "core_marker_format",
446 ret
= ltt_marker_disconnect("metadata", "core_marker_id",
449 ret
= ltt_probe_unregister(&default_probe
);
451 disconnect_all_markers();
452 //ust// kmem_cache_destroy(markers_loaded_cachep);
453 //ust// marker_synchronize_unregister();
455 //ust// module_exit(marker_control_exit);
457 //ust// MODULE_LICENSE("GPL");
458 //ust// MODULE_AUTHOR("Mathieu Desnoyers");
459 //ust// MODULE_DESCRIPTION("Linux Trace Toolkit Marker Control");