ScholarQuill logoScholarQuillUniversity Notes
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
Study Tools
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
Contact
ScholarQuill logo
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
ScholarQuill logoScholarQuillUniversity Notes
Study PortalCSI-306Cache Coherence
Ctrl + K
Login
Explore
Search
Semester
Papers
CGPA
    CSI-306

    Digital Logic Design

    Progress0 / 47 done
    Topics47
    1Overview of Binary Numbers2Boolean Algebra3Switching Algebra4Logic Gates5Karnaugh Map6Quin-McCluskey Methods7Simplification of Boolean Functions
    8Two-Level NAND/NOR Implementation9Tabular Minimization
    10Adders11Subtracters12Code Converters13Parity Checkers14Multilevel NAND/NOR/XOR Circuits15MSI Components16Design and Use of Encoders17Design and Use of Decoders18Design and Use of Multiplexers19BCD Adders20Comparators21Latches and Flip-Flops22Synchronous Sequential Circuit Design and Analysis23Registers24Synchronous and Asynchronous Counters25Memories26Control Logic Design27Wired Logic and Characteristics of Logic Gate Families28ROMs29PLDs30PLAs31State Reduction and Good State Variable Assignments32Algorithmic State Machine (ASM) Charts33Asynchronous Circuits34Memory Systems35Functional Organization36Multiprocessor and Alternative Architectures37Introduction to SIMD38Introduction to MIMD39Introduction to VLIW40Introduction to EPIC41Systolic Architecture42Interconnection Networks43Shared Memory Systems44Cache Coherence45Memory Models and Memory Consistency46Performance Enhancements47Contemporary Architectures
    8 min read
    Topic 44 of 47
    Topic Study Note Illustration
    44

    Cache Coherence

    Cache coherence refers to the consistency of data stored in multiple caches that are part of a shared memory system. In multiprocessor systems, each processor often has...

    Cache Coherence in Shared Memory Systems

    Cache coherence refers to the consistency of data stored in multiple caches that are part of a shared memory system. In multiprocessor systems, each processor often has its own local cache to store frequently accessed data. When multiple processors access the same memory location, inconsistencies can arise if one processor updates its local cache, but other processors continue to use outdated values from their own caches or from the main memory. Cache coherence protocols are designed to ensure that all processors in a system have a consistent view of the memory.

    Why Cache Coherence is Important

    In multiprocessor systems, the memory is typically shared among multiple processors, and each processor has its own private cache. If different processors have cached copies of the same memory location, inconsistencies can occur when one processor updates its cached copy. Without proper cache coherence, a processor might read outdated data from its cache, leading to incorrect results.

    For example, if Processor A writes to a shared variable and Processor B reads it, but Processor B still sees the old value from its cache, the two processors will not have a coherent view of the memory.

    Cache Coherence Problem

    The key issue in cache coherence arises when multiple caches hold copies of the same memory location. If one processor writes to that location, the other processors' caches must be updated or invalidated to reflect the change. This problem becomes especially complicated in systems with a large number of processors.

    Common problems include:

    • Stale Data: One processor updates its cache, but other processors continue to use outdated copies from their own caches.
    • Race Conditions: Multiple processors attempt to update the same memory location, leading to unpredictable results.
    • Inconsistency: The data in different caches can be inconsistent with each other and with main memory, causing conflicts.

    Cache Coherence Protocols

    To manage the consistency of cached data in shared memory systems, cache coherence protocols are used. These protocols define rules for updating, invalidating, or propagating changes to the shared data in the system's memory hierarchy.

    Two main classes of cache coherence protocols are:

    1. Write-invalidate Protocols
    2. Write-update Protocols

    1. Write-Invalidate Protocols

    In a write-invalidate protocol, when a processor writes to a memory location, it invalidates the copies of that memory location in all other caches. This ensures that no processor reads stale data from another cache, but it introduces additional latency when a processor needs to fetch the updated data from the main memory.

    Example: MESI Protocol (Modified, Exclusive, Shared, Invalid)

    One of the most commonly used cache coherence protocols is the MESI protocol. It operates on the principle of maintaining the state of each cache line in one of four states:

    1. Modified (M): The cache holds the most recent copy of the data, and the data has been modified. The cache is the only copy that is up-to-date, and the value is not present in memory.

    2. Exclusive (E): The cache holds the only copy of the data, and it is not modified. The data is consistent with memory, but no other cache has the data.

    3. Shared (S): The data is present in multiple caches, but none of them have modified it. It is still consistent with memory.

    4. Invalid (I): The cache does not have a valid copy of the data. It must be fetched from memory if needed.

    The MESI protocol ensures that whenever a processor writes to a shared location, other caches with a copy of that location are either invalidated or updated, maintaining cache coherence.

    MESI State Transitions:

    • Read Miss: If a processor accesses a memory location not in its cache, it fetches the value from main memory or from another cache that has it in the Shared or Modified state.
    • Write Miss: When a processor writes to a memory location, it broadcasts an invalidation message to all other caches. If the location is Modified in another cache, it will be updated with the new value.
    • Write Hit: If the processor writes to its cache, it will update the data. Depending on the protocol, it may invalidate or update other caches.

    2. Write-update Protocols

    In write-update protocols, instead of invalidating other caches when a processor writes to a memory location, the processor sends an update message to all caches holding a copy of the data. This ensures that all caches are updated with the most recent value of the data.

    Example: MOESI Protocol (Modified, Owned, Exclusive, Shared, Invalid)

    The MOESI protocol is an extension of the MESI protocol and adds an Owned state, which helps reduce the number of memory accesses by keeping the most recent data in the processor's cache. The Owned state allows the processor to update other caches with the most recent data without needing to go back to memory.

    The states in MOESI are:

    1. Modified (M): Same as in MESI, the cache contains the most recent data, and it is the only copy.
    2. Owned (O): The processor has the most recent copy of the data, and it is the only processor that can modify it, but other caches may also have a copy.
    3. Exclusive (E): The cache has the only copy of the data and it is consistent with memory.
    4. Shared (S): The data is present in multiple caches and is consistent with memory.
    5. Invalid (I): The cache does not have a valid copy of the data.

    Cache Coherence Protocols: Key Concepts

    1. Bus-based Protocols:

      • In systems that use a shared bus to connect processors and memory, the bus is used to broadcast changes (like invalidations or updates) to all caches. Bus snooping is a common technique where caches monitor (snoop) the bus to check for changes made by other processors.
    2. Directory-based Protocols:

      • In large-scale systems, a directory-based protocol may be used, where a centralized or distributed directory keeps track of which caches hold copies of each memory block. This helps reduce the overhead of broadcasting messages to all processors, especially in systems with a large number of processors.
      • In directory-based protocols, when a processor wants to write to a memory location, it first checks the directory to determine which caches need to be invalidated or updated. This reduces the need for global broadcasts.
    3. False Sharing:

      • False sharing occurs when processors cache different data but share the same cache line. This happens when two processors write to different variables that happen to be in the same memory block (cache line). The cache coherence protocol may unnecessarily invalidate or update the cache line, even though the actual data accessed by each processor is independent. This results in unnecessary overhead and performance degradation.
      • Optimizing memory layout to ensure that frequently accessed data by different processors resides in separate cache lines can mitigate false sharing.

    Challenges of Cache Coherence

    1. Scalability:

      • As the number of processors in a system increases, the complexity of maintaining cache coherence grows. More processors mean more cache lines to track, more invalidation or update messages, and higher memory access latency.
    2. Synchronization:

      • Efficient synchronization mechanisms are required to manage multiple processors accessing shared memory concurrently. Poor synchronization can lead to race conditions, where multiple processors attempt to modify the same data simultaneously, causing inconsistencies.
    3. Performance Overhead:

      • Maintaining cache coherence incurs performance overhead due to the need for frequent invalidations, updates, or checks across caches. This can result in cache misses and increased traffic on the interconnection network.

    Applications of Cache Coherence

    1. Multiprocessor Systems:

      • Cache coherence protocols are essential in systems with multiple processors (e.g., NUMA systems or multi-core processors). These protocols ensure that all processors work with the most up-to-date data.
    2. Parallel Computing:

      • Parallel applications that involve shared memory models (e.g., OpenMP, CUDA) require cache coherence to ensure correct and efficient execution of parallel threads.
    3. High-Performance Computing (HPC):

      • In HPC systems, cache coherence is critical for ensuring the accuracy and efficiency of parallel computations across many processors.

    Conclusion

    Cache coherence is a fundamental aspect of shared memory systems, ensuring that processors' caches maintain a consistent and up-to-date view of the memory. Cache coherence protocols, such as MESI and MOESI, provide rules and mechanisms for handling shared memory access in multiprocessor systems, addressing issues like race conditions and stale data. While these protocols improve performance and simplify programming in shared memory systems, they introduce challenges related to scalability, overhead, and synchronization. Optimizing cache coherence protocols is key to the efficient functioning of modern multiprocessor systems, especially in large-scale, high-performance computing environments.

    ← Previous topic 43
    Shared Memory Systems
    Next topic 45 →
    Memory Models and Memory Consistency

    Past Papers

    Open this section to view and download past papers

    Click on Show Past Papers to load available exam papers.

    Reading Progress
    0%
    8mremaining
    1.4kwords
    Intermediatelevel
    On This Page

    No headings found

    Study Toolkit

    Subject Portal

    Digital Logic Design