1 /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
5 * Copyright (C) 2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 #include <linux/module.h>
9 #include <linux/kmod.h>
10 #include <linux/mutex.h>
12 #include <wrapper/trace-clock.h>
13 #include <lttng/events.h>
14 #include <lttng/tracer.h>
16 struct lttng_trace_clock
*lttng_trace_clock
;
17 EXPORT_SYMBOL_GPL(lttng_trace_clock
);
19 static DEFINE_MUTEX(clock_mutex
);
20 static struct module
*lttng_trace_clock_mod
; /* plugin */
21 static int clock_used
; /* refcount */
23 int lttng_clock_register_plugin(struct lttng_trace_clock
*ltc
,
28 mutex_lock(&clock_mutex
);
33 if (lttng_trace_clock_mod
) {
38 WRITE_ONCE(lttng_trace_clock
, ltc
);
39 lttng_trace_clock_mod
= mod
;
41 mutex_unlock(&clock_mutex
);
44 EXPORT_SYMBOL_GPL(lttng_clock_register_plugin
);
46 void lttng_clock_unregister_plugin(struct lttng_trace_clock
*ltc
,
49 mutex_lock(&clock_mutex
);
50 WARN_ON_ONCE(clock_used
);
51 if (!lttng_trace_clock_mod
) {
54 WARN_ON_ONCE(lttng_trace_clock_mod
!= mod
);
56 WRITE_ONCE(lttng_trace_clock
, NULL
);
57 lttng_trace_clock_mod
= NULL
;
59 mutex_unlock(&clock_mutex
);
61 EXPORT_SYMBOL_GPL(lttng_clock_unregister_plugin
);
63 void lttng_clock_ref(void)
65 mutex_lock(&clock_mutex
);
67 if (lttng_trace_clock_mod
) {
70 ret
= try_module_get(lttng_trace_clock_mod
);
72 printk(KERN_ERR
"LTTng: LTTng-clock cannot get clock plugin module\n");
73 WRITE_ONCE(lttng_trace_clock
, NULL
);
74 lttng_trace_clock_mod
= NULL
;
77 mutex_unlock(&clock_mutex
);
79 EXPORT_SYMBOL_GPL(lttng_clock_ref
);
81 void lttng_clock_unref(void)
83 mutex_lock(&clock_mutex
);
85 if (lttng_trace_clock_mod
)
86 module_put(lttng_trace_clock_mod
);
87 mutex_unlock(&clock_mutex
);
89 EXPORT_SYMBOL_GPL(lttng_clock_unref
);
91 MODULE_LICENSE("GPL and additional rights");
92 MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
93 MODULE_DESCRIPTION("LTTng Clock");
94 MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION
) "."
95 __stringify(LTTNG_MODULES_MINOR_VERSION
) "."
96 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION
)
97 LTTNG_MODULES_EXTRAVERSION
);