As asked
Explain cache coherence. What problem does it solve, what is the MESI protocol, and what happens at the hardware level when two cores on an AMD Ryzen processor write to the same cache line?
Sample answer outline
Cache coherence ensures that all cores see a consistent view of memory. MESI defines four states per cache line: Modified (dirty, owned), Exclusive (clean, owned), Shared (clean, multiple owners), Invalid. When core A holds a line in Modified and core B requests it, a snoop is issued over the CCX interconnect, core A writes back to L3 or main memory, and core B fetches the updated value. On AMD Ryzen, the CCX interconnect uses the Infinity Fabric to communicate between CCXs, so cross-CCX snoops have higher latency than same-CCX snoops.
Expect these follow-ups
- What is false sharing, and how would you detect and fix it in a C++ program?
- How does the AMD Infinity Fabric affect the coherence latency compared to Intel's ring bus?