random_gen.cc revision 12396
11689SN/A/* 29783Sandreas.hansson@arm.com * Copyright (c) 2012-2013, 2016-2017 ARM Limited 310239Sbinhpham@cs.rutgers.edu * All rights reserved 47598Sminkyu.jeong@arm.com * 57598Sminkyu.jeong@arm.com * The license below extends only to copyright in the software and shall 67598Sminkyu.jeong@arm.com * not be construed as granting a license to any other intellectual 77598Sminkyu.jeong@arm.com * property including but not limited to intellectual property relating 87598Sminkyu.jeong@arm.com * to a hardware implementation of the functionality of the software 97598Sminkyu.jeong@arm.com * licensed here under. You may use the software subject to the license 107598Sminkyu.jeong@arm.com * terms below provided that you ensure that this notice is replicated 117598Sminkyu.jeong@arm.com * unmodified and in its entirety in all distributions of the software, 127598Sminkyu.jeong@arm.com * modified or unmodified, in source code or in binary form. 137598Sminkyu.jeong@arm.com * 147598Sminkyu.jeong@arm.com * Redistribution and use in source and binary forms, with or without 152326SN/A * modification, are permitted provided that the following conditions are 161689SN/A * met: redistributions of source code must retain the above copyright 171689SN/A * notice, this list of conditions and the following disclaimer; 181689SN/A * redistributions in binary form must reproduce the above copyright 191689SN/A * notice, this list of conditions and the following disclaimer in the 201689SN/A * documentation and/or other materials provided with the distribution; 211689SN/A * neither the name of the copyright holders nor the names of its 221689SN/A * contributors may be used to endorse or promote products derived from 231689SN/A * this software without specific prior written permission. 241689SN/A * 251689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 261689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 271689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 281689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 291689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 301689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 311689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 321689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 331689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 341689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 351689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 361689SN/A * 371689SN/A * Authors: Thomas Grass 381689SN/A * Andreas Hansson 391689SN/A * Sascha Bischoff 402665Ssaidi@eecs.umich.edu * Neha Agarwal 412665Ssaidi@eecs.umich.edu */ 421689SN/A 431689SN/A#include "cpu/testers/traffic_gen/random_gen.hh" 449944Smatt.horsnell@ARM.com 459944Smatt.horsnell@ARM.com#include <algorithm> 469944Smatt.horsnell@ARM.com 471060SN/A#include "base/random.hh" 481060SN/A#include "base/trace.hh" 491689SN/A#include "debug/TrafficGen.hh" 501060SN/A#include "proto/packet.pb.h" 511060SN/A 521060SN/Avoid 538230Snate@binkert.orgRandomGen::enter() 546658Snate@binkert.org{ 558887Sgeoffrey.blake@arm.com // reset the counter to zero 562292SN/A dataManipulated = 0; 571717SN/A} 588229Snate@binkert.org 598232Snate@binkert.orgPacketPtr 609444SAndreas.Sandberg@ARM.comRandomGen::getNextPacket() 618232Snate@binkert.org{ 629527SMatt.Horsnell@arm.com // choose if we generate a read or a write here 635529Snate@binkert.org bool isRead = readPercent != 0 && 641060SN/A (readPercent == 100 || random_mt.random(0, 100) < readPercent); 656221Snate@binkert.org 666221Snate@binkert.org assert((readPercent == 0 && !isRead) || (readPercent == 100 && isRead) || 671681SN/A readPercent != 100); 685529Snate@binkert.org 692873Sktlim@umich.edu // address of the request 704329Sktlim@umich.edu Addr addr = random_mt.random(startAddr, endAddr - 1); 714329Sktlim@umich.edu 724329Sktlim@umich.edu // round down to start address of block 732292SN/A addr -= addr % blocksize; 742292SN/A 752292SN/A DPRINTF(TrafficGen, "RandomGen::getNextPacket: %c to addr %x, size %d\n", 762292SN/A isRead ? 'r' : 'w', addr, blocksize); 772820Sktlim@umich.edu 782292SN/A // add the amount of data manipulated to the total 792820Sktlim@umich.edu dataManipulated += blocksize; 802820Sktlim@umich.edu 819444SAndreas.Sandberg@ARM.com // create a new request packet 821060SN/A return getPacket(addr, blocksize, 8310172Sdam.sunwoo@arm.com isRead ? MemCmd::ReadReq : MemCmd::WriteReq); 8410172Sdam.sunwoo@arm.com} 8510172Sdam.sunwoo@arm.com 8610172Sdam.sunwoo@arm.comTick 8710172Sdam.sunwoo@arm.comRandomGen::nextPacketTick(bool elastic, Tick delay) const 8810172Sdam.sunwoo@arm.com{ 8910172Sdam.sunwoo@arm.com // Check to see if we have reached the data limit. If dataLimit is 9010172Sdam.sunwoo@arm.com // zero we do not have a data limit and therefore we will keep 9110172Sdam.sunwoo@arm.com // generating requests for the entire residency in this state. 9210172Sdam.sunwoo@arm.com if (dataLimit && dataManipulated >= dataLimit) 9310172Sdam.sunwoo@arm.com { 9410172Sdam.sunwoo@arm.com DPRINTF(TrafficGen, "Data limit for RandomGen reached.\n"); 9510172Sdam.sunwoo@arm.com // No more requests. Return MaxTick. 962292SN/A return MaxTick; 972292SN/A } else { 982292SN/A // return the time when the next request should take place 991060SN/A Tick wait = random_mt.random(minPeriod, maxPeriod); 1001060SN/A 1011060SN/A // compensate for the delay experienced to not be elastic, by 1021060SN/A // default the value we generate is from the time we are 1031060SN/A // asked, so the elasticity happens automatically 1041060SN/A if (!elastic) { 1051681SN/A if (wait < delay) 1066221Snate@binkert.org wait = 0; 1076221Snate@binkert.org else 1086221Snate@binkert.org wait -= delay; 1096221Snate@binkert.org } 1102292SN/A 1112292SN/A return curTick() + wait; 1122820Sktlim@umich.edu } 1132820Sktlim@umich.edu} 1142292SN/A