From: "Michael J. Ruhl" <michael.j.ruhl-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
To: linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH 2/3] ibacm: Calculate correct tv_nsec value in event_wait()
Date: Fri, 10 Nov 2017 17:29:02 -0500 [thread overview]
Message-ID: <20171110222853.10387.81730.stgit@phlsvslse11.ph.intel.com> (raw)
In-Reply-To: <20171110222658.10387.16845.stgit-K+u1se/DcYrLESAwzcoQNrvm/XP+8Wra@public.gmane.org>
From: Michael J. Ruhl <michael.j.ruhl-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
The event_wait() function calculates a tv_nsec value based on the
given timeout. If the tv_nsec value calculation ends ups larger
than 1 second, the pthread_cond_timedwait() will return EINVAL,
and will not wait.
This causes the retry loop to spin (busy wait) until the actual
timeout occurs.
Ensure that the tv_nsec value is less than 1 second.
Reviewed-by: Mike Marciniszyn <mike.marciniszyn-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Reviewed-by: Dennis Dalessandro <dennis.dalessandro-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Signed-off-by: Michael J. Ruhl <michael.j.ruhl-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
---
ibacm/linux/osd.h | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
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);
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2017-11-10 22:29 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-10 22:28 [PATCH 0/3] ibacm: acmp retry issues Michael J. Ruhl
[not found] ` <20171110222658.10387.16845.stgit-K+u1se/DcYrLESAwzcoQNrvm/XP+8Wra@public.gmane.org>
2017-11-10 22:28 ` [PATCH 1/3] ibacm: Fix an incorrect expiration check for the retry timer Michael J. Ruhl
2017-11-10 22:29 ` Michael J. Ruhl [this message]
[not found] ` <20171110222853.10387.81730.stgit-K+u1se/DcYrLESAwzcoQNrvm/XP+8Wra@public.gmane.org>
2017-11-11 16:26 ` [PATCH 2/3] ibacm: Calculate correct tv_nsec value in event_wait() Jason Gunthorpe
[not found] ` <20171111162610.GL17451-uk2M96/98Pc@public.gmane.org>
2017-11-13 13:30 ` Ruhl, Michael J
2017-11-10 22:29 ` [PATCH 3/3] ibacm: Fix a retry loop calculation race condition Michael J. Ruhl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171110222853.10387.81730.stgit@phlsvslse11.ph.intel.com \
--to=michael.j.ruhl-ral2jqcrhueavxtiumwx3w@public.gmane.org \
--cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox