45#include "debug/ElasticTrace.hh"
59 depWindowSize(params.depWindowSize),
60 dataTraceStream(
nullptr),
61 instTraceStream(
nullptr),
62 startTraceInst(params.startTraceInst),
64 traceVirtAddr(params.traceVirtAddr),
67 cpu =
dynamic_cast<CPU *
>(params.manager);
69 fatal_if(!cpu,
"Manager of %s is not of type O3CPU and thus does not "\
70 "support dependency tracing.\n",
name());
72 fatal_if(depWindowSize == 0,
"depWindowSize parameter must be non-zero. "\
73 "Recommended size is 3x ROB size in the O3CPU.\n");
75 fatal_if(cpu->numThreads > 1,
"numThreads = %i, %s supports tracing for"\
76 "single-threaded workload only", cpu->numThreads,
name());
78 fatal_if(params.instFetchTraceFile ==
"",
"Assign instruction fetch "\
79 "trace file path to instFetchTraceFile");
80 fatal_if(params.dataDepTraceFile ==
"",
"Assign data dependency "\
81 "trace file path to dataDepTraceFile");
83 params.instFetchTraceFile);
88 ProtoMessage::PacketHeader inst_pkt_header;
89 inst_pkt_header.set_obj_id(
name());
91 instTraceStream->write(inst_pkt_header);
94 ProtoMessage::InstDepRecordHeader data_rec_header;
95 data_rec_header.set_obj_id(
name());
97 data_rec_header.set_window_size(depWindowSize);
98 dataTraceStream->write(data_rec_header);
106 inform(
"@%llu: regProbeListeners() called, startTraceInst = %llu",
124 inform(
"@%llu: No. of instructions committed = %llu, registering elastic"
156 req->getPC(), req->getVaddr(), req->getPaddr(),
157 req->getFlags(), req->getSize(),
curTick());
161 ProtoMessage::Packet inst_fetch_pkt;
162 inst_fetch_pkt.set_tick(
curTick());
164 inst_fetch_pkt.set_pc(req->getPC());
165 inst_fetch_pkt.set_flags(req->getFlags());
166 inst_fetch_pkt.set_addr(req->getPaddr());
167 inst_fetch_pkt.set_size(req->getSize());
183 has already retired (mostly squashed)", dyn_inst->seqNum);
196 auto itr_exec_info =
tempStore.find(dyn_inst->seqNum);
198 exec_info_ptr = itr_exec_info->second;
201 tempStore[dyn_inst->seqNum] = exec_info_ptr;
216 auto itr_exec_info =
tempStore.find(dyn_inst->seqNum);
219 " skipping.\n", dyn_inst->seqNum);
247 int8_t max_regs = dyn_inst->numSrcRegs();
248 for (
int src_idx = 0; src_idx < max_regs; src_idx++) {
250 const RegId& src_reg = dyn_inst->srcRegIdx(src_idx);
253 PhysRegIdPtr phys_src_reg = dyn_inst->renamedSrcIdx(src_idx);
255 " %i (%s)\n", seq_num,
277 max_regs = dyn_inst->numDestRegs();
278 for (
int dest_idx = 0; dest_idx < max_regs; dest_idx++) {
281 const RegId& dest_reg = dyn_inst->destRegIdx(dest_idx);
286 dyn_inst->renamedDestIdx(dest_idx);
288 " %i (%s)\n", seq_num, phys_dest_reg->
flatIndex(),
301 inst_reg_pair.second);
302 auto itr_regdep_map =
physRegDepMap.find(inst_reg_pair.second);
313 auto itr_exec_info =
tempStore.find(head_inst->seqNum);
325 head_inst->hasRequest() &&
326 head_inst->getFault() ==
NoFault) {
342 if (!head_inst->isNop()) {
348 auto itr_temp_store =
tempStore.find(head_inst->seqNum);
351 "store, skipping.\n", head_inst->seqNum);
371 if (head_inst->getFault() !=
NoFault) {
373 "skip adding it to the trace\n",
374 (head_inst->isMemRef() ?
"Load/store" :
"Comp inst."),
376 }
else if (head_inst->isMemRef() && !head_inst->hasRequest()) {
378 "skip adding it to the trace\n", head_inst->seqNum);
379 }
else if (!head_inst->readPredicate()) {
381 "skip adding it to the trace\n",
382 (head_inst->isMemRef() ?
"Load/store" :
"Comp inst."),
404 new_record->
instNum = head_inst->seqNum;
405 new_record->
commit = commit;
406 new_record->
type = head_inst->isLoad() ? Record::LOAD :
407 (head_inst->isStore() ? Record::STORE :
411 new_record->
reqFlags = head_inst->memReqFlags;
412 new_record->
virtAddr = head_inst->effAddr;
413 new_record->
physAddr = head_inst->physEffAddr;
415 new_record->
size = head_inst->effSize;
416 new_record->
pc = head_inst->pcState().instAddr();
442 if (head_inst->isLoad() && !commit) {
447 std::set<InstSeqNum>::const_iterator dep_set_it;
457 "%lli\n", new_record->
instNum, *dep_set_it);
458 TraceInfo* reg_dep = trace_info_itr->second;
474 "%lli is skipped\n",new_record->
instNum, *dep_set_it);
482 if (head_inst->isStore()) {
503 (commit ?
"committed" :
"squashed"), new_record->
instNum);
524 bool find_load_not_store)
532 uint32_t num_go_back = 0;
537 while (num_go_back <
depWindowSize && from_itr != until_itr) {
538 if (find_load_not_store) {
558 past_record = *from_itr;
572 uint32_t num_go_back = 0;
573 Tick execute_tick = 0;
575 if (new_record->
isLoad()) {
579 }
else if (new_record->
isStore()) {
592 while (num_go_back <
depWindowSize && from_itr != until_itr) {
604 past_record = *from_itr;
627 Tick execute_tick)
const
634 Tick execute_tick)
const
642 Tick execute_tick)
const
651 Tick execute_tick)
const
664 auto itr_exec_info =
tempStore.find(temp_sn);
668 delete exec_info_ptr;
684 int64_t comp_delay = -1;
685 Tick execution_tick = 0, completion_tick = 0;
694 if (past_record->
isLoad()) {
700 }
else if (past_record->
isStore()) {
702 }
else if (past_record->
isComp()){
705 assert(execution_tick >= completion_tick);
706 comp_delay = execution_tick - completion_tick;
709 execution_tick, completion_tick, comp_delay);
728 int64_t comp_delay = -1;
729 Tick execution_tick = 0, completion_tick = 0;
747 assert(execution_tick >= completion_tick);
748 comp_delay = execution_tick - completion_tick;
750 execution_tick, completion_tick, comp_delay);
794 uint16_t num_filtered_nodes = 0;
797 while (num_to_write > 0) {
799 assert(temp_ptr->
type != Record::INVALID);
806 "is as follows:\n", temp_ptr->
instNum);
810 "size %i, flags %i\n", temp_ptr->
physAddr,
818 }
else if (temp_ptr->
isStore()) {
829 ProtoMessage::InstDepRecord dep_pkt;
830 dep_pkt.set_seq_num(temp_ptr->
instNum);
831 dep_pkt.set_type(temp_ptr->
type);
832 dep_pkt.set_pc(temp_ptr->
pc);
834 dep_pkt.set_flags(temp_ptr->
reqFlags);
835 dep_pkt.set_p_addr(temp_ptr->
physAddr);
839 dep_pkt.set_v_addr(temp_ptr->
virtAddr);
840 dep_pkt.set_size(temp_ptr->
size);
842 dep_pkt.set_comp_delay(temp_ptr->
compDelay);
849 dep_pkt.add_rob_dep(temp_ptr->
robDepList.front());
861 if (num_filtered_nodes != 0) {
866 dep_pkt.set_weight(num_filtered_nodes);
867 num_filtered_nodes = 0;
875 ++num_filtered_nodes;
882 depTrace.erase(dep_trace_itr_start, dep_trace_itr);
886 : statistics::
Group(parent),
887 ADD_STAT(numRegDep, statistics::units::Count::get(),
888 "Number of register dependencies recorded during tracing"),
889 ADD_STAT(numOrderDepStores, statistics::units::Count::get(),
890 "Number of commit order (rob) dependencies for a store "
891 "recorded on a past load/store during tracing"),
892 ADD_STAT(numIssueOrderDepLoads, statistics::units::Count::get(),
893 "Number of loads that got assigned issue order dependency "
894 "because they were dependency-free"),
895 ADD_STAT(numIssueOrderDepStores, statistics::units::Count::get(),
896 "Number of stores that got assigned issue order dependency "
897 "because they were dependency-free"),
898 ADD_STAT(numIssueOrderDepOther, statistics::units::Count::get(),
899 "Number of non load/store insts that got assigned issue order "
900 "dependency because they were dependency-free"),
901 ADD_STAT(numFilteredNodes, statistics::units::Count::get(),
902 "No. of nodes filtered out before writing the output trace"),
903 ADD_STAT(maxNumDependents, statistics::units::Count::get(),
904 "Maximum number or dependents on any instruction"),
905 ADD_STAT(maxTempStoreSize, statistics::units::Count::get(),
906 "Maximum size of the temporary store during the run"),
907 ADD_STAT(maxPhysRegDepMapSize, statistics::units::Count::get(),
908 "Maximum size of register dependency map")
915 return Record::RecordType_Name(
type);
A ProtoOutputStream wraps a coded stream, potentially with compression, based on looking at the file ...
void write(const google::protobuf::Message &msg)
Write a message to the stream, preprending it with the message size.
virtual ThreadContext * getContext(int tn)
Given a thread num get tho thread context for it.
static Counter numSimulatedInsts()
std::string resolve(const std::string &name) const
Returns relative file names prepended with name of this directory.
const RegIndex & flatIndex() const
Flat index accessor.
constexpr const char * className() const
Return a const char* with the register class name.
ProbeListenerArg generates a listener for the class of Arg and the class type T which is the class co...
This class is a minimal wrapper around SimObject.
std::vector< ProbeListener * > listeners
If you want a reference counting pointer to a mutable object, create it like this:
Register ID: describe an architectural register with its class and index.
constexpr bool is(RegClassType reg_class) const
constexpr const char * className() const
Return a const char* with the register class name.
virtual void scheduleInstCountEvent(Event *event, Tick count)=0
O3CPU class, has each of the stages (fetch through commit) within it, as well as all of the time buff...
The elastic trace is a type of probe listener and listens to probe points in multiple stages of the O...
void compDelayRob(TraceInfo *past_record, TraceInfo *new_record)
Calculate the computational delay between an instruction and a subsequent instruction that has an ROB...
const bool traceVirtAddr
Whether to trace virtual addresses for memory requests.
bool hasCompCompleted(TraceInfo *past_record, Tick execute_tick) const
Check if past record is a comp node that completed earlier than the execute tick.
void updateIssueOrderDep(TraceInfo *new_record)
Reverse iterate through the graph, search for an issue order dependency for a new node and update the...
bool allProbesReg
Whther the elastic trace listener has been registered for all probes.
std::vector< TraceInfo * >::iterator depTraceItr
Typedef of iterator to the instruction dependency trace.
void addCommittedInst(const DynInstConstPtr &head_inst)
Add an instruction that is at the head of the ROB and is committed.
bool hasLoadCompleted(TraceInfo *past_record, Tick execute_tick) const
Check if past record is a load that completed earlier than the execute tick.
ProtoOutputStream * dataTraceStream
Protobuf output stream for data dependency trace.
void recordToCommTick(const DynInstConstPtr &dyn_inst)
Populate the timestamp field in an InstExecInfo object for an instruction in flight when it is execut...
std::unordered_map< InstSeqNum, InstExecInfo * > tempStore
Temporary store of InstExecInfo objects.
void writeDepTrace(uint32_t num_to_write)
Write out given number of records to the trace starting with the first record in depTrace and iterati...
std::vector< TraceInfo * > depTrace
The instruction dependency trace containing TraceInfo objects.
void clearTempStoreUntil(const DynInstConstPtr &head_inst)
Clear entries in the temporary store of execution info objects to free allocated memory until the pre...
uint32_t depWindowSize
The maximum distance for a dependency and is set by a top level level parameter.
void assignRobDep(TraceInfo *past_record, TraceInfo *new_record)
The new_record has an order dependency on a past_record, thus update the new record's Rob dependency ...
ElasticTrace(const ElasticTraceParams ¶ms)
Constructor.
CPU * cpu
Pointer to the O3CPU that is this listener's parent a.k.a.
bool firstWin
Used for checking the first window for processing and writing of dependency trace.
std::reverse_iterator< depTraceItr > depTraceRevItr
Typedef of the reverse iterator to the instruction dependency trace.
void addDepTraceRecord(const DynInstConstPtr &head_inst, InstExecInfo *exec_info_ptr, bool commit)
Add a record to the dependency trace depTrace which is a sequential container.
void compDelayPhysRegDep(TraceInfo *past_record, TraceInfo *new_record)
Calculate the computational delay between an instruction and a subsequent instruction that has a Phys...
void removeRegDepMapEntry(const SeqNumRegPair &inst_reg_pair)
When an instruction gets squashed the destination register mapped to it is freed up in the rename sta...
EventFunctionWrapper regEtraceListenersEvent
Event to trigger registering this listener for all probe points.
void regEtraceListeners()
Register all listeners.
void recordExecTick(const DynInstConstPtr &dyn_inst)
Populate the execute timestamp field in an InstExecInfo object for an instruction in flight.
void regProbeListeners()
Register the probe listeners that is the methods called on a probe point notify() call.
std::unordered_map< RegIndex, InstSeqNum > physRegDepMap
Map for recording the producer of a physical register to check Read After Write dependencies.
std::unordered_map< InstSeqNum, TraceInfo * > traceInfoMap
Map where the instruction sequence number is mapped to the pointer to the TraceInfo object.
void addSquashedInst(const DynInstConstPtr &head_inst)
Add an instruction that is at the head of the ROB and is squashed only if it is a load and a request ...
bool hasLoadBeenSent(TraceInfo *past_record, Tick execute_tick) const
Check if past record is a load sent earlier than the execute tick.
void fetchReqTrace(const RequestPtr &req)
Take the fields of the request class object that are relevant to create an instruction fetch request.
InstSeqNum lastClearedSeqNum
The last cleared instruction sequence number used to free up the memory allocated in the temporary st...
gem5::o3::ElasticTrace::ElasticTraceStats stats
ProtoOutputStream * instTraceStream
Protobuf output stream for instruction fetch trace.
void updateRegDep(const DynInstConstPtr &dyn_inst)
Record a Read After Write physical register dependency if there has been a write to the source regist...
void flushTraces()
Process any outstanding trace records, flush them out to the protobuf output streams and delete the s...
void updateCommitOrderDep(TraceInfo *new_record, bool find_load_not_store)
Reverse iterate through the graph, search for a store-after-store or store-after-load dependency and ...
const InstSeqNum startTraceInst
Number of instructions after which to enable tracing.
bool hasStoreCommitted(TraceInfo *past_record, Tick execute_tick) const
Check if past record is a store sent earlier than the execute tick.
Counter value() const
Return the current value of this stat as its base type.
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
Tick executeTick
Timestamp when instruction was first processed by execute stage.
Tick toCommitTick
Timestamp when instruction execution is completed in execute stage and instruction is marked as ready...
std::set< InstSeqNum > physRegDepSet
Set of instruction sequence numbers that this instruction depends on due to Read After Write data dep...
const std::string & typeToStr() const
Return string specifying the type of the node.
Request::FlagsType reqFlags
bool isLoad() const
Is the record a load.
std::list< InstSeqNum > robDepList
std::list< InstSeqNum > physRegDepList
int64_t compDelay
Computational delay after the last dependent inst.
bool isComp() const
Is the record a fetch triggering an Icache request.
RecordType type
The type of trace record for the instruction node.
bool isStore() const
Is the record a store.
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Tick Frequency
The simulated frequency of curTick(). (In ticks per second)
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
std::shared_ptr< Request > RequestPtr
Tick curTick()
The universal simulation clock.
uint64_t Tick
Tick count type.
void registerExitCallback(const std::function< void()> &callback)
Register an exit callback.
constexpr decltype(nullptr) NoFault
@ MiscRegClass
Control (misc) register.
Declaration of the Packet class.
statistics::Scalar maxNumDependents
Maximum number of dependents on any instruction.
statistics::Scalar maxTempStoreSize
Maximum size of the temporary store mostly useful as a check that it is not growing.
statistics::Scalar numIssueOrderDepLoads
Number of load insts that got assigned an issue order dependency because they were dependency-free.
statistics::Scalar numIssueOrderDepStores
Number of store insts that got assigned an issue order dependency because they were dependency-free.
ElasticTraceStats(statistics::Group *parent)
statistics::Scalar numRegDep
Number of register dependencies recorded during tracing.
statistics::Scalar numFilteredNodes
Number of filtered nodes.
statistics::Scalar maxPhysRegDepMapSize
Maximum size of the map that holds the last writer to a physical register.
statistics::Scalar numIssueOrderDepOther
Number of non load/store insts that got assigned an issue order dependency because they were dependen...
Tick getExecuteTick() const
Get the execute tick of the instruction.
const std::string & name()