From: Jens Gustedt <jens.gustedt@inria.fr>
To: musl@lists.openwall.com
Subject: Re: [PATCH 1/2] let them spin
Date: Sun, 30 Aug 2015 23:48:00 +0200 [thread overview]
Message-ID: <1440971280.693.25.camel@inria.fr> (raw)
In-Reply-To: <20150830170239.GM7833@brightrain.aerifal.cx>
[-- Attachment #1: Type: text/plain, Size: 2187 bytes --]
Am Sonntag, den 30.08.2015, 13:02 -0400 schrieb Rich Felker:
> On Sun, Aug 30, 2015 at 10:41:53AM +0200, Jens Gustedt wrote:
> > > > So the difference isn't dramatic, just one order of magnitude and
> > > > everybody gets his chance. These chances are not equal, sure, but
> > > > NEVER in capitals is certainly a big word.
> > >
> > > Try this: on a machine with at least 3 physical cores, 3 threads
> > > hammer on the same lock, counting the number of times they succeed in
> > > taking it. Once any one thread has taken it at least 10 million times
> > > or so, stop and print the counts. With your spin strategy I would
> > > expect to see 2 threads with counts near 10 million and one thread
> > > with a count in the hundreds or less, maybe even a single-digit count.
> > > With the current behavior (never spinning if there's a waiter) I would
> > > expect all 3 counts to be similar.
> >
> > The setting that you describe is really a pathological one, where the
> > threads don't do any work between taking the lock and releasing it. Do
> > I understand that correctly?
>
> If you're using locks to implement fake greater-than-wordsize atomics
> then it's the normal case, not a pathological one. You have
> (effectively) things like:
>
> _Atomic long double x;
> __lock(global_lock);
> x++;
> __unlock(global_lock);
you probably just mean "volatile" instead of "_Atomic"?
In any case, this already has a memory write inside the critical
section, that is not nothing compared to the fast path of the
__lock/__unlock operation.
> For a more realistic example, consider atomic CAS on a linked-list
> prev/next pointer pair.
So that one would be similar to the different tests I did for
<stdatomic.h>. So far I wasn't able to observe your "NEVER" case, and
I did a substantial number of runs over the last weeks.
Jens
--
:: INRIA Nancy Grand Est ::: Camus ::::::: ICube/ICPS :::
:: ::::::::::::::: office Strasbourg : +33 368854536 ::
:: :::::::::::::::::::::: gsm France : +33 651400183 ::
:: ::::::::::::::: gsm international : +49 15737185122 ::
:: http://icube-icps.unistra.fr/index.php/Jens_Gustedt ::
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
prev parent reply other threads:[~2015-08-30 21:48 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-29 8:50 Jens Gustedt
2015-08-29 17:16 ` Rich Felker
2015-08-29 19:38 ` Jens Gustedt
2015-08-30 0:39 ` Rich Felker
2015-08-30 8:41 ` Jens Gustedt
2015-08-30 17:02 ` Rich Felker
2015-08-30 21:48 ` Jens Gustedt [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1440971280.693.25.camel@inria.fr \
--to=jens.gustedt@inria.fr \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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 NNTP newsgroup(s).