@@ -1230,8 +1230,14 @@ static unsigned long long timestamp_calc(unsigned long long ts, int cpu,
ts *= handle->ts2secs;
} else if (handle->tsc_calc.mult) {
/* auto calculated TSC clock frequency */
- ts -= handle->tsc_calc.offset;
- ts = mul_u64_u32_shr(ts, handle->tsc_calc.mult, handle->tsc_calc.shift);
+ if (ts > handle->tsc_calc.offset) {
+ ts -= handle->tsc_calc.offset;
+ ts = mul_u64_u32_shr(ts, handle->tsc_calc.mult, handle->tsc_calc.shift);
+ } else {
+ tracecmd_warning("Timestamp $llu is before the initial offset %llu, set it to 0",
+ ts, handle->tsc_calc.offset);
+ ts = 0;
+ }
}
/* User specified time offset with --ts-offset or --date options */
When converting TSC timestamps to nanoseconds, an offset is used. That offset is subtracted from each TSC timestamp, before the conversion. However, if the timestamp is lower that the offset this causes an overflow, as both timestamp and offset are unsigned long integers. A check is added to verify the subtraction will not cause an overflow. In case of an overflow, the timestamp is set to 0 and a warning message is printed. Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com> --- lib/trace-cmd/trace-input.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)