2 * Copyright (C) 2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; version 2.1 of
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <usterr-signal-safe.h>
24 #include <lttng/ust-clock.h>
25 #include <urcu/system.h>
26 #include <urcu/arch.h>
31 struct lttng_trace_clock
*lttng_trace_clock
;
34 struct lttng_trace_clock user_tc
;
36 int lttng_ust_trace_clock_set_read64_cb(uint64_t (*read64
)(void))
38 if (CMM_LOAD_SHARED(lttng_trace_clock
))
40 user_tc
.read64
= read64
;
44 int lttng_ust_trace_clock_set_freq_cb(uint64_t (*freq
)(void))
46 if (CMM_LOAD_SHARED(lttng_trace_clock
))
52 int lttng_ust_trace_clock_set_uuid_cb(int (*uuid
)(char *uuid
))
54 if (CMM_LOAD_SHARED(lttng_trace_clock
))
60 int lttng_ust_trace_clock_set_name_cb(const char *(*name
)(void))
62 if (CMM_LOAD_SHARED(lttng_trace_clock
))
68 int lttng_ust_trace_clock_set_description_cb(const char *(*description
)(void))
70 if (CMM_LOAD_SHARED(lttng_trace_clock
))
72 user_tc
.description
= description
;
76 int lttng_ust_enable_trace_clock_override(void)
78 if (CMM_LOAD_SHARED(lttng_trace_clock
))
86 if (!user_tc
.description
)
88 /* Use default uuid cb when NULL */
89 cmm_smp_mb(); /* Store callbacks before trace clock */
90 CMM_STORE_SHARED(lttng_trace_clock
, &user_tc
);
94 void lttng_ust_clock_init(void)
98 void (*libinit
)(void);
101 libname
= lttng_secure_getenv("LTTNG_UST_CLOCK_PLUGIN");
104 handle
= dlopen(libname
, RTLD_NOW
);
106 PERROR("Cannot load LTTng UST clock override library %s",
111 libinit
= (void (*)(void)) dlsym(handle
,
112 "lttng_ust_clock_plugin_init");
114 PERROR("Cannot find LTTng UST clock override library %s initialization function lttng_ust_clock_plugin_init()",