From: Shawn Lewis Date: Wed, 21 Nov 2007 08:38:13 +0000 (+0100) Subject: fix utime_since overflow X-Git-Tag: fio-1.17.3~33 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=10927316a4bd0e2ceba98e62c062e352c0e312fe;p=fio.git fix utime_since overflow utime_since was using a long for its return which overflows when the difference between times is more than about 35 minutes. Signed-off-by: Jens Axboe --- diff --git a/fio.c b/fio.c index e71537fc..e9b27d9c 100644 --- a/fio.c +++ b/fio.c @@ -787,9 +787,8 @@ static int clear_io_state(struct thread_data *td) */ static void *thread_main(void *data) { - unsigned long long runtime[2]; + unsigned long long runtime[2], elapsed; struct thread_data *td = data; - unsigned long elapsed; int clear_state; if (!td->o.use_thread) diff --git a/fio.h b/fio.h index 5ca2ad36..2e43473f 100644 --- a/fio.h +++ b/fio.h @@ -777,8 +777,8 @@ extern void add_agg_sample(unsigned long, enum fio_ddir); /* * Time functions */ -extern unsigned long utime_since(struct timeval *, struct timeval *); -extern unsigned long utime_since_now(struct timeval *); +extern unsigned long long utime_since(struct timeval *, struct timeval *); +extern unsigned long long utime_since_now(struct timeval *); extern unsigned long mtime_since(struct timeval *, struct timeval *); extern unsigned long mtime_since_now(struct timeval *); extern unsigned long time_since_now(struct timeval *); diff --git a/time.c b/time.c index 4fbc98bb..6d79ecdc 100644 --- a/time.c +++ b/time.c @@ -6,10 +6,11 @@ static struct timeval genesis; static unsigned long ns_granularity; -unsigned long utime_since(struct timeval *s, struct timeval *e) +unsigned long long utime_since(struct timeval *s, struct timeval *e) { - long sec, usec, ret; - + long sec, usec; + unsigned long long ret; + sec = e->tv_sec - s->tv_sec; usec = e->tv_usec - s->tv_usec; if (sec > 0 && usec < 0) { @@ -17,19 +18,18 @@ unsigned long utime_since(struct timeval *s, struct timeval *e) usec += 1000000; } - sec *= 1000000UL; - ret = sec + usec; - /* * time warp bug on some kernels? */ - if (ret < 0) - ret = 0; - + if (sec < 0 || (sec == 0 && usec < 0)) + return 0; + + ret = sec * 1000000ULL + usec; + return ret; } -unsigned long utime_since_now(struct timeval *s) +unsigned long long utime_since_now(struct timeval *s) { struct timeval t;