2 * Copyright (C) 2010 Pierre-Marc Fournier
3 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; version 2.1 of
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28 #include <urcu/system.h>
29 #include <urcu/arch.h>
30 #include <lttng/ust-clock.h>
32 #include <common/compat/uuid.h>
36 struct lttng_trace_clock
{
37 uint64_t (*read64
)(void);
38 uint64_t (*freq
)(void);
39 int (*uuid
)(char *uuid
);
40 const char *(*name
)(void);
41 const char *(*description
)(void);
44 extern struct lttng_trace_clock
*lttng_trace_clock
;
46 void lttng_ust_clock_init(void);
49 * Currently using the kernel MONOTONIC clock, waiting for kernel-side
50 * LTTng to implement mmap'd trace clock.
53 /* Choosing correct trace clock */
56 uint64_t trace_clock_read64_monotonic(void)
60 clock_gettime(CLOCK_MONOTONIC
, &ts
);
61 return ((uint64_t) ts
.tv_sec
* 1000000000ULL) + ts
.tv_nsec
;
65 uint64_t trace_clock_freq_monotonic(void)
71 int trace_clock_uuid_monotonic(char *uuid
)
78 * boot_id needs to be read once before being used concurrently
79 * to deal with a Linux kernel race. A fix is proposed for
80 * upstream, but the work-around is needed for older kernels.
82 fp
= fopen("/proc/sys/kernel/random/boot_id", "r");
86 len
= fread(uuid
, 1, LTTNG_UST_UUID_STR_LEN
- 1, fp
);
87 if (len
< LTTNG_UST_UUID_STR_LEN
- 1) {
91 uuid
[LTTNG_UST_UUID_STR_LEN
- 1] = '\0';
98 const char *trace_clock_name_monotonic(void)
104 const char *trace_clock_description_monotonic(void)
106 return "Monotonic Clock";
110 uint64_t trace_clock_read64(void)
112 struct lttng_trace_clock
*ltc
= CMM_LOAD_SHARED(lttng_trace_clock
);
114 if (caa_likely(!ltc
)) {
115 return trace_clock_read64_monotonic();
117 cmm_read_barrier_depends(); /* load ltc before content */
118 return ltc
->read64();
123 uint64_t trace_clock_freq(void)
125 struct lttng_trace_clock
*ltc
= CMM_LOAD_SHARED(lttng_trace_clock
);
128 return trace_clock_freq_monotonic();
130 cmm_read_barrier_depends(); /* load ltc before content */
136 int trace_clock_uuid(char *uuid
)
138 struct lttng_trace_clock
*ltc
= CMM_LOAD_SHARED(lttng_trace_clock
);
140 cmm_read_barrier_depends(); /* load ltc before content */
141 /* Use default UUID cb when NULL */
142 if (!ltc
|| !ltc
->uuid
) {
143 return trace_clock_uuid_monotonic(uuid
);
145 return ltc
->uuid(uuid
);
150 const char *trace_clock_name(void)
152 struct lttng_trace_clock
*ltc
= CMM_LOAD_SHARED(lttng_trace_clock
);
155 return trace_clock_name_monotonic();
157 cmm_read_barrier_depends(); /* load ltc before content */
163 const char *trace_clock_description(void)
165 struct lttng_trace_clock
*ltc
= CMM_LOAD_SHARED(lttng_trace_clock
);
168 return trace_clock_description_monotonic();
170 cmm_read_barrier_depends(); /* load ltc before content */
171 return ltc
->description();
175 #endif /* _UST_CLOCK_H */
This page took 0.032819 seconds and 4 git commands to generate.