Skip to content

Latest commit

 

History

History
91 lines (57 loc) · 3.45 KB

cache.md

File metadata and controls

91 lines (57 loc) · 3.45 KB

Cache

Example

Shut up and do an ASCII art example, first direct mapped then set.

Direct mapped

One possible cache location per memory address.

Upside: simple circuit, fast to find which is it, and small area.

Downside: you might invalidate an entry that was recently accessed, even if all other entries are old.

Fully associative

One cache entry for every memory, so would be perfect because no conflicts.

But of course, requires a cache as large as main memory, thus useless.

Set associative

Middle ground between direct mapped.

Now address specifies the set where it might be, and the tag can be anywhere in that set.

Unlike direct mapped, you now have the fun choice of which entry to evict when a set is full: https://en.wikipedia.org/wiki/Cache_replacement_policies

Bits

Forgetting SMP coherency.

Validity bit

If false, indicates that the given data is invalid, and must be re-fetched.

When it is set to invalid:

  • at startup, everything is set invalid, otherwise we wouldn't be able to differentiate between valid data and the noise present at startup. This is the major use case.
  • another processor modifies main memory for a cache that we hold https://en.wikipedia.org/wiki/Bus_snooping

Dirty bit

Set whenever the CPU writes to cache, unset when cache is written to main memory.

Tag

Part of the original address (MSB), stored in the cache, to disambiguate if a cache line is a hit or not.

Virtual or physical memory

Four possibilities: virtual or physical addressed or tagged.

TODO: which one is best / most common and why?

Cache coherency

You have many CPUs modifying memory. How to keep caches up to date.

Register vs cache

TODO physically different? Apparently not, both made of flip-flops (SRAM), registers can be seen as an L0 cache.