2 * Copyright (C) 2010 Pierre-Marc Fournier
3 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 * SPDX-License-Identifier: GPL-2.0-only
12 #include <common/compat/time.h>
17 #include <urcu/system.h>
18 #include <urcu/arch.h>
19 #include <lttng/ust-clock.h>
21 #include <common/uuid.h>
25 struct lttng_trace_clock
{
26 uint64_t (*read64
)(void);
27 uint64_t (*freq
)(void);
28 int (*uuid
)(char *uuid
);
29 const char *(*name
)(void);
30 const char *(*description
)(void);
33 extern struct lttng_trace_clock
*lttng_trace_clock
;
35 void lttng_ust_clock_init(void);
38 * Currently using the kernel MONOTONIC clock, waiting for kernel-side
39 * LTTng to implement mmap'd trace clock.
42 /* Choosing correct trace clock */
45 uint64_t trace_clock_read64_monotonic(void)
49 if (lttng_clock_gettime(CLOCK_MONOTONIC
, &ts
)) {
50 /* TODO Report error cleanly up the chain. */
51 PERROR("clock_gettime CLOCK_MONOTONIC");
55 return ((uint64_t) ts
.tv_sec
* 1000000000ULL) + ts
.tv_nsec
;
59 uint64_t trace_clock_freq_monotonic(void)
65 int trace_clock_uuid_monotonic(char *uuid
)
72 * boot_id needs to be read once before being used concurrently
73 * to deal with a Linux kernel race. A fix is proposed for
74 * upstream, but the work-around is needed for older kernels.
76 fp
= fopen("/proc/sys/kernel/random/boot_id", "r");
80 len
= fread(uuid
, 1, LTTNG_UST_UUID_STR_LEN
- 1, fp
);
81 if (len
< LTTNG_UST_UUID_STR_LEN
- 1) {
85 uuid
[LTTNG_UST_UUID_STR_LEN
- 1] = '\0';
92 const char *trace_clock_name_monotonic(void)
98 const char *trace_clock_description_monotonic(void)
100 return "Monotonic Clock";
104 uint64_t trace_clock_read64(void)
106 struct lttng_trace_clock
*ltc
= CMM_LOAD_SHARED(lttng_trace_clock
);
108 if (caa_likely(!ltc
)) {
109 return trace_clock_read64_monotonic();
111 cmm_read_barrier_depends(); /* load ltc before content */
112 return ltc
->read64();
117 uint64_t trace_clock_freq(void)
119 struct lttng_trace_clock
*ltc
= CMM_LOAD_SHARED(lttng_trace_clock
);
122 return trace_clock_freq_monotonic();
124 cmm_read_barrier_depends(); /* load ltc before content */
130 int trace_clock_uuid(char *uuid
)
132 struct lttng_trace_clock
*ltc
= CMM_LOAD_SHARED(lttng_trace_clock
);
134 cmm_read_barrier_depends(); /* load ltc before content */
135 /* Use default UUID cb when NULL */
136 if (!ltc
|| !ltc
->uuid
) {
137 return trace_clock_uuid_monotonic(uuid
);
139 return ltc
->uuid(uuid
);
144 const char *trace_clock_name(void)
146 struct lttng_trace_clock
*ltc
= CMM_LOAD_SHARED(lttng_trace_clock
);
149 return trace_clock_name_monotonic();
151 cmm_read_barrier_depends(); /* load ltc before content */
157 const char *trace_clock_description(void)
159 struct lttng_trace_clock
*ltc
= CMM_LOAD_SHARED(lttng_trace_clock
);
162 return trace_clock_description_monotonic();
164 cmm_read_barrier_depends(); /* load ltc before content */
165 return ltc
->description();
169 #endif /* _UST_CLOCK_H */
This page took 0.034814 seconds and 4 git commands to generate.