Message ID | 20171110222853.10387.81730.stgit@phlsvslse11.ph.intel.com (mailing list archive) |
---|---|
State | Changes Requested |
Headers | show |
On Fri, Nov 10, 2017 at 05:29:02PM -0500, Michael J. Ruhl wrote:
> gettimeofday(&curtime, NULL);
Ugh, the use of gettimeofday for this kind of stuff is also a serious bug.
This needs to use clock_gettime(CLOCK_MONOTONIC) and
pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
> -----Original Message----- > From: Jason Gunthorpe [mailto:jgg@ziepe.ca] > Sent: Saturday, November 11, 2017 11:26 AM > To: Ruhl, Michael J <michael.j.ruhl@intel.com> > Cc: linux-rdma@vger.kernel.org > Subject: Re: [PATCH 2/3] ibacm: Calculate correct tv_nsec value in > event_wait() > > On Fri, Nov 10, 2017 at 05:29:02PM -0500, Michael J. Ruhl wrote: > > gettimeofday(&curtime, NULL); > > Ugh, the use of gettimeofday for this kind of stuff is also a serious bug. > > This needs to use clock_gettime(CLOCK_MONOTONIC) and > pthread_condattr_setclock(&attr, CLOCK_MONOTONIC); Yeah, that one is a lot cleaner. I will get a new patch out shortly. Thanks, Mike > Jason -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/ibacm/linux/osd.h b/ibacm/linux/osd.h index 95713e6..d6cbb8f 100644 --- a/ibacm/linux/osd.h +++ b/ibacm/linux/osd.h @@ -92,6 +92,7 @@ static inline void event_init(event_t *e) pthread_mutex_init(&e->mutex, NULL); } #define event_signal(e) pthread_cond_signal(&(e)->cond) +#define ONE_SEC_IN_NSEC 1000000000 static inline int event_wait(event_t *e, int timeout) { struct timeval curtime; @@ -101,6 +102,10 @@ static inline int event_wait(event_t *e, int timeout) gettimeofday(&curtime, NULL); wait.tv_sec = curtime.tv_sec + ((unsigned) timeout) / 1000; wait.tv_nsec = (curtime.tv_usec + (((unsigned) timeout) % 1000) * 1000) * 1000; + if (wait.tv_nsec > ONE_SEC_IN_NSEC) { + wait.tv_sec++; + wait.tv_nsec -= ONE_SEC_IN_NSEC; + } pthread_mutex_lock(&e->mutex); ret = pthread_cond_timedwait(&e->cond, &e->mutex, &wait); pthread_mutex_unlock(&e->mutex);