Multitasking and cache let's say I'm running two programs at once, a media player playing an MP3 and a video game. Let's assume for the moment that the other cores of the system are taken out with other programs my question is about the CPU cache.
Every time the computer has to change contexts to run the different programs does it have to flush the CPU cache?
How often does this happen and does anyone have any good online references for this sort of question I'm looking to learn more about operating systems.
Every time the computer has to change contexts to run the different programs does it have to flush the CPU cache?
Which cache (in which CPU)?
Some caches (e.g. L2 cache and L3 cache in 80x86 CPUs) are physically indexed and not flushed when contexts are changed (because the "context" has no influence when you're looking at physical RAM and physical addresses); but "least recently used eviction" (and variations thereof) tend to mean that over a short period of time data for the previous program is evicted to make room in the cache for data used by the current program.
Some caches (e.g. L1 instruction cache, trace cache, "cache of virtual memory translations"/TLB, ...) might or might not be flushed. Sometimes they're tagged with some kind of ID and not flushed (so that stuff for the program with ID #45 is simply ignored but possibly evicted due to "least recently used" when the program with ID #67 is running). Sometimes the OS explicitly flushes for security purposes (e.g. spectre vulnerability mitigations).