Re: [PATCH] Fix errors in expand_atomic_store.
On 11/02/2011 08:44 AM, Andrew MacLeod wrote: > that should work shouldnt it? Yes, so long as the atomic_flag object only wants one memory model. Which I suppose it does for implementing a mutex. r~
Re: [PATCH] Fix errors in expand_atomic_store.
On 11/02/2011 11:25 AM, Richard Henderson wrote: On 11/02/2011 07:18 AM, Andrew MacLeod wrote: OK, I think i need to revert my position and introduce __atomic_test_and_set() and __atomic_clear(). bah. I'll work on that today. I don't think you do. We already have the __sync functions, and we should just use those. actually, that should be sufficinent. What we need is a preprocessor flag that tells you that you need to use those older sync routines. why? its only for the atomic_flag object that those routines are even used, so the C++ or C1x implementation of atomic_flag can just use the existing __sync routines. Since they are defined by the standard as being required to be lock free, I dont need to worry about them in the library which is what I was thinking. I'd just change store and exchange to not try to use those patterns, and then use the sync patterns in implementing atomic_flag. They would be documented as required for that functionality. that should work shouldnt it? Andrew
Re: [PATCH] Fix errors in expand_atomic_store.
On 11/02/2011 07:18 AM, Andrew MacLeod wrote: > OK, I think i need to revert my position and introduce > __atomic_test_and_set() and __atomic_clear(). bah. I'll work on > that today. I don't think you do. We already have the __sync functions, and we should just use those. What we need is a preprocessor flag that tells you that you need to use those older sync routines. r~
Re: [PATCH] Fix errors in expand_atomic_store.
On 11/01/2011 04:48 PM, Richard Henderson wrote: On 11/01/2011 01:20 PM, David Miller wrote: Unfortunately, this is not true. Otherwise we could change the 32-bit default code generation to v9 from v7 under Linux. For v7, pa-risc, and sh, we originally allowed the test_and_set and lock_release patterns to do non-obvious things with 0/1 constants. My proposal is to *not* carry that over to the __atomic patterns. The PA and SH targets have already switched to use kernel helpers, and no longer rely on this hack. The only one left is Sparc v7. C++11 and C1x atomics do have an atomic_flag object which implements test _and_set and clear on a flag, and the standard requires that these *are* lock free . I was hoping to avoid introducing new routines just for that object and using the store and exchange since they are basically the same thing. If this is going to be a big issue, then maybe we should reverse my decision to combine their functionality and add __atomic_test_and_set and __atomic_clear to the __atomic library stable... Im not fond of that since its just a subclass of exchange and store... is it their weirdness on those targets you are concerned with? I could argue that those weirdnesses are only going to show up on targets which dont have other support anyway... hmm. As I make that argument, it also occurs to me how it can break. If atomic_flag HAS to be lockfree, it possible that there is another object the same size which is not lock free, and if I try to exchange (1) or store(0) into that object, the test_and-set or clear routine would be invoked and in a lock-free way.. which is going to break that object.. sigh. OK, I think i need to revert my position and introduce __atomic_test_and_set() and __atomic_clear(). bah. I'll work on that today. btw, how did that patch pass __sync_release tests? expand_builtin_sync_lock_release calls the __atomic_store expander now with 0... oh, its probably doing a compare_and_swap loop... in any case, the sync_lock_release expander would have to be put back in place. Andrew
Re: [PATCH] Fix errors in expand_atomic_store.
On 11/01/2011 11:15 AM, Richard Henderson wrote: On 11/01/2011 04:56 AM, Andrew MacLeod wrote: well, the reason for it was so that __atomic_store can be used as a replacement for sync_lock_release on such targets... And what was your replacement for sync_test_and_set? If you don't have that pair, you don't have a replacement. store (m, 0) is release and t = exchange (m, 1) is test_and_set.
Re: [PATCH] Fix errors in expand_atomic_store.
> (1) Are there really live v7 still around? > > At least with v8 we have SWAP, with which we can implement the full > __atomic_exchange pattern sans hackery. We can't do that with just > LDSTUB. I think that we can drop v7 support at this point but not v8 because of Leon. -- Eric Botcazou
Re: [PATCH] Fix errors in expand_atomic_store.
From: Richard Henderson Date: Tue, 01 Nov 2011 13:48:26 -0700 > (2) Can we have the kernel implement some {SWAP,CAS}{4,8} primitives (possibly > via a special trap) that we can export from libgcc, as we do for ARM, PA, > & SH? > > I believe that would allow all of the non-embedded linux to support all of > the c++11 atomic operations without having to resort to spinlocks. Yes, I was just looking into this right now. I didn't realize that PA, SH, and ARM had added these kernel hooks to solve this problem.
Re: [PATCH] Fix errors in expand_atomic_store.
On 11/01/2011 01:20 PM, David Miller wrote: > Unfortunately, this is not true. > > Otherwise we could change the 32-bit default code generation to > v9 from v7 under Linux. For v7, pa-risc, and sh, we originally allowed the test_and_set and lock_release patterns to do non-obvious things with 0/1 constants. My proposal is to *not* carry that over to the __atomic patterns. The PA and SH targets have already switched to use kernel helpers, and no longer rely on this hack. The only one left is Sparc v7. (1) Are there really live v7 still around? At least with v8 we have SWAP, with which we can implement the full __atomic_exchange pattern sans hackery. We can't do that with just LDSTUB. (2) Can we have the kernel implement some {SWAP,CAS}{4,8} primitives (possibly via a special trap) that we can export from libgcc, as we do for ARM, PA, & SH? I believe that would allow all of the non-embedded linux to support all of the c++11 atomic operations without having to resort to spinlocks. r~
Re: [PATCH] Fix errors in expand_atomic_store.
From: Richard Henderson Date: Tue, 01 Nov 2011 08:15:51 -0700 > Given that I believe that essentially all Sparcs still running > are actually v9 and have native CAS, I think we can ignore this > problem entirely. Unfortunately, this is not true. Otherwise we could change the 32-bit default code generation to v9 from v7 under Linux.
Re: [PATCH] Fix errors in expand_atomic_store.
On 11/01/2011 04:56 AM, Andrew MacLeod wrote: > well, the reason for it was so that __atomic_store can be used as a > replacement for sync_lock_release on such targets... And what was your replacement for sync_test_and_set? If you don't have that pair, you don't have a replacement. > Im just concerned that we now lose the ability to implement the > boolean class test_and_set and clear now on such a target... It's not like the __sync functions are going away. Thankfully there aren't many such targets. ... indeed, there's only one left: Sparc v8. The others that I was thinking of (PA and SH) have dropped that support and now only use linux-atomic.asm kernel implementations. Given that I believe that essentially all Sparcs still running are actually v9 and have native CAS, I think we can ignore this problem entirely. r~
Re: [PATCH] Fix errors in expand_atomic_store.
On 11/01/2011 12:50 AM, Richard Henderson wrote: * optabs.c (expand_atomic_store): Use create_fixed_operand for atomic_store optab. Don't try to fall back to sync_lock_release. --- The create_fixed_operand thinko is obvious. The sync_lock_release is more subtle. The target is allowed to support only storing 0/1 with the test_and_set/lock_release pair, and it's allowed to support that in non-obvious ways. We don't want to get involved in that. well, the reason for it was so that __atomic_store can be used as a replacement for sync_lock_release on such targets... ie, we dont need a different builtin for a target which has only a boolean test and set and clear. Is there harm in allowing that as a fall back? Is there a way of detecting sync_lock_release with those limitations? ie, if there is a lock_release and no compare_and_swap on the target...we could issue it. Im just concerned that we now lose the ability to implement the boolean class test_and_set and clear now on such a target... Andrew