112396SRiken.Gohil@arm.com/*
212811Sandreas.sandberg@arm.com * Copyright (c) 2012-2013, 2017-2018 ARM Limited
312396SRiken.Gohil@arm.com * All rights reserved
412396SRiken.Gohil@arm.com *
512396SRiken.Gohil@arm.com * The license below extends only to copyright in the software and shall
612396SRiken.Gohil@arm.com * not be construed as granting a license to any other intellectual
712396SRiken.Gohil@arm.com * property including but not limited to intellectual property relating
812396SRiken.Gohil@arm.com * to a hardware implementation of the functionality of the software
912396SRiken.Gohil@arm.com * licensed here under.  You may use the software subject to the license
1012396SRiken.Gohil@arm.com * terms below provided that you ensure that this notice is replicated
1112396SRiken.Gohil@arm.com * unmodified and in its entirety in all distributions of the software,
1212396SRiken.Gohil@arm.com * modified or unmodified, in source code or in binary form.
1312396SRiken.Gohil@arm.com *
1412396SRiken.Gohil@arm.com * Redistribution and use in source and binary forms, with or without
1512396SRiken.Gohil@arm.com * modification, are permitted provided that the following conditions are
1612396SRiken.Gohil@arm.com * met: redistributions of source code must retain the above copyright
1712396SRiken.Gohil@arm.com * notice, this list of conditions and the following disclaimer;
1812396SRiken.Gohil@arm.com * redistributions in binary form must reproduce the above copyright
1912396SRiken.Gohil@arm.com * notice, this list of conditions and the following disclaimer in the
2012396SRiken.Gohil@arm.com * documentation and/or other materials provided with the distribution;
2112396SRiken.Gohil@arm.com * neither the name of the copyright holders nor the names of its
2212396SRiken.Gohil@arm.com * contributors may be used to endorse or promote products derived from
2312396SRiken.Gohil@arm.com * this software without specific prior written permission.
2412396SRiken.Gohil@arm.com *
2512396SRiken.Gohil@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2612396SRiken.Gohil@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2712396SRiken.Gohil@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2812396SRiken.Gohil@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2912396SRiken.Gohil@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3012396SRiken.Gohil@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3112396SRiken.Gohil@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3212396SRiken.Gohil@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3312396SRiken.Gohil@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3412396SRiken.Gohil@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3512396SRiken.Gohil@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3612396SRiken.Gohil@arm.com *
3712396SRiken.Gohil@arm.com * Authors: Thomas Grass
3812396SRiken.Gohil@arm.com *          Andreas Hansson
3912396SRiken.Gohil@arm.com *          Sascha Bischoff
4012396SRiken.Gohil@arm.com *          Neha Agarwal
4112396SRiken.Gohil@arm.com */
4212396SRiken.Gohil@arm.com
4312396SRiken.Gohil@arm.com/**
4412396SRiken.Gohil@arm.com * @file
4512396SRiken.Gohil@arm.com * Declaration of the base generator class for all generators.
4612396SRiken.Gohil@arm.com */
4712396SRiken.Gohil@arm.com
4812396SRiken.Gohil@arm.com#ifndef __CPU_TRAFFIC_GEN_BASE_GEN_HH__
4912396SRiken.Gohil@arm.com#define __CPU_TRAFFIC_GEN_BASE_GEN_HH__
5012396SRiken.Gohil@arm.com
5112396SRiken.Gohil@arm.com#include "base/bitfield.hh"
5212396SRiken.Gohil@arm.com#include "base/intmath.hh"
5312396SRiken.Gohil@arm.com#include "mem/packet.hh"
5412396SRiken.Gohil@arm.com
5512811Sandreas.sandberg@arm.comclass BaseTrafficGen;
5612811Sandreas.sandberg@arm.com
5712396SRiken.Gohil@arm.com/**
5812396SRiken.Gohil@arm.com * Base class for all generators, with the shared functionality and
5912396SRiken.Gohil@arm.com * virtual functions for entering, executing and leaving the
6012396SRiken.Gohil@arm.com * generator.
6112396SRiken.Gohil@arm.com */
6212396SRiken.Gohil@arm.comclass BaseGen
6312396SRiken.Gohil@arm.com{
6412396SRiken.Gohil@arm.com
6512396SRiken.Gohil@arm.com  protected:
6612396SRiken.Gohil@arm.com
6712396SRiken.Gohil@arm.com    /** Name to use for status and debug printing */
6812396SRiken.Gohil@arm.com    const std::string _name;
6912396SRiken.Gohil@arm.com
7012396SRiken.Gohil@arm.com    /** The MasterID used for generating requests */
7112396SRiken.Gohil@arm.com    const MasterID masterID;
7212396SRiken.Gohil@arm.com
7312396SRiken.Gohil@arm.com    /**
7412396SRiken.Gohil@arm.com     * Generate a new request and associated packet
7512396SRiken.Gohil@arm.com     *
7612396SRiken.Gohil@arm.com     * @param addr Physical address to use
7712396SRiken.Gohil@arm.com     * @param size Size of the request
7812396SRiken.Gohil@arm.com     * @param cmd Memory command to send
7912396SRiken.Gohil@arm.com     * @param flags Optional request flags
8012396SRiken.Gohil@arm.com     */
8112396SRiken.Gohil@arm.com    PacketPtr getPacket(Addr addr, unsigned size, const MemCmd& cmd,
8212396SRiken.Gohil@arm.com                        Request::FlagsType flags = 0);
8312396SRiken.Gohil@arm.com
8412396SRiken.Gohil@arm.com  public:
8512396SRiken.Gohil@arm.com
8612396SRiken.Gohil@arm.com    /** Time to spend in this state */
8712396SRiken.Gohil@arm.com    const Tick duration;
8812396SRiken.Gohil@arm.com
8912396SRiken.Gohil@arm.com    /**
9012396SRiken.Gohil@arm.com     * Create a base generator.
9112396SRiken.Gohil@arm.com     *
9212844Sgiacomo.travaglini@arm.com     * @param obj simobject owning the generator
9312396SRiken.Gohil@arm.com     * @param master_id MasterID set on each request
9412396SRiken.Gohil@arm.com     * @param _duration duration of this state before transitioning
9512396SRiken.Gohil@arm.com     */
9612844Sgiacomo.travaglini@arm.com    BaseGen(SimObject &obj, MasterID master_id, Tick _duration);
9712396SRiken.Gohil@arm.com
9812396SRiken.Gohil@arm.com    virtual ~BaseGen() { }
9912396SRiken.Gohil@arm.com
10012396SRiken.Gohil@arm.com    /**
10112396SRiken.Gohil@arm.com     * Get the name, useful for DPRINTFs.
10212396SRiken.Gohil@arm.com     *
10312396SRiken.Gohil@arm.com     * @return the given name
10412396SRiken.Gohil@arm.com     */
10512396SRiken.Gohil@arm.com    std::string name() const { return _name; }
10612396SRiken.Gohil@arm.com
10712396SRiken.Gohil@arm.com    /**
10812396SRiken.Gohil@arm.com     * Enter this generator state.
10912396SRiken.Gohil@arm.com     */
11012396SRiken.Gohil@arm.com    virtual void enter() = 0;
11112396SRiken.Gohil@arm.com
11212396SRiken.Gohil@arm.com    /**
11312396SRiken.Gohil@arm.com     * Get the next generated packet.
11412396SRiken.Gohil@arm.com     *
11512396SRiken.Gohil@arm.com     * @return A packet to be sent at the current tick
11612396SRiken.Gohil@arm.com     */
11712396SRiken.Gohil@arm.com    virtual PacketPtr getNextPacket() = 0;
11812396SRiken.Gohil@arm.com
11912396SRiken.Gohil@arm.com    /**
12012396SRiken.Gohil@arm.com     * Exit this generator state. By default do nothing.
12112396SRiken.Gohil@arm.com     */
12212396SRiken.Gohil@arm.com    virtual void exit() { };
12312396SRiken.Gohil@arm.com
12412396SRiken.Gohil@arm.com    /**
12512396SRiken.Gohil@arm.com     * Determine the tick when the next packet is available. MaxTick
12612396SRiken.Gohil@arm.com     * means that there will not be any further packets in the current
12712396SRiken.Gohil@arm.com     * activation cycle of the generator.
12812396SRiken.Gohil@arm.com     *
12912396SRiken.Gohil@arm.com     * @param elastic should the injection respond to flow control or not
13012396SRiken.Gohil@arm.com     * @param delay time the previous packet spent waiting
13112396SRiken.Gohil@arm.com     * @return next tick when a packet is available
13212396SRiken.Gohil@arm.com     */
13312396SRiken.Gohil@arm.com    virtual Tick nextPacketTick(bool elastic, Tick delay) const = 0;
13412396SRiken.Gohil@arm.com
13512396SRiken.Gohil@arm.com};
13612396SRiken.Gohil@arm.com
13712811Sandreas.sandberg@arm.comclass StochasticGen : public BaseGen
13812811Sandreas.sandberg@arm.com{
13912811Sandreas.sandberg@arm.com  public:
14012844Sgiacomo.travaglini@arm.com    StochasticGen(SimObject &obj,
14112844Sgiacomo.travaglini@arm.com                  MasterID master_id, Tick _duration,
14212844Sgiacomo.travaglini@arm.com                  Addr start_addr, Addr end_addr,
14312844Sgiacomo.travaglini@arm.com                  Addr _blocksize, Addr cacheline_size,
14412811Sandreas.sandberg@arm.com                  Tick min_period, Tick max_period,
14512811Sandreas.sandberg@arm.com                  uint8_t read_percent, Addr data_limit);
14612811Sandreas.sandberg@arm.com
14712811Sandreas.sandberg@arm.com  protected:
14812811Sandreas.sandberg@arm.com    /** Start of address range */
14912811Sandreas.sandberg@arm.com    const Addr startAddr;
15012811Sandreas.sandberg@arm.com
15112811Sandreas.sandberg@arm.com    /** End of address range */
15212811Sandreas.sandberg@arm.com    const Addr endAddr;
15312811Sandreas.sandberg@arm.com
15412811Sandreas.sandberg@arm.com    /** Blocksize and address increment */
15512811Sandreas.sandberg@arm.com    const Addr blocksize;
15612811Sandreas.sandberg@arm.com
15712844Sgiacomo.travaglini@arm.com    /** Cache line size in the simulated system */
15812844Sgiacomo.travaglini@arm.com    const Addr cacheLineSize;
15912844Sgiacomo.travaglini@arm.com
16012811Sandreas.sandberg@arm.com    /** Request generation period */
16112811Sandreas.sandberg@arm.com    const Tick minPeriod;
16212811Sandreas.sandberg@arm.com    const Tick maxPeriod;
16312811Sandreas.sandberg@arm.com
16412811Sandreas.sandberg@arm.com    /**
16512811Sandreas.sandberg@arm.com     * Percent of generated transactions that should be reads
16612811Sandreas.sandberg@arm.com     */
16712811Sandreas.sandberg@arm.com    const uint8_t readPercent;
16812811Sandreas.sandberg@arm.com
16912811Sandreas.sandberg@arm.com    /** Maximum amount of data to manipulate */
17012811Sandreas.sandberg@arm.com    const Addr dataLimit;
17112811Sandreas.sandberg@arm.com};
17212811Sandreas.sandberg@arm.com
17312396SRiken.Gohil@arm.com#endif
174