4 * Copyright (C) 2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; only
9 * version 2.1 of the License.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <linux/module.h>
22 #include <linux/kmod.h>
23 #include <linux/mutex.h>
25 #include <wrapper/trace-clock.h>
26 #include <lttng-events.h>
27 #include <lttng-tracer.h>
29 struct lttng_trace_clock
*lttng_trace_clock
;
30 EXPORT_SYMBOL_GPL(lttng_trace_clock
);
32 static DEFINE_MUTEX(clock_mutex
);
33 static struct module
*lttng_trace_clock_mod
; /* plugin */
34 static int clock_used
; /* refcount */
36 int lttng_clock_register_plugin(struct lttng_trace_clock
*ltc
,
41 mutex_lock(&clock_mutex
);
46 if (lttng_trace_clock_mod
) {
51 ACCESS_ONCE(lttng_trace_clock
) = ltc
;
52 lttng_trace_clock_mod
= mod
;
54 mutex_unlock(&clock_mutex
);
57 EXPORT_SYMBOL_GPL(lttng_clock_register_plugin
);
59 void lttng_clock_unregister_plugin(struct lttng_trace_clock
*ltc
,
62 mutex_lock(&clock_mutex
);
63 WARN_ON_ONCE(clock_used
);
64 if (!lttng_trace_clock_mod
) {
67 WARN_ON_ONCE(lttng_trace_clock_mod
!= mod
);
69 ACCESS_ONCE(lttng_trace_clock
) = NULL
;
70 lttng_trace_clock_mod
= NULL
;
72 mutex_unlock(&clock_mutex
);
74 EXPORT_SYMBOL_GPL(lttng_clock_unregister_plugin
);
76 void lttng_clock_ref(void)
78 mutex_lock(&clock_mutex
);
80 if (lttng_trace_clock_mod
) {
83 ret
= try_module_get(lttng_trace_clock_mod
);
85 printk(KERN_ERR
"LTTng-clock cannot get clock plugin module\n");
86 ACCESS_ONCE(lttng_trace_clock
) = NULL
;
87 lttng_trace_clock_mod
= NULL
;
90 mutex_unlock(&clock_mutex
);
92 EXPORT_SYMBOL_GPL(lttng_clock_ref
);
94 void lttng_clock_unref(void)
96 mutex_lock(&clock_mutex
);
98 if (lttng_trace_clock_mod
)
99 module_put(lttng_trace_clock_mod
);
100 mutex_unlock(&clock_mutex
);
102 EXPORT_SYMBOL_GPL(lttng_clock_unref
);
104 MODULE_LICENSE("GPL and additional rights");
105 MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
106 MODULE_DESCRIPTION("LTTng Clock");
107 MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION
) "."
108 __stringify(LTTNG_MODULES_MINOR_VERSION
) "."
109 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION
)
110 LTTNG_MODULES_EXTRAVERSION
);