memtest.hh revision 12085
11689SN/A/* 22329SN/A * Copyright (c) 2015 ARM Limited 31689SN/A * All rights reserved 41689SN/A * 51689SN/A * The license below extends only to copyright in the software and shall 61689SN/A * not be construed as granting a license to any other intellectual 71689SN/A * property including but not limited to intellectual property relating 81689SN/A * to a hardware implementation of the functionality of the software 91689SN/A * licensed hereunder. You may use the software subject to the license 101689SN/A * terms below provided that you ensure that this notice is replicated 111689SN/A * unmodified and in its entirety in all distributions of the software, 121689SN/A * modified or unmodified, in source code or in binary form. 131689SN/A * 141689SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 151689SN/A * All rights reserved. 161689SN/A * 171689SN/A * Redistribution and use in source and binary forms, with or without 181689SN/A * modification, are permitted provided that the following conditions are 191689SN/A * met: redistributions of source code must retain the above copyright 201689SN/A * notice, this list of conditions and the following disclaimer; 211689SN/A * redistributions in binary form must reproduce the above copyright 221689SN/A * notice, this list of conditions and the following disclaimer in the 231689SN/A * documentation and/or other materials provided with the distribution; 241689SN/A * neither the name of the copyright holders nor the names of its 251689SN/A * contributors may be used to endorse or promote products derived from 261689SN/A * this software without specific prior written permission. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 292831Sksewell@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 301689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 311689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 321858SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 331717SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 341060SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 352980Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 362292SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 371061SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 382292SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 392980Sgblack@eecs.umich.edu * 402292SN/A * Authors: Erik Hallnor 411060SN/A * Steve Reinhardt 421060SN/A * Andreas Hansson 431060SN/A */ 442292SN/A 451060SN/A#ifndef __CPU_MEMTEST_MEMTEST_HH__ 462292SN/A#define __CPU_MEMTEST_MEMTEST_HH__ 472877Sksewell@umich.edu 482292SN/A#include <set> 492292SN/A#include <unordered_map> 502292SN/A 512292SN/A#include "base/statistics.hh" 522980Sgblack@eecs.umich.edu#include "mem/mem_object.hh" 532292SN/A#include "params/MemTest.hh" 542292SN/A#include "sim/eventq.hh" 552292SN/A#include "sim/stats.hh" 562292SN/A 572292SN/A/** 582292SN/A * The MemTest class tests a cache coherent memory system by 592292SN/A * generating false sharing and verifying the read data against a 602292SN/A * reference updated on the completion of writes. Each tester reads 612292SN/A * and writes a specific byte in a cache line, as determined by its 622292SN/A * unique id. Thus, all requests issued by the MemTest instance are a 632292SN/A * single byte and a specific address is only ever touched by a single 642292SN/A * tester. 652292SN/A * 662292SN/A * In addition to verifying the data, the tester also has timeouts for 672292SN/A * both requests and responses, thus checking that the memory-system 682292SN/A * is making progress. 692292SN/A */ 702292SN/Aclass MemTest : public MemObject 712292SN/A{ 722292SN/A 732292SN/A public: 742292SN/A 752292SN/A typedef MemTestParams Params; 762292SN/A MemTest(const Params *p); 772292SN/A 782292SN/A virtual void regStats(); 792292SN/A 802292SN/A virtual BaseMasterPort &getMasterPort(const std::string &if_name, 812292SN/A PortID idx = InvalidPortID); 822292SN/A 832292SN/A protected: 842292SN/A 852292SN/A void tick(); 862292SN/A 872292SN/A EventFunctionWrapper tickEvent; 882292SN/A 892292SN/A void noRequest(); 902292SN/A 912292SN/A EventFunctionWrapper noRequestEvent; 922292SN/A 932292SN/A void noResponse(); 942292SN/A 952292SN/A EventFunctionWrapper noResponseEvent; 962292SN/A 972292SN/A class CpuPort : public MasterPort 982292SN/A { 992292SN/A MemTest &memtest; 1001060SN/A 1011060SN/A public: 1021061SN/A 1031060SN/A CpuPort(const std::string &_name, MemTest &_memtest) 1042733Sktlim@umich.edu : MasterPort(_name, &_memtest), memtest(_memtest) 1051060SN/A { } 1061060SN/A 1071060SN/A protected: 1082292SN/A 1092292SN/A bool recvTimingResp(PacketPtr pkt); 1102292SN/A 1112292SN/A void recvTimingSnoopReq(PacketPtr pkt) { } 1121060SN/A 1132292SN/A void recvFunctionalSnoop(PacketPtr pkt) { } 1142292SN/A 1152292SN/A Tick recvAtomicSnoop(PacketPtr pkt) { return 0; } 1162292SN/A 1172292SN/A void recvReqRetry(); 1182292SN/A }; 1192292SN/A 1202292SN/A CpuPort port; 1212980Sgblack@eecs.umich.edu 1222292SN/A PacketPtr retryPkt; 1232292SN/A 1242292SN/A const unsigned size; 1252292SN/A 1262292SN/A const Cycles interval; 1272307SN/A 1282307SN/A const unsigned percentReads; 1292307SN/A const unsigned percentFunctional; 1302307SN/A const unsigned percentUncacheable; 1312307SN/A 1322307SN/A /** Request id for all generated traffic */ 1332307SN/A MasterID masterId; 1342307SN/A 1352307SN/A unsigned int id; 1362307SN/A 1372307SN/A std::set<Addr> outstandingAddrs; 1382307SN/A 1392307SN/A // store the expected value for the addresses we have touched 1402307SN/A std::unordered_map<Addr, uint8_t> referenceData; 1412307SN/A 1422307SN/A const unsigned blockSize; 1432307SN/A 1442307SN/A const Addr blockAddrMask; 1452307SN/A 1462307SN/A /** 1472307SN/A * Get the block aligned address. 1482307SN/A * 1492307SN/A * @param addr Address to align 1502307SN/A * @return The block aligned address 1512307SN/A */ 1522292SN/A Addr blockAlign(Addr addr) const 1532292SN/A { 1542292SN/A return (addr & ~blockAddrMask); 1552292SN/A } 1562292SN/A 1572292SN/A Addr baseAddr1; 1583867Sbinkertn@umich.edu Addr baseAddr2; 1592292SN/A Addr uncacheAddr; 1603867Sbinkertn@umich.edu 1613867Sbinkertn@umich.edu const unsigned progressInterval; // frequency of progress reports 1622292SN/A const Cycles progressCheck; 1633867Sbinkertn@umich.edu Tick nextProgressMessage; // access # for next progress report 1643867Sbinkertn@umich.edu 1653867Sbinkertn@umich.edu uint64_t numReads; 1662292SN/A uint64_t numWrites; 1673867Sbinkertn@umich.edu const uint64_t maxLoads; 1682292SN/A 1693867Sbinkertn@umich.edu const bool atomic; 1702292SN/A 1712292SN/A const bool suppressFuncWarnings; 1722292SN/A 1732292SN/A Stats::Scalar numReadsStat; 1742292SN/A Stats::Scalar numWritesStat; 1752292SN/A 1762292SN/A /** 1772292SN/A * Complete a request by checking the response. 1782292SN/A * 1792292SN/A * @param pkt Response packet 1802292SN/A * @param functional Whether the access was functional or not 1812292SN/A */ 1822292SN/A void completeRequest(PacketPtr pkt, bool functional = false); 1832292SN/A 1841060SN/A bool sendPkt(PacketPtr pkt); 1851060SN/A 1861061SN/A void recvRetry(); 1871060SN/A 1881060SN/A}; 1891060SN/A 1902292SN/A#endif // __CPU_MEMTEST_MEMTEST_HH__ 1911061SN/A