简体   繁体   中英

What is the price of a cache miss

I'm analyzing some code and using cachegrind to get the number of cachemisses(L2 and L3) in the execution.

My question is how do I determine the time spend waiting for the cache to get readdy based on the cache misses?

I would like to be able to say something like, "my code get 90% cpu utilization"

is it posible to do this based on the cache grind output?

Cachegrind simply simulates execution on a CPU, emulating how the cache and branch predictor might behave. To be able to know how long you would spend blocking on the cache would require a lot more information. Specifically you need to know when execution can be speculated and how many instructions can be dispatched in parallel (as well as how memory memory accesses can be coordinated simultaneously). Cachegrind can't do this, and any tool that could would depend heavily on the processor (whereas cache misses are much less processor dependent).

If you have access to a modern Intel CPU I'd recommend getting a free copy of VTune (for non-commercial purposes) and seeing what it says. It can tell the processor to collect data on cache misses and will report it back to you, so you can see what actually happened rather then just simulating. It will give you a clocks per instruction for each line of code, and using this you can see which lines are blocking on the cache (and how long for), it can also give you all the other information cachegrind can.

You can get it here:

http://software.intel.com/en-us/articles/non-commercial-software-download/

唯一可以确定的方法是使用CPU的性能监视计数器来测量特定的CPU - 即使这样,结果也非常具体,基于此的任何优化都可能对具有不同高速缓存大小的CPU表现得非常糟糕,总线架构或内存配置。

A variable can be fetched from the cache in a few clock cycles.

It can take more than one hundred clock cycles to fetch it from RAM if it isnt in the cache.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM