From 497cc2d373d1559aaae0263635b88f670fd239cd Mon Sep 17 00:00:00 2001 From: Arthur Perais Date: Wed, 21 Dec 2016 15:07:16 -0600 Subject: cpu: disallow speculative update of branch predictor tables (o3) The Minor and o3 cpu models share the branch prediction code. Minor relies on the BPredUnit::squash() function to update the branch predictor tables on a branch mispre- diction. This is fine because Minor executes in-order, so the update is on the correct path. However, this causes the branch predictor to be updated on out-of-order branch mispredictions when using the o3 model, which should not be the case. This patch guards against speculative update of the branch prediction tables. On a branch misprediction, BPredUnit::squash() calls BpredUnit::update(..., squashed = true). The underlying branch predictor tests against the value of squashed. If it is true, it restores any speculatively updated internal state it might have (e.g., global/local branch history), then returns. If false, it updates its prediction tables. Previously, exist- ing predictors did not test against the "squashed" parameter. To accomodate for this change, the Minor model must now call BPredUnit::squash() then BPredUnit::update(..., squashed = false) on branch mispredictions. Before, calling BpredUnit::squash() performed the prediction tables update. The effect is a slight MPKI improvement when using the o3 model. A further patch should perform the same modifications for the indirect target predictor and BTB (less critical). Signed-off-by: Jason Lowe-Power --- src/cpu/minor/fetch2.cc | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/cpu/minor') diff --git a/src/cpu/minor/fetch2.cc b/src/cpu/minor/fetch2.cc index 394fe8549..15d362da7 100644 --- a/src/cpu/minor/fetch2.cc +++ b/src/cpu/minor/fetch2.cc @@ -152,6 +152,10 @@ Fetch2::updateBranchPrediction(const BranchData &branch) DPRINTF(Branch, "Unpredicted branch seen inst: %s\n", *inst); branchPredictor.squash(inst->id.fetchSeqNum, branch.target, true, inst->id.threadId); + // Update after squashing to accomodate O3CPU + // using the branch prediction code. + branchPredictor.update(inst->id.fetchSeqNum, + inst->id.threadId); break; case BranchData::CorrectlyPredictedBranch: /* Predicted taken, was taken */ @@ -164,6 +168,10 @@ Fetch2::updateBranchPrediction(const BranchData &branch) DPRINTF(Branch, "Branch mis-predicted inst: %s\n", *inst); branchPredictor.squash(inst->id.fetchSeqNum, branch.target /* Not used */, false, inst->id.threadId); + // Update after squashing to accomodate O3CPU + // using the branch prediction code. + branchPredictor.update(inst->id.fetchSeqNum, + inst->id.threadId); break; case BranchData::BadlyPredictedBranchTarget: /* Predicted taken, was taken but to a different target */ -- cgit v1.2.3