2 * LTT core in-kernel infrastructure.
4 * Copyright 2006 - Mathieu Desnoyers mathieu.desnoyers@polymtl.ca
6 * Dual LGPL v2.1/GPL v2 license.
9 #include <linux/percpu.h>
10 #include <linux/module.h>
11 #include <linux/debugfs.h>
12 #include <linux/kref.h>
13 #include <linux/cpu.h>
15 #include "ltt-tracer-core.h"
17 /* Traces structures */
18 struct ltt_traces ltt_traces
= {
19 .setup_head
= LIST_HEAD_INIT(ltt_traces
.setup_head
),
20 .head
= LIST_HEAD_INIT(ltt_traces
.head
),
22 EXPORT_SYMBOL(ltt_traces
);
24 /* Traces list writer locking */
25 static DEFINE_MUTEX(ltt_traces_mutex
);
27 /* root dentry mutex */
28 static DEFINE_MUTEX(ltt_root_mutex
);
29 /* dentry of ltt's root dir */
30 static struct dentry
*ltt_root_dentry
;
31 static struct kref ltt_root_kref
= {
32 .refcount
= ATOMIC_INIT(0),
35 static void ltt_root_release(struct kref
*ref
)
37 debugfs_remove(ltt_root_dentry
);
38 ltt_root_dentry
= NULL
;
41 void put_ltt_root(void)
43 mutex_lock(<t_root_mutex
);
45 kref_put(<t_root_kref
, ltt_root_release
);
46 mutex_unlock(<t_root_mutex
);
48 EXPORT_SYMBOL_GPL(put_ltt_root
);
50 struct dentry
*get_ltt_root(void)
52 mutex_lock(<t_root_mutex
);
53 if (!ltt_root_dentry
) {
54 ltt_root_dentry
= debugfs_create_dir(LTT_ROOT
, NULL
);
55 if (!ltt_root_dentry
) {
56 printk(KERN_ERR
"LTT : create ltt root dir failed\n");
59 kref_init(<t_root_kref
);
62 kref_get(<t_root_kref
);
64 mutex_unlock(<t_root_mutex
);
65 return ltt_root_dentry
;
67 EXPORT_SYMBOL_GPL(get_ltt_root
);
70 * ltt_lock_traces/ltt_unlock_traces also disables cpu hotplug.
72 void ltt_lock_traces(void)
74 mutex_lock(<t_traces_mutex
);
77 EXPORT_SYMBOL_GPL(ltt_lock_traces
);
79 void ltt_unlock_traces(void)
82 mutex_unlock(<t_traces_mutex
);
84 EXPORT_SYMBOL_GPL(ltt_unlock_traces
);
86 DEFINE_PER_CPU(unsigned int, ltt_nesting
);
87 EXPORT_PER_CPU_SYMBOL(ltt_nesting
);
89 int ltt_run_filter_default(void *trace
, uint16_t eID
)
94 /* This function pointer is protected by a trace activation check */
95 ltt_run_filter_functor ltt_run_filter
= ltt_run_filter_default
;
96 EXPORT_SYMBOL_GPL(ltt_run_filter
);
98 void ltt_filter_register(ltt_run_filter_functor func
)
100 ltt_run_filter
= func
;
102 EXPORT_SYMBOL_GPL(ltt_filter_register
);
104 void ltt_filter_unregister(void)
106 ltt_run_filter
= ltt_run_filter_default
;
108 EXPORT_SYMBOL_GPL(ltt_filter_unregister
);
110 MODULE_LICENSE("GPL and additional rights");
111 MODULE_AUTHOR("Mathieu Desnoyers");
112 MODULE_DESCRIPTION("Linux Trace Toolkit Next Generation Tracer Core");