#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
-#include <errno.h>
+#include <urcu/system.h>
+#include <urcu/arch.h>
+#include <lttng/ust-clock.h>
#include <common/compat/uuid.h>
/* TRACE CLOCK */
+struct lttng_trace_clock {
+ uint64_t (*read64)(void);
+ uint64_t (*freq)(void);
+ int (*uuid)(char *uuid);
+ const char *(*name)(void);
+ const char *(*description)(void);
+};
+
+extern struct lttng_trace_clock *lttng_trace_clock;
+
+void lttng_ust_clock_init(void);
+
/*
* Currently using the kernel MONOTONIC clock, waiting for kernel-side
* LTTng to implement mmap'd trace clock.
/* Choosing correct trace clock */
static __inline__
-uint64_t trace_clock_read64(void)
+uint64_t trace_clock_read64_monotonic(void)
{
struct timespec ts;
}
static __inline__
-uint64_t trace_clock_freq(void)
+uint64_t trace_clock_freq_monotonic(void)
{
return 1000000000ULL;
}
static __inline__
-int trace_clock_uuid(char *uuid)
+int trace_clock_uuid_monotonic(char *uuid)
{
int ret = 0;
size_t len;
if (!fp) {
return -ENOENT;
}
- len = fread(uuid, 1, UUID_STR_LEN - 1, fp);
- if (len < UUID_STR_LEN - 1) {
+ len = fread(uuid, 1, LTTNG_UST_UUID_STR_LEN - 1, fp);
+ if (len < LTTNG_UST_UUID_STR_LEN - 1) {
ret = -EINVAL;
goto end;
}
- uuid[UUID_STR_LEN - 1] = '\0';
+ uuid[LTTNG_UST_UUID_STR_LEN - 1] = '\0';
end:
fclose(fp);
return ret;
}
+static __inline__
+const char *trace_clock_name_monotonic(void)
+{
+ return "monotonic";
+}
+
+static __inline__
+const char *trace_clock_description_monotonic(void)
+{
+ return "Monotonic Clock";
+}
+
+static __inline__
+uint64_t trace_clock_read64(void)
+{
+ struct lttng_trace_clock *ltc = CMM_LOAD_SHARED(lttng_trace_clock);
+
+ if (caa_likely(!ltc)) {
+ return trace_clock_read64_monotonic();
+ } else {
+ cmm_read_barrier_depends(); /* load ltc before content */
+ return ltc->read64();
+ }
+}
+
+static __inline__
+uint64_t trace_clock_freq(void)
+{
+ struct lttng_trace_clock *ltc = CMM_LOAD_SHARED(lttng_trace_clock);
+
+ if (!ltc) {
+ return trace_clock_freq_monotonic();
+ } else {
+ cmm_read_barrier_depends(); /* load ltc before content */
+ return ltc->freq();
+ }
+}
+
+static __inline__
+int trace_clock_uuid(char *uuid)
+{
+ struct lttng_trace_clock *ltc = CMM_LOAD_SHARED(lttng_trace_clock);
+
+ cmm_read_barrier_depends(); /* load ltc before content */
+ /* Use default UUID cb when NULL */
+ if (!ltc || !ltc->uuid) {
+ return trace_clock_uuid_monotonic(uuid);
+ } else {
+ return ltc->uuid(uuid);
+ }
+}
+
+static __inline__
+const char *trace_clock_name(void)
+{
+ struct lttng_trace_clock *ltc = CMM_LOAD_SHARED(lttng_trace_clock);
+
+ if (!ltc) {
+ return trace_clock_name_monotonic();
+ } else {
+ cmm_read_barrier_depends(); /* load ltc before content */
+ return ltc->name();
+ }
+}
+
+static __inline__
+const char *trace_clock_description(void)
+{
+ struct lttng_trace_clock *ltc = CMM_LOAD_SHARED(lttng_trace_clock);
+
+ if (!ltc) {
+ return trace_clock_description_monotonic();
+ } else {
+ cmm_read_barrier_depends(); /* load ltc before content */
+ return ltc->description();
+ }
+}
+
#endif /* _UST_CLOCK_H */
int measure_single_clock_offset(struct offset_sample *sample)
{
uint64_t offset, monotonic[2], measure_delta, realtime;
+ uint64_t tcf = trace_clock_freq();
struct timespec rts = { 0, 0 };
int ret;
offset = (monotonic[0] + monotonic[1]) >> 1;
realtime = (uint64_t) rts.tv_sec * 1000000000ULL;
realtime += rts.tv_nsec;
+ if (tcf != 1000000000ULL) {
+ realtime /= 1000000000ULL / tcf;
+ }
offset = realtime - offset;
sample->offset = offset;
sample->measure_delta = measure_delta;
ret = lttng_metadata_printf(session,
"clock {\n"
- " name = %s;\n",
- "monotonic"
+ " name = \"%s\";\n",
+ trace_clock_name()
);
if (ret)
goto end;
}
ret = lttng_metadata_printf(session,
- " description = \"Monotonic Clock\";\n"
+ " description = \"%s\";\n"
" freq = %" PRIu64 "; /* Frequency, in Hz */\n"
" /* clock value offset from Epoch is: offset * (1/freq) */\n"
" offset = %" PRIu64 ";\n"
"};\n\n",
+ trace_clock_description(),
trace_clock_freq(),
measure_clock_offset()
);
ret = lttng_metadata_printf(session,
"typealias integer {\n"
" size = 27; align = 1; signed = false;\n"
- " map = clock.monotonic.value;\n"
+ " map = clock.%s.value;\n"
"} := uint27_clock_monotonic_t;\n"
"\n"
"typealias integer {\n"
" size = 32; align = %u; signed = false;\n"
- " map = clock.monotonic.value;\n"
+ " map = clock.%s.value;\n"
"} := uint32_clock_monotonic_t;\n"
"\n"
"typealias integer {\n"
" size = 64; align = %u; signed = false;\n"
- " map = clock.monotonic.value;\n"
+ " map = clock.%s.value;\n"
"} := uint64_clock_monotonic_t;\n\n",
+ trace_clock_name(),
session->uint32_t_alignment,
- session->uint64_t_alignment
+ trace_clock_name(),
+ session->uint64_t_alignment,
+ trace_clock_name()
);
if (ret)
goto end;