Boost C++ Libraries: Ticket #9426: boost::atomic gcc-cas related specializations patch https://svn.boost.org/trac10/ticket/9426 <p> Patch adds <strong><em>BOOST_ATOMIC_ALLOW_GCC_CAS</em></strong> library configuration option causing preferred use of atomic implementation specializations from <em>gcc-cas.hpp</em> instead of default ones. </p> <p> Patch includes also all changes necessary to fix compilation problems of <em>gcc-cas.hpp</em>, and <em>cas32strong.hpp</em>. </p> <p> Tested with gcc 4.5.3 (and few earlier versions) on ARM (manually forced) and on mipsel platforms. </p> <p> The gcc-cas atomic specializations (full memory barrier based) appeared to perform better on platforms where the default ones where used (pthread mutex based ones). </p> <p> However, the original author has disabled gcc-cas specialization with the following comment: </p> <blockquote> <p> <em>/* currently does not work correctly */</em> </p> </blockquote> <p> which is a good reason for making use of it optional so far. </p> <p> Anyway, it would be great to know the details of the problems related the above comment, which could help in deciding if a new option can be used (and possibly help in solving of the issue). </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9426 Trac 1.4.3 Piotr Kobzda <pikob@…> Sat, 23 Nov 2013 01:14:17 GMT attachment set https://svn.boost.org/trac10/ticket/9426 https://svn.boost.org/trac10/ticket/9426 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">boost_1_55_0_atomic_gcc_cas.patch</span> </li> </ul> Ticket timblechmann Sat, 23 Nov 2013 11:48:59 GMT <link>https://svn.boost.org/trac10/ticket/9426#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9426#comment:1</guid> <description> <p> unfortunately the original author disappeared and i have no idea what's the problem with the original code. could be a compiler bug which may or may not have been fixed ... in general, the patch looks ok to me, though... </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andrey Semashev</dc:creator> <pubDate>Sat, 23 Nov 2013 14:55:02 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9426#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9426#comment:2</guid> <description> <p> I welcome the compilation fixes for the gcc-cas.hpp and cas32strong.hpp headers but I don't see the point in the configuration macro. The ARM target should use the implementation from gcc-armv6plus.hpp (not lock-based). If it doesn't then that's probably a bug in the target detection in platform.hpp and I'd prefer it to be fixed instead. gcc-cas.hpp should be included only since gcc 4.1, because <code>__sync*</code> intrinsics were not available before. It should also check if <code>__GCC_HAVE_SYNC_COMPARE_AND_SWAP_N</code> macros are defined. I suppose, that implementation would be used in case of MIPS. In any case, there is no need in forcing gcc-cas.hpp, unless I'm missing something. </p> <p> PS: I'm not aware of any hidden problems with gcc-cas.hpp. When it's compilation problems are fixed I'm in favor of enabling it in platform.hpp. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andrey Semashev</dc:creator> <pubDate>Sat, 23 Nov 2013 14:55:52 GMT</pubDate> <title>cc set https://svn.boost.org/trac10/ticket/9426#comment:3 https://svn.boost.org/trac10/ticket/9426#comment:3 <ul> <li><strong>cc</strong> <span class="trac-author">Andrey.Semashev@…</span> added </li> </ul> Ticket timblechmann Sat, 23 Nov 2013 15:14:40 GMT <link>https://svn.boost.org/trac10/ticket/9426#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9426#comment:4</guid> <description> <p> iirc the <code>__GCC_HAVE_SYNC</code> macros have been introduced with a later gcc version, so it is probably a good idea only to use the gcc-cas version when these macros are available. </p> <p> regaring arm, it may actually be a good idea to use gcc-cas on armv7, because it provides a double-width ll/sc, which is currently not supported by boost.atomic (but quite useful for many lock-free algorithms). or implement the complete arm support in assembly to avoid the ll/sc emulating cas emulating atomics issue ... </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andrey Semashev</dc:creator> <pubDate>Sat, 23 Nov 2013 16:26:14 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9426#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9426#comment:5</guid> <description> <blockquote class="citation"> <p> or implement the complete arm support in assembly to avoid the ll/sc emulating cas emulating atomics issue </p> </blockquote> <p> That was my idea, yes. </p> </description> <category>Ticket</category> </item> <item> <author>Piotr Kobzda <pikob@…></author> <pubDate>Sat, 23 Nov 2013 18:12:47 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9426#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9426#comment:6</guid> <description> <p> Just to make it clear, my patch was not ARM targeted (nor any other possible target that uses default atomics impl. currently) -- I just used ARM to verify gcc-cas implementation correctness. I guess that current selection for ARMs is usually better than gcc-cas (at least for ARMs 6+). My primary intent was to allow use of gcc-cas on MIPSel platforms on which pthread mutexes are currently being selected by default. BTW, I'd prefer to use lower level APIs for that, but currently I can not use nothing better then generic atomics for Mips implemented based on strong memory barrier only -- which most likely gives no noticeable advantages over implementation from gcc-cas. </p> <p> Regarding optional use of gcc-cas, if you think, that unconditional use of it (besides of earlier checks from platform.hpp and additional check for minimum gcc version supporting <code>__sync</code> API of course) is safe enough and better than default selection, I'd also opt for that. </p> </description> <category>Ticket</category> </item> <item> <author>tim@…</author> <pubDate>Sat, 23 Nov 2013 18:23:02 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9426#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9426#comment:7</guid> <description> <p> piotr: not being familiar with mipsel toolchains, i wonder: what (gcc) compilers are commonly used for this architecture? e.g. is it common to use gcc older than 4.4? iirc 4.3 or 4.4 started to define the <code>__GCC_HAVE_SYNC</code> macros ... and tbo i'd rather not spend too much time on toolchains which are hardly used these days (e.g. gcc-3.X) or the like ... </p> <p> andrey: real native arm support would be great, but also here i wonder: is it really worth to spend time on this? i suppose that most arm toolchains provide std::atomic these days... </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andrey Semashev</dc:creator> <pubDate>Sat, 23 Nov 2013 20:17:27 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9426#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9426#comment:8</guid> <description> <blockquote class="citation"> <p> real native arm support would be great, but also here i wonder: is it really worth to spend time on this? i suppose that most arm toolchains provide std::atomic these days... </p> </blockquote> <p> Well, I'd like Boost.Atomic to be at least not worse than std::atomic on all supported targets. If Boost.Atomic offers additional features, such as specialized operations, this may be a good reason to prefer it over std::atomic. </p> </description> <category>Ticket</category> </item> <item> <author>Piotr Kobzda <pikob@…></author> <pubDate>Sun, 24 Nov 2013 00:29:31 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9426#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9426#comment:9</guid> <description> <blockquote class="citation"> <p> not being familiar with mipsel toolchains, i wonder: what (gcc) compilers are commonly used for this architecture? </p> </blockquote> <p> Hard to tell precisely, since it depends on strategy of the processor vendors adopted to theirs individual customers (which, in general, I'm not too aware of). But I'm afraid, that some people can still use toolchains for Mips older than 4.1 (which I think is initial version supporting <code>__sync_synchronize</code> builtin). Nevertheless, I agree that having just gcc version check would most likely be enough here -- anyone interested in using of older toolchains will still safely use default alternative. </p> <p> I'm just not sure, whether suggested use of <code>__GCC_HAVE_SYNC_*</code> macros shall be preferred before simple gcc version check -- official documentation for gcc 4.1 does not list it in predefined macros list, thus I'd rather prefer use of version check. </p> </description> <category>Ticket</category> </item> <item> <author>Piotr Kobzda <pikob@…></author> <pubDate>Sun, 24 Nov 2013 17:47:30 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/9426 https://svn.boost.org/trac10/ticket/9426 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">boost_1_55_0_atomic_gcc_cas_no_opt.patch</span> </li> </ul> Ticket Piotr Kobzda <pikob@…> Sun, 24 Nov 2013 17:48:48 GMT <link>https://svn.boost.org/trac10/ticket/9426#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9426#comment:10</guid> <description> <p> Added patch that checks gcc version (4.1+) instead of use of BOOST_ATOMIC_ALLOW_GCC_CAS option before inclusion of gcc-cas.hpp. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>timblechmann</dc:creator> <pubDate>Sat, 07 Dec 2013 09:49:16 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/9426#comment:11 https://svn.boost.org/trac10/ticket/9426#comment:11 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> applied the patch to git </p> Ticket