From: Mathieu Desnoyers Date: Sun, 12 Oct 2014 11:46:20 +0000 (+0200) Subject: clock plugin: increase offset measurement accuracy X-Git-Tag: v2.7.0-rc1~45 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=6e1b0543ef96dc12ff2bf1ca123a5637064d8c5e;p=lttng-tools.git clock plugin: increase offset measurement accuracy Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-sessiond/ust-metadata.c b/src/bin/lttng-sessiond/ust-metadata.c index b67921ef8..ea5978888 100644 --- a/src/bin/lttng-sessiond/ust-metadata.c +++ b/src/bin/lttng-sessiond/ust-metadata.c @@ -38,6 +38,7 @@ #define max_t(type, a, b) ((type) ((a) > (b) ? (a) : (b))) #endif +#define NSEC_PER_SEC 1000000000ULL #define NR_CLOCK_OFFSET_SAMPLES 10 struct offset_sample { @@ -543,10 +544,11 @@ int measure_single_clock_offset(struct offset_sample *sample) return 0; } offset = (monotonic[0] + monotonic[1]) >> 1; - realtime = (uint64_t) rts.tv_sec * 1000000000ULL; - realtime += rts.tv_nsec; - if (tcf != 1000000000ULL) { - realtime /= 1000000000ULL / tcf; + realtime = (uint64_t) rts.tv_sec * tcf; + if (tcf == NSEC_PER_SEC) { + realtime += rts.tv_nsec; + } else { + realtime += (uint64_t) rts.tv_nsec * tcf / NSEC_PER_SEC; } offset = realtime - offset; sample->offset = offset;