有人指出,由於乒乓效應,訪問位於同一緩存行中的數據元素的性能很差。 但是,我寫的代碼沒有和valgrind --tool = cachegrind測試不顯示此行爲。希望對此有所瞭解?爲什麼多線程訪問同一緩存行中的數據的緩存未命中率較低?
以下附件是函數,每個並行線程執行:
void test_cache(void* arg)
{
long id = (long) arg;
uint32_t idx = (uint32_t) id;
uint32_t ctr = 0;
uint32_t total_sum = 0;
for(; ctr < 500000; ++ctr)
{
total_sum += shared[idx];
AO_fetch_and_add(&shared[idx], idx);
}
printf("%d %d,\n",id, total_sum);
}
謝謝尼古拉。我的印象是他們有單獨的L2緩存。感謝您指出。我在雙核和Xeon處理器上嘗試過。 – Sandeep 2010-11-06 18:35:19