views:

163

answers:

2

On 64-bit Solaris on Sparc, is the atomic_cas_64() function call implemented using load-link/condition-store?

If not, what if any API does Solaris offer for user-mode C code to utilize ll/sc?

A: 

You could have a look at the SPARC and SPARCv9 implementations to see exactly what they do... you should have a look at the membar_* functions (in the same files) to see what you can do to have stronger guarantees.

Michael van der Westhuizen
I was hoping not to have to learn some assembly - generally, there exist C APIs which map onto these lower level constructs and all I need is either double word CAS (which isn't available on Sparc) or LL/SC (which is). If Sparc CAS *is* LL/SC, then fine - if not, then I need a way to actually use LL/SC from C and I'm hoping there's a function call I can use, rather than inline assembler.
Blank Xavier
You don't have to learn too much about assembly. These are C APIs. Have a look at the docs here http://docs.sun.com/app/docs/doc/816-5168/atomic-cas-3c?a=view and here http://docs.sun.com/app/docs/doc/816-5168/membar-ops-3c?a=view. That should be enough to get you going. If you need an example, have a look at https://svn.boost.org/trac/boost/browser/trunk/boost/smart_ptr/detail/sp_counted_base_solaris.hpp. That uses atomic_cas_32, but the same principle applies.
Michael van der Westhuizen
The problem is that I'm using double word CAS to resolve the ABA problem. Sparc doens't support double word CAS, but it has LL/SC, which is single word but solves the ABA problem. If the single word Sparc CAS really *is* CAS, then it's no use to me. If OTOH internally it's implemented using LL/SC, then it's fine. As such, the Sun docs on their atomic ops C API weren't any use. Boost wasn't either, because it didn't answer the question.
Blank Xavier
Google has already indexed this question! (been less than an hour)
Blank Xavier
Have a look at http://developers.sun.com/solaris/articles/atomic_sparc/ - this is written with SPARCv9 (64 bit) in mind, but the general advice applies to SPARCv8 (32 bit) as well. You'll see they mention the membar instructions there. Essentially, if you want to use your cas operations for sequencing, you'll need to use membar_enter and membar_exit as documented. This all gets fuzzy with SPARC (based on the memory ordering model being changeable), but if you're just targeting Solaris then the memory ordering model guaranteed to be Total Store Order (TSO).
Michael van der Westhuizen
Actually, the SPARCv9 atomic.s file is useful and I hadn't seen that before. I have however suddenly begun to think that Sparc does not in fact implement LL/SC *OR* double word CAS!
Blank Xavier
Hmm. Will read about membars more closely - I thought they were memory fences, e.g. guaranteeing instruction execution ordering, and so not useful in this case.
Blank Xavier
A: 

Sparc64 - alone amongst modern CPUs - implements neither double wide CAS nor LL/SC. As such, implementing lock-free code is problematic. There a solutions, but they are solutions to a problem (ABA) which does not exist on other platforms because of their support for CAS or LL/SC. Furthermore, a range of lock-free algorithms cannot be implemented on Sparce because of this limitation.

Blank Xavier