3 ms·
A context switch changes the virtual-to-physical mapping. So, _if_ a cache uses virtual addresses for determining whether data is in the cache a context switch
by Someone 10y ago
A context switch changes the virtual-to-physical mapping. So, _if_ a cache uses virtual addresses for determining whether data is in the cache a context switch has to flush the cache.
It looks like (1) x86 is virtually indexed and physically tagged (i.e. you need a virtual address to find the cache line data might be in, and the physical address to check whether that line actually holds the data. See https://en.wikipedia.org/wiki/CPU_cache#Address_translation https://en.wikipedia.org/wiki/CPU_cache#Address_translation for details))
(1) http://www.realworldtech.com/sandy-bridge/7/ http://www.realworldtech.com/sandy-bridge/7/ but that may have changed, they might use different strategies for the various cache levels, or they may by now use some other tricks. Address translation is very hairy in multi-core systems.
- bogomipz 10y ago>" So, _if_ a cache uses virtual addresses for determining whether data ..." I was curious about your "if" caveat. I believe nearly all modern CPUs uses the virtual address as it doesn't know about the physical addresses no?
- pm215 10y agoThe CPU does know the physical address, because the MMU is part of the CPU; so you can have a physically indexed cache if you want. The problem is just that you can't do the cache lookup in parallel with the MMU physical-to-virtual lookup, so it's slower than if you used a virtually-indexed cache.
- bogomipz 10y agoSure, I didn't articulate my comment very well. I meant to say that the L1-3 caches operate on virtual addresses because they don't know the physical address but the MMU does since all memory access must transit through the MMU.
- Someone 10y agoThe reason for the "_if_" is that I know too little about current hardware to know whether that's the norm, the exception, or extinct, so I tried to be careful. Also, I'm using CPU for (CPU+MMU) because that's the case on all modern CPUs that have a MMU, as far as I know.