| Summary: | solaris port missing atomics if not using gcc | ||
|---|---|---|---|
| Product: | SDL | Reporter: | binarycrusader |
| Component: | atomic | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | major | ||
| Priority: | P2 | ||
| Version: | 2.0.0 | ||
| Hardware: | All | ||
| OS: | Solaris | ||
| Attachments: |
solaris atomics support when not using gcc
solaris atomics support when not using gcc |
||
|
Description
binarycrusader
2014-07-02 01:21:15 UTC
I'll provide a patch soon, this is not a request for the developers to implement themselves! Solaris Studio compiler references for compiler barriers: http://www.oracle.com/technetwork/server-storage/solarisstudio/documentation/oss-compiler-barriers-176055.pdf ...and memory fences and memory barriers: http://www.oracle.com/technetwork/server-storage/solarisstudio/documentation/oss-memory-barriers-fences-176056.pdf References for Solaris native memory barrier interfaces: http://www.unix.com/man-page/OpenSolaris/9f/membar_consumer/ Alright, I have a working atomic implementation for Solaris when not using gcc:
$ ./testatomic
INFO:
spin lock---------------------------------------
INFO: AtomicLock lock=1
INFO: AtomicUnlock lock=0
INFO:
atomic -----------------------------------------
INFO: AtomicSet(10) tfret=TRUE val=10
INFO: AtomicAdd(10) tfret=FALSE val=20
INFO: AtomicIncRef() tfret=TRUE val=1
INFO: AtomicIncRef() tfret=TRUE val=2
INFO: AtomicDecRef() tfret=FALSE val=1
INFO: AtomicDecRef() tfret=FALSE val=0
INFO: AtomicCAS() tfret=TRUE val=10
INFO: AtomicCAS() tfret=TRUE val=20
INFO:
epic test---------------------------------------
INFO: Size asserted to be >= 32-bit
INFO: Check static initializer
INFO: Test negative values
INFO: Verify maximum value
INFO: Test compare and exchange
INFO: Test Add
INFO: Test Add (Negative values)
INFO: Reset before count down test
INFO: Counting down from 2147483647, Expect 47 remaining
INFO: Thread subtracting 100 10737418 times
INFO: Thread subtracting 100 10737418 times
INFO: Finished in 0.600000 sec
INFO: Atomic 47 Non-Atomic 662054347
INFO:
FIFO test---------------------------------------
INFO: Mode: Mutex
INFO: Starting 4 readers
INFO: Starting 4 writers
INFO: Finished in 1.989000 sec
INFO:
INFO: Writer 0 wrote 1000000 events, had 126953 waits
INFO: Writer 1 wrote 1000000 events, had 63130 waits
INFO: Writer 2 wrote 1000000 events, had 106669 waits
INFO: Writer 3 wrote 1000000 events, had 68188 waits
INFO: Writers wrote 4000000 total events
INFO:
INFO: Reader 0 read 813760 events, had 23350 waits
INFO: { 150961, 183206, 299678, 179915 }
INFO: Reader 1 read 1195736 events, had 45272 waits
INFO: { 340375, 309743, 206178, 339440 }
INFO: Reader 2 read 815857 events, had 20744 waits
INFO: { 167507, 189029, 285866, 173455 }
INFO: Reader 3 read 1174647 events, had 42712 waits
INFO: { 341157, 318022, 208278, 307190 }
INFO: Readers read 4000000 total events
INFO:
FIFO test---------------------------------------
INFO: Mode: LockFree
INFO: Starting 4 readers
INFO: Starting 4 writers
INFO: Finished in 0.787000 sec
INFO:
INFO: Writer 0 wrote 1000000 events, had 516 waits
INFO: Writer 1 wrote 1000000 events, had 899 waits
INFO: Writer 2 wrote 1000000 events, had 875 waits
INFO: Writer 3 wrote 1000000 events, had 0 waits
INFO: Writers wrote 4000000 total events
INFO:
INFO: Reader 0 read 1012443 events, had 71221 waits
INFO: { 258346, 258274, 236799, 259024 }
INFO: Reader 1 read 1036510 events, had 68317 waits
INFO: { 257074, 254655, 275780, 249001 }
INFO: Reader 2 read 1016088 events, had 71329 waits
INFO: { 258316, 259286, 238192, 260294 }
INFO: Reader 3 read 934959 events, had 65052 waits
INFO: { 226264, 227785, 249229, 231681 }
INFO: Readers read 4000000 total events
Created attachment 1725 [details]
solaris atomics support when not using gcc
Also fixes build failure due to redundant -no-undefined in Makefile.in and incorrect platform check for Solaris that should check __SVR4 in addition to __sun.
I've tested linux build after applying the attached patch; everything seems fine still. Please note that the attached patch assumes that the patch for bug 2618 was applied first. They're not technically dependent on each other since the first just deletes code, but this one might not apply cleanly without it. Comment on attachment 1725 [details]
solaris atomics support when not using gcc
Ooops; I missed the fact that some of the results in testatomic were actually wrong (I was expect it to exit with failure).
Specifically, I didn't realise that the AtomicAdd function was supposed to return the *previous* value instead of the new value.
Created attachment 1735 [details]
solaris atomics support when not using gcc
Now actually passes testatomic (return value is previous value for SDL_AtomicAdd instead of previous value). Again, this was due to the unexpected behaviour of testatomic not failing if previous value is not returned and I missed that:
INFO:
spin lock---------------------------------------
INFO: AtomicLock lock=1
INFO: AtomicUnlock lock=0
INFO:
atomic -----------------------------------------
INFO: AtomicSet(10) tfret=TRUE val=10
INFO: AtomicAdd(10) tfret=TRUE val=20
INFO: AtomicIncRef() tfret=TRUE val=1
INFO: AtomicIncRef() tfret=TRUE val=2
INFO: AtomicDecRef() tfret=TRUE val=1
INFO: AtomicDecRef() tfret=TRUE val=0
INFO: AtomicCAS() tfret=TRUE val=10
INFO: AtomicCAS() tfret=TRUE val=20
INFO:
epic test---------------------------------------
INFO: Size asserted to be >= 32-bit
INFO: Check static initializer
INFO: Test negative values
INFO: Verify maximum value
INFO: Test compare and exchange
INFO: Test Add
INFO: Test Add (Negative values)
INFO: Reset before count down test
INFO: Counting down from 2147483647, Expect 47 remaining
INFO: Thread subtracting 100 10737418 times
INFO: Thread subtracting 100 10737418 times
INFO: Finished in 0.703000 sec
INFO: Atomic 47 Non-Atomic 863928447
INFO:
FIFO test---------------------------------------
INFO: Mode: Mutex
INFO: Starting 4 readers
INFO: Starting 4 writers
INFO: Finished in 2.073000 sec
INFO:
INFO: Writer 0 wrote 1000000 events, had 50449 waits
INFO: Writer 1 wrote 1000000 events, had 52441 waits
INFO: Writer 2 wrote 1000000 events, had 3274 waits
INFO: Writer 3 wrote 1000000 events, had 52781 waits
INFO: Writers wrote 4000000 total events
INFO:
INFO: Reader 0 read 1308624 events, had 141510 waits
INFO: { 396818, 371875, 217309, 322622 }
INFO: Reader 1 read 1230506 events, had 151150 waits
INFO: { 357893, 315857, 256915, 299841 }
INFO: Reader 2 read 672899 events, had 130716 waits
INFO: { 121218, 137596, 221141, 192944 }
INFO: Reader 3 read 787971 events, had 153719 waits
INFO: { 124071, 174672, 304635, 184593 }
INFO: Readers read 4000000 total events
INFO:
FIFO test---------------------------------------
INFO: Mode: LockFree
INFO: Starting 4 readers
INFO: Starting 4 writers
INFO: Finished in 0.792000 sec
INFO:
INFO: Writer 0 wrote 1000000 events, had 23031 waits
INFO: Writer 1 wrote 1000000 events, had 27192 waits
INFO: Writer 2 wrote 1000000 events, had 25128 waits
INFO: Writer 3 wrote 1000000 events, had 19426 waits
INFO: Writers wrote 4000000 total events
INFO:
INFO: Reader 0 read 1135708 events, had 20304 waits
INFO: { 284329, 283726, 284818, 282835 }
INFO: Reader 1 read 1087647 events, had 21484 waits
INFO: { 272969, 268527, 273379, 272772 }
INFO: Reader 2 read 645245 events, had 18298 waits
INFO: { 158509, 164122, 158612, 164002 }
INFO: Reader 3 read 1131400 events, had 20425 waits
INFO: { 284193, 283625, 283191, 280391 }
INFO: Readers read 4000000 total events
Fixed, thanks! https://hg.libsdl.org/SDL/rev/1e283b7a1580 I didn't accept the top level Makefile.in change, and the change to testatomic.c looked wrong to me, but everything else looks good. If you need either of the two changes I didn't accept, go ahead and submit a new bug for each of them. Thanks! |