Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

To live is always desirable. -- Eleen the Capellan, "Friday's Child", stardate 3498.9


devel / comp.lang.c++ / How long does x86 PAUSE last ?

SubjectAuthor
* How long does x86 PAUSE last ?Bonita Montero
`- Re: How long does x86 PAUSE last ?Bonita Montero

1
How long does x86 PAUSE last ?

<u9dib5$36d8p$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=935&group=comp.lang.c%2B%2B#935

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: How long does x86 PAUSE last ?
Date: Fri, 21 Jul 2023 11:15:18 +0200
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <u9dib5$36d8p$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 21 Jul 2023 09:15:17 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="eab0bdde3d4fe538e58ee7a8d92b7e3b";
logging-data="3355929"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/3vlsk3i+oFcPtTMKEvICFJaqMod4w89k="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:hA86clNsIH/NHgAzhY8Ky1NyD/M=
Content-Language: de-DE
 by: Bonita Montero - Fri, 21 Jul 2023 09:15 UTC

Years ago I wrote a mutex that allows multiple read accesses
or exclusive write access. Instead, I use limited configurable
spinning. Each spinning interval has an x86 PAUSE instruction
to conserve power and not suffocate other threads on the core.
This got me wondering how long a PAUSE instruction takes on
different x86 CPUs. That's why I wrote a small test C++20
program that you can try out. Here it is:

#include <iostream>
#include <chrono>
#include <cstdint>
#include <utility>
#if defined(_MSC_VER)
#include <intrin.h>
#else
#include <x86intrin.h>
#endif

using namespace std;
using namespace chrono;

void pauseLoop( size_t count )
{ auto unroll = []<size_t ...Indices>( index_sequence<Indices ...>, auto fn )
{
(fn.template operator ()<Indices>(), ...);
};
for( ; count >= 10; count -= 10 )
unroll( make_index_sequence<10>(), [&]<size_t I>() { _mm_pause(); } );
while( count-- )
_mm_pause();
}

int main()
{ using hrc_tp = time_point<high_resolution_clock>;
static size_t const TURNS = 100'000'000;
hrc_tp start = high_resolution_clock::now();
pauseLoop( TURNS );
double ns = (int64_t)duration_cast<nanoseconds>(
high_resolution_clock::now() - start ).count() / (double)TURNS;
cout << ns << "ns" << endl;
}

Agners tables give not values for all CPUs. My Skylake Linux PC
has a latency of 42ns per instruction, my Zen4 Windows PC has a
latency of 12ns.

Re: How long does x86 PAUSE last ?

<u9djap$36hru$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=936&group=comp.lang.c%2B%2B#936

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: How long does x86 PAUSE last ?
Date: Fri, 21 Jul 2023 11:32:11 +0200
Organization: A noiseless patient Spider
Lines: 3
Message-ID: <u9djap$36hru$1@dont-email.me>
References: <u9dib5$36d8p$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 21 Jul 2023 09:32:09 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="eab0bdde3d4fe538e58ee7a8d92b7e3b";
logging-data="3360638"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Ym3tUr9Wn0eVSDqicN9HWjf6kjLIL3os="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:a7HONSh8D5A2vTaLaevfFgK3iIE=
Content-Language: de-DE
In-Reply-To: <u9dib5$36d8p$1@dont-email.me>
 by: Bonita Montero - Fri, 21 Jul 2023 09:32 UTC

And can tell me someone a reliable way to check for asm("yield")
capabilities with compiler-specific macros with g++ and clang++ ?
It should be verifiable with Godbolt.


devel / comp.lang.c++ / How long does x86 PAUSE last ?

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor