public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* improve future::poll calibration loop
@ 2021-03-26  5:50 Alexandre Oliva
  2021-03-27 19:44 ` Jonathan Wakely
  0 siblings, 1 reply; 3+ messages in thread
From: Alexandre Oliva @ 2021-03-26  5:50 UTC (permalink / raw)
  To: libstdc++; +Cc: gcc-patches


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<int> pc;
+      future<int> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: improve future::poll calibration loop
  2021-03-26  5:50 improve future::poll calibration loop Alexandre Oliva
@ 2021-03-27 19:44 ` Jonathan Wakely
  2021-03-31 18:36   ` Alexandre Oliva
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Wakely @ 2021-03-27 19:44 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: libstdc++, gcc-patches

On 26/03/21 02:50 -0300, Alexandre Oliva wrote:
>
>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,

On trunk and gcc-10 branch yes, but not in any released version.

>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.

Yes, the relative performance of different future ops are quite
different on trunk.

>Regstrapped on x86_64-linux-gnu and cross-tested for x86_64-vx7r2 along
>with other patches, mostly for the testsuite.  Ok to install?

OK, thanks.

>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<int> pc;
>+      future<int> 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
>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: improve future::poll calibration loop
  2021-03-27 19:44 ` Jonathan Wakely
@ 2021-03-31 18:36   ` Alexandre Oliva
  0 siblings, 0 replies; 3+ messages in thread
From: Alexandre Oliva @ 2021-03-31 18:36 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: libstdc++, gcc-patches

On Mar 27, 2021, Jonathan Wakely <jwakely@redhat.com> wrote:

> OK, thanks.

Thanks, I'm finally checking this in.

>> for  libstdc++-v3/ChangeLog
>> 
>> * testsuite/30_threads/future/members/poll.cc: Use faster
>> after-ready call in the calibration loop.


Thanks for the patch and for having kept me posted on the random_device
changes too!

-- 
Alexandre Oliva, happy hacker  https://FSFLA.org/blogs/lxo/
   Free Software Activist         GNU Toolchain Engineer
        Vim, Vi, Voltei pro Emacs -- GNUlius Caesar

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-03-31 18:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-26  5:50 improve future::poll calibration loop Alexandre Oliva
2021-03-27 19:44 ` Jonathan Wakely
2021-03-31 18:36   ` Alexandre Oliva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).