Skip to content

Remove redundant fence and reload from 64-bit atomic_load_acquire - #9722

Merged
alexreinking merged 1 commit into
mainfrom
abadams/fix_atomic_load_acquire
Nov 25, 2026
Merged

alexreinking merged 1 commit into
mainfrom
abadams/fix_atomic_load_acquire

Conversation

@abadams

@abadams abadams commented Nov 24, 2026

Copy link
Copy Markdown
Member

Copilot says:

The 64-bit atomic_load_acquire in src/runtime/runtime_atomics.h does an __ATOMIC_ACQUIRE load, then __sync_synchronize(), then a second plain load *val = *addr. The last two lines are the body of the 32-bit __sync variant. They appear to have been pasted in by mistake when the wrappers moved out of synchronization_common.h in #7429; before that, the 64-bit version was just the acquire load.

The extra lines don't break correctness, but they cost a full barrier on every acquire load. The reload is also a non-atomic read of a location other threads write. This PR restores the single acquire load. The 32-bit variant is unchanged. Current callers are the semaphore try-acquire in thread_pool_common.h and tracing.cpp.

Checklist

  • Tests added or updated (not required for docs, CI config, or typo fixes)
  • Documentation updated (if public API changed)
  • Python bindings updated (if public API changed)
  • Benchmarks are included here if the change is intended to affect performance.
  • Commits include AI attribution where applicable (see Code of Conduct)

No new tests. This is a behavior-preserving cleanup. Validation:

  • tracing.cpp and posix_threads.cpp compile with the runtime flags (-DBITS_64), and the IR shows a single load atomic ... acquire with no fence.
  • make -j64 bin/correctness_{async,async_device_copy,async_order,parallel_nested_1,sliding_reduction,tracing,tracing_stack,tracing_bounds,tracing_broadcast}, then ran each: all passed.

When the atomic wrappers moved to runtime_atomics.h (#7429), the 64-bit
atomic_load_acquire picked up the body of the 32-bit __sync variant after
its __atomic acquire load: a full fence followed by a second, plain load
that overwrites the result. That is a needless full barrier on every
acquire load, and the plain reload is a non-atomic read of a shared
location. Restore the plain __atomic acquire load.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@codecov

codecov Bot commented Nov 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.40%. Comparing base (05113e0) to head (2bdd139).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #9722   +/-   ##
=======================================
  Coverage   73.40%   73.40%           
=======================================
  Files         266      266           
  Lines       83749    83749           
  Branches    20573    20573           
=======================================
+ Hits        61474    61480    +6     
+ Misses      15808    15807    -1     
+ Partials     6467     6462    -5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@alexreinking alexreinking left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops!

@alexreinking

Copy link
Copy Markdown
Member

Labeling backport because I haven't done that work yet and this one is trivial.

@alexreinking
alexreinking merged commit d1bce45 into main Nov 25, 2026
28 checks passed
alexreinking pushed a commit that referenced this pull request Nov 29, 2026
)

When the atomic wrappers moved to runtime_atomics.h (#7429), the 64-bit
atomic_load_acquire picked up the body of the 32-bit __sync variant after
its __atomic acquire load: a full fence followed by a second, plain load
that overwrites the result. That is a needless full barrier on every
acquire load, and the plain reload is a non-atomic read of a shared
location. Restore the plain __atomic acquire load.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
(cherry picked from commit d1bce45)
@alexreinking alexreinking added the backport:complete Cherry-picked to the active release branch label Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:complete Cherry-picked to the active release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants