Re: [PATCH v3 4/4] ibacm: Use MONOTONIC time base to avoid timer expiration issues

Jason Gunthorpe
2017-11-14T23:56:25Z

On Tue, Nov 14, 2017 at 11:44:17AM -0500, Michael J. Ruhl wrote:
> static inline int event_wait(event_t *e, int timeout)
> {
> - struct timeval curtime;
> struct timespec wait;
> int ret;
>
> - gettimeofday(&curtime, NULL);
> - wait.tv_sec = curtime.tv_sec + ((unsigned) timeout) / 1000;
> - wait.tv_nsec = (curtime.tv_usec + (((unsigned) timeout) % 1000) * 1000) * 1000;
> + clock_gettime(CLOCK_MONOTONIC, &wait);
> + wait.tv_sec = wait.tv_sec + ((unsigned int) timeout) / 1000;
> + wait.tv_nsec = (wait.tv_nsec + (((unsigned int) timeout) % 1000) * 1000000);

since timeout must be positive just declare it as 'unsigned int' in the
function signature and all the ugly casts go away and the function
argument range is now documented..

Jason