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 "lttng-ust-uuid.h"
34 struct lttng_trace_clock
{
35 uint64_t (*read64
)(void);
36 uint64_t (*freq
)(void);
37 int (*uuid
)(char *uuid
);
38 const char *(*name
)(void);
39 const char *(*description
)(void);
42 extern struct lttng_trace_clock
*lttng_trace_clock
;
44 void lttng_ust_clock_init(void);
46 /* Use the kernel MONOTONIC clock. */
49 uint64_t trace_clock_read64_monotonic(void)
53 if (caa_unlikely(clock_gettime(CLOCK_MONOTONIC
, &ts
))) {
57 return ((uint64_t) ts
.tv_sec
* 1000000000ULL) + ts
.tv_nsec
;
61 uint64_t trace_clock_freq_monotonic(void)
67 int trace_clock_uuid_monotonic(char *uuid
)
74 * boot_id needs to be read once before being used concurrently
75 * to deal with a Linux kernel race. A fix is proposed for
76 * upstream, but the work-around is needed for older kernels.
78 fp
= fopen("/proc/sys/kernel/random/boot_id", "r");
82 len
= fread(uuid
, 1, LTTNG_UST_UUID_STR_LEN
- 1, fp
);
83 if (len
< LTTNG_UST_UUID_STR_LEN
- 1) {
87 uuid
[LTTNG_UST_UUID_STR_LEN
- 1] = '\0';
94 const char *trace_clock_name_monotonic(void)
100 const char *trace_clock_description_monotonic(void)
102 return "Monotonic Clock";
106 uint64_t trace_clock_read64(void)
108 struct lttng_trace_clock
*ltc
= CMM_LOAD_SHARED(lttng_trace_clock
);
110 if (caa_likely(!ltc
)) {
111 return trace_clock_read64_monotonic();
113 cmm_read_barrier_depends(); /* load ltc before content */
114 return ltc
->read64();
119 uint64_t trace_clock_freq(void)
121 struct lttng_trace_clock
*ltc
= CMM_LOAD_SHARED(lttng_trace_clock
);
124 return trace_clock_freq_monotonic();
126 cmm_read_barrier_depends(); /* load ltc before content */
132 int trace_clock_uuid(char *uuid
)
134 struct lttng_trace_clock
*ltc
= CMM_LOAD_SHARED(lttng_trace_clock
);
136 cmm_read_barrier_depends(); /* load ltc before content */
137 /* Use default UUID cb when NULL */
138 if (!ltc
|| !ltc
->uuid
) {
139 return trace_clock_uuid_monotonic(uuid
);
141 return ltc
->uuid(uuid
);
146 const char *trace_clock_name(void)
148 struct lttng_trace_clock
*ltc
= CMM_LOAD_SHARED(lttng_trace_clock
);
151 return trace_clock_name_monotonic();
153 cmm_read_barrier_depends(); /* load ltc before content */
159 const char *trace_clock_description(void)
161 struct lttng_trace_clock
*ltc
= CMM_LOAD_SHARED(lttng_trace_clock
);
164 return trace_clock_description_monotonic();
166 cmm_read_barrier_depends(); /* load ltc before content */
167 return ltc
->description();
171 #endif /* _UST_CLOCK_H */
This page took 0.047737 seconds and 5 git commands to generate.