Evaluating the Cost of Atomic Operations on Modern Architectures

Hermann Schweizer, Maciej Besta, Torsten Hoefler · OpenReview

TL;DR

Atomic operations like Compare-and-Swap (CAS) and Fetch-and-Add (FAA) are the bedrock of modern concurrent programming, yet their actual hardware costs have long been obscured by conventional wisdom. This paper introduces a comprehensive performance model and benchmarking methodology across four major x86 microarchitectures, revealing that different atomic operations incur nearly identical latencies and completely eliminate instruction-level parallelism (ILP).

What Problem Does This Paper Address?

In parallel programming, atomic operations are essential for building lock-free data structures and coordinating multi-core communication. However, developers often rely on "folklore" when choosing between them—for instance, the common assumption that CAS is inherently slower than FAA.

Prior research lacked a detailed analysis of how these operations interact with complex, multi-level cache hierarchies and modern cache coherence protocols (like MESIF and MOESI). This paper fills that gap by providing a rigorous performance model and empirical benchmarks to quantify the latency and bandwidth of atomics under various cache states and contention levels.

Methods

The authors developed a performance model centered on the mechanics of a "read for ownership" (RFO) request. When a core executes an atomic operation, it must first fetch the cache line and invalidate all other copies across the system before modifying it. The model splits atomic latency into the RFO latency, the execution/locking overhead, and protocol-specific overheads.

To validate this model, they extended the X86membench framework to measure:

  1. Latency via pointer-chasing loops, forcing serialized execution.
  2. Bandwidth via sequential array modifications, designed to expose potential instruction-level parallelism.

To ensure clean measurements, they meticulously disabled hardware prefetchers, Turbo Boost, and Hyper-Threading, while utilizing huge pages to eliminate TLB misses.

Datasets

As a hardware performance study, this paper does not use traditional software datasets. Instead, it evaluates four distinct hardware architectures representing both commodity and high-performance computing (HPC) systems:

  • Intel Haswell (Core i7-4770)
  • Intel Ivy Bridge (Xeon E5-2697v2)
  • AMD Bulldozer (Opteron 6272)
  • Intel MIC / Xeon Phi (Phi 7120)

Key Insights and Ideas

  • The "CAS is slower than FAA" Myth is Busted: Across almost all tested cache states and architectures, CAS, FAA, and Swap (SWP) exhibit nearly identical latencies. The theoretical complexity (consensus number) of an atomic operation does not dictate its hardware execution cost.
  • Atomics are Absolute ILP Killers: While normal writes leverage write buffers to hide latency and enable parallel execution, atomic operations force write buffers to drain completely. This prevents any instruction-level parallelism, even when there are no data dependencies between successive atomic instructions.
  • Unsuccessful CAS Still Pays the Full Price: When a CAS operation fails because the memory value doesn't match the expected register value, it still issues an RFO and invalidates copies in other caches, creating unnecessary coherence traffic.
  • Unaligned Atomics are Catastrophic: Accessing an atomic variable that spans two cache lines forces the CPU to lock the entire system bus, causing latency to skyrocket up to 750ns.

Key Results

  • Cache-Level Anomalies: On Intel Ivy Bridge, executing a CAS inside the local L1 cache is actually 2–3ns faster than an FAA or SWP. This is due to an internal L1 optimization that detects when a modification won't be applied, bypassing the write phase.
Ivy Bridge CAS Latency vs FAA/SWP
  • Bandwidth Degradation: Across all testbeds, the bandwidth of atomic operations is 5x to 30x lower than standard writes because they cannot exploit ILP.
Haswell Bandwidth Comparison
  • Real-World Impact (Graph500 BFS): By applying these insights to a parallel Breadth-First Search (BFS) algorithm, the authors demonstrated that a Swap-based implementation outperforms a CAS-based implementation simply because it avoids the "wasted work" semantics of CAS loops, despite having identical hardware latency.

Limitations and Future Work

A primary limitation is the closed-source nature of modern hardware; because microarchitectural details are proprietary intellectual property of Intel and AMD, some variance in the overhead term ($O$) could only be conjectured rather than definitively proven.

For future work, the authors propose two hardware-level optimizations:

  1. Extending Cache Coherence Protocols: Introducing "Local" states (e.g., Owned-Local) to prevent unnecessary invalidation broadcasts to remote CPU sockets.
  2. Relaxed Atomics (FastLock): Introducing an instruction prefix that allows the CPU to reorder independent atomic operations on non-overlapping memory regions, unlocking massive bandwidth improvements.

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