Skip to content

[codex] Add standalone SC switch#905

Merged
jensen-yan merged 4 commits into
xs-devfrom
codex/standalone-sc-switch
Jun 15, 2026
Merged

[codex] Add standalone SC switch#905
jensen-yan merged 4 commits into
xs-devfrom
codex/standalone-sc-switch

Conversation

@jensen-yan

@jensen-yan jensen-yan commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Motivation

Add a small opt-in switch for standalone SC experiments so TAGE can be disabled from the mainline configuration without maintaining a long-lived experiment branch.

Approach

  • Add --standalone-sc to the XiangShan config options.
  • In kmhv3.py, disable MicroTAGE and TAGE for this mode, then force MGSC to use SC output.
  • Add allowMissingTageInfo so MGSC can explicitly run with default TAGE metadata only when TAGE is intentionally disabled.
  • Keep the normal path strict with panic_if when MGSC is missing TAGE metadata unexpectedly.
  • Add a focused MGSC unit test for the missing-TAGE fallback path.

This PR intentionally does not include IMHist or skill/documentation updates.

Validation

  • git diff --check
  • scons build/RISCV/cpu/pred/btb/test/mgsc.test.debug --unit-test -j64
  • ./build/RISCV/cpu/pred/btb/test/mgsc.test.debug
  • scons build/RISCV/gem5.opt --gold-linker -j16
  • timeout 20s ./build/RISCV/gem5.opt configs/example/kmhv3.py --help | rg -- '--standalone-sc'

Note: an initial gem5.opt -j64 build hit a generated-header parallel dependency race, then the -j16 rebuild completed successfully.

Summary by CodeRabbit

  • New Features

    • Added a --standalone-sc command-line flag to enable standalone SC prediction mode (disables direction TAGE sources).
    • Branch predictor can optionally fall back to a default TAGE context when direction info is missing.
    • Tracing now records an additional SC-mismatch indicator for diagnostics.
  • Tests

    • Added a unit test verifying fallback behavior when TAGE info is absent.
  • Chores

    • Test temporary-directory names now include the process ID to reduce collisions.

Change-Id: I782cb5acc1c54ef4018cdec025bd9e954b1b3222
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ed01cb66-39d4-4a7a-9fd9-a92b286fe4bc

📥 Commits

Reviewing files that changed from the base of the PR and between 8953f97 and f2c6ed7.

📒 Files selected for processing (2)
  • src/cpu/pred/btb/btb_mgsc.cc
  • src/cpu/pred/btb/common.hh

📝 Walkthrough

Walkthrough

This PR enables standalone SC (MGSC) mode by adding a new --standalone-sc CLI flag and a BTBMGSC allowMissingTageInfo parameter; when enabled, TAGE sources are disabled and MGSC may use a default TAGE context instead of panicking when TAGE info is missing. Changes include parameter, header/test accessor, lookup fallback logic, CLI wiring, a unit test, and a minor gtest fixture tweak.

Changes

Standalone SC Mode with TAGE Fallback

Layer / File(s) Summary
Parameter definition and contract
src/cpu/pred/BranchPredictor.py
BTBMGSC introduces allowMissingTageInfo: Param.Bool(False) to govern fallback behavior when TAGE metadata is missing.
Header member and unit-test accessor
src/cpu/pred/btb/btb_mgsc.hh
BTBMGSC class adds allowMissingTageInfo member and extends TestAccess with a static accessor for unit-test manipulation and inspection.
Core MGSC lookup, tracing, and initialization
src/cpu/pred/btb/btb_mgsc.cc, src/cpu/pred/btb/common.hh
lookupHelper now panics or falls back to a default TageInfoForMGSC when TAGE info is missing depending on allowMissingTageInfo; constructors initialize the flag; updates logging/trace fields and records scWrong.
CLI flag and kmhv3 configuration
configs/common/xiangshan.py, configs/example/kmhv3.py
Registers --standalone-sc CLI flag; KMHv3 decoupled BPU setup disables microtage and tage, forces MGSC SC usage, and enables allowMissingTageInfo when the flag is set.
Unit test for missing TAGE fallback
src/cpu/pred/btb/test/btb_mgsc.test.cc
New gtest MissingTageInfoUsesDefaultFallbackContext exercises bias-table-only prediction with fallback TAGE context and asserts prediction flags and bias-index selection.
GTest tempdir PID uniqueness
src/base/gtest/serialization_fixture.hh
Adds <unistd.h> and includes getpid() in generated temp-directory names for gtest serialization fixtures.

Sequence Diagram

sequenceDiagram
  participant CLI as Xiangshan CLI
  participant KMH as KMHv3 setup
  participant BTB as BTBMGSC
  participant TAGE as TageProvider

  CLI->>KMH: set --standalone-sc
  KMH->>BTB: set allowMissingTageInfo / disable TAGE sources
  BTB->>TAGE: request TageInfoForMGSC (PC,startPC,tid,asid)
  TAGE-->>BTB: return TageInfo or missing
  alt TageInfo missing and allowMissingTageInfo == false
    BTB->>BTB: panic_if(missing TageInfo)
  else TageInfo missing but allowed
    BTB->>BTB: use default TageInfoForMGSC and continue prediction
  end
  BTB->>BTB: generate prediction, push trace (useSc, scPred, scWrong)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • OpenXiangShan/GEM5#639: Also modifies btb_mgsc.cc and MGSC prediction/statistics instrumentation overlapping with BTBMGSC changes.
  • OpenXiangShan/GEM5#686: Related MGSC/TAGE trace and prediction plumbing updates affecting MgscTrace and BTBMGSC tracing.
  • OpenXiangShan/GEM5#710: Prior work on BTBMGSC TestAccess and MGSC unit-test infrastructure that this PR extends.

Suggested labels

align-kmhv3

Suggested reviewers

  • Yakkhini
  • CJ362ff

Poem

🐰 I nibble at flags and hop through code,

When TAGE goes missing, I find a road.
MGSC stands ready, no panic to show,
A default context helps predictions grow.
Tests hum softly — the rabbit says "go!"

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title '[codex] Add standalone SC switch' accurately reflects the main change: introducing a new --standalone-sc command-line flag to enable standalone SC experiments by disabling TAGE sources.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/standalone-sc-switch

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 and usage tips.

@jensen-yan jensen-yan marked this pull request as ready for review June 12, 2026 07:48
Copilot AI review requested due to automatic review settings June 12, 2026 07:48

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.

Pull request overview

This PR adds an opt-in “standalone SC” mode for XiangShan’s kmhv3 configuration, allowing experiments to disable MicroTAGE/TAGE while still running MGSC by using a defined default TAGE-metadata fallback path.

Changes:

  • Add --standalone-sc CLI option and wire it into kmhv3.py to disable MicroTAGE/TAGE and force MGSC to use SC output.
  • Extend MGSC with allowMissingTageInfo to permit a deliberate “missing TAGE metadata” fallback (while keeping the default path strict via panic_if).
  • Add a focused MGSC unit test covering the missing-TAGE fallback behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/cpu/pred/btb/test/btb_mgsc.test.cc Adds a unit test ensuring MGSC behaves correctly when TAGE metadata is intentionally absent.
src/cpu/pred/btb/btb_mgsc.hh Adds the allowMissingTageInfo flag and exposes it via TestAccess.
src/cpu/pred/btb/btb_mgsc.cc Replaces assert(false) with a panic_if + explicit default fallback when allowed.
src/cpu/pred/BranchPredictor.py Adds the SimObject param for allowMissingTageInfo so it can be configured from Python configs.
configs/example/kmhv3.py Implements --standalone-sc behavior by disabling MicroTAGE/TAGE and forcing MGSC SC-only mode.
configs/common/xiangshan.py Adds the --standalone-sc argument to the XiangShan config parser.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/cpu/pred/btb/btb_mgsc.hh
Comment thread src/cpu/pred/BranchPredictor.py

@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: 1d42b8ce0d

ℹ️ 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 configs/example/kmhv3.py
Change-Id: Id21ffa64f328c7f6dc9903004d10baa16c900fa9
@github-actions

Copy link
Copy Markdown

🚀 Coremark Smoke Test Results

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

✅ Difftest smoke test passed!

Change-Id: Idd6fd6a6a7ab6a272ecba38de85bcfba6735f5ad
Change-Id: I1c71019b49e59f75d6bf701e426bd868a4cd8066
@github-actions

Copy link
Copy Markdown

🚀 Coremark Smoke Test Results

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

✅ Difftest smoke test passed!

1 similar comment
@github-actions

Copy link
Copy Markdown

🚀 Coremark Smoke Test Results

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

✅ Difftest smoke test passed!

@jensen-yan jensen-yan merged commit dda01e1 into xs-dev Jun 15, 2026
2 checks passed
@jensen-yan jensen-yan deleted the codex/standalone-sc-switch branch June 15, 2026 02:36
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.

3 participants