From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from rock.gnat.com (rock.gnat.com [IPv6:2620:20:4000:0:a9e:1ff:fe9b:1d1]) by sourceware.org (Postfix) with ESMTP id C33093858028; Fri, 26 Mar 2021 05:50:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C33093858028 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oliva@adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 70D2056056; Fri, 26 Mar 2021 01:50:10 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id DyBvwngTAHps; Fri, 26 Mar 2021 01:50:10 -0400 (EDT) Received: from free.home (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPS id 39C1B56055; Fri, 26 Mar 2021 01:50:10 -0400 (EDT) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 12Q5o1m5594527 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 26 Mar 2021 02:50:03 -0300 From: Alexandre Oliva To: libstdc++@gcc.gnu.org Cc: gcc-patches@gcc.gnu.org Subject: improve future::poll calibration loop Organization: Free thinker, does not speak for AdaCore Errors-To: aoliva@lxoliva.fsfla.org Date: Fri, 26 Mar 2021 02:50:01 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Mar 2021 05:50:12 -0000 The calibration loop I've recently added to the libstdc++ future/members/poll.cc tests could still select iteration counts that might yield zero-time measurements for the wait_for when ready loop. Waiting for a future that has already had a value set is presumably uniformly faster than a zero-timed wait for a result, so I've changed the calibration loop to use the former. We might still be unlucky and get nonzero from the initial loop, so that the calibration is skipped altogether, but then get zero from the later when-ready loop. I'm not dealing with this case in this patch. In gcc-10 testing, I also had to bump up some multipliers from 100 to 150, but IIUC there have been changes for GCC 11 that will hopefully render those unnecessary, so I'm leaving them out. Regstrapped on x86_64-linux-gnu and cross-tested for x86_64-vx7r2 along with other patches, mostly for the testsuite. Ok to install? for libstdc++-v3/ChangeLog * testsuite/30_threads/future/members/poll.cc: Use faster after-ready call in the calibration loop. --- .../testsuite/30_threads/future/members/poll.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/testsuite/30_threads/future/members/poll.cc b/libstdc++-v3/testsuite/30_threads/future/members/poll.cc index 133dae15ac471..4c846d0b7baf5 100644 --- a/libstdc++-v3/testsuite/30_threads/future/members/poll.cc +++ b/libstdc++-v3/testsuite/30_threads/future/members/poll.cc @@ -55,6 +55,12 @@ int main() Attempt to calibrate it. */ if (start == stop) { + /* After set_value, wait_for is faster, so use that for the + calibration to avoid zero at low clock resultions. */ + promise pc; + future fc = pc.get_future(); + pc.set_value(1); + /* Loop until the clock advances, so that start is right after a time increment. */ do @@ -65,7 +71,7 @@ int main() after another time increment. */ do { - f.wait_for(chrono::seconds(0)); + fc.wait_for(chrono::seconds(0)); stop = chrono::high_resolution_clock::now(); i++; } -- Alexandre Oliva, happy hacker https://FSFLA.org/blogs/lxo/ Free Software Activist GNU Toolchain Engineer Vim, Vi, Voltei pro Emacs -- GNUlius Caesar