clflush() in i3 or i7 processors

2020-03-31 02:16发布

Is it possible to use the clflush instruction/function in i3/i7 processors to the flush the cache and check if the cache is empty or not?? If so - please suggest a correct format of usage (in C directly or inline assembly in C)

I was told that clflush does work properly beyond core 2 duo processors. I am stating this question after having been redirected from this link (below) ------->

¨Is there a way to check whether the processor cache has been flushed recently?¨

my results are not matching as expected. This is what I am getting these results:

took 83 ticks

took 66 ticks

flush: took 52 ticks

took 45 ticks

-------------------> how can the cpu take less ticks after having flushed the cache? (refer to line 2 and 3 of the results that i have gotten)

1条回答
爷、活的狠高调
2楼-- · 2020-03-31 02:56

rdtsc isn't a serializing instruction, as such the measurement is not accurate. As a quick hack you can insert a cpuid call, taking care to update the clobber list too:

asm volatile ("cpuid; rdtsc" : "=a" (a), "=d" (d) : : "ebx", "ecx");

At least for me, that changed the output to match expectations.

查看更多
登录 后发表回答