changeset 76f75db08e09 in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=76f75db08e09
description:
        proto, probe: Add elastic trace probe to o3 cpu

        The elastic trace is a type of probe listener and listens to probe 
points
        in multiple stages of the O3CPU. The notify method is called on a probe
        point typically when an instruction successfully progresses through that
        stage.

        As different listener methods mapped to the different probe points 
execute,
        relevant information about the instruction, e.g. timestamps and register
        accesses, are captured and stored in temporary InstExecInfo class 
objects.
        When the instruction progresses through the commit stage, the timing 
and the
        dependency information about the instruction is finalised and 
encapsulated in
        a struct called TraceInfo. TraceInfo objects are collected in a list 
instead
        of writing them out to the trace file one a time. This is required as 
the
        trace is processed in chunks to evaluate order dependencies and 
computational
        delay in case an instruction does not have any register dependencies. 
By this
        we achieve a simpler algorithm during replay because every record in the
        trace can be hooked onto a record in its past. The instruction 
dependency
        trace is written out as a protobuf format file. A second trace 
containing
        fetch requests at absolute timestamps is written to a separate protobuf
        format file.

        If the instruction is not executed then it is not added to the trace.
        The code checks if the instruction had a fault, if it predicated
        false and thus previous register values were restored or if it was a
        load/store that did not have a request (e.g. when the size of the
        request is zero). In all these cases the instruction is set as
        executed by the Execute stage and is picked up by the commit probe
        listener. But a request is not issued and registers are not written.
        So practically, skipping these should not hurt the dependency modelling.

        If squashing results in squashing younger instructions, it may happen 
that
        the squash probe discards the inst and removes it from the temporary
        store but execute stage deals with the instruction in the next cycle 
which
        results in the execute probe seeing this inst as 'new' inst. A sequence
        number of the last processed trace record is used to trap these cases 
and
        not add to the temporary store.

        The elastic instruction trace and fetch request trace can be read in and
        played back by the TraceCPU.

diffstat:

 src/cpu/o3/probe/ElasticTrace.py  |   62 ++
 src/cpu/o3/probe/SConscript       |    5 +
 src/cpu/o3/probe/elastic_trace.cc |  939 ++++++++++++++++++++++++++++++++++++++
 src/cpu/o3/probe/elastic_trace.hh |  537 +++++++++++++++++++++
 src/proto/SConscript              |    1 +
 src/proto/inst_dep_record.proto   |   75 +++
 src/proto/packet.proto            |    3 +
 7 files changed, 1622 insertions(+), 0 deletions(-)

diffs (truncated from 1670 to 300 lines):

diff -r 93d2a1526103 -r 76f75db08e09 src/cpu/o3/probe/ElasticTrace.py
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/src/cpu/o3/probe/ElasticTrace.py  Mon Dec 07 16:42:15 2015 -0600
@@ -0,0 +1,62 @@
+# Copyright (c) 2013 - 2015 ARM Limited
+# All rights reserved.
+#
+# The license below extends only to copyright in the software and shall
+# not be construed as granting a license to any other intellectual
+# property including but not limited to intellectual property relating
+# to a hardware implementation of the functionality of the software
+# licensed hereunder.  You may use the software subject to the license
+# terms below provided that you ensure that this notice is replicated
+# unmodified and in its entirety in all distributions of the software,
+# modified or unmodified, in source code or in binary form.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# Authors: Radhika Jagtap
+#          Andreas Hansson
+#          Thomas Grass
+
+from Probe import *
+
+class ElasticTrace(ProbeListenerObject):
+    type = 'ElasticTrace'
+    cxx_header = 'cpu/o3/probe/elastic_trace.hh'
+
+    # Trace files for the following params are created in the output directory.
+    # User is forced to provide these when an instance of this class is 
created.
+    instFetchTraceFile = Param.String(desc="Protobuf trace file name for " \
+                                        "instruction fetch tracing")
+    dataDepTraceFile = Param.String(desc="Protobuf trace file name for " \
+                                    "data dependency tracing")
+    # The dependency window size param must be equal to or greater than the
+    # number of entries in the O3CPU ROB, a typical value is 3 times ROB size
+    depWindowSize = Param.Unsigned(desc="Instruction window size used for " \
+                                    "recording and processing data " \
+                                    "dependencies")
+    # The committed instruction count from which to start tracing
+    startTraceInst = Param.UInt64(0, "The number of committed instructions " \
+                                    "after which to start tracing. Default " \
+                                    "zero means start tracing from first " \
+                                    "committed instruction.")
+
diff -r 93d2a1526103 -r 76f75db08e09 src/cpu/o3/probe/SConscript
--- a/src/cpu/o3/probe/SConscript       Mon Dec 07 16:42:15 2015 -0600
+++ b/src/cpu/o3/probe/SConscript       Mon Dec 07 16:42:15 2015 -0600
@@ -43,3 +43,8 @@
     SimObject('SimpleTrace.py')
     Source('simple_trace.cc')
     DebugFlag('SimpleTrace')
+
+    if env['HAVE_PROTOBUF']:
+        SimObject('ElasticTrace.py')
+        Source('elastic_trace.cc')
+        DebugFlag('ElasticTrace')
diff -r 93d2a1526103 -r 76f75db08e09 src/cpu/o3/probe/elastic_trace.cc
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/src/cpu/o3/probe/elastic_trace.cc Mon Dec 07 16:42:15 2015 -0600
@@ -0,0 +1,939 @@
+/*
+ * Copyright (c) 2013 - 2015 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder.  You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Radhika Jagtap
+ *          Andreas Hansson
+ *          Thomas Grass
+ */
+
+#include "cpu/o3/probe/elastic_trace.hh"
+
+#include "base/callback.hh"
+#include "base/output.hh"
+#include "base/trace.hh"
+#include "cpu/reg_class.hh"
+#include "debug/ElasticTrace.hh"
+#include "mem/packet.hh"
+
+ElasticTrace::ElasticTrace(const ElasticTraceParams* params)
+    :  ProbeListenerObject(params),
+       regEtraceListenersEvent(this),
+       firstWin(true),
+       lastClearedSeqNum(0),
+       depWindowSize(params->depWindowSize),
+       dataTraceStream(nullptr),
+       instTraceStream(nullptr),
+       startTraceInst(params->startTraceInst),
+       allProbesReg(false)
+{
+    cpu = dynamic_cast<FullO3CPU<O3CPUImpl>*>(params->manager);
+    fatal_if(!cpu, "Manager of %s is not of type O3CPU and thus does not "\
+                "support dependency tracing.\n", name());
+
+    fatal_if(depWindowSize == 0, "depWindowSize parameter must be non-zero. "\
+                "Recommended size is 3x ROB size in the O3CPU.\n");
+
+    fatal_if(cpu->numThreads > 1, "numThreads = %i, %s supports tracing for"\
+                "single-threaded workload only", cpu->numThreads, name());
+    // Initialize the protobuf output stream
+    fatal_if(params->instFetchTraceFile == "", "Assign instruction fetch "\
+                "trace file path to instFetchTraceFile");
+    fatal_if(params->dataDepTraceFile == "", "Assign data dependency "\
+                "trace file path to dataDepTraceFile");
+    std::string filename = simout.resolve(name() + "." +
+                                            params->instFetchTraceFile);
+    instTraceStream = new ProtoOutputStream(filename);
+    filename = simout.resolve(name() + "." + params->dataDepTraceFile);
+    dataTraceStream = new ProtoOutputStream(filename);
+    // Create a protobuf message for the header and write it to the stream
+    ProtoMessage::PacketHeader inst_pkt_header;
+    inst_pkt_header.set_obj_id(name());
+    inst_pkt_header.set_tick_freq(SimClock::Frequency);
+    instTraceStream->write(inst_pkt_header);
+    // Create a protobuf message for the header and write it to
+    // the stream
+    ProtoMessage::InstDepRecordHeader data_rec_header;
+    data_rec_header.set_obj_id(name());
+    data_rec_header.set_tick_freq(SimClock::Frequency);
+    data_rec_header.set_window_size(depWindowSize);
+    dataTraceStream->write(data_rec_header);
+    // Register a callback to flush trace records and close the output streams.
+    Callback* cb = new MakeCallback<ElasticTrace,
+        &ElasticTrace::flushTraces>(this);
+    registerExitCallback(cb);
+}
+
+void
+ElasticTrace::regProbeListeners()
+{
+    inform("@%llu: regProbeListeners() called, startTraceInst = %llu",
+        curTick(), startTraceInst);
+    if (startTraceInst == 0) {
+        // If we want to start tracing from the start of the simulation,
+        // register all elastic trace probes now.
+        regEtraceListeners();
+    } else {
+        // Schedule an event to register all elastic trace probes when
+        // specified no. of instructions are committed.
+        cpu->comInstEventQueue[(ThreadID)0]->schedule(&regEtraceListenersEvent,
+                                                      startTraceInst);
+    }
+}
+
+void
+ElasticTrace::regEtraceListeners()
+{
+    assert(!allProbesReg);
+    inform("@%llu: No. of instructions committed = %llu, registering elastic"
+        " probe listeners", curTick(), cpu->numSimulatedInsts());
+    // Create new listeners: provide method to be called upon a notify() for
+    // 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, 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));
+    allProbesReg = true;
+}
+
+void
+ElasticTrace::fetchReqTrace(const RequestPtr &req)
+{
+
+    DPRINTFR(ElasticTrace, "Fetch Req %i,(%lli,%lli,%lli),%i,%i,%lli\n",
+             (MemCmd::ReadReq),
+             req->getPC(), req->getVaddr(), req->getPaddr(),
+             req->getFlags(), req->getSize(), curTick());
+
+    // Create a protobuf message including the request fields necessary to
+    // recreate the request in the TraceCPU.
+    ProtoMessage::Packet inst_fetch_pkt;
+    inst_fetch_pkt.set_tick(curTick());
+    inst_fetch_pkt.set_cmd(MemCmd::ReadReq);
+    inst_fetch_pkt.set_pc(req->getPC());
+    inst_fetch_pkt.set_flags(req->getFlags());
+    inst_fetch_pkt.set_addr(req->getPaddr());
+    inst_fetch_pkt.set_size(req->getSize());
+    // Write the message to the stream.
+    instTraceStream->write(inst_fetch_pkt);
+}
+
+void
+ElasticTrace::recordExecTick(const DynInstPtr &dyn_inst)
+{
+
+    // In a corner case, a retired instruction is propagated backward to the
+    // IEW instruction queue to handle some side-channel information. But we
+    // must not process an instruction again. So we test the sequence number
+    // against the lastClearedSeqNum and skip adding the instruction for such
+    // corner cases.
+    if (dyn_inst->seqNum <= lastClearedSeqNum) {
+        DPRINTFR(ElasticTrace, "[sn:%lli] Ignoring in execute as instruction \
+        has already retired (mostly squashed)", dyn_inst->seqNum);
+        // Do nothing as program has proceeded and this inst has been
+        // propagated backwards to handle something.
+        return;
+    }
+
+    DPRINTFR(ElasticTrace, "[sn:%lli] Execute Tick = %i\n", dyn_inst->seqNum,
+                curTick());
+    // Either the execution info object will already exist if this
+    // instruction had a register dependency recorded in the rename probe
+    // listener before entering execute stage or it will not exist and will
+    // need to be created here.
+    InstExecInfo* exec_info_ptr;
+    auto itr_exec_info = tempStore.find(dyn_inst->seqNum);
+    if (itr_exec_info != tempStore.end()) {
+        exec_info_ptr = itr_exec_info->second;
+    } else {
+        exec_info_ptr = new InstExecInfo;
+        tempStore[dyn_inst->seqNum] = exec_info_ptr;
+    }
+
+    exec_info_ptr->executeTick = curTick();
+    maxTempStoreSize = std::max(tempStore.size(),
+                                (std::size_t)maxTempStoreSize.value());
+}
+
+void
+ElasticTrace::recordToCommTick(const DynInstPtr &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
+    // the tick it started execution. Simply return until we see an instruction
+    // that is found in the tempStore.
+    auto itr_exec_info = tempStore.find(dyn_inst->seqNum);
+    if (itr_exec_info == tempStore.end()) {
+        DPRINTFR(ElasticTrace, "recordToCommTick: [sn:%lli] Not in temp store,"
+                    " skipping.\n", dyn_inst->seqNum);
+        return;
+    }
+
+    DPRINTFR(ElasticTrace, "[sn:%lli] To Commit Tick = %i\n", dyn_inst->seqNum,
+                curTick());
+    InstExecInfo* exec_info_ptr = itr_exec_info->second;
+    exec_info_ptr->toCommitTick = curTick();
+
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to