From patchwork Tue Nov 14 16:43:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael J. Ruhl" X-Patchwork-Id: 10057891 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 00AFC60231 for ; Tue, 14 Nov 2017 16:43:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7312297A7 for ; Tue, 14 Nov 2017 16:43:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DC52929871; Tue, 14 Nov 2017 16:43:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5852E297A7 for ; Tue, 14 Nov 2017 16:43:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754969AbdKNQne (ORCPT ); Tue, 14 Nov 2017 11:43:34 -0500 Received: from mga05.intel.com ([192.55.52.43]:37373 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753794AbdKNQne (ORCPT ); Tue, 14 Nov 2017 11:43:34 -0500 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Nov 2017 08:43:33 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,395,1505804400"; d="scan'208";a="2181081" Received: from sedona.ch.intel.com ([143.182.228.65]) by orsmga003.jf.intel.com with ESMTP; 14 Nov 2017 08:43:33 -0800 Received: from phlsvsles11.ph.intel.com (phlsvsles11.ph.intel.com [10.228.195.43]) by sedona.ch.intel.com (8.13.6/8.14.3/Standard MailSET/Hub) with ESMTP id vAEGhWCa014236 for ; Tue, 14 Nov 2017 09:43:32 -0700 Received: from phlsvslse11.ph.intel.com (localhost [127.0.0.1]) by phlsvsles11.ph.intel.com with ESMTP id vAEGhWKN024666 for ; Tue, 14 Nov 2017 11:43:32 -0500 Subject: [PATCH v3 2/4] ibacm: Calculate correct tv_nsec value in event_wait() To: linux-rdma@vger.kernel.org From: "Michael J. Ruhl" Date: Tue, 14 Nov 2017 11:43:32 -0500 Message-ID: <20171114164324.24557.29863.stgit@phlsvslse11.ph.intel.com> In-Reply-To: <20171114164006.24557.72093.stgit@phlsvslse11.ph.intel.com> References: <20171114164006.24557.72093.stgit@phlsvslse11.ph.intel.com> User-Agent: StGit/0.16 MIME-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Michael J. Ruhl 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 Reviewed-by: Dennis Dalessandro Signed-off-by: Michael J. Ruhl --- ibacm/linux/osd.h | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) -- 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..eabf5ed 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 1000000000ULL 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);