Boost C++ Libraries: Ticket #6308: Add sp_counted_base_aix.hpp using AIX atomic operations https://svn.boost.org/trac10/ticket/6308 <p> Add sp_counted_base_aix.hpp that uses fetch_and_add and compare_and_swap atomic operations available on AIX (see <a class="ext-link" href="http://publib.boulder.ibm.com/infocenter/aix/v6r1/index.jsp?topic=%2Fcom.ibm.aix.kerneltechref%2Fdoc%2Fktechrf1%2Ffetch_and_add.htm"><span class="icon">​</span>http://publib.boulder.ibm.com/infocenter/aix/v6r1/index.jsp?topic=%2Fcom.ibm.aix.kerneltechref%2Fdoc%2Fktechrf1%2Ffetch_and_add.htm</a>). </p> <p> The average time for each iteration in the attached test.cpp was reduced from 23 microseconds to 4.7 microseconds on a machine running AIX 5.3 with <a class="missing wiki">VisualAge</a> C++ 8.0. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6308 Trac 1.4.3 aaron.riekenberg@… Tue, 20 Dec 2011 23:53:09 GMT attachment set https://svn.boost.org/trac10/ticket/6308 https://svn.boost.org/trac10/ticket/6308 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">sp_counted_base_aix.patch</span> </li> </ul> <p> Patch </p> Ticket aaron.riekenberg@… Tue, 20 Dec 2011 23:54:03 GMT attachment set https://svn.boost.org/trac10/ticket/6308 https://svn.boost.org/trac10/ticket/6308 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">test.cpp</span> </li> </ul> <p> Benchmark program </p> Ticket Peter Dimov Wed, 21 Dec 2011 00:36:57 GMT <link>https://svn.boost.org/trac10/ticket/6308#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6308#comment:1</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/76086" title="Apply AIX patch from #6308. Refs #6308.">[76086]</a>) Apply AIX patch from <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6308" title="#6308: Feature Requests: Add sp_counted_base_aix.hpp using AIX atomic operations (closed: fixed)">#6308</a>. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6308" title="#6308: Feature Requests: Add sp_counted_base_aix.hpp using AIX atomic operations (closed: fixed)">#6308</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Wed, 21 Dec 2011 00:43:58 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/6308#comment:2 https://svn.boost.org/trac10/ticket/6308#comment:2 <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> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/76087" title="Merge [76086] to release. Fixes #6308.">[76087]</a>) Merge <a class="changeset" href="https://svn.boost.org/trac10/changeset/76086" title="Apply AIX patch from #6308. Refs #6308.">[76086]</a> to release. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6308" title="#6308: Feature Requests: Add sp_counted_base_aix.hpp using AIX atomic operations (closed: fixed)">#6308</a>. </p> Ticket aaron.riekenberg@… Thu, 22 Dec 2011 21:05:45 GMT attachment set https://svn.boost.org/trac10/ticket/6308 https://svn.boost.org/trac10/ticket/6308 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">sp_counted_base_aix_memory_barrier.patch</span> </li> </ul> <p> Patch to add memory barrier to sp_counted_base_aix.hpp </p> Ticket aaron.riekenberg@… Thu, 22 Dec 2011 21:07:25 GMT status changed; resolution deleted https://svn.boost.org/trac10/ticket/6308#comment:3 https://svn.boost.org/trac10/ticket/6308#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> </ul> <p> As documented in smart_ptr/detail/atomic_count.hpp, in cases when the reference count is decremented to 0 we need a memory barrier before destroying the pointed-to object. </p> <p> sp_counted_base_aix_memory_barrier.patch adds this using the isync instruction. </p> Ticket Peter Dimov Thu, 22 Dec 2011 22:12:24 GMT <link>https://svn.boost.org/trac10/ticket/6308#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6308#comment:4</guid> <description> <p> If fetch_and_add doesn't contain any memory barriers, a trailing isync is not enough, we need a leading (lw)sync as well. See sp_counted_base_gcc_ppc.hpp. Does AIX only work on PPC? </p> </description> <category>Ticket</category> </item> <item> <author>aaron.riekenberg@…</author> <pubDate>Fri, 23 Dec 2011 13:12:15 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/6308 https://svn.boost.org/trac10/ticket/6308 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">sp_counted_base_aix_122311.hpp</span> </li> </ul> Ticket aaron.riekenberg@… Fri, 23 Dec 2011 13:18:36 GMT <link>https://svn.boost.org/trac10/ticket/6308#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6308#comment:5</guid> <description> <p> AIX only runs on POWER and PowerPC. </p> <p> fetch_and_add is not documented to do any memory barrier. I looked at the instructions for fetch_and_add with listi in dbx. It does lwarx and stwcx but does not do lwsync, sync, or isync. So I believe it does not contain a barrier. </p> <p> I am attaching a new version of sp_counted_base_aix.hpp (sp_counted_base_aix_122311.hpp). This version is written more in the style of sp_counted_base_gcc_ppc.hpp. I added a leading sync instruction to atomic_decrement and a trailing isync for a full barrier. </p> <p> The performance of this version is a bit worse than my original no-barrier version. Each iteration of the test program now takes about 8.8 microseconds. This is still 2.5X faster than using pthread_mutex. </p> <p> Thanks for your patience in getting this correct. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Fri, 23 Dec 2011 15:03:41 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6308#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6308#comment:6</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/76119" title="Add memory barriers to sp_counted_base_aix.hpp. Refs #6308.">[76119]</a>) Add memory barriers to sp_counted_base_aix.hpp. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6308" title="#6308: Feature Requests: Add sp_counted_base_aix.hpp using AIX atomic operations (closed: fixed)">#6308</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Fri, 23 Dec 2011 15:07:21 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6308#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6308#comment:7</guid> <description> <p> lwsync should be faster. We didn't use it in the PPC version because, as I recall, GCC didn't support it. I'm not sure what compiler are you targeting on AIX. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Fri, 23 Dec 2011 15:10:53 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6308#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6308#comment:8</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/76120" title="Merge [76119] to release. Refs #6308.">[76120]</a>) Merge <a class="changeset" href="https://svn.boost.org/trac10/changeset/76119" title="Add memory barriers to sp_counted_base_aix.hpp. Refs #6308.">[76119]</a> to release. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6308" title="#6308: Feature Requests: Add sp_counted_base_aix.hpp using AIX atomic operations (closed: fixed)">#6308</a>. </p> </description> <category>Ticket</category> </item> <item> <author>aaron.riekenberg@…</author> <pubDate>Fri, 23 Dec 2011 17:23:14 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/6308 https://svn.boost.org/trac10/ticket/6308 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">sp_counted_base_aix_builtin_ns.patch</span> </li> </ul> Ticket aaron.riekenberg@… Fri, 23 Dec 2011 17:28:15 GMT <link>https://svn.boost.org/trac10/ticket/6308#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6308#comment:9</guid> <description> <p> I experimented with lwsync. It was slightly faster than sync in my tests (around 300 nanoseconds). lwsync does not enforce ordering of stores followed by loads (<a class="ext-link" href="http://www.ibm.com/developerworks/systems/articles/powerpc.html"><span class="icon">​</span>http://www.ibm.com/developerworks/systems/articles/powerpc.html</a>). So I think I'll stick with sync for this reason, and to be consistent with sp_counted_base_gcc_ppc.hpp. </p> <p> I am attaching one last (hopefully!) patch which does the following: </p> <ol><li>Uses builtin functions sync() and isync() instead of inline asm. </li></ol><ol start="2"><li>Puts the atomic_* functions inside the boost::detail namespace - I accidentally put them in the boost namespace previously. </li></ol><p> Thanks again for all your help on this. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Fri, 23 Dec 2011 17:35:43 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6308#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6308#comment:10</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/6308#comment:9" title="Comment 9">aaron.riekenberg@…</a>: </p> <blockquote class="citation"> <p> I experimented with lwsync. It was slightly faster than sync in my tests (around 300 nanoseconds). lwsync does not enforce ordering of stores followed by loads (<a class="ext-link" href="http://www.ibm.com/developerworks/systems/articles/powerpc.html"><span class="icon">​</span>http://www.ibm.com/developerworks/systems/articles/powerpc.html</a>). </p> </blockquote> <p> Yes, I know what lwsync does. You don't need sync here. </p> </description> <category>Ticket</category> </item> <item> <author>aaron.riekenberg@…</author> <pubDate>Fri, 23 Dec 2011 20:45:04 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/6308 https://svn.boost.org/trac10/ticket/6308 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">sp_counted_base_aix_lwsync.patch</span> </li> </ul> <p> Switch from sync to lwsync </p> Ticket aaron.riekenberg@… Fri, 23 Dec 2011 20:49:01 GMT <link>https://svn.boost.org/trac10/ticket/6308#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6308#comment:11</guid> <description> <p> I convinced myself you are correct about lwsync. </p> <p> Average performance of all approaches in test.cpp per iteration: </p> <p> Original pthread_mutex implementation: 23 microseconds Atomic operations, barrier using sync: 8.8 microseconds Atomic operations, barrier using lwsync: 8.2 microseconds Atomic operations, no barrier (broken): 4.7 microseconds </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Fri, 23 Dec 2011 23:10:39 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6308#comment:12 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6308#comment:12</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/76123" title="sp_counted_base_aix.hpp: switch to lwsync and builtins. Refs #6308.">[76123]</a>) sp_counted_base_aix.hpp: switch to lwsync and builtins. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6308" title="#6308: Feature Requests: Add sp_counted_base_aix.hpp using AIX atomic operations (closed: fixed)">#6308</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Fri, 23 Dec 2011 23:12:53 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6308#comment:13 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6308#comment:13</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/76124" title="Merge [76123] to release. Refs #6308.">[76124]</a>) Merge <a class="changeset" href="https://svn.boost.org/trac10/changeset/76123" title="sp_counted_base_aix.hpp: switch to lwsync and builtins. Refs #6308.">[76123]</a> to release. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6308" title="#6308: Feature Requests: Add sp_counted_base_aix.hpp using AIX atomic operations (closed: fixed)">#6308</a>. </p> </description> <category>Ticket</category> </item> <item> <author>vfried@…</author> <pubDate>Thu, 01 Nov 2012 17:21:27 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6308#comment:14 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6308#comment:14</guid> <description> <p> What is the status of sp_counted_base_aix.hpp? It is not #included in sp_counted_base.hpp, but it is a part of the official sources and there is no warning that it is e.g. experimental or for testing only. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Thu, 01 Nov 2012 17:28:40 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6308#comment:15 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6308#comment:15</guid> <description> <p> Hmm. It seems that the patch in <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6667" title="#6667: Patches: sp_counted_base for VACPP with atomic builtins; Linux enabled (closed: fixed)">#6667</a> removed the #ifdef _AIX part of sp_counted_base.hpp for some reason and I didn't notice. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Thu, 01 Nov 2012 17:50:44 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6308#comment:16 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6308#comment:16</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/81134" title="Add back _AIX-specific #ifdef that was mistakenly removed. Refs #6308. ...">[81134]</a>) Add back _AIX-specific #ifdef that was mistakenly removed. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6308" title="#6308: Feature Requests: Add sp_counted_base_aix.hpp using AIX atomic operations (closed: fixed)">#6308</a>. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6667" title="#6667: Patches: sp_counted_base for VACPP with atomic builtins; Linux enabled (closed: fixed)">#6667</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Wed, 14 Nov 2012 12:09:32 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/6308#comment:17 https://svn.boost.org/trac10/ticket/6308#comment:17 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/81336" title="Merged [81134] from trunk. Fixes #6308. Refs #6667.">[81336]</a>) Merged <a class="changeset" href="https://svn.boost.org/trac10/changeset/81134" title="Add back _AIX-specific #ifdef that was mistakenly removed. Refs #6308. ...">[81134]</a> from trunk. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6308" title="#6308: Feature Requests: Add sp_counted_base_aix.hpp using AIX atomic operations (closed: fixed)">#6308</a>. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6667" title="#6667: Patches: sp_counted_base for VACPP with atomic builtins; Linux enabled (closed: fixed)">#6667</a>. </p> Ticket