News for hackers. Stuff that matters.
Re:Errata prompt Intel to disable TSX in Haswell, early Broa... by mrb on Tuesday August 12, 2014 @02:58PM (#8169489)
For those wondering, the TSX instruction set is http://en.wikipedia.org/wiki/Transactional_Synchronization_E...

I first heard about transactional memory when Sun had plans to implement it for its UltraSPARC Rock processor. There is a decent overview of the concept at http://en.wikipedia.org/wiki/Transactional_memory

Re:Errata prompt Intel to disable TSX in Haswell, early Broa... by fmstephe on Tuesday August 12, 2014 @04:42PM (#8170042)
There has been a CPU with transactional memory running big business servers. The Vega boxes from Azuul (~800 cores) running their JVMs. I know of two good internet discussions available talking about their real world experience using them

Gil Tene https://groups.google.com/forum/#!searchin/mechanical-sympat...

Cliff Click http://www.azulsystems.com/blog/cliff/2009-02-25-and-now-som...

It can be enlightening to hear from a real application of these technologies. I am sad to see it disabled. Had it in the back of my head to play around with it some time.

Re:Errata prompt Intel to disable TSX in Haswell, early Broa... by Marat_Dukhan on Tuesday August 12, 2014 @05:37PM (#8170345)
PowerPC A2 (Blue Gene/Q) and POWER 8 support hardware transactional memory as well
Re:Errata prompt Intel to disable TSX in Haswell, early Broa... by fmstephe on Tuesday August 12, 2014 @06:02PM (#8170447)
It's such a shame. The Intel one is our best chance to get HTM under my desk. Alas :)
Re:Errata prompt Intel to disable TSX in Haswell, early Broa... by Alupis on Wednesday August 13, 2014 @02:07AM (#8171637)
> Some of the savviest software developers are likely building TSX-enabled software right about now.

Really a non-statement statement. The only people who are using CPU instructions in their code will be low level maintainers, ie. kernel devs and other OS devs. So this doesn't effect really anyone except those folks (and of course the benefits it may have provided up the stack via layers of abstractions).

Re:Errata prompt Intel to disable TSX in Haswell, early Broa... by dakull on Wednesday August 13, 2014 @05:51AM (#8172166)
Yours also sounds like a "non-statement statement" e.g.:

https://www.mikeperham.com/2013/12/31/rubys-gil-and-transact...

Re:Errata prompt Intel to disable TSX in Haswell, early Broa... by Alupis on Wednesday August 13, 2014 @10:37AM (#8173083)
This is something implemented in the ruby language/platform -- not something a programmer who is using ruby for a project would worry about/implement.
Re:Errata prompt Intel to disable TSX in Haswell, early Broa... by fmstephe on Wednesday August 13, 2014 @05:07AM (#8172045)
The finance sector produces a lot of low level code driving business applications directly. But, broadly you are right I think.
Re:Errata prompt Intel to disable TSX in Haswell, early Broa... by sdab on Tuesday August 12, 2014 @03:25PM (#8169633)
As a systems guy who was intially very skeptical of Transactional Memory, I've been very excited about TSX for a while. Unfortunately, it seems that the initial implementation in the haswell processors wasnt very efficient[1]. Im looking forward to future hardware implementations by intel.

1. http://natsys-lab.blogspot.ru/2013/11/studying-intel-tsx-per...

Re:Errata prompt Intel to disable TSX in Haswell, early Broa... by hendzen on Tuesday August 12, 2014 @03:34PM (#8169697)
As someone who has used TSX to optimize synchronization primitives, you can expect to see a ~15-20% performance increase, if (big if) your program is heavy on disjoint data access, i.e. a lock is needed for correctness, but conflicts are rare in practice. If you have a lot of threads frequently writing the same cache lines, you are probably going to see worse performance with TSX as opposed to traditional locking. It helps to think about TSX as transparently performing optimistic concurrency control, which is actually pretty much how it is implemented under the hood.

While the API of TSX (_xbegin(), _xabort(), _xend()) gives the appearance of implementing transactional memory, it is really an optimized fast path - the abort rate will determine performance. The technical term for what TSX actually implements is 'Hardware Lock Elision'.

If you are going to use TSX, don't use it directly unless you are writing your own primitives (i.e. transactional condition variables [0]), prefer using Andi Kleene's TSX enabled glibc [1] or the speculative_spin_mutex [2] in TBB.

[0] - http://transact09.cs.washington.edu/9_paper.pdf

[1] - https://github.com/andikleen/glibc

[2] - http://www.threadingbuildingblocks.org/docs/doxygen/a00248.h...

Re:Errata prompt Intel to disable TSX in Haswell, early Broa... by sdab on Tuesday August 12, 2014 @03:52PM (#8169788)
Thanks for the links. Im aware of Andi's work and enjoy reading his posts on TSX. You're absolutely right about HLE vs HTM.

Mostly I wish there was a better fallback than locking when transactions fail, but I suppose this is more in line with thinking of them as optimistic locks (such as what I assume the speculative spin lock does).

Re:Errata prompt Intel to disable TSX in Haswell, early Broa... by beagle3 on Wednesday August 13, 2014 @03:50AM (#8171861)
Do you have any insight into how it compares to lock-free techniques?

A full-blown (say) lock-free hash table is almost insurmountable - I recall seeing an efficient reusable implementation a couple of years ago, but most before that had serious performance or correctness issues. However, if you take this into account early enough in the design of the system, you can usually do with much simpler lock free data structures (seqlock and friends).

transactional memory is, of course, a useful abstraction when you can't (or didn't) take this into account upfront.

Re:Errata prompt Intel to disable TSX in Haswell, early Broa... by colanderman on Wednesday August 13, 2014 @11:32AM (#8173350)
Lock-freedom is all about progress, not performance. i.e. generally the only reason to use a lock-free algorithm is if you have issues with ill-behaved code stalling other processes. (I can think of several simple ways to make a fast concurrent hash table, none of which provide lock-freedom, yet which avoid taking locks when necessary.)

Transactional memory is an access abstraction that presents memory as something over which transactions can be made. It says nothing about whether the implementation is lock-free (though the better implementations approach, or are lock-free). There exist software TM algorithms which lock during the transaction, which lock only briefly at the end of the transaction, and which are lock-free, and some which are a combination of these.

TSX (specifically HLE) only takes a lock if the transaction fails without taking a lock, in order to guarantee forward progress in the absence of an ill-behaved transaction (assuming fair locks). Were the software fallback implemented using lock-free techniques (possible with the more general RTM portion of TSX), this guarantee would extend to ill-behaved transactions as well.

Re:Errata prompt Intel to disable TSX in Haswell, early Broa... by beagle3 on Wednesday August 13, 2014 @02:34PM (#8174336)
> Lock-freedom is all about progress, not performance. i.e. generally the only reason to use a lock-free algorithm is if you have issues with ill-behaved code stalling other processes.

Lock freedom is about progress, but in many practical cases (short time between load-linked/store-conditional pair, for example) it beats locks and everything else in performance -- basically, in the best case you do the same work as locks (i.e. synchronize caches among CPUs), and in the worst case, you spin instead of suspending the process.

Of course, if you do a lot of work between the load and store (or whatever pair of operations need to surround your concurrent operation), and there's a good chance of contention, then ... yes, it will not perform well. But that's not how you should use it (or how it is used most of the time).

And .. transactional memory is an abstraction the leaks differently than locks, but you must still be aware of the failure modes. It's higher level, but does not magically resolve contention.

Re:Errata prompt Intel to disable TSX in Haswell, early Broa... by lelf on Tuesday August 12, 2014 @03:44PM (#8169745)
And it was the only widespread TM implementation in metal.

So N years more till we see software transactional memory with dedicated hardware support.

Re:Errata prompt Intel to disable TSX in Haswell, early Broa... by wahern on Tuesday August 12, 2014 @08:35PM (#8170944)
Strong LL/SC provides the ability to do real software transactional memory. I believe ARM has the strongest LL/SC implementation, with the architecture supporting transaction blocks up to 2KB in size! Although ARM has specified LL/SC such that vendors can choose to only support blocks much smaller than 2KB.

Note that people have totally confused the terms. Originally "software transactional memory" meant using primitives like [strong] LL/SC to get lock-free, wait-free algorithms. Strong LL/SC has been proven to be a universal primitive which can be used to implement most known lock-free, wait-free algorithms.

"Hardware transactional memory" gave you access to lock-free, wait-free algorithms in a much more convenient manner. But really it's a difference of degree because strong LL/SC requires _significant_ hardware support.

These days people (like the PyPy project and most STM libraries) use "software transactional memory" for implementations which just use a mutex under the hood. It's emulated STM; they're just being fanciful.

I believe TSX is more like strong LL/SC. Maybe stronger. OTOH I'm not sure if it's universal enough to implement wait-free algorithms.

Re:Errata prompt Intel to disable TSX in Haswell, early Broa... by tedunangst on Tuesday August 12, 2014 @08:42PM (#8170969)
More like N more months. They say they've already fixed it.
Re:Errata prompt Intel to disable TSX in Haswell, early Broa... by mnarayan01 on Tuesday August 12, 2014 @03:22PM (#8169619)
The techreport.com article says:

  The obvious initial targets for TSX optimization are server-class applications like transactional database servers.
Looking at your wiki links though, I would think this would be awesome for almost any high-performance multi-threaded program. Am I wrong about that?
Re:Errata prompt Intel to disable TSX in Haswell, early Broa... by sdab on Tuesday August 12, 2014 @03:28PM (#8169653)
In theory yes, though thinking in terms of transactions is subtly different from thinking in terms of threading critical sections. Particularly, they differ in how they handle contention. Locks block while transactions abort/fail. Simply retry-ing a transaction is also not a good idea which is why it is currently suggested to fallback on locks [1]. So I assume the suggestion of using it for dbs is because it would be more straight-forward as dbs are already used to transactions.

1. https://software.intel.com/en-us/blogs/2013/06/23/tsx-fallba...

Re:Errata prompt Intel to disable TSX in Haswell, early Broa... by blt on Tuesday August 12, 2014 @04:30PM (#8169971)
It won't make any difference if the load is embarrassingly parallel, like rendering one frame of video per core. In those cases the amount of independent work is huge compared to time spent dealing with locks.
Re:Errata prompt Intel to disable TSX in Haswell, early Broa... by colanderman on Tuesday August 12, 2014 @04:27PM (#8169960)
The idea with HLE at least, was that anywhere you had a highly contended lock that protected not-highly-write-contended data, it was a drop-in performance boost. Really sucks that they had to pull the plug on it.