diff options
author | Rekai Gonzalez-Alberquilla <rekai.gonzalezalberquilla@arm.com> | 2017-02-06 11:10:06 +0000 |
---|---|---|
committer | Giacomo Gabrielli <giacomo.gabrielli@arm.com> | 2018-11-16 10:39:03 +0000 |
commit | 0c50a0b4fe3956f9d2e08e75d47c9cbd79bf0268 (patch) | |
tree | 7679abe2343e0504c93eb73d09635d546a211455 /src/cpu/o3/probe | |
parent | 338a173e822298bd22741342a7b24352450afdd1 (diff) | |
download | gem5-0c50a0b4fe3956f9d2e08e75d47c9cbd79bf0268.tar.xz |
cpu: Fix the usage of const DynInstPtr
Summary: Usage of const DynInstPtr& when possible and introduction of
move operators to RefCountingPtr.
In many places, scoped references to dynamic instructions do a copy of
the DynInstPtr when a reference would do. This is detrimental to
performance. On top of that, in case there is a need for reference
tracking for debugging, the redundant copies make the process much more
painful than it already is.
Also, from the theoretical point of view, a function/method that
defines a convenience name to access an instruction should not be
considered an owner of the data, i.e., doing a copy and not a reference
is not justified.
On a related topic, C++11 introduces move semantics, and those are
useful when, for example, there is a class modelling a HW structure that
contains a list, and has a getHeadOfList function, to prevent doing a
copy to an internal variable -> update pointer, remove from the list ->
update pointer, return value making a copy to the assined variable ->
update pointer, destroy the returned value -> update pointer.
Change-Id: I3bb46c20ef23b6873b469fd22befb251ac44d2f6
Signed-off-by: Giacomo Gabrielli <giacomo.gabrielli@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/13105
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
Maintainer: Jason Lowe-Power <jason@lowepower.com>
Diffstat (limited to 'src/cpu/o3/probe')
-rw-r--r-- | src/cpu/o3/probe/elastic_trace.cc | 39 | ||||
-rw-r--r-- | src/cpu/o3/probe/elastic_trace.hh | 15 | ||||
-rw-r--r-- | src/cpu/o3/probe/simple_trace.cc | 13 | ||||
-rw-r--r-- | src/cpu/o3/probe/simple_trace.hh | 4 |
4 files changed, 40 insertions, 31 deletions
diff --git a/src/cpu/o3/probe/elastic_trace.cc b/src/cpu/o3/probe/elastic_trace.cc index 508140e0c..a4a201398 100644 --- a/src/cpu/o3/probe/elastic_trace.cc +++ b/src/cpu/o3/probe/elastic_trace.cc @@ -124,18 +124,23 @@ ElasticTrace::regEtraceListeners() // each probe point. listeners.push_back(new ProbeListenerArg<ElasticTrace, RequestPtr>(this, "FetchRequest", &ElasticTrace::fetchReqTrace)); - listeners.push_back(new ProbeListenerArg<ElasticTrace, DynInstPtr>(this, - "Execute", &ElasticTrace::recordExecTick)); - listeners.push_back(new ProbeListenerArg<ElasticTrace, DynInstPtr>(this, - "ToCommit", &ElasticTrace::recordToCommTick)); - listeners.push_back(new ProbeListenerArg<ElasticTrace, DynInstPtr>(this, - "Rename", &ElasticTrace::updateRegDep)); + listeners.push_back(new ProbeListenerArg<ElasticTrace, + DynInstConstPtr>(this, "Execute", + &ElasticTrace::recordExecTick)); + listeners.push_back(new ProbeListenerArg<ElasticTrace, + DynInstConstPtr>(this, "ToCommit", + &ElasticTrace::recordToCommTick)); + listeners.push_back(new ProbeListenerArg<ElasticTrace, + DynInstConstPtr>(this, "Rename", + &ElasticTrace::updateRegDep)); listeners.push_back(new ProbeListenerArg<ElasticTrace, SeqNumRegPair>(this, "SquashInRename", &ElasticTrace::removeRegDepMapEntry)); - listeners.push_back(new ProbeListenerArg<ElasticTrace, DynInstPtr>(this, - "Squash", &ElasticTrace::addSquashedInst)); - listeners.push_back(new ProbeListenerArg<ElasticTrace, DynInstPtr>(this, - "Commit", &ElasticTrace::addCommittedInst)); + listeners.push_back(new ProbeListenerArg<ElasticTrace, + DynInstConstPtr>(this, "Squash", + &ElasticTrace::addSquashedInst)); + listeners.push_back(new ProbeListenerArg<ElasticTrace, + DynInstConstPtr>(this, "Commit", + &ElasticTrace::addCommittedInst)); allProbesReg = true; } @@ -162,7 +167,7 @@ ElasticTrace::fetchReqTrace(const RequestPtr &req) } void -ElasticTrace::recordExecTick(const DynInstPtr &dyn_inst) +ElasticTrace::recordExecTick(const DynInstConstPtr& dyn_inst) { // In a corner case, a retired instruction is propagated backward to the @@ -199,7 +204,7 @@ ElasticTrace::recordExecTick(const DynInstPtr &dyn_inst) } void -ElasticTrace::recordToCommTick(const DynInstPtr &dyn_inst) +ElasticTrace::recordToCommTick(const DynInstConstPtr& dyn_inst) { // If tracing has just been enabled then the instruction at this stage of // execution is far enough that we cannot gather info about its past like @@ -220,7 +225,7 @@ ElasticTrace::recordToCommTick(const DynInstPtr &dyn_inst) } void -ElasticTrace::updateRegDep(const DynInstPtr &dyn_inst) +ElasticTrace::updateRegDep(const DynInstConstPtr& dyn_inst) { // Get the sequence number of the instruction InstSeqNum seq_num = dyn_inst->seqNum; @@ -298,7 +303,7 @@ ElasticTrace::removeRegDepMapEntry(const SeqNumRegPair &inst_reg_pair) } void -ElasticTrace::addSquashedInst(const DynInstPtr &head_inst) +ElasticTrace::addSquashedInst(const DynInstConstPtr& head_inst) { // If the squashed instruction was squashed before being processed by // execute stage then it will not be in the temporary store. In this case @@ -326,7 +331,7 @@ ElasticTrace::addSquashedInst(const DynInstPtr &head_inst) } void -ElasticTrace::addCommittedInst(const DynInstPtr &head_inst) +ElasticTrace::addCommittedInst(const DynInstConstPtr& head_inst) { DPRINTFR(ElasticTrace, "Attempt to add committed inst [sn:%lli]\n", head_inst->seqNum); @@ -385,7 +390,7 @@ ElasticTrace::addCommittedInst(const DynInstPtr &head_inst) } void -ElasticTrace::addDepTraceRecord(const DynInstPtr &head_inst, +ElasticTrace::addDepTraceRecord(const DynInstConstPtr& head_inst, InstExecInfo* exec_info_ptr, bool commit) { // Create a record to assign dynamic intruction related fields. @@ -648,7 +653,7 @@ ElasticTrace::hasCompCompleted(TraceInfo* past_record, } void -ElasticTrace::clearTempStoreUntil(const DynInstPtr head_inst) +ElasticTrace::clearTempStoreUntil(const DynInstConstPtr& head_inst) { // Clear from temp store starting with the execution info object // corresponding the head_inst and continue clearing by decrementing the diff --git a/src/cpu/o3/probe/elastic_trace.hh b/src/cpu/o3/probe/elastic_trace.hh index 08e02daef..21029b94c 100644 --- a/src/cpu/o3/probe/elastic_trace.hh +++ b/src/cpu/o3/probe/elastic_trace.hh @@ -90,6 +90,7 @@ class ElasticTrace : public ProbeListenerObject public: typedef typename O3CPUImpl::DynInstPtr DynInstPtr; + typedef typename O3CPUImpl::DynInstConstPtr DynInstConstPtr; typedef typename std::pair<InstSeqNum, PhysRegIndex> SeqNumRegPair; /** Trace record types corresponding to instruction node types */ @@ -132,7 +133,7 @@ class ElasticTrace : public ProbeListenerObject * * @param dyn_inst pointer to dynamic instruction in flight */ - void recordExecTick(const DynInstPtr &dyn_inst); + void recordExecTick(const DynInstConstPtr& dyn_inst); /** * Populate the timestamp field in an InstExecInfo object for an @@ -141,7 +142,7 @@ class ElasticTrace : public ProbeListenerObject * * @param dyn_inst pointer to dynamic instruction in flight */ - void recordToCommTick(const DynInstPtr &dyn_inst); + void recordToCommTick(const DynInstConstPtr& dyn_inst); /** * Record a Read After Write physical register dependency if there has @@ -152,7 +153,7 @@ class ElasticTrace : public ProbeListenerObject * * @param dyn_inst pointer to dynamic instruction in flight */ - void updateRegDep(const DynInstPtr &dyn_inst); + void updateRegDep(const DynInstConstPtr& dyn_inst); /** * When an instruction gets squashed the destination register mapped to it @@ -169,14 +170,14 @@ class ElasticTrace : public ProbeListenerObject * * @param head_inst pointer to dynamic instruction to be squashed */ - void addSquashedInst(const DynInstPtr &head_inst); + void addSquashedInst(const DynInstConstPtr& head_inst); /** * Add an instruction that is at the head of the ROB and is committed. * * @param head_inst pointer to dynamic instruction to be committed */ - void addCommittedInst(const DynInstPtr &head_inst); + void addCommittedInst(const DynInstConstPtr& head_inst); /** Register statistics for the elastic trace. */ void regStats(); @@ -385,7 +386,7 @@ class ElasticTrace : public ProbeListenerObject * @param exec_info_ptr Pointer to InstExecInfo for that instruction * @param commit True if instruction is committed, false if squashed */ - void addDepTraceRecord(const DynInstPtr &head_inst, + void addDepTraceRecord(const DynInstConstPtr& head_inst, InstExecInfo* exec_info_ptr, bool commit); /** @@ -394,7 +395,7 @@ class ElasticTrace : public ProbeListenerObject * * @param head_inst pointer to dynamic instruction */ - void clearTempStoreUntil(const DynInstPtr head_inst); + void clearTempStoreUntil(const DynInstConstPtr& head_inst); /** * Calculate the computational delay between an instruction and a diff --git a/src/cpu/o3/probe/simple_trace.cc b/src/cpu/o3/probe/simple_trace.cc index 060b4df13..4c7b676b4 100644 --- a/src/cpu/o3/probe/simple_trace.cc +++ b/src/cpu/o3/probe/simple_trace.cc @@ -42,14 +42,14 @@ #include "base/trace.hh" #include "debug/SimpleTrace.hh" -void SimpleTrace::traceCommit(const O3CPUImpl::DynInstPtr &dynInst) +void SimpleTrace::traceCommit(const O3CPUImpl::DynInstConstPtr& dynInst) { DPRINTFR(SimpleTrace, "[%s]: Commit 0x%08x %s.\n", name(), dynInst->instAddr(), dynInst->staticInst->disassemble(dynInst->instAddr())); } -void SimpleTrace::traceFetch(const O3CPUImpl::DynInstPtr &dynInst) +void SimpleTrace::traceFetch(const O3CPUImpl::DynInstConstPtr& dynInst) { DPRINTFR(SimpleTrace, "[%s]: Fetch 0x%08x %s.\n", name(), dynInst->instAddr(), @@ -58,9 +58,12 @@ void SimpleTrace::traceFetch(const O3CPUImpl::DynInstPtr &dynInst) void SimpleTrace::regProbeListeners() { - typedef ProbeListenerArg<SimpleTrace, O3CPUImpl::DynInstPtr> DynInstListener; - listeners.push_back(new DynInstListener(this, "Commit", &SimpleTrace::traceCommit)); - listeners.push_back(new DynInstListener(this, "Fetch", &SimpleTrace::traceFetch)); + typedef ProbeListenerArg<SimpleTrace, + O3CPUImpl::DynInstConstPtr> DynInstListener; + listeners.push_back(new DynInstListener(this, "Commit", + &SimpleTrace::traceCommit)); + listeners.push_back(new DynInstListener(this, "Fetch", + &SimpleTrace::traceFetch)); } SimpleTrace* diff --git a/src/cpu/o3/probe/simple_trace.hh b/src/cpu/o3/probe/simple_trace.hh index 663128810..928062eaa 100644 --- a/src/cpu/o3/probe/simple_trace.hh +++ b/src/cpu/o3/probe/simple_trace.hh @@ -66,8 +66,8 @@ class SimpleTrace : public ProbeListenerObject { const std::string name() const { return ProbeListenerObject::name() + ".trace"; } private: - void traceFetch(const O3CPUImpl::DynInstPtr &dynInst); - void traceCommit(const O3CPUImpl::DynInstPtr &dynInst); + void traceFetch(const O3CPUImpl::DynInstConstPtr& dynInst); + void traceCommit(const O3CPUImpl::DynInstConstPtr& dynInst); }; #endif//__CPU_O3_PROBE_SIMPLE_TRACE_HH__ |