base.hh revision 12919
112810Sandreas.sandberg@arm.com/* 212810Sandreas.sandberg@arm.com * Copyright (c) 2012-2013, 2016-2018 ARM Limited 312810Sandreas.sandberg@arm.com * All rights reserved 412810Sandreas.sandberg@arm.com * 512810Sandreas.sandberg@arm.com * The license below extends only to copyright in the software and shall 612810Sandreas.sandberg@arm.com * not be construed as granting a license to any other intellectual 712810Sandreas.sandberg@arm.com * property including but not limited to intellectual property relating 812810Sandreas.sandberg@arm.com * to a hardware implementation of the functionality of the software 912810Sandreas.sandberg@arm.com * licensed hereunder. You may use the software subject to the license 1012810Sandreas.sandberg@arm.com * terms below provided that you ensure that this notice is replicated 1112810Sandreas.sandberg@arm.com * unmodified and in its entirety in all distributions of the software, 1212810Sandreas.sandberg@arm.com * modified or unmodified, in source code or in binary form. 1312810Sandreas.sandberg@arm.com * 1412810Sandreas.sandberg@arm.com * Redistribution and use in source and binary forms, with or without 1512810Sandreas.sandberg@arm.com * modification, are permitted provided that the following conditions are 1612810Sandreas.sandberg@arm.com * met: redistributions of source code must retain the above copyright 1712810Sandreas.sandberg@arm.com * notice, this list of conditions and the following disclaimer; 1812810Sandreas.sandberg@arm.com * redistributions in binary form must reproduce the above copyright 1912810Sandreas.sandberg@arm.com * notice, this list of conditions and the following disclaimer in the 2012810Sandreas.sandberg@arm.com * documentation and/or other materials provided with the distribution; 2112810Sandreas.sandberg@arm.com * neither the name of the copyright holders nor the names of its 2212810Sandreas.sandberg@arm.com * contributors may be used to endorse or promote products derived from 2312810Sandreas.sandberg@arm.com * this software without specific prior written permission. 2412810Sandreas.sandberg@arm.com * 2512810Sandreas.sandberg@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2612810Sandreas.sandberg@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2712810Sandreas.sandberg@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2812810Sandreas.sandberg@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2912810Sandreas.sandberg@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3012810Sandreas.sandberg@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3112810Sandreas.sandberg@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3212810Sandreas.sandberg@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3312810Sandreas.sandberg@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3412810Sandreas.sandberg@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3512810Sandreas.sandberg@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3612810Sandreas.sandberg@arm.com * 3712810Sandreas.sandberg@arm.com * Authors: Thomas Grass 3812810Sandreas.sandberg@arm.com * Andreas Hansson 3912810Sandreas.sandberg@arm.com * Sascha Bischoff 4012810Sandreas.sandberg@arm.com */ 4112810Sandreas.sandberg@arm.com 4212810Sandreas.sandberg@arm.com#ifndef __CPU_TRAFFIC_GEN_BASE_HH__ 4312810Sandreas.sandberg@arm.com#define __CPU_TRAFFIC_GEN_BASE_HH__ 4412810Sandreas.sandberg@arm.com 4512810Sandreas.sandberg@arm.com#include <memory> 4612810Sandreas.sandberg@arm.com#include <tuple> 4712810Sandreas.sandberg@arm.com 4812810Sandreas.sandberg@arm.com#include "base/statistics.hh" 4912810Sandreas.sandberg@arm.com#include "mem/mem_object.hh" 5012810Sandreas.sandberg@arm.com#include "mem/qport.hh" 5112810Sandreas.sandberg@arm.com 5212810Sandreas.sandberg@arm.comclass BaseGen; 5312919Sgiacomo.travaglini@arm.comclass StreamGen; 5412810Sandreas.sandberg@arm.comclass System; 5512810Sandreas.sandberg@arm.comstruct BaseTrafficGenParams; 5612810Sandreas.sandberg@arm.com 5712810Sandreas.sandberg@arm.com/** 5812810Sandreas.sandberg@arm.com * The traffic generator is a master module that generates stimuli for 5912810Sandreas.sandberg@arm.com * the memory system, based on a collection of simple generator 6012810Sandreas.sandberg@arm.com * behaviours that are either probabilistic or based on traces. It can 6112810Sandreas.sandberg@arm.com * be used stand alone for creating test cases for interconnect and 6212810Sandreas.sandberg@arm.com * memory controllers, or function as a black box replacement for 6312810Sandreas.sandberg@arm.com * system components that are not yet modelled in detail, e.g. a video 6412810Sandreas.sandberg@arm.com * engine or baseband subsystem. 6512810Sandreas.sandberg@arm.com */ 6612810Sandreas.sandberg@arm.comclass BaseTrafficGen : public MemObject 6712810Sandreas.sandberg@arm.com{ 6812811Sandreas.sandberg@arm.com friend class BaseGen; 6912811Sandreas.sandberg@arm.com 7012810Sandreas.sandberg@arm.com protected: // Params 7112810Sandreas.sandberg@arm.com /** 7212810Sandreas.sandberg@arm.com * The system used to determine which mode we are currently operating 7312810Sandreas.sandberg@arm.com * in. 7412810Sandreas.sandberg@arm.com */ 7512810Sandreas.sandberg@arm.com System *const system; 7612810Sandreas.sandberg@arm.com 7712810Sandreas.sandberg@arm.com /** 7812810Sandreas.sandberg@arm.com * Determine whether to add elasticity in the request injection, 7912810Sandreas.sandberg@arm.com * thus responding to backpressure by slowing things down. 8012810Sandreas.sandberg@arm.com */ 8112810Sandreas.sandberg@arm.com const bool elasticReq; 8212810Sandreas.sandberg@arm.com 8312810Sandreas.sandberg@arm.com /** 8412810Sandreas.sandberg@arm.com * Time to tolerate waiting for retries (not making progress), 8512810Sandreas.sandberg@arm.com * until we declare things broken. 8612810Sandreas.sandberg@arm.com */ 8712810Sandreas.sandberg@arm.com const Tick progressCheck; 8812810Sandreas.sandberg@arm.com 8912810Sandreas.sandberg@arm.com private: 9012810Sandreas.sandberg@arm.com /** 9112810Sandreas.sandberg@arm.com * Receive a retry from the neighbouring port and attempt to 9212810Sandreas.sandberg@arm.com * resend the waiting packet. 9312810Sandreas.sandberg@arm.com */ 9412810Sandreas.sandberg@arm.com void recvReqRetry(); 9512810Sandreas.sandberg@arm.com 9612810Sandreas.sandberg@arm.com /** Transition to the next generator */ 9712810Sandreas.sandberg@arm.com void transition(); 9812810Sandreas.sandberg@arm.com 9912810Sandreas.sandberg@arm.com /** 10012810Sandreas.sandberg@arm.com * Schedule the update event based on nextPacketTick and 10112810Sandreas.sandberg@arm.com * nextTransitionTick. 10212810Sandreas.sandberg@arm.com */ 10312810Sandreas.sandberg@arm.com void scheduleUpdate(); 10412810Sandreas.sandberg@arm.com 10512810Sandreas.sandberg@arm.com /** 10612810Sandreas.sandberg@arm.com * Method to inform the user we have made no progress. 10712810Sandreas.sandberg@arm.com */ 10812810Sandreas.sandberg@arm.com void noProgress(); 10912810Sandreas.sandberg@arm.com 11012810Sandreas.sandberg@arm.com /** 11112810Sandreas.sandberg@arm.com * Event to keep track of our progress, or lack thereof. 11212810Sandreas.sandberg@arm.com */ 11312810Sandreas.sandberg@arm.com EventFunctionWrapper noProgressEvent; 11412810Sandreas.sandberg@arm.com 11512810Sandreas.sandberg@arm.com /** Time of next transition */ 11612810Sandreas.sandberg@arm.com Tick nextTransitionTick; 11712810Sandreas.sandberg@arm.com 11812810Sandreas.sandberg@arm.com /** Time of the next packet. */ 11912810Sandreas.sandberg@arm.com Tick nextPacketTick; 12012810Sandreas.sandberg@arm.com 12112810Sandreas.sandberg@arm.com 12212810Sandreas.sandberg@arm.com /** Master port specialisation for the traffic generator */ 12312810Sandreas.sandberg@arm.com class TrafficGenPort : public MasterPort 12412810Sandreas.sandberg@arm.com { 12512810Sandreas.sandberg@arm.com public: 12612810Sandreas.sandberg@arm.com 12712810Sandreas.sandberg@arm.com TrafficGenPort(const std::string& name, BaseTrafficGen& traffic_gen) 12812810Sandreas.sandberg@arm.com : MasterPort(name, &traffic_gen), trafficGen(traffic_gen) 12912810Sandreas.sandberg@arm.com { } 13012810Sandreas.sandberg@arm.com 13112810Sandreas.sandberg@arm.com protected: 13212810Sandreas.sandberg@arm.com 13312810Sandreas.sandberg@arm.com void recvReqRetry() { trafficGen.recvReqRetry(); } 13412810Sandreas.sandberg@arm.com 13512810Sandreas.sandberg@arm.com bool recvTimingResp(PacketPtr pkt); 13612810Sandreas.sandberg@arm.com 13712810Sandreas.sandberg@arm.com void recvTimingSnoopReq(PacketPtr pkt) { } 13812810Sandreas.sandberg@arm.com 13912810Sandreas.sandberg@arm.com void recvFunctionalSnoop(PacketPtr pkt) { } 14012810Sandreas.sandberg@arm.com 14112810Sandreas.sandberg@arm.com Tick recvAtomicSnoop(PacketPtr pkt) { return 0; } 14212810Sandreas.sandberg@arm.com 14312810Sandreas.sandberg@arm.com private: 14412810Sandreas.sandberg@arm.com 14512810Sandreas.sandberg@arm.com BaseTrafficGen& trafficGen; 14612810Sandreas.sandberg@arm.com 14712810Sandreas.sandberg@arm.com }; 14812810Sandreas.sandberg@arm.com 14912810Sandreas.sandberg@arm.com /** 15012810Sandreas.sandberg@arm.com * Schedules event for next update and generates a new packet or 15112810Sandreas.sandberg@arm.com * requests a new generatoir depending on the current time. 15212810Sandreas.sandberg@arm.com */ 15312810Sandreas.sandberg@arm.com void update(); 15412810Sandreas.sandberg@arm.com 15512810Sandreas.sandberg@arm.com /** The instance of master port used by the traffic generator. */ 15612810Sandreas.sandberg@arm.com TrafficGenPort port; 15712810Sandreas.sandberg@arm.com 15812810Sandreas.sandberg@arm.com /** Packet waiting to be sent. */ 15912810Sandreas.sandberg@arm.com PacketPtr retryPkt; 16012810Sandreas.sandberg@arm.com 16112810Sandreas.sandberg@arm.com /** Tick when the stalled packet was meant to be sent. */ 16212810Sandreas.sandberg@arm.com Tick retryPktTick; 16312810Sandreas.sandberg@arm.com 16412810Sandreas.sandberg@arm.com /** Event for scheduling updates */ 16512810Sandreas.sandberg@arm.com EventFunctionWrapper updateEvent; 16612810Sandreas.sandberg@arm.com 16712918SMichiel.VanTol@arm.com /** Count the number of dropped requests. */ 16812918SMichiel.VanTol@arm.com Stats::Scalar numSuppressed; 16912810Sandreas.sandberg@arm.com 17012810Sandreas.sandberg@arm.com private: // Stats 17112810Sandreas.sandberg@arm.com /** Count the number of generated packets. */ 17212810Sandreas.sandberg@arm.com Stats::Scalar numPackets; 17312810Sandreas.sandberg@arm.com 17412810Sandreas.sandberg@arm.com /** Count the number of retries. */ 17512810Sandreas.sandberg@arm.com Stats::Scalar numRetries; 17612810Sandreas.sandberg@arm.com 17712810Sandreas.sandberg@arm.com /** Count the time incurred from back-pressure. */ 17812810Sandreas.sandberg@arm.com Stats::Scalar retryTicks; 17912810Sandreas.sandberg@arm.com 18012810Sandreas.sandberg@arm.com public: 18112810Sandreas.sandberg@arm.com BaseTrafficGen(const BaseTrafficGenParams* p); 18212810Sandreas.sandberg@arm.com 18312919Sgiacomo.travaglini@arm.com ~BaseTrafficGen(); 18412810Sandreas.sandberg@arm.com 18512810Sandreas.sandberg@arm.com BaseMasterPort& getMasterPort(const std::string &if_name, 18612810Sandreas.sandberg@arm.com PortID idx = InvalidPortID) override; 18712810Sandreas.sandberg@arm.com 18812810Sandreas.sandberg@arm.com void init() override; 18912810Sandreas.sandberg@arm.com 19012810Sandreas.sandberg@arm.com DrainState drain() override; 19112810Sandreas.sandberg@arm.com 19212810Sandreas.sandberg@arm.com void serialize(CheckpointOut &cp) const override; 19312810Sandreas.sandberg@arm.com void unserialize(CheckpointIn &cp) override; 19412810Sandreas.sandberg@arm.com 19512810Sandreas.sandberg@arm.com /** Register statistics */ 19612810Sandreas.sandberg@arm.com void regStats() override; 19712810Sandreas.sandberg@arm.com 19812811Sandreas.sandberg@arm.com public: // Generator factory methods 19912811Sandreas.sandberg@arm.com std::shared_ptr<BaseGen> createIdle(Tick duration); 20012811Sandreas.sandberg@arm.com std::shared_ptr<BaseGen> createExit(Tick duration); 20112811Sandreas.sandberg@arm.com 20212811Sandreas.sandberg@arm.com std::shared_ptr<BaseGen> createLinear( 20312811Sandreas.sandberg@arm.com Tick duration, 20412811Sandreas.sandberg@arm.com Addr start_addr, Addr end_addr, Addr blocksize, 20512811Sandreas.sandberg@arm.com Tick min_period, Tick max_period, 20612811Sandreas.sandberg@arm.com uint8_t read_percent, Addr data_limit); 20712811Sandreas.sandberg@arm.com 20812811Sandreas.sandberg@arm.com std::shared_ptr<BaseGen> createRandom( 20912811Sandreas.sandberg@arm.com Tick duration, 21012811Sandreas.sandberg@arm.com Addr start_addr, Addr end_addr, Addr blocksize, 21112811Sandreas.sandberg@arm.com Tick min_period, Tick max_period, 21212811Sandreas.sandberg@arm.com uint8_t read_percent, Addr data_limit); 21312811Sandreas.sandberg@arm.com 21412811Sandreas.sandberg@arm.com std::shared_ptr<BaseGen> createDram( 21512811Sandreas.sandberg@arm.com Tick duration, 21612811Sandreas.sandberg@arm.com Addr start_addr, Addr end_addr, Addr blocksize, 21712811Sandreas.sandberg@arm.com Tick min_period, Tick max_period, 21812811Sandreas.sandberg@arm.com uint8_t read_percent, Addr data_limit, 21912811Sandreas.sandberg@arm.com unsigned int num_seq_pkts, unsigned int page_size, 22012811Sandreas.sandberg@arm.com unsigned int nbr_of_banks_DRAM, unsigned int nbr_of_banks_util, 22112811Sandreas.sandberg@arm.com unsigned int addr_mapping, 22212811Sandreas.sandberg@arm.com unsigned int nbr_of_ranks); 22312811Sandreas.sandberg@arm.com 22412811Sandreas.sandberg@arm.com std::shared_ptr<BaseGen> createDramRot( 22512811Sandreas.sandberg@arm.com Tick duration, 22612811Sandreas.sandberg@arm.com Addr start_addr, Addr end_addr, Addr blocksize, 22712811Sandreas.sandberg@arm.com Tick min_period, Tick max_period, 22812811Sandreas.sandberg@arm.com uint8_t read_percent, Addr data_limit, 22912811Sandreas.sandberg@arm.com unsigned int num_seq_pkts, unsigned int page_size, 23012811Sandreas.sandberg@arm.com unsigned int nbr_of_banks_DRAM, unsigned int nbr_of_banks_util, 23112811Sandreas.sandberg@arm.com unsigned int addr_mapping, 23212811Sandreas.sandberg@arm.com unsigned int nbr_of_ranks, 23312811Sandreas.sandberg@arm.com unsigned int max_seq_count_per_rank); 23412811Sandreas.sandberg@arm.com 23512811Sandreas.sandberg@arm.com std::shared_ptr<BaseGen> createTrace( 23612811Sandreas.sandberg@arm.com Tick duration, 23712811Sandreas.sandberg@arm.com const std::string& trace_file, Addr addr_offset); 23812811Sandreas.sandberg@arm.com 23912810Sandreas.sandberg@arm.com protected: 24012810Sandreas.sandberg@arm.com void start(); 24112810Sandreas.sandberg@arm.com 24212810Sandreas.sandberg@arm.com virtual std::shared_ptr<BaseGen> nextGenerator() = 0; 24312810Sandreas.sandberg@arm.com 24412810Sandreas.sandberg@arm.com /** 24512810Sandreas.sandberg@arm.com * MasterID used in generated requests. 24612810Sandreas.sandberg@arm.com */ 24712810Sandreas.sandberg@arm.com const MasterID masterID; 24812810Sandreas.sandberg@arm.com 24912810Sandreas.sandberg@arm.com /** Currently active generator */ 25012810Sandreas.sandberg@arm.com std::shared_ptr<BaseGen> activeGenerator; 25112919Sgiacomo.travaglini@arm.com 25212919Sgiacomo.travaglini@arm.com /** Stream/SubStreamID Generator */ 25312919Sgiacomo.travaglini@arm.com std::unique_ptr<StreamGen> streamGenerator; 25412810Sandreas.sandberg@arm.com}; 25512810Sandreas.sandberg@arm.com 25612810Sandreas.sandberg@arm.com#endif //__CPU_TRAFFIC_GEN_BASE_HH__ 257