gem5 v24.1.0.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
inst_tracker.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
30
31namespace gem5
32{
33
34LocalInstTracker::LocalInstTracker(const LocalInstTrackerParams &params)
35 : ProbeListenerObject(params),
36 ifListening(params.start_listening),
37 globalInstTracker(params.global_inst_tracker)
38{
39 DPRINTF(InstTracker, "ifListening = %s\n", ifListening ? "true" : "false");
40}
41
42void
44{
45 if (ifListening) {
46 if (listeners.empty()) {
47 listeners.push_back(new LocalInstTrackerListener(this,
48 "RetiredInsts",
50 DPRINTF(InstTracker, "Start listening to RetiredInsts\n");
51 }
52 }
53}
54
55void
60
61void
63{
64 ifListening = false;
65 bool _ifRemoved;
66 for (auto &_listener : listeners) {
67 _ifRemoved = getProbeManager()->removeListener(
68 "RetiredInsts",
69 *_listener
70 );
71 panic_if(!_ifRemoved, "Failed to remove listener");
72 if (_listener != nullptr) {
73 delete(_listener);
74 DPRINTF(InstTracker, "Deleted Listener pointer\n");
75 }
76 }
77 listeners.clear();
78 DPRINTF(InstTracker, "Stop listening to RetiredInsts\n");
79}
80
81
82GlobalInstTracker::GlobalInstTracker(const GlobalInstTrackerParams &params)
83 : SimObject(params),
84 instCount(0)
85{
86 for (const auto &threshold : params.inst_thresholds) {
87 instThresholdSet.insert(threshold);
88 DPRINTF(InstTracker, "adding the instruction threshold\n"
89 "instThreshold = %lu\n", threshold);
90 }
91 DPRINTF(InstTracker, "instThresholdSet size = %lu\n",
92 instThresholdSet.size());
93}
94
95void
97{
98 instCount ++;
99 if (instThresholdSet.find(instCount) != instThresholdSet.end()) {
100 DPRINTF(InstTracker, "Instruction count reached the threshold\n"
101 "instCount = %lu\n",
102 instCount);
104 // note that when the threshold is reached, the simulation will raise
105 // and exit event but it will not reset the instruction counter.
106 // user can reset the counter by calling the resetCounter() function
107 // in the simulation script.
108 exitSimLoopNow("a thread reached the max instruction count");
109 }
110}
111
112} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:209
std::unordered_set< uint64_t > instThresholdSet
a set of thresholds for the number of instructions that should be executed before the simulation exit...
GlobalInstTracker(const GlobalInstTrackerParams &params)
uint64_t instCount
the number of instructions that have been executed across all the cores
void updateAndCheckInstCount(const uint64_t &inst)
this function is called by the LocalInstTracker object to update the instruction count and check if t...
virtual void regProbeListeners()
setup the probelistener
bool ifListening
a boolean variable that determines if the LocalInstTracker is listening to the ProbePoints or not
GlobalInstTracker * globalInstTracker
the pointer to the GlobalInstTracker object.
void stopListening()
stop listening to the ProbePoints
LocalInstTracker(const LocalInstTrackerParams &params)
ProbeListenerArg< LocalInstTracker, uint64_t > LocalInstTrackerListener
void retiredInstsHandler(const uint64_t &inst)
this function is called when the ProbePoint "RetiredInsts" is notified
This class is a minimal wrapper around SimObject.
Definition probe.hh:108
ProbeManager * getProbeManager()
Definition probe.hh:116
std::vector< ProbeListener * > listeners
Definition probe.hh:111
bool removeListener(std::string point_name, ProbeListener &listener)
Remove a ProbeListener from the ProbePoint named by pointName.
Definition probe.cc:103
Abstract superclass for simulation objects.
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition logging.hh:214
const Params & params() const
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
void exitSimLoopNow(const std::string &message, int exit_code, Tick repeat, bool serialize)
Schedule an event as above, but make it high priority so it runs before any normal events which are s...
Definition sim_events.cc:99

Generated on Mon Jan 13 2025 04:28:32 for gem5 by doxygen 1.9.8