traffic_gen.hh revision 12085
1/* 2 * Copyright (c) 2012-2013, 2016 ARM Limited 3 * All rights reserved 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software 9 * licensed hereunder. You may use the software subject to the license 10 * terms below provided that you ensure that this notice is replicated 11 * unmodified and in its entirety in all distributions of the software, 12 * modified or unmodified, in source code or in binary form. 13 * 14 * Redistribution and use in source and binary forms, with or without 15 * modification, are permitted provided that the following conditions are 16 * met: redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer; 18 * redistributions in binary form must reproduce the above copyright 19 * notice, this list of conditions and the following disclaimer in the 20 * documentation and/or other materials provided with the distribution; 21 * neither the name of the copyright holders nor the names of its 22 * contributors may be used to endorse or promote products derived from 23 * this software without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 * 37 * Authors: Thomas Grass 38 * Andreas Hansson 39 * Sascha Bischoff 40 */ 41#ifndef __CPU_TRAFFIC_GEN_TRAFFIC_GEN_HH__ 42#define __CPU_TRAFFIC_GEN_TRAFFIC_GEN_HH__ 43 44#include <unordered_map> 45 46#include "base/statistics.hh" 47#include "cpu/testers/traffic_gen/generators.hh" 48#include "mem/mem_object.hh" 49#include "mem/qport.hh" 50#include "params/TrafficGen.hh" 51 52/** 53 * The traffic generator is a master module that generates stimuli for 54 * the memory system, based on a collection of simple generator 55 * behaviours that are either probabilistic or based on traces. It can 56 * be used stand alone for creating test cases for interconnect and 57 * memory controllers, or function as a black box replacement for 58 * system components that are not yet modelled in detail, e.g. a video 59 * engine or baseband subsystem. 60 */ 61class TrafficGen : public MemObject 62{ 63 64 private: 65 66 /** 67 * Determine next state and perform the transition. 68 */ 69 void transition(); 70 71 /** 72 * Enter a new state. 73 * 74 * @param newState identifier of state to enter 75 */ 76 void enterState(uint32_t newState); 77 78 /** 79 * Resolve a file path in the configuration file. 80 * 81 * This method resolves a relative path to a file that has been 82 * referenced in the configuration file. It first tries to resolve 83 * the file relative to the configuration file's path. If that 84 * fails, it falls back to constructing a path relative to the 85 * current working directory. 86 * 87 * Absolute paths are returned unmodified. 88 * 89 * @param name Path to resolve 90 */ 91 std::string resolveFile(const std::string &name); 92 93 /** 94 * Parse the config file and build the state map and 95 * transition matrix. 96 */ 97 void parseConfig(); 98 99 /** 100 * Schedules event for next update and executes an update on the 101 * state graph, either performing a state transition or executing 102 * the current state, depending on the current time. 103 */ 104 void update(); 105 106 /** 107 * Receive a retry from the neighbouring port and attempt to 108 * resend the waiting packet. 109 */ 110 void recvReqRetry(); 111 112 /** 113 * Method to inform the user we have made no progress. 114 */ 115 void noProgress(); 116 117 /** Struct to represent a probabilistic transition during parsing. */ 118 struct Transition { 119 uint32_t from; 120 uint32_t to; 121 double p; 122 }; 123 124 /** 125 * The system used to determine which mode we are currently operating 126 * in. 127 */ 128 System* system; 129 130 /** 131 * MasterID used in generated requests. 132 */ 133 MasterID masterID; 134 135 /** 136 * The config file to parse. 137 */ 138 const std::string configFile; 139 140 /** 141 * Determine whether to add elasticity in the request injection, 142 * thus responding to backpressure by slowing things down. 143 */ 144 const bool elasticReq; 145 146 /** 147 * Time to tolerate waiting for retries (not making progress), 148 * until we declare things broken. 149 */ 150 const Tick progressCheck; 151 152 /** 153 * Event to keep track of our progress, or lack thereof. 154 */ 155 EventFunctionWrapper noProgressEvent; 156 157 /** Time of next transition */ 158 Tick nextTransitionTick; 159 160 /** Time of the next packet. */ 161 Tick nextPacketTick; 162 163 /** State transition matrix */ 164 std::vector<std::vector<double> > transitionMatrix; 165 166 /** Index of the current state */ 167 uint32_t currState; 168 169 /** Map of generator states */ 170 std::unordered_map<uint32_t, BaseGen*> states; 171 172 /** Master port specialisation for the traffic generator */ 173 class TrafficGenPort : public MasterPort 174 { 175 public: 176 177 TrafficGenPort(const std::string& name, TrafficGen& traffic_gen) 178 : MasterPort(name, &traffic_gen), trafficGen(traffic_gen) 179 { } 180 181 protected: 182 183 void recvReqRetry() { trafficGen.recvReqRetry(); } 184 185 bool recvTimingResp(PacketPtr pkt); 186 187 void recvTimingSnoopReq(PacketPtr pkt) { } 188 189 void recvFunctionalSnoop(PacketPtr pkt) { } 190 191 Tick recvAtomicSnoop(PacketPtr pkt) { return 0; } 192 193 private: 194 195 TrafficGen& trafficGen; 196 197 }; 198 199 /** The instance of master port used by the traffic generator. */ 200 TrafficGenPort port; 201 202 /** Packet waiting to be sent. */ 203 PacketPtr retryPkt; 204 205 /** Tick when the stalled packet was meant to be sent. */ 206 Tick retryPktTick; 207 208 /** Event for scheduling updates */ 209 EventFunctionWrapper updateEvent; 210 211 uint64_t numSuppressed; 212 213 /** Count the number of generated packets. */ 214 Stats::Scalar numPackets; 215 216 /** Count the number of retries. */ 217 Stats::Scalar numRetries; 218 219 /** Count the time incurred from back-pressure. */ 220 Stats::Scalar retryTicks; 221 222 public: 223 224 TrafficGen(const TrafficGenParams* p); 225 226 ~TrafficGen() {} 227 228 BaseMasterPort& getMasterPort(const std::string &if_name, 229 PortID idx = InvalidPortID) override; 230 231 void init() override; 232 233 void initState() override; 234 235 DrainState drain() override; 236 237 void serialize(CheckpointOut &cp) const override; 238 void unserialize(CheckpointIn &cp) override; 239 240 /** Register statistics */ 241 void regStats() override; 242 243}; 244 245#endif //__CPU_TRAFFIC_GEN_TRAFFIC_GEN_HH__ 246