From patchwork Fri Apr 19 18:05:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Hefty, Sean" X-Patchwork-Id: 10909521 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 95F5F1515 for ; Fri, 19 Apr 2019 18:49:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 855F02854F for ; Fri, 19 Apr 2019 18:49:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 74ACC28CC6; Fri, 19 Apr 2019 18:49:51 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 CC60528A78 for ; Fri, 19 Apr 2019 18:49:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727976AbfDSSts convert rfc822-to-8bit (ORCPT ); Fri, 19 Apr 2019 14:49:48 -0400 Received: from mga14.intel.com ([192.55.52.115]:11707 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727845AbfDSSts (ORCPT ); Fri, 19 Apr 2019 14:49:48 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Apr 2019 11:05:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,370,1549958400"; d="scan'208";a="339105173" Received: from orsmsx103.amr.corp.intel.com ([10.22.225.130]) by fmsmga005.fm.intel.com with ESMTP; 19 Apr 2019 11:05:40 -0700 Received: from orsmsx109.amr.corp.intel.com ([169.254.11.52]) by ORSMSX103.amr.corp.intel.com ([169.254.5.76]) with mapi id 14.03.0415.000; Fri, 19 Apr 2019 11:05:40 -0700 From: "Hefty, Sean" To: "linux-rdma (linux-rdma@vger.kernel.org)" Subject: [PATCH rdma-core 2/5] rsockets: Adjust poll timeout based on time already used Thread-Topic: [PATCH rdma-core 2/5] rsockets: Adjust poll timeout based on time already used Thread-Index: AdT22aY+MLMlQqo9QUumPkxFeomrbw== Date: Fri, 19 Apr 2019 18:05:40 +0000 Message-ID: <1828884A29C6694DAF28B7E6B8A82373B3E1F905@ORSMSX109.amr.corp.intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiM2UzMzZiNTQtMmVkOS00MjcyLWJkMDAtNzA2MGZhMjY3NmIwIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiZFJ0XC9rTGN3a0d4VFpHNEgrMFdaTEFRTnFuUXJ4cVozc1VFVFZcL216T29iUEV3aFMrTlJpR2FhMVc1TlwvVTVNUiJ9 x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.600.7 dlp-reaction: no-action x-originating-ip: [10.22.254.139] 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 In rpoll(), we spin for a short period of time prior to calling poll(). And poll() is called in a loop, in order to handle events that may not update the desired rsocket state. For example, we could wake up from poll() to process a control message, such as a credit update, but be waiting for app data to be avaialble. This can result in the calling thread re-entering poll(). In order to avoid waiting in poll() for longer than the user specified timeout, track when we enter the call and update the timeout passed to poll() accordingly. Signed-off-by: Sean Hefty --- librdmacm/rsocket.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/librdmacm/rsocket.c b/librdmacm/rsocket.c index f64719e8..cee3bd01 100644 --- a/librdmacm/rsocket.c +++ b/librdmacm/rsocket.c @@ -2973,6 +2973,14 @@ ssize_t rwritev(int socket, const struct iovec *iov, int iovcnt) return rsendv(socket, iov, iovcnt, 0); } +static uint64_t rs_time_us(void) +{ + struct timeval now; + + gettimeofday(&now, NULL); + return now.tv_sec * 1000000 + now.tv_usec; +} + static struct pollfd *rs_fds_alloc(nfds_t nfds) { static __thread struct pollfd *rfds; @@ -3139,8 +3147,8 @@ static int rs_poll_events(struct pollfd *rfds, struct pollfd *fds, nfds_t nfds) */ int rpoll(struct pollfd *fds, nfds_t nfds, int timeout) { - struct timeval s, e; struct pollfd *rfds; + uint64_t start_time; uint32_t poll_time = 0; int ret; @@ -3150,11 +3158,9 @@ int rpoll(struct pollfd *fds, nfds_t nfds, int timeout) return ret; if (!poll_time) - gettimeofday(&s, NULL); + start_time = rs_time_us(); - gettimeofday(&e, NULL); - poll_time = (e.tv_sec - s.tv_sec) * 1000000 + - (e.tv_usec - s.tv_usec) + 1; + poll_time = (uint32_t) (rs_time_us() - start_time); } while (poll_time <= polling_time); rfds = rs_fds_alloc(nfds); @@ -3166,6 +3172,12 @@ int rpoll(struct pollfd *fds, nfds_t nfds, int timeout) if (ret) break; + if (timeout >= 0) { + timeout -= (int) ((rs_time_us() - start_time) / 1000); + if (timeout <= 0) + return 0; + } + ret = poll(rfds, nfds, timeout); if (ret <= 0) break;