clock offset: print negative value in metadata for lttng-ust metadata
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 2/2 clock offset: print negative value in metadata for lttng-ust metadata
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.
--- src/bin/lttng-sessiond/ust-metadata.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
src/bin/lttng-sessiond/ust-metadata.c +5 -10
@@ -41,7 +41,7 @@#define NR_CLOCK_OFFSET_SAMPLES 10struct offset_sample { -uint64_t offset;/* correlation offset */ +int64_t offset;/* correlation offset */ 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. -* 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 (); -int64_t offset;struct timespec rts = {0 ,0 };int ret;
@@ -639,11 +637,7 @@ int measure_single_clock_offset(struct offset_sample *sample) }else { realtime += (uint64_t ) rts.tv_nsec * tcf /NSEC_PER_SEC ; } - offset = (int64_t ) realtime - monotonic_avg; -if (offset <0 ) - sample->offset =0 ; -else - sample->offset = offset; + sample->offset = (int64_t ) realtime - monotonic_avg; sample->measure_delta = measure_delta;return 0 ; }
@@ -652,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. +* May return a negative offset. */ static -uint64_t measure_clock_offset (void ) +int64_t measure_clock_offset (void ) {int i;struct offset_sample offset_best_sample = {
@@ -802,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" -" offset = %" PRIu64";\n" +" offset = %" PRId64";\n" "};\n\n" ,trace_clock_description (), trace_clock_freq(),
Signature · 1 line
2.1.4
Re: [PATCH lttng-tools 1/2] Fix: handle negative clock offset for lttng-ust metadata
In reply to a message not in the archiveMerged in master and stable-2.7 (first patch), thanks!
Jérémie
Quoted 68 lines · Mathieu Desnoyers
In the unlikely situation where a system sets its hardware clock (
CLOCK_REALTIME) to 0 (Epoch) after boot, the differencemonotonic - realtime
becomes negative.
Fixup this situation by returning a 0 offset in this case.
This ensures that trace viewer implementations (e.g. babeltrace) which currently cannot handle the negative offset (known bug) still work with the generated traces.
This patch should be applied to master and stable-2.7.
Signed-off-by Mathieu Desnoyers <[email protected]>--- src/bin/lttng-sessiond/ust-metadata.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)src/bin/lttng-sessiond/ust-metadata.c +13
-5@@ -604,11 +604,17 @@ 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. +* Currently handle this by flooring the offset at 0. +*/ static int measure_single_clock_offset (struct offset_sample *sample) { -uint64_t offset, monotonic[2 ], measure_delta, realtime; +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;@@ -626,15 +632,18 @@ int measure_single_clock_offset(struct offset_sample *sample)*/ return 0 ; } - 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; }else { realtime += (uint64_t ) rts.tv_nsec * tcf /NSEC_PER_SEC ; } - offset = realtime - offset; - sample->offset = offset; + offset = (int64_t ) realtime - monotonic_avg; +if (offset <0 ) + sample->offset =0 ; +else + sample->offset = offset; sample->measure_delta = measure_delta;return 0 ; } --2.1.4
Signature · 8 lines
Jérémie Galarneau EfficiOS Inc. http://www.efficios.com _______________________________________________ lttng-dev mailing list [email protected] http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev