trace_gen.hh revision 12844
17405SAli.Saidi@ARM.com/*
28868SMatt.Horsnell@arm.com * Copyright (c) 2012-2013, 2017-2018 ARM Limited
37405SAli.Saidi@ARM.com * All rights reserved
47405SAli.Saidi@ARM.com *
57405SAli.Saidi@ARM.com * The license below extends only to copyright in the software and shall
67405SAli.Saidi@ARM.com * not be construed as granting a license to any other intellectual
77405SAli.Saidi@ARM.com * property including but not limited to intellectual property relating
87405SAli.Saidi@ARM.com * to a hardware implementation of the functionality of the software
97405SAli.Saidi@ARM.com * licensed here under.  You may use the software subject to the license
107405SAli.Saidi@ARM.com * terms below provided that you ensure that this notice is replicated
117405SAli.Saidi@ARM.com * unmodified and in its entirety in all distributions of the software,
127405SAli.Saidi@ARM.com * modified or unmodified, in source code or in binary form.
137405SAli.Saidi@ARM.com *
147405SAli.Saidi@ARM.com * Redistribution and use in source and binary forms, with or without
157405SAli.Saidi@ARM.com * modification, are permitted provided that the following conditions are
167405SAli.Saidi@ARM.com * met: redistributions of source code must retain the above copyright
177405SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer;
187405SAli.Saidi@ARM.com * redistributions in binary form must reproduce the above copyright
197405SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer in the
207405SAli.Saidi@ARM.com * documentation and/or other materials provided with the distribution;
217405SAli.Saidi@ARM.com * neither the name of the copyright holders nor the names of its
227405SAli.Saidi@ARM.com * contributors may be used to endorse or promote products derived from
237405SAli.Saidi@ARM.com * this software without specific prior written permission.
247405SAli.Saidi@ARM.com *
257405SAli.Saidi@ARM.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
267405SAli.Saidi@ARM.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
277405SAli.Saidi@ARM.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
287405SAli.Saidi@ARM.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
297405SAli.Saidi@ARM.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
307405SAli.Saidi@ARM.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
317405SAli.Saidi@ARM.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
327405SAli.Saidi@ARM.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
337405SAli.Saidi@ARM.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
347405SAli.Saidi@ARM.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
357405SAli.Saidi@ARM.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
367405SAli.Saidi@ARM.com *
377405SAli.Saidi@ARM.com * Authors: Thomas Grass
387405SAli.Saidi@ARM.com *          Andreas Hansson
397405SAli.Saidi@ARM.com *          Sascha Bischoff
407405SAli.Saidi@ARM.com *          Neha Agarwal
417405SAli.Saidi@ARM.com */
429050Schander.sudanthi@arm.com
438887Sgeoffrey.blake@arm.com/**
448232Snate@binkert.org * @file
458232Snate@binkert.org * Declaration of the trace generator that reads a trace file
467678Sgblack@eecs.umich.edu * and plays the transactions.
478059SAli.Saidi@ARM.com */
488284SAli.Saidi@ARM.com
497405SAli.Saidi@ARM.com#ifndef __CPU_TRAFFIC_GEN_TRACE_GEN_HH__
507405SAli.Saidi@ARM.com#define __CPU_TRAFFIC_GEN_TRACE_GEN_HH__
517405SAli.Saidi@ARM.com
527405SAli.Saidi@ARM.com#include "base/bitfield.hh"
537427Sgblack@eecs.umich.edu#include "base/intmath.hh"
547427Sgblack@eecs.umich.edu#include "base_gen.hh"
557427Sgblack@eecs.umich.edu#include "mem/packet.hh"
567427Sgblack@eecs.umich.edu#include "proto/protoio.hh"
578299Schander.sudanthi@arm.com
587427Sgblack@eecs.umich.edu/**
597427Sgblack@eecs.umich.edu * The trace replay generator reads a trace file and plays
607427Sgblack@eecs.umich.edu * back the transactions. The trace is offset with respect to
617427Sgblack@eecs.umich.edu * the time when the state was entered.
627427Sgblack@eecs.umich.edu */
637427Sgblack@eecs.umich.educlass TraceGen : public BaseGen
647427Sgblack@eecs.umich.edu{
657604SGene.Wu@arm.com
667427Sgblack@eecs.umich.edu  private:
677427Sgblack@eecs.umich.edu
687427Sgblack@eecs.umich.edu    /**
697427Sgblack@eecs.umich.edu     * This struct stores a line in the trace file.
707427Sgblack@eecs.umich.edu     */
717427Sgblack@eecs.umich.edu    struct TraceElement {
727427Sgblack@eecs.umich.edu
737427Sgblack@eecs.umich.edu        /** Specifies if the request is to be a read or a write */
747427Sgblack@eecs.umich.edu        MemCmd cmd;
757427Sgblack@eecs.umich.edu
769050Schander.sudanthi@arm.com        /** The address for the request */
778299Schander.sudanthi@arm.com        Addr addr;
788299Schander.sudanthi@arm.com
797427Sgblack@eecs.umich.edu        /** The size of the access for the request */
807427Sgblack@eecs.umich.edu        Addr blocksize;
817427Sgblack@eecs.umich.edu
827427Sgblack@eecs.umich.edu        /** The time at which the request should be sent */
837427Sgblack@eecs.umich.edu        Tick tick;
847427Sgblack@eecs.umich.edu
857427Sgblack@eecs.umich.edu        /** Potential request flags to use */
867427Sgblack@eecs.umich.edu        Request::FlagsType flags;
877427Sgblack@eecs.umich.edu
887427Sgblack@eecs.umich.edu        /**
897427Sgblack@eecs.umich.edu         * Check validity of this element.
907427Sgblack@eecs.umich.edu         *
917427Sgblack@eecs.umich.edu         * @return if this element is valid
927427Sgblack@eecs.umich.edu         */
937427Sgblack@eecs.umich.edu        bool isValid() const {
947427Sgblack@eecs.umich.edu            return cmd != MemCmd::InvalidCmd;
957427Sgblack@eecs.umich.edu        }
967427Sgblack@eecs.umich.edu
977427Sgblack@eecs.umich.edu        /**
987427Sgblack@eecs.umich.edu         * Make this element invalid.
997427Sgblack@eecs.umich.edu         */
1007427Sgblack@eecs.umich.edu        void clear() {
1017427Sgblack@eecs.umich.edu            cmd = MemCmd::InvalidCmd;
1027427Sgblack@eecs.umich.edu        }
1037427Sgblack@eecs.umich.edu    };
1047427Sgblack@eecs.umich.edu
1057427Sgblack@eecs.umich.edu    /**
1067436Sdam.sunwoo@arm.com     * The InputStream encapsulates a trace file and the
1077436Sdam.sunwoo@arm.com     * internal buffers and populates TraceElements based on
1087436Sdam.sunwoo@arm.com     * the input.
1097436Sdam.sunwoo@arm.com     */
1107436Sdam.sunwoo@arm.com    class InputStream
1117436Sdam.sunwoo@arm.com    {
1127436Sdam.sunwoo@arm.com
1137436Sdam.sunwoo@arm.com      private:
1147436Sdam.sunwoo@arm.com
1157436Sdam.sunwoo@arm.com        /// Input file stream for the protobuf trace
1167436Sdam.sunwoo@arm.com        ProtoInputStream trace;
1177436Sdam.sunwoo@arm.com
1187436Sdam.sunwoo@arm.com      public:
1197436Sdam.sunwoo@arm.com
1207436Sdam.sunwoo@arm.com        /**
1217436Sdam.sunwoo@arm.com         * Create a trace input stream for a given file name.
1227436Sdam.sunwoo@arm.com         *
1237436Sdam.sunwoo@arm.com         * @param filename Path to the file to read from
1247436Sdam.sunwoo@arm.com         */
1257436Sdam.sunwoo@arm.com        InputStream(const std::string& filename);
1267436Sdam.sunwoo@arm.com
1277436Sdam.sunwoo@arm.com        /**
1287436Sdam.sunwoo@arm.com         * Reset the stream such that it can be played once
1297436Sdam.sunwoo@arm.com         * again.
1307436Sdam.sunwoo@arm.com         */
1317436Sdam.sunwoo@arm.com        void reset();
1327436Sdam.sunwoo@arm.com
1337436Sdam.sunwoo@arm.com        /**
1347436Sdam.sunwoo@arm.com         * Check the trace header to make sure that it is of the right
1357436Sdam.sunwoo@arm.com         * format.
1367436Sdam.sunwoo@arm.com         */
1377436Sdam.sunwoo@arm.com        void init();
1387644Sali.saidi@arm.com
1397644Sali.saidi@arm.com        /**
1408147SAli.Saidi@ARM.com         * Attempt to read a trace element from the stream,
1418147SAli.Saidi@ARM.com         * and also notify the caller if the end of the file
1428147SAli.Saidi@ARM.com         * was reached.
1438520SAli.Saidi@ARM.com         *
1448147SAli.Saidi@ARM.com         * @param element Trace element to populate
1458147SAli.Saidi@ARM.com         * @return True if an element could be read successfully
1468147SAli.Saidi@ARM.com         */
1478147SAli.Saidi@ARM.com        bool read(TraceElement& element);
1488147SAli.Saidi@ARM.com    };
1498147SAli.Saidi@ARM.com
1507427Sgblack@eecs.umich.edu  public:
1517427Sgblack@eecs.umich.edu
1527427Sgblack@eecs.umich.edu    /**
1537405SAli.Saidi@ARM.com     * Create a trace generator.
1547405SAli.Saidi@ARM.com     *
1557405SAli.Saidi@ARM.com     * @param obj SimObject owning this sequence generator
1567405SAli.Saidi@ARM.com     * @param master_id MasterID related to the memory requests
1577614Sminkyu.jeong@arm.com     * @param _duration duration of this state before transitioning
1587614Sminkyu.jeong@arm.com     * @param trace_file File to read the transactions from
1597614Sminkyu.jeong@arm.com     * @param addr_offset Positive offset to add to trace address
1607614Sminkyu.jeong@arm.com     */
1617614Sminkyu.jeong@arm.com    TraceGen(SimObject &obj, MasterID master_id, Tick _duration,
1627614Sminkyu.jeong@arm.com             const std::string& trace_file, Addr addr_offset)
1637614Sminkyu.jeong@arm.com        : BaseGen(obj, master_id, _duration),
1647614Sminkyu.jeong@arm.com          trace(trace_file),
1657614Sminkyu.jeong@arm.com          tickOffset(0),
1667614Sminkyu.jeong@arm.com          addrOffset(addr_offset),
1677614Sminkyu.jeong@arm.com          traceComplete(false)
1687405SAli.Saidi@ARM.com    {
1697405SAli.Saidi@ARM.com    }
1707405SAli.Saidi@ARM.com
1717405SAli.Saidi@ARM.com    void enter();
1727405SAli.Saidi@ARM.com
1737405SAli.Saidi@ARM.com    PacketPtr getNextPacket();
1749050Schander.sudanthi@arm.com
1759050Schander.sudanthi@arm.com    void exit();
1767405SAli.Saidi@ARM.com
1777405SAli.Saidi@ARM.com    /**
1787720Sgblack@eecs.umich.edu     * Returns the tick when the next request should be generated. If
1797720Sgblack@eecs.umich.edu     * the end of the file has been reached, it returns MaxTick to
1807720Sgblack@eecs.umich.edu     * indicate that there will be no more requests.
1817405SAli.Saidi@ARM.com     */
1827405SAli.Saidi@ARM.com    Tick nextPacketTick(bool elastic, Tick delay) const;
1837757SAli.Saidi@ARM.com
1847405SAli.Saidi@ARM.com  private:
1857405SAli.Saidi@ARM.com
1867757SAli.Saidi@ARM.com    /** Input stream used for reading the input trace file */
1877405SAli.Saidi@ARM.com    InputStream trace;
1888284SAli.Saidi@ARM.com
1899050Schander.sudanthi@arm.com    /** Store the current and next element in the trace */
1909050Schander.sudanthi@arm.com    TraceElement currElement;
1918873SAli.Saidi@ARM.com    TraceElement nextElement;
1929050Schander.sudanthi@arm.com
1939050Schander.sudanthi@arm.com    /**
1949050Schander.sudanthi@arm.com     * Stores the time when the state was entered. This is to add an
1959050Schander.sudanthi@arm.com     * offset to the times stored in the trace file. This is mutable
1969050Schander.sudanthi@arm.com     * to allow us to change it as part of nextPacketTick.
1979050Schander.sudanthi@arm.com     */
1989050Schander.sudanthi@arm.com    mutable Tick tickOffset;
1999050Schander.sudanthi@arm.com
2008284SAli.Saidi@ARM.com    /**
2018468Swade.walker@arm.com     * Offset for memory requests. Used to shift the trace
2028468Swade.walker@arm.com     * away from the CPU address space.
2038468Swade.walker@arm.com     */
2048468Swade.walker@arm.com    Addr addrOffset;
2058468Swade.walker@arm.com
2068284SAli.Saidi@ARM.com    /**
2078284SAli.Saidi@ARM.com     * Set to true when the trace replay for one instance of
2088284SAli.Saidi@ARM.com     * state is complete.
2097405SAli.Saidi@ARM.com     */
2107731SAli.Saidi@ARM.com    bool traceComplete;
2118468Swade.walker@arm.com};
2128468Swade.walker@arm.com
2138468Swade.walker@arm.com#endif
2147405SAli.Saidi@ARM.com