0

Does it make any sense in flushing the CPU cache manually, if it is implemented as a write-through cache?

San
  • 71
  • 1
  • 6

1 Answers1

2

When a word is written at a write-through (WT) cache by a store instruction, it is also sent to the following level of the memory hierarchy (see cache entry at wikipedia). Hence, cache blocks at the WT cache are clean, that is, are coherent with their copies at the next level, and write-backs would not be necessary.

WT invalidations could be required in case of Direct Memory Acceses (DMA) that make cache contents stale, but, as far as I know, these are not manually operations, but OS or hardware driven.

Related to manually flushing, for example, according to the Intel Architecture Software Developer’s Manual (Volume 2, Instruction Set Reference):

WBINVD — Write Back and Invalidate Cache This instruction writes back all modified cache lines in the processor’s internal cache to main memory and invalidates (flushes) the internal caches.

So I think that, in case of a WT cache, this instruction just invalidates all the cache lines.

chus
  • 1,577
  • 15
  • 25
  • 1
    Thanks chus. If the backing store for a cache line is volatile (DMA), then isn't invalidating the cache ideal than flushing it? – San Apr 09 '13 at 02:55
  • You are right. I have edited my answer to make it more accurate. – chus Apr 09 '13 at 12:27
  • Yes. Now since WT cache line entries are always clean, an explicit flush of the cache line should not result in a write to actual memory isn't it? CPU should just discard the flush instruction. – San Apr 09 '13 at 15:48
  • I think so. By the way, be aware that the cache flush instruction is a privileged one. See this [question](http://stackoverflow.com/questions/1756825/cpu-cache-flush) and [this one](http://stackoverflow.com/questions/6745665/wbinvd-instruction-usage) – chus Apr 09 '13 at 18:24