HardRace: A Dynamic Data Race Monitor for Production Use

Xudong Sun, Zhuo Chen, Jingyang Shi, Yiyu Zhang, Peng Di, Xuandong Li, Zhiqiang ZuoarXiv 2024

TL;DR

This paper introduces HardRace, a novel dynamic data race monitor designed for production environments. By combining static analysis to prune unnecessary memory accesses with Intel's hardware tracing capabilities (PTWRITE), HardRace achieves significantly lower runtime overhead and higher detection accuracy than existing tools, enabling it to detect all types of data races with less than 2% overhead on average.

What Problem Does This Paper Address?

In today's multi-threaded world, data races are a persistent and insidious bug. These concurrency errors can lead to unpredictable crashes, security vulnerabilities, and incorrect computations, causing significant real-world problems. Despite extensive testing, data races often slip into deployed software because they are highly sensitive to specific execution states and thread interleavings, making them difficult to reproduce and fix offline. Existing solutions for detecting these races fall into two camps: static analysis, which suffers from high false positive rates, and dynamic analysis, which typically incurs prohibitively high runtime overhead, rendering them impractical for production use. This paper aims to bridge this gap by providing a dynamic data race detector that is both highly accurate and efficient enough for production monitoring.

Methods

HardRace employs a two-pronged approach:

  1. Static Selective Instrumentation: This is the core innovation. Instead of naively tracing all memory accesses, HardRace first uses static analysis to identify a minimal set of memory accesses that are actually relevant to data races. This involves:
  2. Value-Set Analysis: A specialized inter-procedural analysis to determine the origin (stack, heap, or global) of register values, identifying accesses to shared memory regions.
  3. Must Race-Free Analysis: This step further prunes trace points by statically determining if certain memory accesses cannot possibly lead to a data race, based on the three conditions for a data race (same address, concurrent access, at least one write).
  4. Redundant Register Elimination: Identifies cases where the value of a register can be statically derived from another, allowing only the deriving register to be traced.
  5. Binary Instrumentation: After identifying the essential trace points, HardRace inserts PTWRITE instructions into the binary to record these specific memory accesses and synchronization events during runtime.
  6. Runtime Trace Collection & Offline Analysis:
    • Hardware Tracing (Intel PTWRITE): The instrumented binary is executed, and Intel PTWRITE efficiently records the selected memory accesses and thread synchronization events with minimal overhead.
  7. Trace Decoding: The raw hardware trace data is decoded into per-thread event sequences (memory accesses and synchronization events).
  8. Data Race Detection: Standard data race detection algorithms (a combination of happens-before and lockset, similar to state-of-the-art tools) are applied to the decoded traces to identify actual data races.

Datasets

The paper evaluates HardRace on two sets of benchmarks:

  • PARSEC/SPLASH-2x benchmark suite: A common set of benchmarks used for performance evaluation.
  • Real-world applications with known data races: This set, borrowed from ProRace, includes 11 buggy program versions (apache, mysql, cherokee, pbzip, aget) each exhibiting a specific, hard-to-trigger data race.

Key Insights and Ideas

  • Static analysis is key to practical dynamic race detection: The paper strongly demonstrates that by intelligently pruning unnecessary trace points before runtime, significant reductions in overhead and data loss are achievable, making dynamic race detection viable for production.
  • Hardware tracing is powerful but needs guidance: While Intel PTWRITE offers low-overhead tracing, naively using it leads to high overhead and data loss. HardRace shows how to harness its power effectively through static pre-filtering.
  • All data races are not created equal (for detection): The paper highlights that some tools (like Kard) only detect specific types of races (e.g., Inconsistent Lock Usage), missing others. HardRace aims for comprehensive detection across all race types.
  • Production monitoring is a realistic goal: The success of HardRace in achieving low overhead and high accuracy suggests that dynamic data race detection can move beyond the debugging phase into continuous production monitoring.

Key Results

  • Runtime Overhead: HardRace achieves an average runtime overhead of only 1.6%, significantly lower than Kard (8.2%) and naive hardware tracing (19.8%). ProRace's overhead varies greatly with sampling rate, reaching over 300% at higher rates.
  • Detection Capability: HardRace detects all kinds of data races in the tested real-world applications without any false negatives. In contrast, ProRace's detection probability varies significantly with sampling rate, and Kard misses non-ILU races.
  • Data Loss: HardRace incurs zero data loss across all tested subjects. Naive hardware tracing, on the other hand, experiences an average of 37.3% data loss.
  • Static Analysis Efficiency: The static analysis phases (value-set, must race-free, redundant elimination) are efficient, taking an average of 14 seconds for most subjects.

Limitations and Future Work

  • Limitations:
    • The paper acknowledges that while HardRace aims for comprehensive detection, the race detection algorithm itself (happens-before and lockset) is a standard one.
  • The effectiveness of HardRace relies on the availability and capabilities of Intel PTWRITE, which is specific to certain processor generations.
  • Future Work:
    • The authors express interest in exploring more attempts along the direction of combining static analysis and hardware tracing for multithreaded program monitoring.
  • They plan to provide the artifact (source code, benchmarks, experimental results) for Artifact Evaluation.

Summary updated

Abstract

Data races are critical issues in multithreaded program, leading to unpredictable, catastrophic and difficult-to-diagnose problems. Despite the extensive in-house testing, data races often escape to deployed software and manifest in production runs. Existing approaches suffer from either prohibitively high runtime overhead or incomplete detection capability. In this paper, we introduce HardRace, a data race monitor to detect races on-the-fly while with sufficiently low runtime overhead and high detection capability. HardRace firstly employs sound static analysis to determine a minimal set of essential memory accesses relevant to data races. It then leverages hardware trace instruction, i.e., Intel PTWRITE, to selectively record only these memory accesses and thread synchronization events during execution with negligible runtime overhead. Given the tracing data, HardRace performs standard data race detection algorithms to timely report potential races occurred in production runs. The experimental evaluations show that HardRace outperforms state-of-the-art tools like ProRace and Kard in terms of both runtime overhead and detection capability -- HardRace can detect all kinds of data races in read-world applications while maintaining a negligible overhead, less than 2% on average.
BibTeX
@misc{sun2024hardrace,
  author = {Xudong Sun and Zhuo Chen and Jingyang Shi and Yiyu Zhang and Peng Di and Xuandong Li and Zhiqiang Zuo},
  title = {{HardRace: A Dynamic Data Race Monitor for Production Use}},
  year = {2024},
  eprint = {2410.18412},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2410.18412},
}
Figure