Quickly discard cache

Is there a way in C ++ to quickly strip the L2 cache of a processor other than iterating through a large fake array?

+3
source share
3 answers

I'm going to suggest that this is for performance testing, and you want to eliminate the effects of cache between runs.

In this case, what you need to know in order to do this effectively:

  • L2 cache allocation size
  • How many allocations are in the L2 cache

Then it is basically a matter of touching the allocation_sizebyte memory from each other until you completely clear the cache.

- wait , , , .

+1

- , , , . , , , .

, , , .

, TLB, .

, , .

+1

You want to use a memory fence. in vC ++:

void SThreadUtil::synchronizeCache()
{
    _mm_mfence();
}

excuse me. For flushing it should be_mm_clflush

-2
source

Source: https://habr.com/ru/post/1729318/


All Articles