From 1c4cc8dbd04b6ae875ca920fcd2ce0ef00cd6b38 Mon Sep 17 00:00:00 2001 From: Melissa Jost Date: Thu, 19 Jan 2023 02:04:39 -0800 Subject: [PATCH] cpu-o3: Move general 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 FetchCPUStats. Change-Id: I48313614edd078631df4ef6b00982c335798fcb1 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/67394 Maintainer: Jason Lowe-Power Tested-by: kokoro Reviewed-by: Bobby Bruce --- src/cpu/base.cc | 28 +++++++++++++++++++++++++++- src/cpu/base.hh | 9 +++++++++ src/cpu/o3/fetch.cc | 33 +++++---------------------------- src/cpu/o3/fetch.hh | 10 ---------- 4 files changed, 41 insertions(+), 39 deletions(-) diff --git a/src/cpu/base.cc b/src/cpu/base.cc index fa30e4b5e6..490e48938a 100644 --- a/src/cpu/base.cc +++ b/src/cpu/base.cc @@ -196,8 +196,15 @@ 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); commitStatptr->ipc = commitStatptr->numInsts / baseStats.numCycles; @@ -862,15 +869,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 +1004,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 a9af865da0..5d0d3cab01 100644 --- a/src/cpu/base.hh +++ b/src/cpu/base.hh @@ -695,9 +695,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/fetch.cc b/src/cpu/o3/fetch.cc index d3cdd2c761..f5fc6c62ec 100644 --- a/src/cpu/o3/fetch.cc +++ b/src/cpu/o3/fetch.cc @@ -158,12 +158,6 @@ Fetch::regProbePoints() Fetch::FetchStatGroup::FetchStatGroup(CPU *cpu, Fetch *fetch) : statistics::Group(cpu, "fetch"), - ADD_STAT(icacheStallCycles, statistics::units::Cycle::get(), - "Number of cycles fetch is stalled on an Icache miss"), - ADD_STAT(insts, statistics::units::Count::get(), - "Number of instructions fetch has processed"), - ADD_STAT(branches, statistics::units::Count::get(), - "Number of branches that fetch encountered"), ADD_STAT(predictedBranches, statistics::units::Count::get(), "Number of branches that fetch has predicted taken"), ADD_STAT(cycles, statistics::units::Cycle::get(), @@ -200,21 +194,8 @@ Fetch::FetchStatGroup::FetchStatGroup(CPU *cpu, Fetch *fetch) "Number of instructions fetched each cycle (Total)"), ADD_STAT(idleRate, statistics::units::Ratio::get(), "Ratio of cycles fetch was idle", - idleCycles / cpu->baseStats.numCycles), - ADD_STAT(branchRate, statistics::units::Ratio::get(), - "Number of branch fetches per cycle", - branches / cpu->baseStats.numCycles), - ADD_STAT(rate, statistics::units::Rate< - statistics::units::Count, statistics::units::Cycle>::get(), - "Number of inst fetches per cycle", - insts / cpu->baseStats.numCycles) + idleCycles / cpu->baseStats.numCycles) { - icacheStallCycles - .prereq(icacheStallCycles); - insts - .prereq(insts); - branches - .prereq(branches); predictedBranches .prereq(predictedBranches); cycles @@ -252,10 +233,6 @@ Fetch::FetchStatGroup::FetchStatGroup(CPU *cpu, Fetch *fetch) .flags(statistics::pdf); idleRate .prereq(idleRate); - branchRate - .flags(statistics::total); - rate - .flags(statistics::total); } void Fetch::setTimeBuffer(TimeBuffer *time_buffer) @@ -540,7 +517,7 @@ Fetch::lookupAndUpdateNextPC(const DynInstPtr &inst, PCStateBase &next_pc) inst->setPredTarg(next_pc); inst->setPredTaken(predict_taken); - ++fetchStats.branches; + cpu->fetchStats[tid]->numBranches++; if (predict_taken) { ++fetchStats.predictedBranches; @@ -1146,7 +1123,7 @@ Fetch::fetch(bool &status_change) fetchCacheLine(fetchAddr, tid, this_pc.instAddr()); if (fetchStatus[tid] == IcacheWaitResponse) - ++fetchStats.icacheStallCycles; + cpu->fetchStats[tid]->icacheStallCycles++; else if (fetchStatus[tid] == ItlbWait) ++fetchStats.tlbCycles; else @@ -1242,7 +1219,7 @@ Fetch::fetch(bool &status_change) staticInst = dec_ptr->decode(this_pc); // Increment stat of fetched instructions. - ++fetchStats.insts; + cpu->fetchStats[tid]->numInsts++; if (staticInst->isMacroop()) { curMacroop = staticInst; @@ -1572,7 +1549,7 @@ Fetch::profileStall(ThreadID tid) ++fetchStats.squashCycles; DPRINTF(Fetch, "[tid:%i] Fetch is squashing!\n", tid); } else if (fetchStatus[tid] == IcacheWaitResponse) { - ++fetchStats.icacheStallCycles; + cpu->fetchStats[tid]->icacheStallCycles++; DPRINTF(Fetch, "[tid:%i] Fetch is waiting cache response!\n", tid); } else if (fetchStatus[tid] == ItlbWait) { diff --git a/src/cpu/o3/fetch.hh b/src/cpu/o3/fetch.hh index cd311913f5..6add31444d 100644 --- a/src/cpu/o3/fetch.hh +++ b/src/cpu/o3/fetch.hh @@ -533,12 +533,6 @@ class Fetch FetchStatGroup(CPU *cpu, Fetch *fetch); // @todo: Consider making these // vectors and tracking on a per thread basis. - /** Stat for total number of cycles stalled due to an icache miss. */ - statistics::Scalar icacheStallCycles; - /** Stat for total number of fetched instructions. */ - statistics::Scalar insts; - /** Total number of fetched branches. */ - statistics::Scalar branches; /** Stat for total number of predicted branches. */ statistics::Scalar predictedBranches; /** Stat for total number of cycles spent fetching. */ @@ -581,10 +575,6 @@ class Fetch statistics::Distribution nisnDist; /** Rate of how often fetch was idle. */ statistics::Formula idleRate; - /** Number of branch fetches per cycle. */ - statistics::Formula branchRate; - /** Number of instruction fetched per cycle. */ - statistics::Formula rate; } fetchStats; };