You do know that all memory access goes through the primary level cache right?
What I think you're after is
- if primary level cache is a miss, how much longer does it take to get it from secondary cache.
- if the secondary level cache is also a miss, how much longer does it take to get it from main memory.
- if the page in main memory is currently swapped out, how much longer does it take to load a page from disk.
This is going to be pretty hard to do without detailed knowledge of your system. It's also going to require some assembler knowledge IMO, since C doesn't care about caches or swap space (they're all taken care of by the hardware and the OS).
You're also going to need a very accurate clock, because L1 to L2 isn't going to be much.
What are you hoping to gain from knowing this information?
--
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.