clock offset: print negative value in metadata for lttng-ust metadata
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 8 Feb 2016 22:13:26 +0000 (17:13 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 11 Feb 2016 20:47:56 +0000 (15:47 -0500)
In the upcoming 2.8, we can print the negative value of clock offset in
the metadata, and expect users to update their viewers to correct any
bug that could prevent them from handling those negative values.

This happens only in cases where the system sets CLOCK_REALTIME to 0
after boot, thus leading to a negative clock offset value between
realtime and monotonic clocks.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/ust-metadata.c

index 276dc7a4414043f9c177abe75bf11a85b50c2c5f..e5d4944ed931ca9c2177cf124734a4dc0d3f6cf2 100644 (file)
@@ -41,7 +41,7 @@
 #define NR_CLOCK_OFFSET_SAMPLES                10
 
 struct offset_sample {
 #define NR_CLOCK_OFFSET_SAMPLES                10
 
 struct offset_sample {
-       uint64_t offset;                /* correlation offset */
+       int64_t offset;                 /* correlation offset */
        uint64_t measure_delta;         /* lower is better */
 };
 
        uint64_t measure_delta;         /* lower is better */
 };
 
@@ -607,14 +607,12 @@ int _lttng_event_header_declare(struct ust_registry_session *session)
 /*
  * The offset between monotonic and realtime clock can be negative if
  * the system sets the REALTIME clock to 0 after boot.
 /*
  * The offset between monotonic and realtime clock can be negative if
  * the system sets the REALTIME clock to 0 after boot.
- * Currently handle this by flooring the offset at 0.
  */
 static
 int measure_single_clock_offset(struct offset_sample *sample)
 {
        uint64_t monotonic_avg, monotonic[2], measure_delta, realtime;
        uint64_t tcf = trace_clock_freq();
  */
 static
 int measure_single_clock_offset(struct offset_sample *sample)
 {
        uint64_t monotonic_avg, monotonic[2], measure_delta, realtime;
        uint64_t tcf = trace_clock_freq();
-       int64_t offset;
        struct timespec rts = { 0, 0 };
        int ret;
 
        struct timespec rts = { 0, 0 };
        int ret;
 
@@ -639,8 +637,7 @@ int measure_single_clock_offset(struct offset_sample *sample)
        } else {
                realtime += (uint64_t) rts.tv_nsec * tcf / NSEC_PER_SEC;
        }
        } else {
                realtime += (uint64_t) rts.tv_nsec * tcf / NSEC_PER_SEC;
        }
-       offset = (int64_t) realtime - monotonic_avg;
-       sample->offset = max(offset, 0);
+       sample->offset = (int64_t) realtime - monotonic_avg;
        sample->measure_delta = measure_delta;
        return 0;
 }
        sample->measure_delta = measure_delta;
        return 0;
 }
@@ -649,9 +646,10 @@ int measure_single_clock_offset(struct offset_sample *sample)
  * Approximation of NTP time of day to clock monotonic correlation,
  * taken at start of trace. Keep the measurement that took the less time
  * to complete, thus removing imprecision caused by preemption.
  * Approximation of NTP time of day to clock monotonic correlation,
  * taken at start of trace. Keep the measurement that took the less time
  * to complete, thus removing imprecision caused by preemption.
+ * May return a negative offset.
  */
 static
  */
 static
-uint64_t measure_clock_offset(void)
+int64_t measure_clock_offset(void)
 {
        int i;
        struct offset_sample offset_best_sample = {
 {
        int i;
        struct offset_sample offset_best_sample = {
@@ -799,7 +797,7 @@ int ust_metadata_session_statedump(struct ust_registry_session *session,
                "       description = \"%s\";\n"
                "       freq = %" PRIu64 "; /* Frequency, in Hz */\n"
                "       /* clock value offset from Epoch is: offset * (1/freq) */\n"
                "       description = \"%s\";\n"
                "       freq = %" PRIu64 "; /* Frequency, in Hz */\n"
                "       /* clock value offset from Epoch is: offset * (1/freq) */\n"
-               "       offset = %" PRIu64 ";\n"
+               "       offset = %" PRId64 ";\n"
                "};\n\n",
                trace_clock_description(),
                trace_clock_freq(),
                "};\n\n",
                trace_clock_description(),
                trace_clock_freq(),
This page took 0.026747 seconds and 4 git commands to generate.