GarnetSyntheticTraffic.cc revision 12129
14120Sgblack@eecs.umich.edu/* 24120Sgblack@eecs.umich.edu * Copyright (c) 2016 Georgia Institute of Technology 34120Sgblack@eecs.umich.edu * All rights reserved. 44120Sgblack@eecs.umich.edu * 57087Snate@binkert.org * Redistribution and use in source and binary forms, with or without 67087Snate@binkert.org * modification, are permitted provided that the following conditions are 77087Snate@binkert.org * met: redistributions of source code must retain the above copyright 87087Snate@binkert.org * notice, this list of conditions and the following disclaimer; 97087Snate@binkert.org * redistributions in binary form must reproduce the above copyright 107087Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 117087Snate@binkert.org * documentation and/or other materials provided with the distribution; 127087Snate@binkert.org * neither the name of the copyright holders nor the names of its 134120Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from 147087Snate@binkert.org * this software without specific prior written permission. 157087Snate@binkert.org * 167087Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 177087Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 187087Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 197087Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 207087Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 217087Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 224120Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 237087Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 244120Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 254120Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 264120Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 274120Sgblack@eecs.umich.edu * 284120Sgblack@eecs.umich.edu * Authors: Tushar Krishna 294120Sgblack@eecs.umich.edu */ 304120Sgblack@eecs.umich.edu 314120Sgblack@eecs.umich.edu#include "cpu/testers/garnet_synthetic_traffic/GarnetSyntheticTraffic.hh" 324120Sgblack@eecs.umich.edu 334120Sgblack@eecs.umich.edu#include <cmath> 344120Sgblack@eecs.umich.edu#include <iomanip> 354120Sgblack@eecs.umich.edu#include <set> 364120Sgblack@eecs.umich.edu#include <string> 374120Sgblack@eecs.umich.edu#include <vector> 384120Sgblack@eecs.umich.edu 394120Sgblack@eecs.umich.edu#include "base/misc.hh" 404120Sgblack@eecs.umich.edu#include "base/random.hh" 414120Sgblack@eecs.umich.edu#include "base/statistics.hh" 424120Sgblack@eecs.umich.edu#include "debug/GarnetSyntheticTraffic.hh" 437629Sgblack@eecs.umich.edu#include "mem/mem_object.hh" 444148Sgblack@eecs.umich.edu#include "mem/packet.hh" 454182Sgblack@eecs.umich.edu#include "mem/port.hh" 464148Sgblack@eecs.umich.edu#include "mem/request.hh" 476216Snate@binkert.org#include "sim/sim_events.hh" 485135Sgblack@eecs.umich.edu#include "sim/stats.hh" 494241Sgblack@eecs.umich.edu#include "sim/system.hh" 504148Sgblack@eecs.umich.edu 514148Sgblack@eecs.umich.eduusing namespace std; 524120Sgblack@eecs.umich.edu 534120Sgblack@eecs.umich.eduint TESTER_NETWORK=0; 544120Sgblack@eecs.umich.edu 557707Sgblack@eecs.umich.edubool 567707Sgblack@eecs.umich.eduGarnetSyntheticTraffic::CpuPort::recvTimingResp(PacketPtr pkt) 575086Sgblack@eecs.umich.edu{ 584148Sgblack@eecs.umich.edu tester->completeRequest(pkt); 594148Sgblack@eecs.umich.edu return true; 604148Sgblack@eecs.umich.edu} 615910Sgblack@eecs.umich.edu 625910Sgblack@eecs.umich.eduvoid 635910Sgblack@eecs.umich.eduGarnetSyntheticTraffic::CpuPort::recvReqRetry() 645910Sgblack@eecs.umich.edu{ 655910Sgblack@eecs.umich.edu tester->doRetry(); 665910Sgblack@eecs.umich.edu} 674148Sgblack@eecs.umich.edu 684148Sgblack@eecs.umich.eduvoid 694148Sgblack@eecs.umich.eduGarnetSyntheticTraffic::sendPkt(PacketPtr pkt) 704148Sgblack@eecs.umich.edu{ 714148Sgblack@eecs.umich.edu if (!cachePort.sendTimingReq(pkt)) { 724148Sgblack@eecs.umich.edu retryPkt = pkt; // RubyPort will retry sending 734148Sgblack@eecs.umich.edu } 744148Sgblack@eecs.umich.edu numPacketsSent++; 754148Sgblack@eecs.umich.edu} 765135Sgblack@eecs.umich.edu 774194Ssaidi@eecs.umich.eduGarnetSyntheticTraffic::GarnetSyntheticTraffic(const Params *p) 785135Sgblack@eecs.umich.edu : MemObject(p), 795135Sgblack@eecs.umich.edu tickEvent([this]{ tick(); }, "GarnetSyntheticTraffic tick", 805135Sgblack@eecs.umich.edu false, Event::CPU_Tick_Pri), 815135Sgblack@eecs.umich.edu cachePort("GarnetSyntheticTraffic", this), 825135Sgblack@eecs.umich.edu retryPkt(NULL), 836329Sgblack@eecs.umich.edu size(p->memory_size), 846329Sgblack@eecs.umich.edu blockSizeBits(p->block_offset), 856329Sgblack@eecs.umich.edu numDestinations(p->num_dest), 866329Sgblack@eecs.umich.edu simCycles(p->sim_cycles), 877693SAli.Saidi@ARM.com numPacketsMax(p->num_packets_max), 887693SAli.Saidi@ARM.com numPacketsSent(0), 894120Sgblack@eecs.umich.edu singleSender(p->single_sender), 904120Sgblack@eecs.umich.edu singleDest(p->single_dest), 914120Sgblack@eecs.umich.edu trafficType(p->traffic_type), 92 injRate(p->inj_rate), 93 injVnet(p->inj_vnet), 94 precision(p->precision), 95 responseLimit(p->response_limit), 96 masterId(p->system->getMasterId(name())) 97{ 98 // set up counters 99 noResponseCycles = 0; 100 schedule(tickEvent, 0); 101 102 initTrafficType(); 103 if (trafficStringToEnum.count(trafficType) == 0) { 104 fatal("Unknown Traffic Type: %s!\n", traffic); 105 } 106 traffic = trafficStringToEnum[trafficType]; 107 108 id = TESTER_NETWORK++; 109 DPRINTF(GarnetSyntheticTraffic,"Config Created: Name = %s , and id = %d\n", 110 name(), id); 111} 112 113BaseMasterPort & 114GarnetSyntheticTraffic::getMasterPort(const std::string &if_name, PortID idx) 115{ 116 if (if_name == "test") 117 return cachePort; 118 else 119 return MemObject::getMasterPort(if_name, idx); 120} 121 122void 123GarnetSyntheticTraffic::init() 124{ 125 numPacketsSent = 0; 126} 127 128 129void 130GarnetSyntheticTraffic::completeRequest(PacketPtr pkt) 131{ 132 Request *req = pkt->req; 133 134 DPRINTF(GarnetSyntheticTraffic, 135 "Completed injection of %s packet for address %x\n", 136 pkt->isWrite() ? "write" : "read\n", 137 req->getPaddr()); 138 139 assert(pkt->isResponse()); 140 noResponseCycles = 0; 141 delete req; 142 delete pkt; 143} 144 145 146void 147GarnetSyntheticTraffic::tick() 148{ 149 if (++noResponseCycles >= responseLimit) { 150 fatal("%s deadlocked at cycle %d\n", name(), curTick()); 151 } 152 153 // make new request based on injection rate 154 // (injection rate's range depends on precision) 155 // - generate a random number between 0 and 10^precision 156 // - send pkt if this number is < injRate*(10^precision) 157 bool sendAllowedThisCycle; 158 double injRange = pow((double) 10, (double) precision); 159 unsigned trySending = random_mt.random<unsigned>(0, (int) injRange); 160 if (trySending < injRate*injRange) 161 sendAllowedThisCycle = true; 162 else 163 sendAllowedThisCycle = false; 164 165 // always generatePkt unless fixedPkts or singleSender is enabled 166 if (sendAllowedThisCycle) { 167 bool senderEnable = true; 168 169 if (numPacketsMax >= 0 && numPacketsSent >= numPacketsMax) 170 senderEnable = false; 171 172 if (singleSender >= 0 && id != singleSender) 173 senderEnable = false; 174 175 if (senderEnable) 176 generatePkt(); 177 } 178 179 // Schedule wakeup 180 if (curTick() >= simCycles) 181 exitSimLoop("Network Tester completed simCycles"); 182 else { 183 if (!tickEvent.scheduled()) 184 schedule(tickEvent, clockEdge(Cycles(1))); 185 } 186} 187 188void 189GarnetSyntheticTraffic::generatePkt() 190{ 191 int num_destinations = numDestinations; 192 int radix = (int) sqrt(num_destinations); 193 unsigned destination = id; 194 int dest_x = -1; 195 int dest_y = -1; 196 int source = id; 197 int src_x = id%radix; 198 int src_y = id/radix; 199 200 if (singleDest >= 0) 201 { 202 destination = singleDest; 203 } else if (traffic == UNIFORM_RANDOM_) { 204 destination = random_mt.random<unsigned>(0, num_destinations - 1); 205 } else if (traffic == BIT_COMPLEMENT_) { 206 dest_x = radix - src_x - 1; 207 dest_y = radix - src_y - 1; 208 destination = dest_y*radix + dest_x; 209 } else if (traffic == BIT_REVERSE_) { 210 unsigned int straight = source; 211 unsigned int reverse = source & 1; // LSB 212 213 int num_bits = (int) log2(num_destinations); 214 215 for (int i = 1; i < num_bits; i++) 216 { 217 reverse <<= 1; 218 straight >>= 1; 219 reverse |= (straight & 1); // LSB 220 } 221 destination = reverse; 222 } else if (traffic == BIT_ROTATION_) { 223 if (source%2 == 0) 224 destination = source/2; 225 else // (source%2 == 1) 226 destination = ((source/2) + (num_destinations/2)); 227 } else if (traffic == NEIGHBOR_) { 228 dest_x = (src_x + 1) % radix; 229 dest_y = src_y; 230 destination = dest_y*radix + dest_x; 231 } else if (traffic == SHUFFLE_) { 232 if (source < num_destinations/2) 233 destination = source*2; 234 else 235 destination = (source*2 - num_destinations + 1); 236 } else if (traffic == TRANSPOSE_) { 237 dest_x = src_y; 238 dest_y = src_x; 239 destination = dest_y*radix + dest_x; 240 } else if (traffic == TORNADO_) { 241 dest_x = (src_x + (int) ceil(radix/2) - 1) % radix; 242 dest_y = src_y; 243 destination = dest_y*radix + dest_x; 244 } 245 else { 246 fatal("Unknown Traffic Type: %s!\n", traffic); 247 } 248 249 // The source of the packets is a cache. 250 // The destination of the packets is a directory. 251 // The destination bits are embedded in the address after byte-offset. 252 Addr paddr = destination; 253 paddr <<= blockSizeBits; 254 unsigned access_size = 1; // Does not affect Ruby simulation 255 256 // Modeling different coherence msg types over different msg classes. 257 // 258 // GarnetSyntheticTraffic assumes the Garnet_standalone coherence protocol 259 // which models three message classes/virtual networks. 260 // These are: request, forward, response. 261 // requests and forwards are "control" packets (typically 8 bytes), 262 // while responses are "data" packets (typically 72 bytes). 263 // 264 // Life of a packet from the tester into the network: 265 // (1) This function generatePkt() generates packets of one of the 266 // following 3 types (randomly) : ReadReq, INST_FETCH, WriteReq 267 // (2) mem/ruby/system/RubyPort.cc converts these to RubyRequestType_LD, 268 // RubyRequestType_IFETCH, RubyRequestType_ST respectively 269 // (3) mem/ruby/system/Sequencer.cc sends these to the cache controllers 270 // in the coherence protocol. 271 // (4) Network_test-cache.sm tags RubyRequestType:LD, 272 // RubyRequestType:IFETCH and RubyRequestType:ST as 273 // Request, Forward, and Response events respectively; 274 // and injects them into virtual networks 0, 1 and 2 respectively. 275 // It immediately calls back the sequencer. 276 // (5) The packet traverses the network (simple/garnet) and reaches its 277 // destination (Directory), and network stats are updated. 278 // (6) Network_test-dir.sm simply drops the packet. 279 // 280 MemCmd::Command requestType; 281 282 Request *req = nullptr; 283 Request::Flags flags; 284 285 // Inject in specific Vnet 286 // Vnet 0 and 1 are for control packets (1-flit) 287 // Vnet 2 is for data packets (5-flit) 288 int injReqType = injVnet; 289 290 if (injReqType < 0 || injReqType > 2) 291 { 292 // randomly inject in any vnet 293 injReqType = random_mt.random(0, 2); 294 } 295 296 if (injReqType == 0) { 297 // generate packet for virtual network 0 298 requestType = MemCmd::ReadReq; 299 req = new Request(paddr, access_size, flags, masterId); 300 } else if (injReqType == 1) { 301 // generate packet for virtual network 1 302 requestType = MemCmd::ReadReq; 303 flags.set(Request::INST_FETCH); 304 req = new Request(0, 0x0, access_size, flags, masterId, 0x0, 0); 305 req->setPaddr(paddr); 306 } else { // if (injReqType == 2) 307 // generate packet for virtual network 2 308 requestType = MemCmd::WriteReq; 309 req = new Request(paddr, access_size, flags, masterId); 310 } 311 312 req->setContext(id); 313 314 //No need to do functional simulation 315 //We just do timing simulation of the network 316 317 DPRINTF(GarnetSyntheticTraffic, 318 "Generated packet with destination %d, embedded in address %x\n", 319 destination, req->getPaddr()); 320 321 PacketPtr pkt = new Packet(req, requestType); 322 pkt->dataDynamic(new uint8_t[req->getSize()]); 323 pkt->senderState = NULL; 324 325 sendPkt(pkt); 326} 327 328void 329GarnetSyntheticTraffic::initTrafficType() 330{ 331 trafficStringToEnum["bit_complement"] = BIT_COMPLEMENT_; 332 trafficStringToEnum["bit_reverse"] = BIT_REVERSE_; 333 trafficStringToEnum["bit_rotation"] = BIT_ROTATION_; 334 trafficStringToEnum["neighbor"] = NEIGHBOR_; 335 trafficStringToEnum["shuffle"] = SHUFFLE_; 336 trafficStringToEnum["tornado"] = TORNADO_; 337 trafficStringToEnum["transpose"] = TRANSPOSE_; 338 trafficStringToEnum["uniform_random"] = UNIFORM_RANDOM_; 339} 340 341void 342GarnetSyntheticTraffic::doRetry() 343{ 344 if (cachePort.sendTimingReq(retryPkt)) { 345 retryPkt = NULL; 346 } 347} 348 349void 350GarnetSyntheticTraffic::printAddr(Addr a) 351{ 352 cachePort.printAddr(a); 353} 354 355 356GarnetSyntheticTraffic * 357GarnetSyntheticTrafficParams::create() 358{ 359 return new GarnetSyntheticTraffic(this); 360} 361