@@ -1287,17 +1287,37 @@ static unsigned long long timestamp_correct(unsigned long long ts, int cpu,
&tsync->ts_samples[mid+1]);
}
+static unsigned long long mul_u64_u32_shr(unsigned long long a,
+ unsigned long long mul, unsigned int shift)
+{
+ unsigned int ah, al;
+ unsigned long long ret;
+
+ al = a;
+ ah = a >> 32;
+
+ ret = (al * mul) >> shift;
+ if (ah)
+ ret += (ah * mul) << (32 - shift);
+
+ return ret;
+}
+
static unsigned long long timestamp_calc(unsigned long long ts, int cpu,
struct tracecmd_input *handle)
{
- unsigned long long tstamp;
+ unsigned long long t;
- tstamp = timestamp_correct(ts, cpu, handle);
+ t = timestamp_correct(ts, cpu, handle);
if (handle->ts2secs)
- tstamp *= handle->ts2secs;
+ t *= handle->ts2secs;
+ else if (handle->tsc_calc.mult) {
+ t = mul_u64_u32_shr(t, handle->tsc_calc.mult, handle->tsc_calc.shift);
+ t += handle->tsc_calc.offset;
+ }
- return tstamp;
+ return t;
}
/*
If there is information for TSC to nanoseconds conversion in the trace file metadata, use it to recalculate the timestamps of all events. Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com> --- lib/trace-cmd/trace-input.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-)