diff mbox

[doc,rfa] improve x86 transactional memory intrinsics section

Message ID 54E947AA.40606@codesourcery.com
State New
Headers show

Commit Message

Sandra Loosemore Feb. 22, 2015, 3:06 a.m. UTC
On 02/19/2015 12:36 PM, Sandra Loosemore wrote:
> On 02/19/2015 09:38 AM, Patrick Marlier wrote:
>> Thanks Sandra. Just a minor comment.
>>
>> -Valid abort status bits (when the value is not
>> @code{_XBEGIN_STARTED}) are:
>> +If the transaction aborts, the return value is one of:
>>
>> Here it is really bits. So maybe something like that:
>> If the transaction aborts, the return value is a combination of the
>> following bits:
>
> So "combination" == "bit mask"?  Can there be more than one abort
> condition at a time?  (If there's more than one _xabort call, it seems
> there can be only one status....)
>
> I'll draft a patch to fix this, and expand the example to show how a
> user should test for these conditions, once I understand how it's
> supposed to work.

I found some additional documentation online that gave me a few clues. 
Is the attached patch OK to commit?

-Sandra

Comments

Patrick Marlier Feb. 23, 2015, 10:36 a.m. UTC | #1
On 02/22/2015 04:06 AM, Sandra Loosemore wrote:
> On 02/19/2015 12:36 PM, Sandra Loosemore wrote:
>> On 02/19/2015 09:38 AM, Patrick Marlier wrote:
>>> Thanks Sandra. Just a minor comment.
>>>
>>> -Valid abort status bits (when the value is not
>>> @code{_XBEGIN_STARTED}) are:
>>> +If the transaction aborts, the return value is one of:
>>>
>>> Here it is really bits. So maybe something like that:
>>> If the transaction aborts, the return value is a combination of the
>>> following bits:
>>
>> So "combination" == "bit mask"?  Can there be more than one abort
>> condition at a time?  (If there's more than one _xabort call, it seems
>> there can be only one status....)
>>
>> I'll draft a patch to fix this, and expand the example to show how a
>> user should test for these conditions, once I understand how it's
>> supposed to work.
>
> I found some additional documentation online that gave me a few clues. 
> Is the attached patch OK to commit?
>
> -Sandra
>


+Here is an example showing handling for @code{_XABORT_RETRY}
+and a fallback path for other failures:
+
+@smallexample
+#include <immintrin.h>
+
+int n_tries, max_tries;
+unsigned status = _XBEGIN_STARTED;

I would suggest to set it to something different. Indeed if max_tries == 
0, then it will end up to do the transactional code with no transaction 
started.

+...
+
+for (n_tries = 0; n_tries < max_tries; n_tries++)
+  @{
+    status = _xbegin ();
+    if (status == _XBEGIN_STARTED || !(status | _XABORT_RETRY))

Should not be || !(status & _XABORT_RETRY) ?

+      break;
+  @}
+if (status == _XBEGIN_STARTED)
+  @{
+    ... transaction code...
+    _xend ();
+  @}
+else
+  @{
+    ... non transactional fallback path...
+  @}
+@end smallexample

Thanks a lot. It gives a good idea on how to use it. I just would like 
to mention that the non transactional and transactional code must 
synchronize together (in most cases) to ensure consistency.
--
Patrick
diff mbox

Patch

Index: gcc/doc/extend.texi
===================================================================
--- gcc/doc/extend.texi	(revision 220892)
+++ gcc/doc/extend.texi	(working copy)
@@ -17274,24 +17274,11 @@  and suitable fallback code always needs 
 Start a RTM (Restricted Transactional Memory) transaction. 
 Returns @code{_XBEGIN_STARTED} when the transaction
 started successfully (note this is not 0, so the constant has to be 
-explicitly tested).  If the transaction aborts, all side-effects
-are undone and an abort code is returned. There is no guarantee
-any transaction ever succeeds, so there always needs to be a valid
-fallback path.
-@end deftypefn
-
-@smallexample
-#include <immintrin.h>
-
-if ((status = _xbegin ()) == _XBEGIN_STARTED) @{
-    ... transaction code...
-    _xend ();
-@} else @{
-    ... non transactional fallback path...
-@}
-@end smallexample
+explicitly tested).  
 
-If the transaction aborts, the return value is one of:
+If the transaction aborts, all side-effects 
+are undone and an abort code encoded as a bit mask is returned.
+The following macros are defined:
 
 @table @code
 @item _XABORT_EXPLICIT
@@ -17309,6 +17296,11 @@  Transaction abort due to a debug trap.
 Transaction abort in an inner nested transaction.
 @end table
 
+There is no guarantee
+any transaction ever succeeds, so there always needs to be a valid
+fallback path.
+@end deftypefn
+
 @deftypefn {RTM Function} {void} _xend ()
 Commit the current transaction. When no transaction is active this faults.
 All memory side-effects of the transaction become visible
@@ -17325,6 +17317,33 @@  The @var{status} is an 8-bit constant; i
 value from @code{_xbegin}.
 @end deftypefn
 
+Here is an example showing handling for @code{_XABORT_RETRY}
+and a fallback path for other failures:
+
+@smallexample
+#include <immintrin.h>
+
+int n_tries, max_tries;
+unsigned status = _XBEGIN_STARTED;
+...
+
+for (n_tries = 0; n_tries < max_tries; n_tries++) 
+  @{
+    status = _xbegin ();
+    if (status == _XBEGIN_STARTED || !(status | _XABORT_RETRY))
+      break;
+  @}
+if (status == _XBEGIN_STARTED) 
+  @{
+    ... transaction code...
+    _xend ();
+  @} 
+else 
+  @{
+    ... non transactional fallback path...
+  @}
+@end smallexample
+
 @node Target Format Checks
 @section Format Checks Specific to Particular Target Machines