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
24 #include <usterr-signal-safe.h>
25 #include <lttng/ust-clock.h>
26 #include <urcu/system.h>
27 #include <urcu/arch.h>
32 struct lttng_trace_clock
*lttng_trace_clock
;
35 struct lttng_trace_clock user_tc
;
40 int lttng_ust_trace_clock_set_read64_cb(uint64_t (*read64
)(void))
42 if (CMM_LOAD_SHARED(lttng_trace_clock
))
44 user_tc
.read64
= read64
;
48 int lttng_ust_trace_clock_set_freq_cb(uint64_t (*freq
)(void))
50 if (CMM_LOAD_SHARED(lttng_trace_clock
))
56 int lttng_ust_trace_clock_set_uuid_cb(int (*uuid
)(char *uuid
))
58 if (CMM_LOAD_SHARED(lttng_trace_clock
))
64 int lttng_ust_trace_clock_set_name_cb(const char *(*name
)(void))
66 if (CMM_LOAD_SHARED(lttng_trace_clock
))
72 int lttng_ust_trace_clock_set_description_cb(const char *(*description
)(void))
74 if (CMM_LOAD_SHARED(lttng_trace_clock
))
76 user_tc
.description
= description
;
80 int lttng_ust_enable_trace_clock_override(void)
82 if (CMM_LOAD_SHARED(lttng_trace_clock
))
90 if (!user_tc
.description
)
92 /* Use default uuid cb when NULL */
93 cmm_smp_mb(); /* Store callbacks before trace clock */
94 CMM_STORE_SHARED(lttng_trace_clock
, &user_tc
);
98 void lttng_ust_clock_init(void)
101 void (*libinit
)(void);
105 libname
= lttng_getenv("LTTNG_UST_CLOCK_PLUGIN");
108 clock_handle
= dlopen(libname
, RTLD_NOW
);
110 PERROR("Cannot load LTTng UST clock override library %s",
115 libinit
= (void (*)(void)) dlsym(clock_handle
,
116 "lttng_ust_clock_plugin_init");
118 PERROR("Cannot find LTTng UST clock override library %s initialization function lttng_ust_clock_plugin_init()",