memtest.hh revision 12085
12SN/A/* 210688Sandreas.hansson@arm.com * Copyright (c) 2015 ARM Limited 310688Sandreas.hansson@arm.com * All rights reserved 410688Sandreas.hansson@arm.com * 510688Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall 610688Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual 710688Sandreas.hansson@arm.com * property including but not limited to intellectual property relating 810688Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software 910688Sandreas.hansson@arm.com * licensed hereunder. You may use the software subject to the license 1010688Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated 1110688Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software, 1210688Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form. 1310688Sandreas.hansson@arm.com * 141762SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 152SN/A * All rights reserved. 162SN/A * 172SN/A * Redistribution and use in source and binary forms, with or without 182SN/A * modification, are permitted provided that the following conditions are 192SN/A * met: redistributions of source code must retain the above copyright 202SN/A * notice, this list of conditions and the following disclaimer; 212SN/A * redistributions in binary form must reproduce the above copyright 222SN/A * notice, this list of conditions and the following disclaimer in the 232SN/A * documentation and/or other materials provided with the distribution; 242SN/A * neither the name of the copyright holders nor the names of its 252SN/A * contributors may be used to endorse or promote products derived from 262SN/A * this software without specific prior written permission. 272SN/A * 282SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 292SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 302SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 312SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 322SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 332SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 342SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 352SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 362SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 372SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 382SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 392665SN/A * 402665SN/A * Authors: Erik Hallnor 412665SN/A * Steve Reinhardt 4210688Sandreas.hansson@arm.com * Andreas Hansson 432SN/A */ 442SN/A 451400SN/A#ifndef __CPU_MEMTEST_MEMTEST_HH__ 461400SN/A#define __CPU_MEMTEST_MEMTEST_HH__ 472SN/A 481298SN/A#include <set> 4910688Sandreas.hansson@arm.com#include <unordered_map> 501298SN/A 511298SN/A#include "base/statistics.hh" 528229Snate@binkert.org#include "mem/mem_object.hh" 535034SN/A#include "params/MemTest.hh" 541400SN/A#include "sim/eventq.hh" 55695SN/A#include "sim/stats.hh" 562SN/A 5710688Sandreas.hansson@arm.com/** 5810688Sandreas.hansson@arm.com * The MemTest class tests a cache coherent memory system by 5910688Sandreas.hansson@arm.com * generating false sharing and verifying the read data against a 6010688Sandreas.hansson@arm.com * reference updated on the completion of writes. Each tester reads 6110688Sandreas.hansson@arm.com * and writes a specific byte in a cache line, as determined by its 6210688Sandreas.hansson@arm.com * unique id. Thus, all requests issued by the MemTest instance are a 6310688Sandreas.hansson@arm.com * single byte and a specific address is only ever touched by a single 6410688Sandreas.hansson@arm.com * tester. 6510688Sandreas.hansson@arm.com * 6610688Sandreas.hansson@arm.com * In addition to verifying the data, the tester also has timeouts for 6710688Sandreas.hansson@arm.com * both requests and responses, thus checking that the memory-system 6810688Sandreas.hansson@arm.com * is making progress. 6910688Sandreas.hansson@arm.com */ 703187SN/Aclass MemTest : public MemObject 712SN/A{ 7210688Sandreas.hansson@arm.com 732SN/A public: 7410688Sandreas.hansson@arm.com 755034SN/A typedef MemTestParams Params; 765034SN/A MemTest(const Params *p); 772SN/A 782SN/A virtual void regStats(); 791634SN/A 809294Sandreas.hansson@arm.com virtual BaseMasterPort &getMasterPort(const std::string &if_name, 819294Sandreas.hansson@arm.com PortID idx = InvalidPortID); 823187SN/A 8310688Sandreas.hansson@arm.com protected: 845314SN/A 8510688Sandreas.hansson@arm.com void tick(); 865606SN/A 8712085Sspwilson2@wisc.edu EventFunctionWrapper tickEvent; 882SN/A 8910688Sandreas.hansson@arm.com void noRequest(); 9010688Sandreas.hansson@arm.com 9112085Sspwilson2@wisc.edu EventFunctionWrapper noRequestEvent; 9210688Sandreas.hansson@arm.com 9310688Sandreas.hansson@arm.com void noResponse(); 9410688Sandreas.hansson@arm.com 9512085Sspwilson2@wisc.edu EventFunctionWrapper noResponseEvent; 964474SN/A 978922Swilliam.wang@arm.com class CpuPort : public MasterPort 983187SN/A { 9910688Sandreas.hansson@arm.com MemTest &memtest; 1003187SN/A 1013187SN/A public: 1023187SN/A 10310688Sandreas.hansson@arm.com CpuPort(const std::string &_name, MemTest &_memtest) 10410688Sandreas.hansson@arm.com : MasterPort(_name, &_memtest), memtest(_memtest) 1053187SN/A { } 1063187SN/A 1073187SN/A protected: 1083187SN/A 10910688Sandreas.hansson@arm.com bool recvTimingResp(PacketPtr pkt); 1103187SN/A 11110688Sandreas.hansson@arm.com void recvTimingSnoopReq(PacketPtr pkt) { } 1123187SN/A 11310688Sandreas.hansson@arm.com void recvFunctionalSnoop(PacketPtr pkt) { } 1148948Sandreas.hansson@arm.com 11510688Sandreas.hansson@arm.com Tick recvAtomicSnoop(PacketPtr pkt) { return 0; } 1163187SN/A 11710713Sandreas.hansson@arm.com void recvReqRetry(); 1183187SN/A }; 1193187SN/A 12010688Sandreas.hansson@arm.com CpuPort port; 1213187SN/A 1223349SN/A PacketPtr retryPkt; 1233187SN/A 12410688Sandreas.hansson@arm.com const unsigned size; 1252SN/A 12610688Sandreas.hansson@arm.com const Cycles interval; 1272SN/A 12810688Sandreas.hansson@arm.com const unsigned percentReads; 12910688Sandreas.hansson@arm.com const unsigned percentFunctional; 13010688Sandreas.hansson@arm.com const unsigned percentUncacheable; 1317544SN/A 1328832SAli.Saidi@ARM.com /** Request id for all generated traffic */ 1338832SAli.Saidi@ARM.com MasterID masterId; 1348832SAli.Saidi@ARM.com 13510688Sandreas.hansson@arm.com unsigned int id; 1361298SN/A 13710688Sandreas.hansson@arm.com std::set<Addr> outstandingAddrs; 1381298SN/A 13910688Sandreas.hansson@arm.com // store the expected value for the addresses we have touched 14010688Sandreas.hansson@arm.com std::unordered_map<Addr, uint8_t> referenceData; 1412SN/A 14210688Sandreas.hansson@arm.com const unsigned blockSize; 1432SN/A 14410688Sandreas.hansson@arm.com const Addr blockAddrMask; 14510688Sandreas.hansson@arm.com 14610688Sandreas.hansson@arm.com /** 14710688Sandreas.hansson@arm.com * Get the block aligned address. 14810688Sandreas.hansson@arm.com * 14910688Sandreas.hansson@arm.com * @param addr Address to align 15010688Sandreas.hansson@arm.com * @return The block aligned address 15110688Sandreas.hansson@arm.com */ 15210688Sandreas.hansson@arm.com Addr blockAlign(Addr addr) const 1532SN/A { 1542SN/A return (addr & ~blockAddrMask); 1552SN/A } 1562SN/A 15710688Sandreas.hansson@arm.com Addr baseAddr1; 15810688Sandreas.hansson@arm.com Addr baseAddr2; 1592SN/A Addr uncacheAddr; 1602SN/A 16110688Sandreas.hansson@arm.com const unsigned progressInterval; // frequency of progress reports 16210688Sandreas.hansson@arm.com const Cycles progressCheck; 1635543SN/A Tick nextProgressMessage; // access # for next progress report 1642SN/A 165695SN/A uint64_t numReads; 1668436SBrad.Beckmann@amd.com uint64_t numWrites; 16710688Sandreas.hansson@arm.com const uint64_t maxLoads; 1683262SN/A 16910688Sandreas.hansson@arm.com const bool atomic; 17010688Sandreas.hansson@arm.com 17110688Sandreas.hansson@arm.com const bool suppressFuncWarnings; 1723262SN/A 1735999SN/A Stats::Scalar numReadsStat; 1745999SN/A Stats::Scalar numWritesStat; 1752SN/A 17610688Sandreas.hansson@arm.com /** 17710688Sandreas.hansson@arm.com * Complete a request by checking the response. 17810688Sandreas.hansson@arm.com * 17910688Sandreas.hansson@arm.com * @param pkt Response packet 18010688Sandreas.hansson@arm.com * @param functional Whether the access was functional or not 18110688Sandreas.hansson@arm.com */ 18210688Sandreas.hansson@arm.com void completeRequest(PacketPtr pkt, bool functional = false); 1833187SN/A 18410688Sandreas.hansson@arm.com bool sendPkt(PacketPtr pkt); 1853262SN/A 18610688Sandreas.hansson@arm.com void recvRetry(); 1872SN/A 1882SN/A}; 1892SN/A 1901400SN/A#endif // __CPU_MEMTEST_MEMTEST_HH__ 191