[LTP] [PATCH] Make getrusage04 be able to loop more times

Cyril Hrubis chrubis@suse.cz
Tue Jun 13 14:58:06 CEST 2017


Hi!
> > We only need to add tst_timeval_diff_us() into tst_timer.h then we can
> > compare the resulting values in microsenconds. Which would mean adding
> > tst_timeval_to_us() and tst_timeval_diff(), then adding the
> > tst_timeval_diff_us() that combines these two.
> 
> This really sounds simpler than compare with timeval directly. But compare
> with timeval directly would make it more difficult to overflow. 
> 
> > 
> > It should be staturated difference though, i.e. the conversion from
> > timeval to microseconds should return LONG_LONG_MAX in a case that the
> > end result would overflow long long.
> 
> That makes sense. But how long would it overflow once? 
> 
> >>> print "%d" % 0xffffffffffffffff
> 18446744073709551615
> >>> print 18446744073709551615 / 1000000
> 18446744073709
> >>> print "%d" % 0xffffffff
> 4294967295
> >>> print 4294967295 / 1000000
> 4294

The time_t in struct timespec and struct timeval are 64bit types on
64bit architectures, hence we can overflow 64 bit long long in a case
that the difference between two tv_sec is greater than
LLONG_MAX/1000000. It's extremly unlikely but may happen for instance if
the structures are overwritten with random mess for some reason.

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list