Evaluating the Cost of Atomic Operations on Modern Architectures

Hermann Schweizer, Maciej Besta, Torsten Hoefler

Abstract

Atomic operations are fundamental to synchronization in multi-core programming, yet their performance characteristics are often misunderstood. This paper provides a comprehensive evaluation of atomic instructions like Compare-and-Swap (CAS) and Fetch-and-Add (FAA) across diverse hardware architectures. The findings debunk the "consensus myth"—that complex atomics are inherently slower—and identify cache coherence transitions and the absence of instruction-level parallelism as the primary drivers of performance degradation.

Introduction

In modern parallel computing, atomic operations (atomics) serve as the building blocks for everything from simple mutexes to complex lock-free data structures. Despite their critical role, developers frequently treat them as "black boxes," relying on folk wisdom that suggests instructions with higher theoretical consensus numbers, such as CAS, are inherently more expensive than simpler ones like FAA. As architectures evolve with deeper cache hierarchies and sophisticated coherence protocols (e.g., MESIF, MOESI), understanding the true latency and bandwidth costs of these operations is essential for optimizing high-performance software.

Methodology

The researchers utilized an enhanced version of the X86membench tool to establish a rigorous benchmarking framework. The evaluation process consists of four distinct phases:

  1. Preparation: Warming the Translation Lookaside Buffer (TLB) and ensuring data resides in specific cache coherency states (Modified, Exclusive, Shared, etc.).
  2. Synchronization: Coordinating all threads to initiate operations simultaneously.
  3. Measurement: Capturing precise latency and bandwidth data using high-resolution RDTSC timestamps.
  4. Aggregation: Collecting and analyzing results across all participating cores.

The study proposes a performance model where atomic latency is a function of the time required for "Read for Ownership" (RFO), instruction execution, and architectural overheads like snooping.

Evaluated Architectures

The study spans several hardware platforms representing different design philosophies:

  • Intel Haswell: A quad-core processor featuring an inclusive L3 cache.
  • Intel Ivy Bridge: A dual-socket system totaling 24 cores, typical of high-performance computing environments.
  • AMD Bulldozer: A design utilizing shared L2 caches and a non-inclusive L3 cache.
  • Intel Xeon Phi (MIC): A many-core coprocessor with 61 cores linked via a ring bus.

To validate these findings in a practical context, the authors applied their insights to the Breadth-First Search (BFS) algorithm within the Graph500 benchmark.

Key Insights

A primary contribution of this work is debunking the "Consensus Myth." Empirical data shows that CAS, FAA, and SWP exhibit nearly identical hardware latency. The perceived performance gap in software often arises from algorithmic overhead, such as retries in a loop, rather than the instructions themselves.

Latency of CAS, FAA, and SWP across cache levels.

Furthermore, the study identifies the "Read for Ownership" tax. Atomics are consistently 5–10ns slower than standard reads because they must secure exclusive ownership of a cache line, invalidating other copies even if the operation (like a CAS) ultimately fails. This is compounded by the "ILP Wall": unlike standard writes that use buffers to hide latency, atomics act as memory fences, draining buffers and halting execution, which can reduce bandwidth by up to 30x compared to normal writes.

Key Results

The experimental results highlight significant performance disparities based on data location and alignment:

  • Latency: On Intel platforms, local L1 access for atomics takes ~15–20ns, while remote socket access spikes to ~60–100ns.
  • Bandwidth: A Haswell core capable of 30 GB/s for standard writes is limited to 1.2–1.5 GB/s for atomics due to the lack of instruction-level parallelism.
  • Cache State: Operations on data in the "Modified" state are often faster than in the "Shared" state, as the latter requires additional invalidation signals.
Latency impact of cache invalidations.

The impact of unaligned atomics is particularly severe; spanning two cache lines can trigger a full memory bus lock, increasing latency to as much as 750ns on Haswell.

Conclusion and Future Work

While this study provides a detailed look at x86-64 architectures, the behavior of atomics on alternative architectures like ARM or RISC-V remains an area for future exploration. The authors suggest that hardware-level optimizations, such as speculative execution of independent atomics and avoiding invalidations for unsuccessful CAS operations, could significantly mitigate current performance bottlenecks.

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