From: Szabolcs Nagy <szabolcs.nagy@arm.com>
To: Florian Weimer <fweimer@redhat.com>
Cc: libc-alpha@sourceware.org, gcc-help@gcc.gnu.org,
"Paul E. McKenney" <paulmck@kernel.org>,
Tulio Magno Quites Machado Filho <tuliom@linux.vnet.ibm.com>
Subject: Re: Help needed for glibc software transaction memory algorithm
Date: Tue, 4 Jan 2022 22:14:27 +0000 [thread overview]
Message-ID: <20220104221427.GO3294453@arm.com> (raw)
In-Reply-To: <87v8yzfv3u.fsf@oldenburg.str.redhat.com>
The 01/04/2022 15:12, Florian Weimer via Libc-alpha wrote:
> I've tried to implement a software transactional memory algorithm
>
> The characteristics are:
>
> * Single writer, multiple readers.
>
> * Two copies of the data.
>
> * A 64-bit version counter tracks modifications. The lowest bit of the
> counter tells the reader which copy of the data to read.
>
> * The writer increments the counter by 2, modifies the STM-protected
> data, and increments the counter by 1.
>
> * The reader loads the counter, reads the STM-protected data, loads the
> counter for a second time, and retries if the counter does not match.
>
> I've attached a model implementation. The glibc implementation has a
> wrapper around the counter updates to support 32-bit implementations as
> well. In both implementations, the writer uses release MO stores for
> the version update, and the reader uses acquire MO loads. The stores
> and loads of the STM data itself are unordered (not even volatile).
>
> It turns out that this does not work: In the reader, loads of the
> STM-protected data can be reordered past the final acquire MO load of
> the STM version. As a result, the reader can observe incoherent data.
> In practice, I only saw this on powerpc64le, where the *compiler*
> performed the reordering:
>
> _dl_find_object miscompilation on powerpc64le
> <https://sourceware.org/bugzilla/show_bug.cgi?id=28745>
>
> Emprically, my stm.c model does not exhibit this behavior.
>
> To fix this, I think it is sufficient to add a release fence just before
> the second version load in the reader. However, from a C memory model
> perspective, I don't quite see what this fence would synchronize
> with. 8-/ And of course once there is one concurrency bug, there might
> be others as well. Do I need to change the writer to use
> acquire-release MO for the version updates?
>
> I think there should be a canned recipe for this scenario (single
> writer, two data copies), but I couldn't find one.
this reminds me the discussion in section 4 and 5 of
https://www.hpl.hp.com/techreports/2012/HPL-2012-68.pdf
there are no 2 data copies here but i think the reasoning
about the synchronization may apply.
next prev parent reply other threads:[~2022-01-04 22:14 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-04 14:12 Florian Weimer
2022-01-04 22:14 ` Szabolcs Nagy [this message]
2022-01-05 11:38 ` Florian Weimer
2022-01-05 13:07 ` Tulio Magno Quites Machado Filho
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=20220104221427.GO3294453@arm.com \
--to=szabolcs.nagy@arm.com \
--cc=fweimer@redhat.com \
--cc=gcc-help@gcc.gnu.org \
--cc=libc-alpha@sourceware.org \
--cc=paulmck@kernel.org \
--cc=tuliom@linux.vnet.ibm.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.
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).