Skip to content

cpu-o3: Replay conflicting SMT load-reserved operations - #1160

Open
jensen-yan wants to merge 2 commits into
xs-devfrom
codex/fix-smt-visible-store-lr-replay
Open

jensen-yan wants to merge 2 commits into
xs-devfrom
codex/fix-smt-visible-store-lr-replay

Conversation

@jensen-yan

@jensen-yan jensen-yan commented Sep 15, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

The SPEC2017 SMT run in Actions run 34924968908 reproducibly failed in mcf_rate_refrate_0 at tick 678519468. CPU 0 committed lr.w a5, (a2) at PC 0xffffffff80152788 and physical address 0x47e951534 with value 7, while the reference and current shared-memory value were 8.

When a store becomes visible, notifyOtherThreadsStoreVisible() already checks byte-overlapping loads in the other SMT contexts. The existing path:

  • invalidated overlapping LR reservations;
  • replayed overlapping loads that had not executed yet; but
  • ignored loads that had already executed, including an executed but uncommitted LR.

That gap allows an LR result from before another context's overlapping visible store to remain speculative and later reach commit.

Approach

When checkLocalStoreVisible() finds an overlapping executed LR with no existing fault, this change assigns ReExec and marks its active request faulted. The LR is therefore squashed and retried through the normal commit-time fault path.

Ordinary executed loads keep their previous behavior: observing the older value may be legal, so they are not replayed unconditionally.

Assigning ReExec alone is not sufficient. Commit runs before IEW in a CPU tick, while IEW consumes the previous doneMemSeqNum only after LSQ writeback processing. A stale speculative doneMemSeqNum can therefore authorize a younger store before the LR squash reaches IEW. Once that store enters the store buffer, the existing isSquashed() check is too late to revoke it.

To close that race at its source, ROB::getHeadGroupLastDoneSeq() now stops at every uncommitted isLoadReserved() instruction. Speculative store-publication authorization can no longer cross an LR whose result may still receive ReExec; the normal committed path can release younger stores after the LR commits. The replay predicate is also narrowed from the generic Request::LLSC flag to DynInst::isLoadReserved().

This is intentionally a conservative behavioral model:

  • it reuses the existing store-visible notification, exact byte-overlap check, and bounded load-queue scan;
  • it adds one predicate to the existing fixed ROB head-group scan, with no whole-ROB, load-queue, or store-queue scan;
  • it adds no cache-block visibility/version metadata and no rollback path for store-buffer entries;
  • it has no dependency on golden memory or difftest state;
  • it may delay younger store publication until an LR commits, so LR/SC-dense SMT workloads can lose some performance.

Three statistics make the modeled boundary observable:

  • smtVisibleStoreLrReexec: executed LRs replayed by another thread's visible store;
  • smtVisibleStoreExecutedLoadIgnored: executed ordinary loads deliberately kept.
  • commit.loadReservedStorePublishBarrierCycles: cycles where an uncommitted LR bounds speculative store publication.

There are no new parameters or configuration changes.

Validation

  • scons build/RISCV/gem5.opt --gold-linker -j64 passes.
  • python3 util/style.py -m src/cpu/o3/commit.cc src/cpu/o3/commit.hh src/cpu/o3/rob.cc src/cpu/o3/rob.hh src/cpu/o3/lsq_unit.cc src/cpu/o3/lsq_unit.hh passes.
  • git diff --check passes.
  • A finite two-hart raw microtest with one hart executing LR plus a younger store and the other hart issuing 2,000 conflicting stores completed normally:
    • 244,945 committed instructions and 244,985 cycles;
    • 977 LR replays;
    • expected final shared values were observed.
  • A no-conflict variant with commitWidth=1 completed normally with 239,343 committed instructions, 214,379 cycles, and 3 loadReservedStorePublishBarrierCycles, directly confirming that the new authorization barrier is exercised.
  • On the failing mcf_rate_refrate_0 checkpoint with the original multi-hart NEMU reference, a 7M any-thread-limit run on reproduction-compatible revision 4c63267dce plus the original LR replay change (before the store-publication barrier commit) completed normally:
    • 13,086,429 total committed instructions;
    • 6,609,667 cycles;
    • 11 LR replays (thread 0: 5, thread 1: 6), or about 0.84 events per million committed instructions;
    • 28 overlapping executed ordinary loads retained (thread 0: 17, thread 1: 11);
    • no original LR difftest abort; the run stopped at the requested instruction limit.
  • A second 4M any-thread-limit run also completed normally with 7,414,162 total committed instructions and the same 11 LR replay events.

The exact original sequence number/tick is not expected to remain stable because an earlier LR replay changes subsequent SMT scheduling. The historical checkpoint evidence is that the model-driven replay path fires, the run passes the original failure window, and difftest remains clean until the requested limit.

Validation limitations

  • The raw two-hart microtests used --disable-difftest; they validate forward progress and the replay/barrier control paths, not reference-model equivalence.
  • The exact stale-doneMemSeqNum/canWB window was not deterministically reproduced under the default SMT configuration: CROB_instPerGroup=2, and the RISC-V LR expands into two micro-ops, placing the following store outside the same head group. The fix instead follows the confirmed CPU/commit/IEW source ordering and closes authorization at the source.
  • The original SPEC checkpoint is no longer present on the shared filesystem, so the historical reproduction-compatible results above could not be refreshed after the second commit.
  • Before the checkpoint disappeared, the old checkpoint could not reach the target window on the then-current base: patched and unpatched runs first met the same unrelated restore/privilege-state mismatch around sequence number 1M (csrrw tp, mscratch, tp, PC 0x80100508, differing mepc).

The full SPEC2017 SMT slice and performance CI have not been rerun yet.

Change-Id: Ia9625dd3502c72681b93919bf7e7489a4fc4a2ef
Copilot AI lite review requested due to automatic review settings September 15, 2026 09:17
@coderabbitai

coderabbitai Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: ac92da50-d8a9-4569-8d7b-f445fedf5ed3

📥 Commits

Reviewing files that changed from the base of the PR and between 4f642da and 9f5692a.

📒 Files selected for processing (6)
  • src/cpu/o3/commit.cc
  • src/cpu/o3/commit.hh
  • src/cpu/o3/lsq_unit.cc
  • src/cpu/o3/lsq_unit.hh
  • src/cpu/o3/rob.cc
  • src/cpu/o3/rob.hh

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

The out-of-order CPU now replays executed load-reserved instructions when a conflicting store from another thread becomes visible. The reorder buffer reports when an uncommitted load-reserved instruction blocks speculative store publication, and Commit records those cycles.

Changes

Load-reserved ordering

Layer / File(s) Summary
Replay load-reserved instructions on visible-store conflicts
src/cpu/o3/lsq_unit.hh, src/cpu/o3/lsq_unit.cc
When a visible store from another thread conflicts with an executed load-reserved instruction, the LSQ sets a ReExec fault on its request. New counters track replayed load-reserved instructions and ignored executed non-LR loads.
Detect and count load-reserved publication barriers
src/cpu/o3/rob.hh, src/cpu/o3/rob.cc, src/cpu/o3/commit.hh, src/cpu/o3/commit.cc
The ROB reports when a load-reserved instruction blocks the head-group done sequence. Commit records cycles with this barrier.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 9f569

The change addresses conflicting SMT load-reserved operations, with no established issue requiring a fix before merge. The reported checkpoint limitation and incomplete benchmark reruns remain validation context, not evidence of a regression introduced here.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: replaying conflicting load-reserved operations in the CPU out-of-order SMT implementation.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-23T04:30:02.323424Z 9f5692a New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 39b14a6ab6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/cpu/o3/lsq_unit.cc

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The replay predicate also covers ARM and MIPS linked loads and must be gated or explicitly supported before approval.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds O3 SMT handling to replay executed load-reserved operations after conflicting stores become visible.

Changes:

  • Replays conflicting executed LRs through the existing fault path.
  • Adds LR replay and ignored-load statistics.
  • Reuses bounded LSQ visibility scans.
File summaries
File Summary
src/cpu/o3/lsq_unit.hh Declares new LSQ statistics.
src/cpu/o3/lsq_unit.cc Registers statistics and replays conflicting executed LLSC loads.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

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

Comment thread src/cpu/o3/lsq_unit.cc Outdated
@github-actions

Copy link
Copy Markdown

🚀 Coremark Smoke Test Results

Branch IPC Change
Base (xs-dev) 2.1869 -
This PR 2.1869 ➡️ 0.0000 (0.00%)

✅ Difftest smoke test passed!

@jensen-yan jensen-yan added the Ready to Merge This PR has completed all required changes and is ready to merge once it passes review. label Sep 15, 2026
Change-Id: I4dbb3d51db0c8865d627fdd10e253e1be492fc04
@github-actions

Copy link
Copy Markdown

🚀 Coremark Smoke Test Results

Branch IPC Change
Base (xs-dev) 2.2398 -
This PR 2.2398 ➡️ 0.0000 (0.00%)

✅ Difftest smoke test passed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready to Merge This PR has completed all required changes and is ready to merge once it passes review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants