[PATCH, Libatomic, Darwin] Initial libatomic port for *darwin*.

Iain Sandoe iain@codesourcery.com
Wed Nov 12 21:24:00 GMT 2014


Hi Richard,

The posix fallback for libatomic locks on unsupported item sizes (using pthreads) might be reliable, but is (not surprisingly) somewhat slow.

Whereas the built-in testsuite from libatomic passes ..
..  every Darwin platform from powerpc-darwin9 (on a G5) .. through x86-64-darwin14 (on Haswell) fails the gcc/exceptions.exp suite with timeouts.

So here's a platform port
(we don't [yet] have ifuncs).

----------------

The patch does the following:

1) When 4byte atomic operations are supported (will always be the case when the lib is built as part of GCC) these are used to guard accesses.

2) When atomic ops are not available, OSSpinLocks are used (available since forever on the OS).  These are also 4byte locks on all current platforms.

3) Some heuristic fiddling with the algorithm for hashing addresses - to try and avoid cache turbulence when items are close-ish together (not unlikely in a typical code).  This might yet bear some more tweaking, but seems OK enough for a first go.

4) We use low-level Mach interfaces to give up our timeslice when blocked, to keep overheads to a minimum.

5) We allow the port to specify the minimum processor that will be available.
   E.G. for x86 darwin defaults to core2, which means that we don't start guarding small items which we could lock natively.

================

Tested across the patch for a while on darwin9..13 (and by Dominique on darwin14)
I jammed the atomic version off to test the Spinlock-based timings.

Typical runtime results  for gcc: atomic.exp 

[all == timeout with trunk implementation]

Port Version		Spinlock 		Atomic
=======================================================
powerpc-darwin9		~30mins			~15mins	2G5 G5
x86-64-darwin{12,13}    ~15mins			~6mins	2G8 Xeon, 2G6 Ivy bridge
x86-64-darwin14		-------			~3mins	(Haswell, AFAIK)

This (for x86-64, Xeon) is about the same as I see on our Linux machines.

OK for trunk?

This is also functional on gcc-4.8 and gcc-4.9...
.. what would the feeling be about back-porting?

Iain

libatomic:

	* config/darwin/host-config.h New.
	* config/darwin/lock.c New.
	* configure.tgt (DEFAULT_X86_CPU): New, (target): New entry for darwin.

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: darwin-libatomic.txt
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20141112/a36163de/attachment.txt>
-------------- next part --------------




More information about the Gcc-patches mailing list