8 ms·
Sort of agree, although my intuition tells me not that there's an excessively-coarse-locking problem, but that there's most likely a contention problem. The es
by lincolnq 16y ago
Sort of agree, although my intuition tells me not that there's an excessively-coarse-locking problem, but that there's most likely a contention problem.
The essence of a contention problem, for those who don't know, is that some shared structure (maybe a counter, or the head of a queue, or something) is polled and updated for every message that needs to be processed. Since processors don't (usually) share their caches, updating a value in shared memory causes that cache line on the other processors to be invalidated, so the next time the other processor needs to poll that value it has to retrieve it from memory, which takes a lot of extra time compared to getting it off the L1.
This problem often arises with shared work queues and counters. For work queues you can solve it by giving each processor its own work queue and having it steal work from other processors when it finishes its own queue.
A textbook by Herlihy and Shavit, The Art of Multiprocessor Programming, discusses this stuff in detail.
- deleted 16y ago[deleted]
- gipyro 16y agoThis is pretty much correct. Another solution to this is to have an array[#CPU] of counters/structures and you only update the counter/structure for that specific CPU.
- kmod 16y agoNot quite -- you need to make sure that the counters are on separate cache lines, otherwise you'll still get the same issue.
- ntoshev 16y agoThis hypothesis makes a lot of sense. One should be able to test it on a Nehalem architecture: benchmark the program running on two cores, once choosing them to be different physical cores versus the same physical core. Your theory predicts the latter option to be much faster, and faster than the single core mode, because the two virtual cores will share the same caches.