From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16463 invoked by alias); 7 Jan 2018 20:55:58 -0000 Mailing-List: contact libstdc++-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libstdc++-owner@gcc.gnu.org Received: (qmail 16378 invoked by uid 89); 7 Jan 2018 20:55:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-27.6 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=expire, 1000000000, Hx-languages-length:2134 X-Spam-User: qpsmtpd, 2 recipients X-HELO: relay.appriver.com Received: from relay101a.appriver.com (HELO relay.appriver.com) (207.97.230.14) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 07 Jan 2018 20:55:55 +0000 X-Note: This Email was scanned by AppRiver SecureTide X-Note-AR-ScanTimeLocal: 01/07/2018 3:53:48 PM X-Note: SecureTide Build: 12/19/2017 1:37:44 PM UTC (2.6.27.2) X-Note: Filtered by 10.238.11.161 X-Note-AR-Scan: None - PIPE Received: by relay.appriver.com (CommuniGate Pro PIPE 6.1.7) with PIPE id 273613011; Sun, 07 Jan 2018 15:53:48 -0500 Received: from [213.210.30.29] (HELO elite.brightsign) by relay.appriver.com (CommuniGate Pro SMTP 6.1.7) with ESMTPS id 273612990; Sun, 07 Jan 2018 15:53:48 -0500 Received: from chuckie.brightsign ([fd44:d8b8:cab5:cb01::19] helo=chuckie) by elite.brightsign with esmtp (Exim 4.89) (envelope-from ) id 1eYHyr-0008ut-KO; Sun, 07 Jan 2018 20:55:45 +0000 Received: from mac by chuckie with local (Exim 4.89) (envelope-from ) id 1eYHyr-0003RE-K0; Sun, 07 Jan 2018 20:55:45 +0000 From: Mike Crowe To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Cc: Mike Crowe Subject: [PATCH 2/5] libstdc++ futex: Use FUTEX_CLOCK_REALTIME for wait Date: Sun, 07 Jan 2018 20:55:00 -0000 Message-Id: <20180107205532.13138-3-mac@mcrowe.com> In-Reply-To: <20180107205532.13138-1-mac@mcrowe.com> References: <20180107205532.13138-1-mac@mcrowe.com> X-Note: This Email was scanned by AppRiver SecureTide X-Note-AR-ScanTimeLocal: 01/07/2018 3:53:48 PM X-Note: SecureTide Build: 12/19/2017 1:37:44 PM UTC (2.6.27.2) X-Note: Filtered by 10.238.11.161 X-Policy: brightsign.biz X-Primary: brightsign.biz@brightsign.biz X-Virus-Scan: V- X-Note: ICH-CT/SI:0-0/SG:1 1/1/0001 12:00:00 AM X-Note-SnifferID: 0 X-Note: TCH-CT/SI:0-43/SG:1 1/7/2018 3:53:04 PM X-GBUdb-Analysis: 0, 213.210.30.29, Ugly c=0.476605 p=-0.960784 Source Normal X-Signature-Violations: 0-0-0-4764-c X-Note: Spam Tests Failed: X-Country-Path: ->->United Kingdom->United States X-Note-Sending-IP: 213.210.30.29 X-Note-Reverse-DNS: elite.brightsigndigital.co.uk X-Note-Return-Path: mcrowe@brightsign.biz X-Note: User Rule Hits: X-Note: Global Rule Hits: G293 G294 G295 G296 G300 G301 G433 X-Note: Encrypt Rule Hits: X-Note: Mail Class: VALID X-IsSubscribed: yes X-SW-Source: 2018-01/txt/msg00033.txt.bz2 The futex system call supports waiting for an absolute time if FUTEX_WAIT_BITSET is used rather than FUTEX_WAIT. Doing so provides two benefits: 1. The call to gettimeofday is not required in order to calculate a relative timeout. 2. If someone changes the system clock during the wait then the futex timeout will correctly expire earlier or later. Currently that only happens if the clock is changed prior to the call to gettimeofday. According to futex(2), support for FUTEX_CLOCK_REALTIME was added in the v2.6.28 Linux kernel and FUTEX_WAIT_BITSET was added in v2.6.25. There is no attempt to detect the kernel version and fall back to the previous method. --- libstdc++-v3/src/c++11/futex.cc | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/libstdc++-v3/src/c++11/futex.cc b/libstdc++-v3/src/c++11/futex.cc index f5000aa77b3..40ec7f9b0f7 100644 --- a/libstdc++-v3/src/c++11/futex.cc +++ b/libstdc++-v3/src/c++11/futex.cc @@ -35,6 +35,9 @@ // Constants for the wait/wake futex syscall operations const unsigned futex_wait_op = 0; +const unsigned futex_wait_bitset_op = 9; +const unsigned futex_clock_realtime_flag = 256; +const unsigned futex_bitset_match_any = ~0; const unsigned futex_wake_op = 1; namespace std _GLIBCXX_VISIBILITY(default) @@ -58,22 +61,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } else { - struct timeval tv; - gettimeofday (&tv, NULL); - // Convert the absolute timeout value to a relative timeout struct timespec rt; - rt.tv_sec = __s.count() - tv.tv_sec; - rt.tv_nsec = __ns.count() - tv.tv_usec * 1000; - if (rt.tv_nsec < 0) - { - rt.tv_nsec += 1000000000; - --rt.tv_sec; - } - // Did we already time out? - if (rt.tv_sec < 0) - return false; - - if (syscall (SYS_futex, __addr, futex_wait_op, __val, &rt) == -1) + rt.tv_sec = __s.count(); + rt.tv_nsec = __ns.count(); + if (syscall (SYS_futex, __addr, futex_wait_bitset_op | futex_clock_realtime_flag, __val, &rt, nullptr, futex_bitset_match_any) == -1) { _GLIBCXX_DEBUG_ASSERT(errno == EINTR || errno == EAGAIN || errno == ETIMEDOUT); -- 2.11.0