[lttng-dev] [PATCH lttng-tools 1/2] Fix: handle negative clock offset for lttng-ust metadata

Jérémie Galarneau jeremie.galarneau at efficios.com
Fri Feb 12 22:04:52 EST 2016


Merged in master and stable-2.7 (first patch), thanks!

Jérémie

On Mon, Feb 8, 2016 at 5:13 PM, Mathieu Desnoyers
<mathieu.desnoyers at efficios.com> wrote:
> In the unlikely situation where a system sets its hardware clock
> (CLOCK_REALTIME) to 0 (Epoch) after boot, the difference
>
>   monotonic - 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 <mathieu.desnoyers at efficios.com>
> ---
>  src/bin/lttng-sessiond/ust-metadata.c | 17 +++++++++++++----
>  1 file changed, 13 insertions(+), 4 deletions(-)
>
> diff --git a/src/bin/lttng-sessiond/ust-metadata.c b/src/bin/lttng-sessiond/ust-metadata.c
> index 984d5f8..f7c8b9d 100644
> --- a/src/bin/lttng-sessiond/ust-metadata.c
> +++ b/src/bin/lttng-sessiond/ust-metadata.c
> @@ -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
>



-- 
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com



More information about the lttng-dev mailing list