cpu: modified with review feedback

x86-global-inst-tracker.py:
- change the incorrect use of comment styly
- add more comments about the usage of the script and the purpose of
the script

src/cpu/probes/inst_tracker.cc:
- change the way of stopListening to use the manager function to remove
listeners. If in the future, the ProbeListner object does not call the
manager to remove itself in the destruction, then we should call it
here.
- fix stlying

src/cpu/probes/inst_tracker.hh:
- fix stlying

Change-Id: I6f3d745e15883a8a702593f72f984e0d4cc4c526
This commit is contained in:
studyztp
2024-08-18 09:50:50 -07:00
committed by Bobby R. Bruce
parent 6e39b737c8
commit 9fede07f44
3 changed files with 56 additions and 35 deletions

View File

@@ -24,6 +24,33 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
This script demonstrates how to use global and local instruction trackers to
monitor and control the simulation based on the number of instructions
committed.
This script will create a global instruction tracker to manage each local
instruction tracker and connects each local instruction tracker to a core.
The global instruction tracker will raise an event when the number of
instructions committed across all cores reaches a certain threshold.
In this script, we expect to start monitorning the instruction committed from
the start of the simulation and raise a SIMPOINT_BEGIN exit event when all
cores in combination have committed 100,000,000 instructions. Then, we will
change the threshold to 20,000 instructions and raise another SIMPOINT_BEGIN
event when the new threshold is reached. Finally, we will stop listening to
instructions.
Usage:
------
scons build/X86/gem5.opt
./build/X86/gem5.opt [--debug-flags=InstTracker] \
configs/example/gem5_library/x86-global-inst-tracker.py
"""
import m5
from m5.objects import (
GlobalInstTracker,
@@ -42,14 +69,6 @@ from gem5.resources.resource import obtain_resource
from gem5.simulate.exit_event import ExitEvent
from gem5.simulate.simulator import Simulator
"""
Usage:
gem5.opt configs/example/gem5_library/x86-global-inst-tracker.py
"""
cache_hierarchy = PrivateL1CacheHierarchy(
l1d_size="64kB",
l1i_size="64kB",
@@ -118,13 +137,10 @@ def max_inst_handler():
# we can stop listening to instructions
for tracker in all_trackers:
tracker.stopListening()
"""
similarly, we can start listening to instructions again by calling:
for tracker in all_trackers:
tracker.startListening()
"""
# similarly, we can start listening to instructions again by calling:
#
# for tracker in all_trackers:
# tracker.startListening()
m5.stats.dump()
m5.stats.reset()
yield False

View File

@@ -43,8 +43,7 @@ void
LocalInstTracker::regProbeListeners()
{
if (ifListening) {
if (listeners.empty())
{
if (listeners.empty()) {
listeners.push_back(new LocalInstTrackerListener(this,
"RetiredInsts",
&LocalInstTracker::retiredInstsHandler));
@@ -63,11 +62,14 @@ void
LocalInstTracker::stopListening()
{
ifListening = false;
for (auto l = listeners.begin(); l != listeners.end(); ++l) {
delete (*l);
bool _ifRemoved;
for (auto &listener : listeners) {
_ifRemoved = getProbeManager()->removeListener(
"RetiredInsts",
*listener
);
DPRINTF(InstTracker, "If removed: %s\n", _ifRemoved ? "Yes" : "No");
}
listeners.clear();
DPRINTF(InstTracker, "Stopped listening\n");
}

View File

@@ -55,7 +55,7 @@ class LocalInstTracker : public ProbeListenerObject
private:
typedef ProbeListenerArg<LocalInstTracker, uint64_t>
LocalInstTrackerListener;
LocalInstTrackerListener;
/** a boolean variable that determines if the LocalInstTracker is
* listening to the ProbePoints or not
@@ -74,10 +74,11 @@ class LocalInstTracker : public ProbeListenerObject
void stopListening();
/** start listening to the ProbePoints */
void startListening()
void
startListening()
{
ifListening = true;
regProbeListeners();
ifListening = true;
regProbeListeners();
}
};
@@ -99,7 +100,6 @@ class GlobalInstTracker : public SimObject
*/
uint64_t instCount;
/**
* the threshold for the number of instructions that should be executed
* before the simulation exits
@@ -107,23 +107,26 @@ class GlobalInstTracker : public SimObject
uint64_t instThreshold;
public:
void changeThreshold(uint64_t new_threshold)
void
changeThreshold(uint64_t new_threshold)
{
instThreshold = new_threshold;
DPRINTF(InstTracker, "Changing the instruction threshold\n"
"instThreshold = %lu\n", instThreshold);
instThreshold = new_threshold;
DPRINTF(InstTracker, "Changing the instruction threshold\n"
"instThreshold = %lu\n", instThreshold);
};
void resetCounter()
void
resetCounter()
{
instCount = 0;
DPRINTF(InstTracker, "Resetting the instruction counter\n"
instCount = 0;
DPRINTF(InstTracker, "Resetting the instruction counter\n"
"instCount = %lu\n", instCount);
};
uint64_t getThreshold() const
uint64_t
getThreshold() const
{
return instThreshold;
return instThreshold;
};
};