Message ID | 1444409557.13186.319.camel@otta |
---|---|
State | New |
Headers | show |
On Fri, 2015-10-09 at 11:52 -0500, Peter Bergner wrote: > On Fri, 2015-10-09 at 16:41 +0200, Torvald Riegel wrote: > > On Thu, 2015-09-03 at 16:58 -0500, Peter Bergner wrote: > >> +Note that the semantics of the above HTM builtins are required to mimic the > >> +locking semantics used for critical sections. Builtins that are used to > >> +create a new transaction or restart a suspended transaction (specifically any > >> +builtin that changes the state from non-transactional to transactional) > > > > Those builtins could be nested in transactions yet would need to provide > > the same semantics at least as far as the compiler is concerned, so > > maybe change "specifically" to "for example"? > > Ah, good point. I forgot about the nested example. In that case, how about > we just drop the text within the ()'s instead? I'm not sure we need it > given your suggested addition below. Sounds good to me. > > I haven't thought enough about txn suspend/resume/abort to make a > > proposal how their required semantics would be specified best. Maybe we > > should call this out explicitly, or maybe the sentences above are > > sufficient because they refer to HTM instructions generally. > > Well we do mention that we need acquire semantics not just for instructions > that start transactions, but also for instructions that resume transactions. > Similar for release and end/suspend, so I guess I'd lean towards what we have > is sufficient. OK. > > > Maybe the second "HTM instructions" should be "builtins" too, I don't > > know. > > Well the builtins expand into multiple hardware instructions and the > memory barriers are only attached to the HTM instructions and not the > other instructions that are generated by the builtins, so I think > HTM instructions is probably more correct here. But if you think > builtins is better, I can change it. No, it's exactly this aspect of the implementation that I didn't know about, and thus wasn't sure. Sounds all good. > Thanks for the review! I've attached the changes to the documentation below. > Is this better? Yes, thanks!
On Fri, 2015-10-09 at 22:19 +0200, Torvald Riegel wrote: > On Fri, 2015-10-09 at 11:52 -0500, Peter Bergner wrote: >> Thanks for the review! I've attached the changes to the documentation below. >> Is this better? > > Yes, thanks! Great, thanks! This is committed a revision 228827. I'm just starting the testing of the backports to the release branches and will commit it there too, assuming everything is clean. Peter
Index: gcc/doc/extend.texi =================================================================== --- gcc/doc/extend.texi (revision 227308) +++ gcc/doc/extend.texi (working copy) @@ -16030,6 +16030,28 @@ unsigned int __builtin_tsuspend (void) @end smallexample +Note that the semantics of the above HTM builtins are required to mimic +the locking semantics used for critical sections. Builtins that are used +to create a new transaction or restart a suspended transaction must have +lock acquisition like semantics while those builtins that end or suspend a +transaction must have lock release like semantics. Specifically, this must +mimic lock semantics as specified by C++11, for example: Lock acquisition is +as-if an execution of __atomic_exchange_n(&globallock,1,__ATOMIC_ACQUIRE) +that returns 0, and lock release is as-if an execution of +__atomic_store(&globallock,0,__ATOMIC_RELEASE), with globallock being an +implicit implementation-defined lock used for all transactions. The HTM +instructions associated with with the builtins inherently provide the +correct acquisition and release hardware barriers required. However, +the compiler must also be prohibited from moving loads and stores across +the builtins in a way that would violate their semantics. This has been +accomplished by adding memory barriers to the associated HTM instructions +(which is a conservative approach to provide acquire and release semantics). +Earlier versions of the compiler did not treat the HTM instructions as +memory barriers. A @code{__TM_FENCE__} macro has been added, which can +be used to determine whether the current compiler treats HTM instructions +as memory barriers or not. This allows the user to explicitly add memory +barriers to their code when using an older version of the compiler. + The following set of built-in functions are available to gain access to the HTM specific special purpose registers.