cpu: reorder functions, add more debug flags and comments

Change-Id: I94bd4771130441a8e2e449a7527e87ba5c355236
This commit is contained in:
studyztp
2024-08-07 22:13:55 -07:00
committed by Bobby R. Bruce
parent 66d3f7c038
commit ddb29819ee
2 changed files with 65 additions and 58 deletions

View File

@@ -31,10 +31,10 @@
namespace gem5
{
LocalInstTracker::LocalInstTracker(const LocalInstTrackerParams &p)
: ProbeListenerObject(p),
globalInstTracker(p.global_inst_tracker),
ifListening(p.start_listening)
LocalInstTracker::LocalInstTracker(const LocalInstTrackerParams &params)
: ProbeListenerObject(params),
ifListening(params.start_listening),
globalInstTracker(params.global_inst_tracker)
{
DPRINTF(InstTracker, "ifListening = %s\n", ifListening ? "true" : "false");
}
@@ -48,11 +48,17 @@ LocalInstTracker::regProbeListeners()
listeners.push_back(new LocalInstTrackerListener(this,
"RetiredInsts",
&LocalInstTracker::retiredInstsHandler));
DPRINTF(InstTracker, "Listening to RetiredInsts\n");
DPRINTF(InstTracker, "Start listening to RetiredInsts\n");
}
}
}
void
LocalInstTracker::retiredInstsHandler(const uint64_t& inst)
{
globalInstTracker->updateAndCheckInstCount(inst);
}
void
LocalInstTracker::stopListening()
{
@@ -64,17 +70,14 @@ LocalInstTracker::stopListening()
DPRINTF(InstTracker, "Stopped listening\n");
}
void
LocalInstTracker::retiredInstsHandler(const uint64_t& inst)
{
globalInstTracker->updateAndCheckInstCount(inst);
}
GlobalInstTracker::GlobalInstTracker(const GlobalInstTrackerParams &p)
: SimObject(p),
GlobalInstTracker::GlobalInstTracker(const GlobalInstTrackerParams &params)
: SimObject(params),
instCount(0),
instThreshold(p.inst_threshold)
{}
instThreshold(params.inst_threshold)
{
DPRINTF(InstTracker, "instThreshold = %lu\n", instThreshold);
}
void
GlobalInstTracker::updateAndCheckInstCount(const uint64_t& inst)
@@ -86,6 +89,10 @@ GlobalInstTracker::updateAndCheckInstCount(const uint64_t& inst)
"instThreshold = %lu\n",
instCount, instThreshold);
// note that when the threshold is reached, the simulation will raise
// and exit event but it will not reset the instruction counter.
// user can reset the counter by calling the resetCounter() function
// in the simulation script.
exitSimLoopNow("a thread reached the max instruction count");
}
}

View File

@@ -38,6 +38,50 @@
namespace gem5
{
class LocalInstTracker : public ProbeListenerObject
{
public:
LocalInstTracker(const LocalInstTrackerParams &params);
/** setup the probelistener */
virtual void regProbeListeners();
/**
* this function is called when the ProbePoint "RetiredInsts" is notified
*
* @param inst the number of retired instructions. It is usually 1.
*/
void retiredInstsHandler(const uint64_t& inst);
private:
typedef ProbeListenerArg<LocalInstTracker, uint64_t>
LocalInstTrackerListener;
/** a boolean variable that determines if the LocalInstTracker is
* listening to the ProbePoints or not
*/
bool ifListening;
/**
* the pointer to the GlobalInstTracker object. It is used to update the
* instruction count and check if the instruction count has reached the
* threshold across all the cores.
*/
GlobalInstTracker *globalInstTracker;
public:
/** stop listening to the ProbePoints */
void stopListening();
/** start listening to the ProbePoints */
void startListening()
{
ifListening = true;
regProbeListeners();
}
};
class GlobalInstTracker : public SimObject
{
public:
@@ -83,50 +127,6 @@ class GlobalInstTracker : public SimObject
};
};
class LocalInstTracker : public ProbeListenerObject
{
public:
LocalInstTracker(const LocalInstTrackerParams &params);
/** setup the probelistener */
virtual void regProbeListeners();
/**
* this function is called when the ProbePoint "RetiredInsts" is notified
*
* @param inst the number of retired instructions. It is usually 1.
*/
void retiredInstsHandler(const uint64_t& inst);
private:
typedef ProbeListenerArg<LocalInstTracker, uint64_t>
LocalInstTrackerListener;
/** a boolean variable that determines if the LocalInstTracker is
* listening to the ProbePoints or not
*/
bool ifListening;
/**
* the pointer to the GlobalInstTracker object. It is used to update the
* instruction count and check if the instruction count has reached the
* threshold across all the cores.
*/
GlobalInstTracker *globalInstTracker;
public:
/** stop listening to the ProbePoints */
void stopListening();
/** start listening to the ProbePoints */
void startListening()
{
ifListening = true;
regProbeListeners();
}
};
}
#endif // __CPU_PROBES_INST_TRACKER_HH__