cpu: add comments and change input type to list
Change inst_threshold param to inst_thresholds, which it is now expecting a list of thresholds instead of one threshold. Add more getter and setter functions: addThreshold: it is for adding new thresholds getCounter: it is for getting the current counter getThresholds: it returns the list of targeted thresholds resetThresholds: it clears all the targeted thresholds Change-Id: I48d022effe7b315112ac150e6a4eaf5aab41c514
This commit is contained in:
@@ -76,14 +76,16 @@ cache_hierarchy = PrivateL1CacheHierarchy(
|
|||||||
|
|
||||||
memory = SingleChannelDDR4_2400("1GB")
|
memory = SingleChannelDDR4_2400("1GB")
|
||||||
|
|
||||||
|
# using 9 cores because when using openmp in SE mode, the number of cores
|
||||||
|
# should be # cores + 1
|
||||||
processor = SimpleProcessor(cpu_type=CPUTypes.TIMING, num_cores=9, isa=ISA.X86)
|
processor = SimpleProcessor(cpu_type=CPUTypes.TIMING, num_cores=9, isa=ISA.X86)
|
||||||
|
|
||||||
# setup instruction tracker
|
# setup instruction tracker
|
||||||
|
|
||||||
# first, we need to create a global instruction tracker
|
# first, we need to create a global instruction tracker
|
||||||
global_inst_tracker = GlobalInstTracker(
|
global_inst_tracker = GlobalInstTracker(
|
||||||
# threshold to trigger the event
|
# a list of thresholds to trigger the event
|
||||||
inst_threshold=100_000_000
|
inst_thresholds=[100_000_000, 100_020_000]
|
||||||
)
|
)
|
||||||
|
|
||||||
# then, we create a local instruction tracker for each core
|
# then, we create a local instruction tracker for each core
|
||||||
@@ -123,14 +125,17 @@ def max_inst_handler():
|
|||||||
# when it reached this function, it means that it successfully raised
|
# when it reached this function, it means that it successfully raised
|
||||||
# the ExitEvent.MAX_INSTS event
|
# the ExitEvent.MAX_INSTS event
|
||||||
print("Reached MAX_INSTS with 100000000 instructions")
|
print("Reached MAX_INSTS with 100000000 instructions")
|
||||||
print("Changing threshold to 20000")
|
yield False
|
||||||
# we can change the threshold of the global instruction tracker
|
print("Reached MAX_INSTS with 100020000 instructions")
|
||||||
global_inst_tracker.changeThreshold(20000)
|
# we can get the current counter of the global instruction tracker
|
||||||
# we need to reset the counter of the global instruction tracker
|
print(f"Current counter: {global_inst_tracker.getCounter()}")
|
||||||
# the counter does not reset automatically
|
# we can reset the counter
|
||||||
global_inst_tracker.resetCounter()
|
global_inst_tracker.resetCounter()
|
||||||
m5.stats.dump()
|
print(f"After reset, current counter: {global_inst_tracker.getCounter()}")
|
||||||
m5.stats.reset()
|
# we can add new threshold to the global instruction tracker
|
||||||
|
global_inst_tracker.addThreshold(20000)
|
||||||
|
# we can get the thresholds
|
||||||
|
print(f"Current thresholds: {global_inst_tracker.getThresholds()}")
|
||||||
yield False
|
yield False
|
||||||
print("Reached MAX_INSTS with 20000 instructions")
|
print("Reached MAX_INSTS with 20000 instructions")
|
||||||
print("Stop listening to instructions")
|
print("Stop listening to instructions")
|
||||||
@@ -141,9 +146,7 @@ def max_inst_handler():
|
|||||||
#
|
#
|
||||||
# for tracker in all_trackers:
|
# for tracker in all_trackers:
|
||||||
# tracker.startListening()
|
# tracker.startListening()
|
||||||
m5.stats.dump()
|
yield True
|
||||||
m5.stats.reset()
|
|
||||||
yield False
|
|
||||||
|
|
||||||
|
|
||||||
simulator = Simulator(
|
simulator = Simulator(
|
||||||
|
|||||||
@@ -41,13 +41,15 @@ class GlobalInstTracker(SimObject):
|
|||||||
cxx_class = "gem5::GlobalInstTracker"
|
cxx_class = "gem5::GlobalInstTracker"
|
||||||
|
|
||||||
cxx_exports = [
|
cxx_exports = [
|
||||||
PyBindMethod("changeThreshold"),
|
PyBindMethod("addThreshold"),
|
||||||
|
PyBindMethod("getCounter"),
|
||||||
PyBindMethod("resetCounter"),
|
PyBindMethod("resetCounter"),
|
||||||
PyBindMethod("getThreshold"),
|
PyBindMethod("getThresholds"),
|
||||||
|
PyBindMethod("resetThresholds"),
|
||||||
]
|
]
|
||||||
|
|
||||||
inst_threshold = Param.Counter(
|
inst_thresholds = VectorParam.Counter(
|
||||||
"The instruction threshold to trigger an" " exit event"
|
"A list of instruction thresholds to trigger an exit event"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -81,22 +81,26 @@ LocalInstTracker::stopListening()
|
|||||||
|
|
||||||
GlobalInstTracker::GlobalInstTracker(const GlobalInstTrackerParams ¶ms)
|
GlobalInstTracker::GlobalInstTracker(const GlobalInstTrackerParams ¶ms)
|
||||||
: SimObject(params),
|
: SimObject(params),
|
||||||
instCount(0),
|
instCount(0)
|
||||||
instThreshold(params.inst_threshold)
|
|
||||||
{
|
{
|
||||||
DPRINTF(InstTracker, "instThreshold = %lu\n", instThreshold);
|
for (const auto &threshold : params.inst_thresholds) {
|
||||||
|
instThresholdSet.insert(threshold);
|
||||||
|
DPRINTF(InstTracker, "adding the instruction threshold\n"
|
||||||
|
"instThreshold = %lu\n", threshold);
|
||||||
|
}
|
||||||
|
DPRINTF(InstTracker, "instThresholdSet size = %lu\n",
|
||||||
|
instThresholdSet.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
GlobalInstTracker::updateAndCheckInstCount(const uint64_t& inst)
|
GlobalInstTracker::updateAndCheckInstCount(const uint64_t& inst)
|
||||||
{
|
{
|
||||||
instCount ++;
|
instCount ++;
|
||||||
if (instCount >= instThreshold) {
|
if (instThresholdSet.find(instCount) != instThresholdSet.end()) {
|
||||||
DPRINTF(InstTracker, "Instruction count reached the threshold\n"
|
DPRINTF(InstTracker, "Instruction count reached the threshold\n"
|
||||||
"instCount = %lu\n"
|
"instCount = %lu\n",
|
||||||
"instThreshold = %lu\n",
|
instCount);
|
||||||
instCount, instThreshold);
|
instThresholdSet.erase(instCount);
|
||||||
|
|
||||||
// note that when the threshold is reached, the simulation will raise
|
// note that when the threshold is reached, the simulation will raise
|
||||||
// and exit event but it will not reset the instruction counter.
|
// and exit event but it will not reset the instruction counter.
|
||||||
// user can reset the counter by calling the resetCounter() function
|
// user can reset the counter by calling the resetCounter() function
|
||||||
|
|||||||
@@ -29,6 +29,8 @@
|
|||||||
#ifndef __CPU_PROBES_INST_TRACKER_HH__
|
#ifndef __CPU_PROBES_INST_TRACKER_HH__
|
||||||
#define __CPU_PROBES_INST_TRACKER_HH__
|
#define __CPU_PROBES_INST_TRACKER_HH__
|
||||||
|
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
#include "debug/InstTracker.hh"
|
#include "debug/InstTracker.hh"
|
||||||
#include "params/GlobalInstTracker.hh"
|
#include "params/GlobalInstTracker.hh"
|
||||||
#include "params/LocalInstTracker.hh"
|
#include "params/LocalInstTracker.hh"
|
||||||
@@ -101,18 +103,24 @@ class GlobalInstTracker : public SimObject
|
|||||||
uint64_t instCount;
|
uint64_t instCount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the threshold for the number of instructions that should be executed
|
* a set of thresholds for the number of instructions that should be
|
||||||
* before the simulation exits
|
* executed before the simulation exits
|
||||||
*/
|
*/
|
||||||
uint64_t instThreshold;
|
std::unordered_set<uint64_t> instThresholdSet;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void
|
void
|
||||||
changeThreshold(uint64_t new_threshold)
|
addThreshold(uint64_t new_threshold)
|
||||||
{
|
{
|
||||||
instThreshold = new_threshold;
|
instThresholdSet.insert(new_threshold);
|
||||||
DPRINTF(InstTracker, "Changing the instruction threshold\n"
|
DPRINTF(InstTracker, "adding the instruction threshold %lu\n",
|
||||||
"instThreshold = %lu\n", instThreshold);
|
new_threshold);
|
||||||
|
};
|
||||||
|
|
||||||
|
uint64_t
|
||||||
|
getCounter() const
|
||||||
|
{
|
||||||
|
return instCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -123,10 +131,17 @@ class GlobalInstTracker : public SimObject
|
|||||||
"instCount = %lu\n", instCount);
|
"instCount = %lu\n", instCount);
|
||||||
};
|
};
|
||||||
|
|
||||||
uint64_t
|
std::unordered_set<uint64_t>
|
||||||
getThreshold() const
|
getThresholds() const
|
||||||
{
|
{
|
||||||
return instThreshold;
|
return instThresholdSet;
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
resetThresholds()
|
||||||
|
{
|
||||||
|
instThresholdSet.clear();
|
||||||
|
DPRINTF(InstTracker, "Resetting the instruction thresholds\n");
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user