From 63a80179f45f34a203417dff2ff00fd5b2fb8996 Mon Sep 17 00:00:00 2001 From: Yan Yue <1131531947@qq.com> Date: Wed, 28 Jan 2026 10:23:41 +0800 Subject: [PATCH 1/3] bpu: sc: test sc again Change-Id: Ifd14d575e4d45744a2582d42d903904f4f77d1d6 --- configs/example/kmhv3.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs/example/kmhv3.py b/configs/example/kmhv3.py index 71844d9478..c5cad62a29 100644 --- a/configs/example/kmhv3.py +++ b/configs/example/kmhv3.py @@ -105,7 +105,7 @@ def setKmhV3Params(args, system): cpu.branchPred.mbtb.enabled = True cpu.branchPred.tage.enabled = True cpu.branchPred.ittage.enabled = True - cpu.branchPred.mgsc.enabled = False + cpu.branchPred.mgsc.enabled = True cpu.branchPred.ras.enabled = True # l1 cache per core From 5871427e72c5e30a65c3ed6cd23e2850924b2ddf Mon Sep 17 00:00:00 2001 From: Yan Yue <1131531947@qq.com> Date: Tue, 27 Jan 2026 14:52:50 +0800 Subject: [PATCH 2/3] bpu: sc: try to use bigger threshold from max 1024 to max 4096 Change-Id: Ic303d37dabcf4d4ee37dc8f8093cb65ad83de32a --- src/cpu/pred/BranchPredictor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpu/pred/BranchPredictor.py b/src/cpu/pred/BranchPredictor.py index a5132f48af..c79ffa47f5 100644 --- a/src/cpu/pred/BranchPredictor.py +++ b/src/cpu/pred/BranchPredictor.py @@ -1126,7 +1126,7 @@ class BTBMGSC(TimedBaseBTBPredictor): thresholdTablelogSize = Param.Unsigned(6, "Log size of update threshold counters tables") - updateThresholdWidth = Param.Unsigned(12, + updateThresholdWidth = Param.Unsigned(14, "Number of bits for the update threshold counter") pUpdateThresholdWidth = Param.Unsigned(8, From 34f1ac8af9822b8ce60eedc745255dd3cf552f6a Mon Sep 17 00:00:00 2001 From: Yan Yue <1131531947@qq.com> Date: Tue, 27 Jan 2026 14:57:15 +0800 Subject: [PATCH 3/3] bpu: sc: ensure threadhold is positive Change-Id: I9aa1d222463d6411b7481d3c93e7fd4fec17a039 --- src/cpu/pred/btb/btb_mgsc.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/cpu/pred/btb/btb_mgsc.cc b/src/cpu/pred/btb/btb_mgsc.cc index 694bb0b3c1..50c5ae1397 100755 --- a/src/cpu/pred/btb/btb_mgsc.cc +++ b/src/cpu/pred/btb/btb_mgsc.cc @@ -413,6 +413,9 @@ BTBMGSC::generateSinglePrediction(const BTBEntry &btb_entry, const Addr &startPC int p_update_thres = enablePCThreshold ? findThreshold(pUpdateThreshold, btb_entry.pc) : 0; int total_thres = (updateThreshold / 8) + p_update_thres; + // Threshold is used as a confidence gate; avoid negative values which + // effectively disable the gate (abs(sum) > negative is almost always true). + total_thres = std::max(total_thres, 0); bool use_sc_pred = forceUseSC; // Force use SC if configured if (!use_sc_pred) { @@ -656,6 +659,11 @@ void BTBMGSC::updateGlobalThreshold(Addr pc, bool update_direction) { updateCounter(update_direction, updateThresholdWidth, updateThreshold); + // Keep global threshold non-negative; negative thresholds make SC gating + // degenerate and can cause overuse of SC. + if (updateThreshold < 0) { + updateThreshold = 0; + } } void