-
Notifications
You must be signed in to change notification settings - Fork 0
/
lttng-clock.c
97 lines (85 loc) · 2.22 KB
/
lttng-clock.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1)
*
* lttng-clock.c
*
* Copyright (C) 2014 Mathieu Desnoyers <[email protected]>
*/
#include <linux/module.h>
#include <linux/kmod.h>
#include <linux/mutex.h>
#include <wrapper/trace-clock.h>
#include <lttng-events.h>
#include <lttng-tracer.h>
struct lttng_trace_clock *lttng_trace_clock;
EXPORT_SYMBOL_GPL(lttng_trace_clock);
static DEFINE_MUTEX(clock_mutex);
static struct module *lttng_trace_clock_mod; /* plugin */
static int clock_used; /* refcount */
int lttng_clock_register_plugin(struct lttng_trace_clock *ltc,
struct module *mod)
{
int ret = 0;
mutex_lock(&clock_mutex);
if (clock_used) {
ret = -EBUSY;
goto end;
}
if (lttng_trace_clock_mod) {
ret = -EEXIST;
goto end;
}
/* set clock */
WRITE_ONCE(lttng_trace_clock, ltc);
lttng_trace_clock_mod = mod;
end:
mutex_unlock(&clock_mutex);
return ret;
}
EXPORT_SYMBOL_GPL(lttng_clock_register_plugin);
void lttng_clock_unregister_plugin(struct lttng_trace_clock *ltc,
struct module *mod)
{
mutex_lock(&clock_mutex);
WARN_ON_ONCE(clock_used);
if (!lttng_trace_clock_mod) {
goto end;
}
WARN_ON_ONCE(lttng_trace_clock_mod != mod);
WRITE_ONCE(lttng_trace_clock, NULL);
lttng_trace_clock_mod = NULL;
end:
mutex_unlock(&clock_mutex);
}
EXPORT_SYMBOL_GPL(lttng_clock_unregister_plugin);
void lttng_clock_ref(void)
{
mutex_lock(&clock_mutex);
clock_used++;
if (lttng_trace_clock_mod) {
int ret;
ret = try_module_get(lttng_trace_clock_mod);
if (!ret) {
printk(KERN_ERR "LTTng-clock cannot get clock plugin module\n");
WRITE_ONCE(lttng_trace_clock, NULL);
lttng_trace_clock_mod = NULL;
}
}
mutex_unlock(&clock_mutex);
}
EXPORT_SYMBOL_GPL(lttng_clock_ref);
void lttng_clock_unref(void)
{
mutex_lock(&clock_mutex);
clock_used--;
if (lttng_trace_clock_mod)
module_put(lttng_trace_clock_mod);
mutex_unlock(&clock_mutex);
}
EXPORT_SYMBOL_GPL(lttng_clock_unref);
MODULE_LICENSE("GPL and additional rights");
MODULE_AUTHOR("Mathieu Desnoyers <[email protected]>");
MODULE_DESCRIPTION("LTTng Clock");
MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION) "."
__stringify(LTTNG_MODULES_MINOR_VERSION) "."
__stringify(LTTNG_MODULES_PATCHLEVEL_VERSION)
LTTNG_MODULES_EXTRAVERSION);