4 ms·
I think this article misses a major point... PAUSE used to have a fixed quite short latency. It now has a variable latency. I would hazard a guess that the
by londons_explore 6y ago
I think this article misses a major point...
PAUSE used to have a fixed quite short latency.
It now has a variable latency. I would hazard a guess that the latency strongly depends what the other cores on the machine are doing, and the other thread on the same core.
Specifically, I would guess intel saw pause being used in spinlocks, and seeing a lot of power and time on functional units being wasted on locks that spin a lot. They decided to deliberately slow down a spinlock's spinning to use less power, and less of other functional units, and in doing so will free up functional units for the computations on the other hyper-thread and power/thermal headroom for other cores in the same CPU.
By doing so, the thought is that overall, the computation should complete sooner.
If both hyperthreads on a core execute pause, I'd expect the latency to go to very low again.
Yet that reasoning didn't work in this case... The only explanation I can think of is that while some threads are executing pause instructions, other threads are executing other kinds of spinlock's without pause instructions. Those other spinlock's end up spinning faster now they have more functional units, but still making no forward progress.
The overall result is the computation isn't sped up, and you still pay a latency penalty to notice the computation is done, hence slower overall.
- saagarjha 6y agoI don't actually think that was the point. Here the code was literally spinning for dozens of milliseconds, running multiple pause instructions sequentially. I'm no expert in this kind of thing, but spinning for that long without checking the condition is really strange, and caused them to actually be hit by the length of the pause instruction very severely since they were essentially spinning for something directly proportional to the length of a pause.
- TwoBit 6y agoPossibly the original authors benchmarked against CPUs of the time and found that multiple pauses worked best.