trace_gen.hh revision 12811
12623SN/A/* 22623SN/A * Copyright (c) 2012-2013, 2017-2018 ARM Limited 32623SN/A * All rights reserved 42623SN/A * 52623SN/A * The license below extends only to copyright in the software and shall 62623SN/A * not be construed as granting a license to any other intellectual 72623SN/A * property including but not limited to intellectual property relating 82623SN/A * to a hardware implementation of the functionality of the software 92623SN/A * licensed here under. You may use the software subject to the license 102623SN/A * terms below provided that you ensure that this notice is replicated 112623SN/A * unmodified and in its entirety in all distributions of the software, 122623SN/A * modified or unmodified, in source code or in binary form. 132623SN/A * 142623SN/A * Redistribution and use in source and binary forms, with or without 152623SN/A * modification, are permitted provided that the following conditions are 162623SN/A * met: redistributions of source code must retain the above copyright 172623SN/A * notice, this list of conditions and the following disclaimer; 182623SN/A * redistributions in binary form must reproduce the above copyright 192623SN/A * notice, this list of conditions and the following disclaimer in the 202623SN/A * documentation and/or other materials provided with the distribution; 212623SN/A * neither the name of the copyright holders nor the names of its 222623SN/A * contributors may be used to endorse or promote products derived from 232623SN/A * this software without specific prior written permission. 242623SN/A * 252623SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 262623SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 272665Ssaidi@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 282665Ssaidi@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 292623SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 302623SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 313170Sstever@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 323806Ssaidi@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 332623SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 344040Ssaidi@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 352623SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 362623SN/A * 373348Sbinkertn@umich.edu * Authors: Thomas Grass 383348Sbinkertn@umich.edu * Andreas Hansson 392623SN/A * Sascha Bischoff 402901Ssaidi@eecs.umich.edu * Neha Agarwal 412623SN/A */ 422623SN/A 432623SN/A/** 442623SN/A * @file 452623SN/A * Declaration of the trace generator that reads a trace file 462623SN/A * and plays the transactions. 472623SN/A */ 482623SN/A 492623SN/A#ifndef __CPU_TRAFFIC_GEN_TRACE_GEN_HH__ 502623SN/A#define __CPU_TRAFFIC_GEN_TRACE_GEN_HH__ 512623SN/A 522623SN/A#include "base/bitfield.hh" 532623SN/A#include "base/intmath.hh" 542623SN/A#include "base_gen.hh" 552623SN/A#include "mem/packet.hh" 562623SN/A#include "proto/protoio.hh" 572623SN/A 582623SN/A/** 592623SN/A * The trace replay generator reads a trace file and plays 602623SN/A * back the transactions. The trace is offset with respect to 612623SN/A * the time when the state was entered. 622623SN/A */ 632856Srdreslin@umich.educlass TraceGen : public BaseGen 642856Srdreslin@umich.edu{ 652856Srdreslin@umich.edu 662856Srdreslin@umich.edu private: 672856Srdreslin@umich.edu 682856Srdreslin@umich.edu /** 692856Srdreslin@umich.edu * This struct stores a line in the trace file. 702856Srdreslin@umich.edu */ 712856Srdreslin@umich.edu struct TraceElement { 722856Srdreslin@umich.edu 732623SN/A /** Specifies if the request is to be a read or a write */ 742623SN/A MemCmd cmd; 752623SN/A 762623SN/A /** The address for the request */ 772623SN/A Addr addr; 782623SN/A 792680Sktlim@umich.edu /** The size of the access for the request */ 802680Sktlim@umich.edu Addr blocksize; 812623SN/A 822623SN/A /** The time at which the request should be sent */ 832680Sktlim@umich.edu Tick tick; 842623SN/A 852623SN/A /** Potential request flags to use */ 862623SN/A Request::FlagsType flags; 872623SN/A 882623SN/A /** 893349Sbinkertn@umich.edu * Check validity of this element. 902623SN/A * 913184Srdreslin@umich.edu * @return if this element is valid 922623SN/A */ 932623SN/A bool isValid() const { 942623SN/A return cmd != MemCmd::InvalidCmd; 952623SN/A } 963349Sbinkertn@umich.edu 972623SN/A /** 983310Srdreslin@umich.edu * Make this element invalid. 993649Srdreslin@umich.edu */ 1002623SN/A void clear() { 1012623SN/A cmd = MemCmd::InvalidCmd; 1022623SN/A } 1033349Sbinkertn@umich.edu }; 1042623SN/A 1053184Srdreslin@umich.edu /** 1063184Srdreslin@umich.edu * The InputStream encapsulates a trace file and the 1072623SN/A * internal buffers and populates TraceElements based on 1082623SN/A * the input. 1092623SN/A */ 1102623SN/A class InputStream 1112623SN/A { 1123647Srdreslin@umich.edu 1133647Srdreslin@umich.edu private: 1143647Srdreslin@umich.edu 1153647Srdreslin@umich.edu /// Input file stream for the protobuf trace 1163647Srdreslin@umich.edu ProtoInputStream trace; 1172626SN/A 1183647Srdreslin@umich.edu public: 1192626SN/A 1202623SN/A /** 1212623SN/A * Create a trace input stream for a given file name. 1222623SN/A * 1232657Ssaidi@eecs.umich.edu * @param filename Path to the file to read from 1242623SN/A */ 1252623SN/A InputStream(const std::string& filename); 1262623SN/A 1272623SN/A /** 1282623SN/A * Reset the stream such that it can be played once 1292623SN/A * again. 1302623SN/A */ 1312623SN/A void reset(); 1322623SN/A 1332640Sstever@eecs.umich.edu /** 1342623SN/A * Check the trace header to make sure that it is of the right 1352623SN/A * format. 1362623SN/A */ 1373647Srdreslin@umich.edu void init(); 1383647Srdreslin@umich.edu 1393647Srdreslin@umich.edu /** 1402663Sstever@eecs.umich.edu * Attempt to read a trace element from the stream, 1413170Sstever@eecs.umich.edu * and also notify the caller if the end of the file 1424022Sstever@eecs.umich.edu * was reached. 1432623SN/A * 1442623SN/A * @param element Trace element to populate 1452663Sstever@eecs.umich.edu * @return True if an element could be read successfully 1463170Sstever@eecs.umich.edu */ 1474022Sstever@eecs.umich.edu bool read(TraceElement& element); 1482641Sstever@eecs.umich.edu }; 1492623SN/A 1502623SN/A public: 1512663Sstever@eecs.umich.edu 1523170Sstever@eecs.umich.edu /** 1534022Sstever@eecs.umich.edu * Create a trace generator. 1542641Sstever@eecs.umich.edu * 1554040Ssaidi@eecs.umich.edu * @param gen Traffic generator owning this sequence generator 1564040Ssaidi@eecs.umich.edu * @param _duration duration of this state before transitioning 1572623SN/A * @param trace_file File to read the transactions from 1582623SN/A * @param addr_offset Positive offset to add to trace address 1592623SN/A */ 1602623SN/A TraceGen(BaseTrafficGen &gen, Tick _duration, 1612623SN/A const std::string& trace_file, Addr addr_offset) 1622623SN/A : BaseGen(gen, _duration), 1632623SN/A trace(trace_file), 1642623SN/A tickOffset(0), 1652623SN/A addrOffset(addr_offset), 1662623SN/A traceComplete(false) 1672915Sktlim@umich.edu { 1682915Sktlim@umich.edu } 1693177Shsul@eecs.umich.edu 1703177Shsul@eecs.umich.edu void enter(); 1713145Shsul@eecs.umich.edu 1722623SN/A PacketPtr getNextPacket(); 1732623SN/A 1742623SN/A void exit(); 1752623SN/A 1762623SN/A /** 1772623SN/A * Returns the tick when the next request should be generated. If 1782623SN/A * the end of the file has been reached, it returns MaxTick to 1792915Sktlim@umich.edu * indicate that there will be no more requests. 1802915Sktlim@umich.edu */ 1813177Shsul@eecs.umich.edu Tick nextPacketTick(bool elastic, Tick delay) const; 1823145Shsul@eecs.umich.edu 1832915Sktlim@umich.edu private: 1842915Sktlim@umich.edu 1852915Sktlim@umich.edu /** Input stream used for reading the input trace file */ 1862915Sktlim@umich.edu InputStream trace; 1872915Sktlim@umich.edu 1882915Sktlim@umich.edu /** Store the current and next element in the trace */ 1893324Shsul@eecs.umich.edu TraceElement currElement; 1903201Shsul@eecs.umich.edu TraceElement nextElement; 1913324Shsul@eecs.umich.edu 1923324Shsul@eecs.umich.edu /** 1933324Shsul@eecs.umich.edu * Stores the time when the state was entered. This is to add an 1943431Sgblack@eecs.umich.edu * offset to the times stored in the trace file. This is mutable 1953495Sktlim@umich.edu * to allow us to change it as part of nextPacketTick. 1963431Sgblack@eecs.umich.edu */ 1973324Shsul@eecs.umich.edu mutable Tick tickOffset; 1982915Sktlim@umich.edu 1992623SN/A /** 2002623SN/A * Offset for memory requests. Used to shift the trace 2012623SN/A * away from the CPU address space. 2022798Sktlim@umich.edu */ 2032623SN/A Addr addrOffset; 2042798Sktlim@umich.edu 2052798Sktlim@umich.edu /** 2062623SN/A * Set to true when the trace replay for one instance of 2072798Sktlim@umich.edu * state is complete. 2082623SN/A */ 2092623SN/A bool traceComplete; 2102623SN/A}; 2112623SN/A 2122623SN/A#endif 2132623SN/A