clock offset: print negative value in metadata
[lttng-modules.git] / lttng-events.c
index f0f5d0f80dbe340bf1e4663681ff621acd25f504..e1364dd5fbd9b6692bf5055f3be07048b1c951b7 100644 (file)
@@ -2023,12 +2023,15 @@ int _lttng_event_header_declare(struct lttng_session *session)
  * taken at start of trace.
  * Yes, this is only an approximation. Yes, we can (and will) do better
  * in future versions.
+ * Return 0 if offset is negative. It may happen if the system sets
+ * the REALTIME clock to 0 after boot.
  */
 static
-uint64_t measure_clock_offset(void)
+int64_t measure_clock_offset(void)
 {
-       uint64_t offset, monotonic[2], realtime;
+       uint64_t monotonic_avg, monotonic[2], realtime;
        uint64_t tcf = trace_clock_freq();
+       int64_t offset;
        struct timespec rts = { 0, 0 };
        unsigned long flags;
 
@@ -2039,7 +2042,7 @@ uint64_t measure_clock_offset(void)
        monotonic[1] = trace_clock_read64();
        local_irq_restore(flags);
 
-       offset = (monotonic[0] + monotonic[1]) >> 1;
+       monotonic_avg = (monotonic[0] + monotonic[1]) >> 1;
        realtime = (uint64_t) rts.tv_sec * tcf;
        if (tcf == NSEC_PER_SEC) {
                realtime += rts.tv_nsec;
@@ -2049,7 +2052,7 @@ uint64_t measure_clock_offset(void)
                do_div(n, NSEC_PER_SEC);
                realtime += n;
        }
-       offset = realtime - offset;
+       offset = (int64_t) realtime - monotonic_avg;
        return offset;
 }
 
@@ -2161,11 +2164,11 @@ int _lttng_session_metadata_statedump(struct lttng_session *session)
                "       description = \"%s\";\n"
                "       freq = %llu; /* Frequency, in Hz */\n"
                "       /* clock value offset from Epoch is: offset * (1/freq) */\n"
-               "       offset = %llu;\n"
+               "       offset = %lld;\n"
                "};\n\n",
                trace_clock_description(),
                (unsigned long long) trace_clock_freq(),
-               (unsigned long long) measure_clock_offset()
+               (long long) measure_clock_offset()
                );
        if (ret)
                goto end;
This page took 0.023368 seconds and 4 git commands to generate.