Skip to content

perf(runtime): publish worker counters without atomic RMW - #1018

Merged
Coldwings merged 1 commit into
mainfrom
perf/worker-counter-publication
Aug 12, 2026
Merged

perf(runtime): publish worker counters without atomic RMW#1018
Coldwings merged 1 commit into
mainfrom
perf/worker-counter-publication

Conversation

@Coldwings

Copy link
Copy Markdown
Owner

Description

Removes atomic read-modify-write instructions from per-resume and successful-steal metric updates. Each worker now increments owner-local counters and publishes the exact updated value through relaxed atomic stores for external readers.

This preserves the public metric APIs, per-resume/per-steal counting meaning, and monotonic relaxed-snapshot behavior while reducing fixed scheduler hot-path cost.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Performance improvement
  • Documentation
  • Refactoring
  • Tests
  • Build/CI

Related Issues

Closes #1017

Changes Made

Core Changes

  • Added worker-owned execution and successful-steal counters.
  • Replaced task and steal fetch_add operations with local increments followed by relaxed atomic snapshot stores.
  • Added a concurrent-reader regression test for monotonic task-count publication.
  • Added microbenchmarks comparing relaxed fetch_add with single-writer publication.
  • Documented the metric publication model in README, wiki, and changelog.

API Changes

None. Existing scheduler metric accessors and return types are unchanged.

Testing

Unit Tests

  • Added concurrent metric-reader coverage
  • All scheduler tests pass locally

Sanitizer Testing

  • Focused ASAN test passed with leak detection
  • Focused TSAN test passed with halt-on-error
  • No sanitizer reports

Test Results

Release build: GCC 12.2, -Werror, debug metadata disabled

elio_tests "[metrics]":
  5 assertions in 1 test case passed

elio_tests "[scheduler]":
  413 assertions in 74 test cases passed

elio_tests_asan "[metrics]": passed
elio_tests_tsan "[metrics]": passed

Primitive microbenchmark:
  relaxed atomic fetch_add:       5.47 ns/update
  single-writer snapshot publish: 0.65 ns/update

Three-run quick_benchmark yield average, same machine/CPU affinity:
  main baseline: 37.92 ns/yield
  this branch:   31.76 ns/yield
  improvement:   16.2%

Spawn and nested context-switch measurements remained within the observed run-to-run noise range.

Checklist

Code Quality

  • Code follows project style
  • Release build has no new warnings under -Werror
  • No unrelated changes

Documentation

  • Updated README, wiki, and changelog

Testing

  • Added tests proving concurrent snapshots remain monotonic
  • Relevant existing tests pass locally
  • Tested with ASAN and TSAN

Compatibility

  • No public API or source compatibility changes
  • Counter semantics remain exact per worker execution/successful steal

Performance

  • Added focused primitive benchmark
  • Compared before/after end-to-end yield performance

Reviewer Guidance

Please focus on:

  • the single-writer invariant for both local counters;
  • whether relaxed atomic stores preserve the documented snapshot semantics;
  • cache-line layout and whether the local/published counter pairing introduces any new sharing concern;
  • whether all successful-steal exits still increment exactly once.

Copilot AI balanced review requested due to automatic review settings August 12, 2026 08:28

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Optimizes scheduler metric publication while preserving existing APIs and semantics.

Changes:

  • Replaces atomic RMW counter updates with worker-local increments and relaxed stores.
  • Adds metric concurrency coverage and microbenchmarks.
  • Documents the new publication model.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
include/elio/runtime/worker_thread.hpp Adds owner-local counters and publication helpers.
include/elio/runtime/scheduler.hpp Uses publication helpers on execution and steal paths.
tests/unit/test_scheduler.cpp Adds concurrent task-counter coverage.
examples/microbench.cpp Benchmarks RMW versus single-writer publication.
README.md Summarizes the optimization.
wiki/Performance-Tuning.md Documents metric publication behavior.
CHANGELOG.md Records the performance change.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/unit/test_scheduler.cpp Outdated
@Coldwings
Coldwings force-pushed the perf/worker-counter-publication branch from b962e1a to f6ac6d2 Compare August 12, 2026 08:36
@Coldwings

Copy link
Copy Markdown
Owner Author

@copilot please re-review only; do not make direct code modifications.

Copilot AI commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

@copilot please re-review only; do not make direct code modifications.

Re-reviewed the revised test. The 128-round two-way handshake correctly guarantees concurrent overlap for every sample: the coroutine cannot advance past round N until the external reader has acknowledged it, so all 128 reads are guaranteed to occur while the coroutine is still live. The active_samples == sample_count assertion makes the overlap requirement explicit and machine-checked. The release/acquire edges on sample_ready and sample_acknowledged give TSAN real synchronisation to observe rather than a race it might miss. The CHECK(monotonic) assertion is now meaningful because each sample is taken at a well-defined point in the yield sequence. No concerns with the updated implementation.

@Coldwings
Coldwings merged commit 17df59c into main Aug 12, 2026
11 checks passed
@Coldwings
Coldwings deleted the perf/worker-counter-publication branch August 12, 2026 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Performance] Avoid atomic RMW for single-writer worker counters

3 participants