Evaluating the Cost of Atomic Operations on Modern Architectures

Hermann Schweizer, Maciej Besta, Torsten Hoefler

TL;DR

This paper dives deep into the performance of atomic operations (like CAS and Fetch-and-Add) across various modern CPU architectures. It reveals that despite differing theoretical complexities, these atomics often perform similarly, and crucially, they don't benefit from instruction-level parallelism, significantly limiting their bandwidth compared to regular writes.

What Problem Does This Paper Address?

In the era of multi-core and many-core processors, atomic operations are fundamental building blocks for parallel programming, enabling synchronization and lock-free data structures. However, understanding their real-world performance across different hardware architectures has been challenging. Developers often rely on assumptions about their relative costs (e.g., CAS being slower than Fetch-and-Add) and how they interact with complex cache hierarchies and coherence protocols. This paper aims to demystify these performance characteristics by providing a rigorous, model-driven analysis of atomic operations on contemporary x86 architectures.

Methods

The authors developed a comprehensive methodology for benchmarking atomic operations, focusing on both latency and bandwidth. This involved:

  • Performance Modeling: Creating a model that accounts for cache coherence states (E, M, S, O) and the multi-level cache hierarchy.
  • Benchmarking Infrastructure: Extending the X86membench infrastructure to measure atomic operations, carefully controlling for factors like TLB misses, clock frequency variations, and prefetchers.
  • Detailed Benchmarks: Designing specific benchmarks for latency (pointer chasing) and bandwidth (sequential access) for Compare-and-Swap (CAS), Fetch-and-Add (FAA), and Swap (SWP). They also analyzed the impact of operand size and unaligned accesses.
  • Architectural Analysis: Testing on a diverse set of modern architectures: Intel Haswell, Xeon Phi, Ivy Bridge, and AMD Bulldozer, each with distinct cache coherence protocols and memory hierarchy designs.

Datasets

Not discussed in the paper. The paper focuses on synthetic benchmarks designed to isolate the performance of atomic operations under controlled conditions.

Key Insights and Ideas

  • Consensus Number Doesn't Dictate Performance: Surprisingly, atomics with different consensus numbers (like CAS with infinite vs. FAA/SWP with 2) often exhibit comparable latency and bandwidth. This suggests that the underlying hardware implementation and cache interactions are more dominant factors than theoretical complexity.
  • No Instruction-Level Parallelism (ILP) for Atomics: A critical finding is that atomic operations, even when there are no data dependencies between them, do not benefit from ILP. This is attributed to hardware mechanisms that prevent write buffers from being merged or reordered, leading to significantly lower bandwidth compared to regular memory writes.
  • Cache Coherence State Matters: The coherence state of a cache line (e.g., Exclusive, Modified, Shared) has a noticeable impact on atomic operation performance, influencing the cost of reads for ownership and invalidations.
  • Architectural Nuances Lead to Surprises: The paper uncovers specific architectural behaviors, such as AMD's MOESI protocol preventing unnecessary write-backs and Intel's potential optimization for certain CAS scenarios, which lead to unexpected performance differences.
  • Unaligned Accesses are Costly: Accessing data that spans cache line boundaries significantly increases the latency of atomic operations, likely due to bus locking mechanisms.

Key Results

  • Comparable Latency: In most cases, CAS, FAA, and SWP exhibit similar latencies. In some specific scenarios (e.g., L1 on Haswell, L3/memory on AMD), CAS can even be faster than FAA.
  • Bandwidth Bottleneck: The bandwidth of atomic operations is consistently much lower (5-30x) than that of regular writes, even when ILP is theoretically possible for FAA/SWP. This is a major performance limitation for bandwidth-intensive workloads.
  • Architectural Differences: The paper details performance variations across Intel and AMD architectures, highlighting how different cache coherence protocols (MESIF, MOESI, MESI-GOLS) and memory hierarchy designs (inclusive vs. non-inclusive L3, presence of L3) influence atomic performance. For instance, Bulldozer's non-inclusive L3 and lack of core valid bits lead to higher latencies for certain operations.
  • Contention Impact: Concurrent access to the same cache line by multiple threads significantly degrades the bandwidth of atomic operations, more so than for regular writes on some architectures.

Limitations and Future Work

  • Hardware Vendor IP: The authors acknowledge that a deeper understanding of microarchitectural details would be beneficial but is often proprietary information from Intel and AMD.
  • Proposed Solutions: The paper suggests several avenues for improvement:
  • Optimizing Unsuccessful CAS: Invalidate cache lines only after a CAS succeeds, as unsuccessful CAS operations don't modify data and thus don't require invalidations.
  • Extending Cache Coherence Protocols: Propose new states (OL/SL) for MOESI or enhancements to AMD's HT Assist to avoid unnecessary remote invalidations on Bulldozer.
  • Enabling ILP for Atomics: Introduce a "FastLock" prefix to allow reordering of atomic operations on non-overlapping memory regions.
  • Future Work: The authors suggest further investigation into the impact of specific hardware mechanisms like prefetchers and power management features, as well as exploring the performance of atomics in more complex, real-world applications.

Summary updated

BibTeX
@inproceedings{schweizer2015evaluating,
  author = {Hermann Schweizer and Maciej Besta and Torsten Hoefler},
  title = {{Evaluating the Cost of Atomic Operations on Modern Architectures}},
  booktitle = {PACT},
  year = {2015},
  doi = {10.1109/pact.2015.24},
}
Figure