base.hh revision 12918
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; 5312810Sandreas.sandberg@arm.comclass System; 5412810Sandreas.sandberg@arm.comstruct BaseTrafficGenParams; 5512810Sandreas.sandberg@arm.com 5612810Sandreas.sandberg@arm.com/** 5712810Sandreas.sandberg@arm.com * The traffic generator is a master module that generates stimuli for 5812810Sandreas.sandberg@arm.com * the memory system, based on a collection of simple generator 5912810Sandreas.sandberg@arm.com * behaviours that are either probabilistic or based on traces. It can 6012810Sandreas.sandberg@arm.com * be used stand alone for creating test cases for interconnect and 6112810Sandreas.sandberg@arm.com * memory controllers, or function as a black box replacement for 6212810Sandreas.sandberg@arm.com * system components that are not yet modelled in detail, e.g. a video 6312810Sandreas.sandberg@arm.com * engine or baseband subsystem. 6412810Sandreas.sandberg@arm.com */ 6512810Sandreas.sandberg@arm.comclass BaseTrafficGen : public MemObject 6612810Sandreas.sandberg@arm.com{ 6712811Sandreas.sandberg@arm.com friend class BaseGen; 6812811Sandreas.sandberg@arm.com 6912810Sandreas.sandberg@arm.com protected: // Params 7012810Sandreas.sandberg@arm.com /** 7112810Sandreas.sandberg@arm.com * The system used to determine which mode we are currently operating 7212810Sandreas.sandberg@arm.com * in. 7312810Sandreas.sandberg@arm.com */ 7412810Sandreas.sandberg@arm.com System *const system; 7512810Sandreas.sandberg@arm.com 7612810Sandreas.sandberg@arm.com /** 7712810Sandreas.sandberg@arm.com * Determine whether to add elasticity in the request injection, 7812810Sandreas.sandberg@arm.com * thus responding to backpressure by slowing things down. 7912810Sandreas.sandberg@arm.com */ 8012810Sandreas.sandberg@arm.com const bool elasticReq; 8112810Sandreas.sandberg@arm.com 8212810Sandreas.sandberg@arm.com /** 8312810Sandreas.sandberg@arm.com * Time to tolerate waiting for retries (not making progress), 8412810Sandreas.sandberg@arm.com * until we declare things broken. 8512810Sandreas.sandberg@arm.com */ 8612810Sandreas.sandberg@arm.com const Tick progressCheck; 8712810Sandreas.sandberg@arm.com 8812810Sandreas.sandberg@arm.com private: 8912810Sandreas.sandberg@arm.com /** 9012810Sandreas.sandberg@arm.com * Receive a retry from the neighbouring port and attempt to 9112810Sandreas.sandberg@arm.com * resend the waiting packet. 9212810Sandreas.sandberg@arm.com */ 9312810Sandreas.sandberg@arm.com void recvReqRetry(); 9412810Sandreas.sandberg@arm.com 9512810Sandreas.sandberg@arm.com /** Transition to the next generator */ 9612810Sandreas.sandberg@arm.com void transition(); 9712810Sandreas.sandberg@arm.com 9812810Sandreas.sandberg@arm.com /** 9912810Sandreas.sandberg@arm.com * Schedule the update event based on nextPacketTick and 10012810Sandreas.sandberg@arm.com * nextTransitionTick. 10112810Sandreas.sandberg@arm.com */ 10212810Sandreas.sandberg@arm.com void scheduleUpdate(); 10312810Sandreas.sandberg@arm.com 10412810Sandreas.sandberg@arm.com /** 10512810Sandreas.sandberg@arm.com * Method to inform the user we have made no progress. 10612810Sandreas.sandberg@arm.com */ 10712810Sandreas.sandberg@arm.com void noProgress(); 10812810Sandreas.sandberg@arm.com 10912810Sandreas.sandberg@arm.com /** 11012810Sandreas.sandberg@arm.com * Event to keep track of our progress, or lack thereof. 11112810Sandreas.sandberg@arm.com */ 11212810Sandreas.sandberg@arm.com EventFunctionWrapper noProgressEvent; 11312810Sandreas.sandberg@arm.com 11412810Sandreas.sandberg@arm.com /** Time of next transition */ 11512810Sandreas.sandberg@arm.com Tick nextTransitionTick; 11612810Sandreas.sandberg@arm.com 11712810Sandreas.sandberg@arm.com /** Time of the next packet. */ 11812810Sandreas.sandberg@arm.com Tick nextPacketTick; 11912810Sandreas.sandberg@arm.com 12012810Sandreas.sandberg@arm.com 12112810Sandreas.sandberg@arm.com /** Master port specialisation for the traffic generator */ 12212810Sandreas.sandberg@arm.com class TrafficGenPort : public MasterPort 12312810Sandreas.sandberg@arm.com { 12412810Sandreas.sandberg@arm.com public: 12512810Sandreas.sandberg@arm.com 12612810Sandreas.sandberg@arm.com TrafficGenPort(const std::string& name, BaseTrafficGen& traffic_gen) 12712810Sandreas.sandberg@arm.com : MasterPort(name, &traffic_gen), trafficGen(traffic_gen) 12812810Sandreas.sandberg@arm.com { } 12912810Sandreas.sandberg@arm.com 13012810Sandreas.sandberg@arm.com protected: 13112810Sandreas.sandberg@arm.com 13212810Sandreas.sandberg@arm.com void recvReqRetry() { trafficGen.recvReqRetry(); } 13312810Sandreas.sandberg@arm.com 13412810Sandreas.sandberg@arm.com bool recvTimingResp(PacketPtr pkt); 13512810Sandreas.sandberg@arm.com 13612810Sandreas.sandberg@arm.com void recvTimingSnoopReq(PacketPtr pkt) { } 13712810Sandreas.sandberg@arm.com 13812810Sandreas.sandberg@arm.com void recvFunctionalSnoop(PacketPtr pkt) { } 13912810Sandreas.sandberg@arm.com 14012810Sandreas.sandberg@arm.com Tick recvAtomicSnoop(PacketPtr pkt) { return 0; } 14112810Sandreas.sandberg@arm.com 14212810Sandreas.sandberg@arm.com private: 14312810Sandreas.sandberg@arm.com 14412810Sandreas.sandberg@arm.com BaseTrafficGen& trafficGen; 14512810Sandreas.sandberg@arm.com 14612810Sandreas.sandberg@arm.com }; 14712810Sandreas.sandberg@arm.com 14812810Sandreas.sandberg@arm.com /** 14912810Sandreas.sandberg@arm.com * Schedules event for next update and generates a new packet or 15012810Sandreas.sandberg@arm.com * requests a new generatoir depending on the current time. 15112810Sandreas.sandberg@arm.com */ 15212810Sandreas.sandberg@arm.com void update(); 15312810Sandreas.sandberg@arm.com 15412810Sandreas.sandberg@arm.com /** The instance of master port used by the traffic generator. */ 15512810Sandreas.sandberg@arm.com TrafficGenPort port; 15612810Sandreas.sandberg@arm.com 15712810Sandreas.sandberg@arm.com /** Packet waiting to be sent. */ 15812810Sandreas.sandberg@arm.com PacketPtr retryPkt; 15912810Sandreas.sandberg@arm.com 16012810Sandreas.sandberg@arm.com /** Tick when the stalled packet was meant to be sent. */ 16112810Sandreas.sandberg@arm.com Tick retryPktTick; 16212810Sandreas.sandberg@arm.com 16312810Sandreas.sandberg@arm.com /** Event for scheduling updates */ 16412810Sandreas.sandberg@arm.com EventFunctionWrapper updateEvent; 16512810Sandreas.sandberg@arm.com 16612918SMichiel.VanTol@arm.com /** Count the number of dropped requests. */ 16712918SMichiel.VanTol@arm.com Stats::Scalar numSuppressed; 16812810Sandreas.sandberg@arm.com 16912810Sandreas.sandberg@arm.com private: // Stats 17012810Sandreas.sandberg@arm.com /** Count the number of generated packets. */ 17112810Sandreas.sandberg@arm.com Stats::Scalar numPackets; 17212810Sandreas.sandberg@arm.com 17312810Sandreas.sandberg@arm.com /** Count the number of retries. */ 17412810Sandreas.sandberg@arm.com Stats::Scalar numRetries; 17512810Sandreas.sandberg@arm.com 17612810Sandreas.sandberg@arm.com /** Count the time incurred from back-pressure. */ 17712810Sandreas.sandberg@arm.com Stats::Scalar retryTicks; 17812810Sandreas.sandberg@arm.com 17912810Sandreas.sandberg@arm.com public: 18012810Sandreas.sandberg@arm.com BaseTrafficGen(const BaseTrafficGenParams* p); 18112810Sandreas.sandberg@arm.com 18212810Sandreas.sandberg@arm.com ~BaseTrafficGen() {} 18312810Sandreas.sandberg@arm.com 18412810Sandreas.sandberg@arm.com BaseMasterPort& getMasterPort(const std::string &if_name, 18512810Sandreas.sandberg@arm.com PortID idx = InvalidPortID) override; 18612810Sandreas.sandberg@arm.com 18712810Sandreas.sandberg@arm.com void init() override; 18812810Sandreas.sandberg@arm.com 18912810Sandreas.sandberg@arm.com DrainState drain() override; 19012810Sandreas.sandberg@arm.com 19112810Sandreas.sandberg@arm.com void serialize(CheckpointOut &cp) const override; 19212810Sandreas.sandberg@arm.com void unserialize(CheckpointIn &cp) override; 19312810Sandreas.sandberg@arm.com 19412810Sandreas.sandberg@arm.com /** Register statistics */ 19512810Sandreas.sandberg@arm.com void regStats() override; 19612810Sandreas.sandberg@arm.com 19712811Sandreas.sandberg@arm.com public: // Generator factory methods 19812811Sandreas.sandberg@arm.com std::shared_ptr<BaseGen> createIdle(Tick duration); 19912811Sandreas.sandberg@arm.com std::shared_ptr<BaseGen> createExit(Tick duration); 20012811Sandreas.sandberg@arm.com 20112811Sandreas.sandberg@arm.com std::shared_ptr<BaseGen> createLinear( 20212811Sandreas.sandberg@arm.com Tick duration, 20312811Sandreas.sandberg@arm.com Addr start_addr, Addr end_addr, Addr blocksize, 20412811Sandreas.sandberg@arm.com Tick min_period, Tick max_period, 20512811Sandreas.sandberg@arm.com uint8_t read_percent, Addr data_limit); 20612811Sandreas.sandberg@arm.com 20712811Sandreas.sandberg@arm.com std::shared_ptr<BaseGen> createRandom( 20812811Sandreas.sandberg@arm.com Tick duration, 20912811Sandreas.sandberg@arm.com Addr start_addr, Addr end_addr, Addr blocksize, 21012811Sandreas.sandberg@arm.com Tick min_period, Tick max_period, 21112811Sandreas.sandberg@arm.com uint8_t read_percent, Addr data_limit); 21212811Sandreas.sandberg@arm.com 21312811Sandreas.sandberg@arm.com std::shared_ptr<BaseGen> createDram( 21412811Sandreas.sandberg@arm.com Tick duration, 21512811Sandreas.sandberg@arm.com Addr start_addr, Addr end_addr, Addr blocksize, 21612811Sandreas.sandberg@arm.com Tick min_period, Tick max_period, 21712811Sandreas.sandberg@arm.com uint8_t read_percent, Addr data_limit, 21812811Sandreas.sandberg@arm.com unsigned int num_seq_pkts, unsigned int page_size, 21912811Sandreas.sandberg@arm.com unsigned int nbr_of_banks_DRAM, unsigned int nbr_of_banks_util, 22012811Sandreas.sandberg@arm.com unsigned int addr_mapping, 22112811Sandreas.sandberg@arm.com unsigned int nbr_of_ranks); 22212811Sandreas.sandberg@arm.com 22312811Sandreas.sandberg@arm.com std::shared_ptr<BaseGen> createDramRot( 22412811Sandreas.sandberg@arm.com Tick duration, 22512811Sandreas.sandberg@arm.com Addr start_addr, Addr end_addr, Addr blocksize, 22612811Sandreas.sandberg@arm.com Tick min_period, Tick max_period, 22712811Sandreas.sandberg@arm.com uint8_t read_percent, Addr data_limit, 22812811Sandreas.sandberg@arm.com unsigned int num_seq_pkts, unsigned int page_size, 22912811Sandreas.sandberg@arm.com unsigned int nbr_of_banks_DRAM, unsigned int nbr_of_banks_util, 23012811Sandreas.sandberg@arm.com unsigned int addr_mapping, 23112811Sandreas.sandberg@arm.com unsigned int nbr_of_ranks, 23212811Sandreas.sandberg@arm.com unsigned int max_seq_count_per_rank); 23312811Sandreas.sandberg@arm.com 23412811Sandreas.sandberg@arm.com std::shared_ptr<BaseGen> createTrace( 23512811Sandreas.sandberg@arm.com Tick duration, 23612811Sandreas.sandberg@arm.com const std::string& trace_file, Addr addr_offset); 23712811Sandreas.sandberg@arm.com 23812810Sandreas.sandberg@arm.com protected: 23912810Sandreas.sandberg@arm.com void start(); 24012810Sandreas.sandberg@arm.com 24112810Sandreas.sandberg@arm.com virtual std::shared_ptr<BaseGen> nextGenerator() = 0; 24212810Sandreas.sandberg@arm.com 24312810Sandreas.sandberg@arm.com /** 24412810Sandreas.sandberg@arm.com * MasterID used in generated requests. 24512810Sandreas.sandberg@arm.com */ 24612810Sandreas.sandberg@arm.com const MasterID masterID; 24712810Sandreas.sandberg@arm.com 24812810Sandreas.sandberg@arm.com /** Currently active generator */ 24912810Sandreas.sandberg@arm.com std::shared_ptr<BaseGen> activeGenerator; 25012810Sandreas.sandberg@arm.com}; 25112810Sandreas.sandberg@arm.com 25212810Sandreas.sandberg@arm.com#endif //__CPU_TRAFFIC_GEN_BASE_HH__ 253