Skip to content

Commit c2636b5

Browse files
compudjjgalar
authored andcommitted
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. Signed-off-by: Mathieu Desnoyers <[email protected]> Signed-off-by: Jérémie Galarneau <[email protected]>
1 parent dc113ec commit c2636b5

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/bin/lttng-sessiond/ust-metadata.c

+5-7
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#define NR_CLOCK_OFFSET_SAMPLES 10
4242

4343
struct offset_sample {
44-
uint64_t offset; /* correlation offset */
44+
int64_t offset; /* correlation offset */
4545
uint64_t measure_delta; /* lower is better */
4646
};
4747

@@ -607,14 +607,12 @@ int _lttng_event_header_declare(struct ust_registry_session *session)
607607
/*
608608
* The offset between monotonic and realtime clock can be negative if
609609
* the system sets the REALTIME clock to 0 after boot.
610-
* Currently handle this by flooring the offset at 0.
611610
*/
612611
static
613612
int measure_single_clock_offset(struct offset_sample *sample)
614613
{
615614
uint64_t monotonic_avg, monotonic[2], measure_delta, realtime;
616615
uint64_t tcf = trace_clock_freq();
617-
int64_t offset;
618616
struct timespec rts = { 0, 0 };
619617
int ret;
620618

@@ -639,8 +637,7 @@ int measure_single_clock_offset(struct offset_sample *sample)
639637
} else {
640638
realtime += (uint64_t) rts.tv_nsec * tcf / NSEC_PER_SEC;
641639
}
642-
offset = (int64_t) realtime - monotonic_avg;
643-
sample->offset = max(offset, 0);
640+
sample->offset = (int64_t) realtime - monotonic_avg;
644641
sample->measure_delta = measure_delta;
645642
return 0;
646643
}
@@ -649,9 +646,10 @@ int measure_single_clock_offset(struct offset_sample *sample)
649646
* Approximation of NTP time of day to clock monotonic correlation,
650647
* taken at start of trace. Keep the measurement that took the less time
651648
* to complete, thus removing imprecision caused by preemption.
649+
* May return a negative offset.
652650
*/
653651
static
654-
uint64_t measure_clock_offset(void)
652+
int64_t measure_clock_offset(void)
655653
{
656654
int i;
657655
struct offset_sample offset_best_sample = {
@@ -799,7 +797,7 @@ int ust_metadata_session_statedump(struct ust_registry_session *session,
799797
" description = \"%s\";\n"
800798
" freq = %" PRIu64 "; /* Frequency, in Hz */\n"
801799
" /* clock value offset from Epoch is: offset * (1/freq) */\n"
802-
" offset = %" PRIu64 ";\n"
800+
" offset = %" PRId64 ";\n"
803801
"};\n\n",
804802
trace_clock_description(),
805803
trace_clock_freq(),

0 commit comments

Comments
 (0)