From 53a12bc8ad1c7ccf0fff43b530c89b0e2fc72f1b Mon Sep 17 00:00:00 2001 From: Melissa Jost Date: Mon, 13 Mar 2023 11:10:14 -0700 Subject: [PATCH] cpu-o3: Copy general O3 fetch stats to BaseCPU::FetchCPUStats The stats moved are from fetch.hh and fetch.cc of O3. Stat branches is now tracked by numBranches. Stat branchRate is now tracked by branchRate in FetchCPUStats. Stat rate is tracked by fetchRate. Stat insts is tracked by numInsts. Stat icacheStallCycles is tracked by icacheStallCycles in BaseCPU::FetchCPUStats. Change-Id: I2a0a48a175bcb4322c66490f16c906dc9597f30e Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/69102 Tested-by: kokoro Maintainer: Bobby Bruce Reviewed-by: Bobby Bruce --- src/cpu/base.cc | 27 ++++++++++++++++++++++++++- src/cpu/base.hh | 9 +++++++++ src/cpu/o3/commit.cc | 2 ++ src/cpu/o3/fetch.cc | 11 ++++++++++- 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/cpu/base.cc b/src/cpu/base.cc index 801a95b087..7c1930744c 100644 --- a/src/cpu/base.cc +++ b/src/cpu/base.cc @@ -196,7 +196,13 @@ BaseCPU::BaseCPU(const Params &p, bool is_checker) executeStats.reserve(numThreads); commitStats.reserve(numThreads); for (int i = 0; i < numThreads; i++) { - fetchStats.emplace_back(new FetchCPUStats(this, i)); + // create fetchStat object for thread i and set rate formulas + FetchCPUStats* fetchStatptr = new FetchCPUStats(this, i); + fetchStatptr->fetchRate = fetchStatptr->numInsts / baseStats.numCycles; + fetchStatptr->branchRate = fetchStatptr->numBranches / + baseStats.numCycles; + fetchStats.emplace_back(fetchStatptr); + executeStats.emplace_back(new ExecuteCPUStats(this, i)); // create commitStat object for thread i and set ipc, cpi formulas CommitCPUStats* commitStatptr = new CommitCPUStats(this, i); @@ -862,15 +868,31 @@ FetchCPUStats::FetchCPUStats(statistics::Group *parent, int thread_id) "Number of instructions fetched (thread level)"), ADD_STAT(numOps, statistics::units::Count::get(), "Number of ops (including micro ops) fetched (thread level)"), + ADD_STAT(fetchRate, statistics::units::Rate< + statistics::units::Count, statistics::units::Cycle>::get(), + "Number of inst fetches per cycle"), ADD_STAT(numBranches, statistics::units::Count::get(), "Number of branches fetched"), + ADD_STAT(branchRate, statistics::units::Ratio::get(), + "Number of branch fetches per cycle"), + ADD_STAT(icacheStallCycles, statistics::units::Cycle::get(), + "ICache total stall cycles"), ADD_STAT(numFetchSuspends, statistics::units::Count::get(), "Number of times Execute suspended instruction fetching") { + fetchRate + .flags(statistics::total); + numBranches .prereq(numBranches); + branchRate + .flags(statistics::total); + + icacheStallCycles + .prereq(icacheStallCycles); + } // means it is incremented in a vector indexing and not directly @@ -981,6 +1003,9 @@ CommitCPUStats::CommitCPUStats(statistics::Group *parent, int thread_id) ADD_STAT(committedControl, statistics::units::Count::get(), "Class of control type instructions committed") { + numInsts + .prereq(numInsts); + cpi.precision(6); ipc.precision(6); diff --git a/src/cpu/base.hh b/src/cpu/base.hh index f1739679f6..946ea6ba87 100644 --- a/src/cpu/base.hh +++ b/src/cpu/base.hh @@ -696,9 +696,18 @@ class BaseCPU : public ClockedObject /* Total number of operations fetched */ statistics::Scalar numOps; + /* Number of instruction fetched per cycle. */ + statistics::Formula fetchRate; + /* Total number of branches fetched */ statistics::Scalar numBranches; + /* Number of branch fetches per cycle. */ + statistics::Formula branchRate; + + /* Number of cycles stalled due to an icache miss */ + statistics::Scalar icacheStallCycles; + /* Number of times fetch was asked to suspend by Execute */ statistics::Scalar numFetchSuspends; diff --git a/src/cpu/o3/commit.cc b/src/cpu/o3/commit.cc index 63bf7aebc4..82ecc0140e 100644 --- a/src/cpu/o3/commit.cc +++ b/src/cpu/o3/commit.cc @@ -1019,6 +1019,8 @@ Commit::commitInsts() if (commit_success) { ++num_committed; + cpu->commitStats[tid] + ->committedInstType[head_inst->opClass()]++; stats.committedInstType[tid][head_inst->opClass()]++; ppCommit->notify(head_inst); diff --git a/src/cpu/o3/fetch.cc b/src/cpu/o3/fetch.cc index d3cdd2c761..89d1b81197 100644 --- a/src/cpu/o3/fetch.cc +++ b/src/cpu/o3/fetch.cc @@ -540,6 +540,8 @@ Fetch::lookupAndUpdateNextPC(const DynInstPtr &inst, PCStateBase &next_pc) inst->setPredTarg(next_pc); inst->setPredTaken(predict_taken); + // update both old and new stats + cpu->fetchStats[tid]->numBranches++; ++fetchStats.branches; if (predict_taken) { @@ -1145,8 +1147,11 @@ Fetch::fetch(bool &status_change) fetchCacheLine(fetchAddr, tid, this_pc.instAddr()); - if (fetchStatus[tid] == IcacheWaitResponse) + if (fetchStatus[tid] == IcacheWaitResponse) { + // update both old and new stats ++fetchStats.icacheStallCycles; + cpu->fetchStats[tid]->icacheStallCycles++; + } else if (fetchStatus[tid] == ItlbWait) ++fetchStats.tlbCycles; else @@ -1242,7 +1247,9 @@ Fetch::fetch(bool &status_change) staticInst = dec_ptr->decode(this_pc); // Increment stat of fetched instructions. + // Update both old and new stats ++fetchStats.insts; + cpu->fetchStats[tid]->numInsts++; if (staticInst->isMacroop()) { curMacroop = staticInst; @@ -1572,6 +1579,8 @@ Fetch::profileStall(ThreadID tid) ++fetchStats.squashCycles; DPRINTF(Fetch, "[tid:%i] Fetch is squashing!\n", tid); } else if (fetchStatus[tid] == IcacheWaitResponse) { + // update both old and new stats + cpu->fetchStats[tid]->icacheStallCycles++; ++fetchStats.icacheStallCycles; DPRINTF(Fetch, "[tid:%i] Fetch is waiting cache response!\n", tid);