public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/66842] libatomic uses multiple locks for locked atomics
       [not found] <bug-66842-4@http.gcc.gnu.org/bugzilla/>
@ 2015-07-13  9:21 ` redi at gcc dot gnu.org
  2015-07-13 15:32 ` bin.x.fan at oracle dot com
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2015-07-13  9:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66842

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|libstdc++                   |c

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This obviously isn't a libstdc++ bug because you're not even using C++!


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

* [Bug c/66842] libatomic uses multiple locks for locked atomics
       [not found] <bug-66842-4@http.gcc.gnu.org/bugzilla/>
  2015-07-13  9:21 ` [Bug c/66842] libatomic uses multiple locks for locked atomics redi at gcc dot gnu.org
@ 2015-07-13 15:32 ` bin.x.fan at oracle dot com
  2015-07-13 16:18 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: bin.x.fan at oracle dot com @ 2015-07-13 15:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66842

--- Comment #2 from Bin Fan <bin.x.fan at oracle dot com> ---
I couldn't find a category for libatomic, and my understand is that C and C++
share libatomic library.

(In reply to Jonathan Wakely from comment #1)
> This obviously isn't a libstdc++ bug because you're not even using C++!


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

* [Bug c/66842] libatomic uses multiple locks for locked atomics
       [not found] <bug-66842-4@http.gcc.gnu.org/bugzilla/>
  2015-07-13  9:21 ` [Bug c/66842] libatomic uses multiple locks for locked atomics redi at gcc dot gnu.org
  2015-07-13 15:32 ` bin.x.fan at oracle dot com
@ 2015-07-13 16:18 ` redi at gcc dot gnu.org
  2015-07-30 18:47 ` [Bug c++/66842] " rth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2015-07-13 16:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66842

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Yes, so either C or C++ might be appropriate, but not libstdc++.


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

* [Bug c++/66842] libatomic uses multiple locks for locked atomics
       [not found] <bug-66842-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2015-07-13 16:18 ` redi at gcc dot gnu.org
@ 2015-07-30 18:47 ` rth at gcc dot gnu.org
  2015-07-31 21:20 ` bin.x.fan at oracle dot com
  2015-08-03 17:44 ` rth at gcc dot gnu.org
  5 siblings, 0 replies; 6+ messages in thread
From: rth at gcc dot gnu.org @ 2015-07-30 18:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66842

Richard Henderson <rth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rth at gcc dot gnu.org
           Severity|normal                      |enhancement

--- Comment #5 from Richard Henderson <rth at gcc dot gnu.org> ---
When libatomic was first written, it wasn't clear what the restrictions
from the various languages would be, nor even if that was the best of
ideas -- things that would Just Work lock-free would fail on other,
less popular platforms.

Thus libatomic is written such that accesses to the same object, via
different aliased pages, will work.  Thus locks are created on a per-
cacheline basis covering one page.

This does lead to inefficiencies wrt a more straight-forward solution,
but very careful thought needs to go into changing it.


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

* [Bug c++/66842] libatomic uses multiple locks for locked atomics
       [not found] <bug-66842-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2015-07-30 18:47 ` [Bug c++/66842] " rth at gcc dot gnu.org
@ 2015-07-31 21:20 ` bin.x.fan at oracle dot com
  2015-08-03 17:44 ` rth at gcc dot gnu.org
  5 siblings, 0 replies; 6+ messages in thread
From: bin.x.fan at oracle dot com @ 2015-07-31 21:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66842

--- Comment #6 from Bin Fan <bin.x.fan at oracle dot com> ---
(In reply to Richard Henderson from comment #5)
> When libatomic was first written, it wasn't clear what the restrictions
> from the various languages would be, nor even if that was the best of
> ideas -- things that would Just Work lock-free would fail on other,
> less popular platforms.
> 
> Thus libatomic is written such that accesses to the same object, via
> different aliased pages, will work.  

Could you clarify what does aliased pages mean? Do you mean the same object is
mapped into two or more different processes with different virtual addresses?
And the locks in libatomic are also shared by the processes? Or something else?

> Thus locks are created on a per-cacheline basis covering one page.

This make sense if the above understand of aliased pages is true. However, what
if the memory is not mapped at page boundaries? Then the object may have
different page offset therefore it is still protected by different locks.

And this does not explain why a locked object is protected by multiple locks.
If memory is always mapped at edge boundaries, then the offset of the object in
the page will always be the same so one lock should work. If memory is not
mapped at page boundaries, then if an object is mapped into two
"non-overlapped" address space inside a page, multiple locks would still don't
work.

> 
> This does lead to inefficiencies wrt a more straight-forward solution,
> but very careful thought needs to go into changing it.

Besides aliased pages, does libatomic consider supporting nested locked atomic
objects? For example, should the following work?

typedef struct {
  _Atomic locked1_t obj1;
  /* other fields */
} locked2_t;

_Atomic locked2_t obj2;

atomic_store(&obj2, ...)
atomic_load(&obj2.obj1, ...)


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

* [Bug c++/66842] libatomic uses multiple locks for locked atomics
       [not found] <bug-66842-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2015-07-31 21:20 ` bin.x.fan at oracle dot com
@ 2015-08-03 17:44 ` rth at gcc dot gnu.org
  5 siblings, 0 replies; 6+ messages in thread
From: rth at gcc dot gnu.org @ 2015-08-03 17:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66842

--- Comment #7 from Richard Henderson <rth at gcc dot gnu.org> ---
(In reply to Bin Fan from comment #6)
> Could you clarify what does aliased pages mean? Do you mean the same object
> is mapped into two or more different processes with different virtual
> addresses? And the locks in libatomic are also shared by the processes? Or
> something else?

The same page mapped into the address space more than once.  Of course
I don't mean different processes, as libatomic is *not* an IPC library.
Such a thing is easily constructable via mmap of a file, however.

> This make sense if the above understand of aliased pages is true. However,
> what if the memory is not mapped at page boundaries?

How do you suppose you'd map a page anywhere other than at a page boundary?
That's nonsensical.  Virtual address spaces don't work that way.

> And this does not explain why a locked object is protected by multiple
> locks. If memory is always mapped at edge boundaries, then the offset of the
> object in the page will always be the same so one lock should work. If
> memory is not mapped at page boundaries, then if an object is mapped into
> two "non-overlapped" address space inside a page, multiple locks would still
> don't work.

...

> Besides aliased pages, does libatomic consider supporting nested locked
> atomic objects? For example, should the following work?
> 
> typedef struct {
>   _Atomic locked1_t obj1;
>   /* other fields */
> } locked2_t;
> 
> _Atomic locked2_t obj2;

Yes.  The end address cannot be inferred from the start address.  Thus we
lock every cacheline the object overlaps.


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

end of thread, other threads:[~2015-08-03 17:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-66842-4@http.gcc.gnu.org/bugzilla/>
2015-07-13  9:21 ` [Bug c/66842] libatomic uses multiple locks for locked atomics redi at gcc dot gnu.org
2015-07-13 15:32 ` bin.x.fan at oracle dot com
2015-07-13 16:18 ` redi at gcc dot gnu.org
2015-07-30 18:47 ` [Bug c++/66842] " rth at gcc dot gnu.org
2015-07-31 21:20 ` bin.x.fan at oracle dot com
2015-08-03 17:44 ` rth at gcc dot gnu.org

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