Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #81571
| From | Bo Persson <bo@bo-persson.se> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Some help needed |
| Date | 2021-09-25 19:05 +0200 |
| Message-ID | <ir937iFps6uU1@mid.individual.net> (permalink) |
| References | <since9$gua$1@dont-email.me> |
On 2021-09-25 at 16:41, Bonita Montero wrote:
> I've developed a monitor-object like that of Java for C++ with some
> improvements. The major improvement is that there's not only a spin
> -loop for locking and unlocking but also for waiting on an event. In
> this case you don't have to lock the mutex but supply a predicate on
> a wait_poll-function and the code repeatedly tries to lock the mutex
> polling and if it can lock the mutex it calls the predicate which
> returns (or moves) a pair of a bool and the result-type.
> Waiting to for a semaphore and or a event-object (Win32) in the kernel
> can easily take from 1.000 to 10.000 clock-cylces even when the call
> immediately returns because the semaphore or event has been set before.
> So there has to be a spin count with a reasonable relationship to this
> waiting-inteval, f.e. spinning one tenth of the minimum interval being
> spent in the kernel.
> With my monitor-object I've taken the spincount recalculation-algorithm
> from the glibc. And I'm also using the PAUSE-instruction. But I think
> that the glibc induces to heavy cacheline-flipping by re-loading the
> mutex-flags immediately after a single PAUSE-instruction. So I decided
> to loop PAUSE several times and to take less spinning iterations there-
> fore.
> To get a reasonable number of PAUSE-spinnings I need the time PAUSE
> takes on different processors. On my CPU PAUSE halts the pipe only
> for about for 0,78 nanoseconds, which is about 3,25 clock-cycles in
> average. I've written a short progam tha repeatedly PAUSEs and takes
> the aveage time. I want to encourage you to compile the code on your
> machine and give me the PAUSE-timing it outputs here.
>
> This is the code:
>
> #include <iostream>
> #include <chrono>
> #include <cstddef>
> #include <cstdint>
> #include <immintrin.h>
>
> using namespace std;
> using namespace chrono;
>
> int main( int argc, char **argv )
> {
> static uint64_t const PAUSE_ROUNDS = 1'000'000'000;
> auto start = high_resolution_clock::now();
> for( uint64_t i = PAUSE_ROUNDS; i; --i )
> _mm_pause();
> double ns = (int64_t)duration_cast<nanoseconds>(
> high_resolution_clock::now() - start ).count() / (double)PAUSE_ROUNDS;
> cout << ns << endl;
> }
I get
30.7635
(Core i9 9900K 5GHz)
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Some help needed Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-25 16:41 +0200
Re: Some help needed Paavo Helde <myfirstname@osa.pri.ee> - 2021-09-25 19:51 +0300
Re: Some help needed Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-25 19:01 +0200
Re: Some help needed Branimir Maksimovic <branimir.maksimovic@gmail.com> - 2021-09-25 17:20 +0000
Re: Some help needed Bo Persson <bo@bo-persson.se> - 2021-09-25 19:05 +0200
Re: Some help needed Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-25 19:14 +0200
Re: Some help needed Branimir Maksimovic <branimir.maksimovic@gmail.com> - 2021-09-25 17:33 +0000
Re: Some help needed Branimir Maksimovic <branimir.maksimovic@gmail.com> - 2021-09-25 17:15 +0000
Re: Some help needed Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-25 19:16 +0200
Re: Some help needed Branimir Maksimovic <branimir.maksimovic@gmail.com> - 2021-09-25 17:29 +0000
Re: Some help needed Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-26 07:26 +0200
Re: Some help needed Branimir Maksimovic <branimir.maksimovic@gmail.com> - 2021-09-26 06:56 +0000
Re: Some help needed - further help Bonita Montero <Bonita.Montero@gmail.com> - 2021-09-27 17:35 +0200
Re: Some help needed - further help Bo Persson <bo@bo-persson.se> - 2021-09-27 19:29 +0200
csiph-web