1
votes

I'm currently trying to optimize my software for better CPU cache usage. There are some posts on SO which suggest that it's sometimes hard to guess what the CPU cache is doing and why there are some performance drops in certain cases. For example:

So in order to get a clue where the cache misses happen, I can run perf to get a count of cache misses and where they occur as well as valgrind --tool=cachegrind to simulate the caches (at least an L1 and a last-level cache).

It's really nice to know where cache misses happen, but I'd like to know why they happen (for example cache trashing etc.). Is there a way to explicitly pause the program and see whats inside the caches (maybe with the program running in valgrind and vgdb attached)?

1
There are only two hard things in Computer Science: cache invalidation and naming things.themagicalyang
@themagicalyang: "There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors". Please don't mutilate well known proverbs.too honest for this site
You don't want to see 'why' they happen at individual times, but 'why' they happen that often.Hans Olsson

1 Answers

0
votes

In my experience you'll need to disassemble your binary and, look to see where the program is using the cache. Look to see where the prefetch or cache instructions are called. That will give you the where and whys of it. It's an unfortunately painful process.