Hi, On 23 February 2017 at 20:55, Chris Taylor <ctaylor@xxxxxxxxxx> wrote: > There is an issue in FIO when using the detailed bandwidth and iops logging with averaging over a period of time > 1 second. > It seems that usecs overflows which later causes negative time diff values resulting in skewed toward 0 results. > I have attached a potential fix that should prevent usecs from going beyond 1000000. Is this problem shown by the following job: ./fio --ioengine=null --write_bw_log=/dev/null --log_avg_msec=2000 --size=100M --runtime=10s --time_based --name=overflow Among Clang's undefined behaviour sanitizer output was this for the above: stat.c:2265:43: runtime error: unsigned integer overflow: 1999 - 2000 cannot be represented in type 'unsigned long' stat.c:2265:28: runtime error: unsigned integer overflow: 3999 - 4294967295 cannot be represented in type 'unsigned long' > diff --git a/time.c b/time.c > index f5dc049..c748bee 100644 > --- a/time.c > +++ b/time.c > @@ -8,11 +8,18 @@ static unsigned long ns_granularity; > > void timeval_add_msec(struct timeval *tv, unsigned int msec) > { > - tv->tv_usec += 1000 * msec; > - if (tv->tv_usec >= 1000000) { > - tv->tv_usec -= 1000000; > - tv->tv_sec++; > - } > + int adj_usec = 1000 * msec; > + int adj_sec = 0; > + tv->tv_usec += adj_usec; > + if (adj_usec >= 1000000) { > + adj_sec = adj_usec / 1000000; > + tv->tv_usec -= adj_sec * 1000000; > + tv->tv_sec += adj_sec; > + } > + if (tv->tv_usec >= 1000000){ > + tv->tv_usec -= 1000000; > + tv->tv_sec++; > + } > } Is it still safe to use int if you're targeting a 32 bit platform? -- Sitsofe | http://sucs.org/~sits/ -- To unsubscribe from this list: send the line "unsubscribe fio" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html