开发者

Cache Hit/Miss for a value in C/C++ Program

This is my requirement,开发者_如何学C I know that certain algorithms makes good use of Cache, some do not, some do more I/O than others on particular data set, etc. I would like to see and analyze that happening myself.

So I was wondering if there was a way I could know how a certain memory/variable is read, i.e. is it from cache, or was there a cache miss. Further if there was a page fault while retrieving this value etc.

Thanks a lot!


If you really want to know when your caches are hitting/missing, modern processors have performance counters that you can use for exactly this purpose. I have used them extensively for academic research. The easiest way to use them is through perfmon2. Perfmon2 has both a library you can link into your program or a stand-alone program that will monitor an existing program. For example, here's the stand-alone program recording all level 1 data cache read requests and misses:

pfmon -eL1D_CACHE_LD:MESI,L1D_CACHE_LD:I_STATE your_program

For reference, Appendix A of this document (PDF) lists Intel's documentation on what hardware counters are available.


I would try using the valgrind cachegrind tool, it can print out annotated source lines with the number of hits/misses in which cache for that line.


I don't know if AMD CodeAnalyst can show that level of granularity but it wouldn't hurt to check.


Depends on the specific compiler, the OS, and the specific model of processor you're running on. Nothing (that I'm aware of) in the C/C++ language give you access to what's happening at the cache level.

There are various measurement tools, but they would be largely independent of the language.

There are some "rules" for minimizing cache and paging issues, though it would take me some time to think of a reasonably comprehensive list.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜