Add ltt-debugfs-abi.h
[lttng-modules.git] / ltt-core.c
1 /*
2 * LTT core in-kernel infrastructure.
3 *
4 * Copyright 2006 - Mathieu Desnoyers mathieu.desnoyers@polymtl.ca
5 *
6 * Dual LGPL v2.1/GPL v2 license.
7 */
8
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>
14
15 #include "ltt-tracer-core.h"
16
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),
21 };
22 EXPORT_SYMBOL(ltt_traces);
23
24 /* Traces list writer locking */
25 static DEFINE_MUTEX(ltt_traces_mutex);
26
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),
33 };
34
35 static void ltt_root_release(struct kref *ref)
36 {
37 debugfs_remove(ltt_root_dentry);
38 ltt_root_dentry = NULL;
39 }
40
41 void put_ltt_root(void)
42 {
43 mutex_lock(&ltt_root_mutex);
44 if (ltt_root_dentry)
45 kref_put(&ltt_root_kref, ltt_root_release);
46 mutex_unlock(&ltt_root_mutex);
47 }
48 EXPORT_SYMBOL_GPL(put_ltt_root);
49
50 struct dentry *get_ltt_root(void)
51 {
52 mutex_lock(&ltt_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");
57 goto out;
58 }
59 kref_init(&ltt_root_kref);
60 goto out;
61 }
62 kref_get(&ltt_root_kref);
63 out:
64 mutex_unlock(&ltt_root_mutex);
65 return ltt_root_dentry;
66 }
67 EXPORT_SYMBOL_GPL(get_ltt_root);
68
69 /*
70 * ltt_lock_traces/ltt_unlock_traces also disables cpu hotplug.
71 */
72 void ltt_lock_traces(void)
73 {
74 mutex_lock(&ltt_traces_mutex);
75 get_online_cpus();
76 }
77 EXPORT_SYMBOL_GPL(ltt_lock_traces);
78
79 void ltt_unlock_traces(void)
80 {
81 put_online_cpus();
82 mutex_unlock(&ltt_traces_mutex);
83 }
84 EXPORT_SYMBOL_GPL(ltt_unlock_traces);
85
86 DEFINE_PER_CPU(unsigned int, ltt_nesting);
87 EXPORT_PER_CPU_SYMBOL(ltt_nesting);
88
89 int ltt_run_filter_default(void *trace, uint16_t eID)
90 {
91 return 1;
92 }
93
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);
97
98 void ltt_filter_register(ltt_run_filter_functor func)
99 {
100 ltt_run_filter = func;
101 }
102 EXPORT_SYMBOL_GPL(ltt_filter_register);
103
104 void ltt_filter_unregister(void)
105 {
106 ltt_run_filter = ltt_run_filter_default;
107 }
108 EXPORT_SYMBOL_GPL(ltt_filter_unregister);
109
110 MODULE_LICENSE("GPL and additional rights");
111 MODULE_AUTHOR("Mathieu Desnoyers");
112 MODULE_DESCRIPTION("Linux Trace Toolkit Next Generation Tracer Core");
This page took 0.033662 seconds and 5 git commands to generate.