memtest.hh revision 3187
113821Sgabeblack@google.com/* 213821Sgabeblack@google.com * Copyright (c) 2002-2005 The Regents of The University of Michigan 313821Sgabeblack@google.com * All rights reserved. 413821Sgabeblack@google.com * 513821Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 613821Sgabeblack@google.com * modification, are permitted provided that the following conditions are 713821Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 813821Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 913821Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 1013821Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1113821Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1213821Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1313821Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1413821Sgabeblack@google.com * this software without specific prior written permission. 1513821Sgabeblack@google.com * 1613821Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1713821Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1813821Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1913821Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2013821Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2113821Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2213821Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2313821Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2413821Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2513821Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2613821Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2713821Sgabeblack@google.com * 2813821Sgabeblack@google.com * Authors: Erik Hallnor 2913821Sgabeblack@google.com * Steve Reinhardt 3013821Sgabeblack@google.com */ 3113821Sgabeblack@google.com 3213821Sgabeblack@google.com#ifndef __CPU_MEMTEST_MEMTEST_HH__ 3313821Sgabeblack@google.com#define __CPU_MEMTEST_MEMTEST_HH__ 3413821Sgabeblack@google.com 3513821Sgabeblack@google.com#include <set> 3613821Sgabeblack@google.com 3713821Sgabeblack@google.com#include "base/statistics.hh" 3813821Sgabeblack@google.com//#include "mem/functional/functional.hh" 3913821Sgabeblack@google.com//#include "mem/mem_interface.hh" 4013821Sgabeblack@google.com#include "sim/eventq.hh" 4113821Sgabeblack@google.com#include "sim/sim_exit.hh" 4213821Sgabeblack@google.com#include "sim/sim_object.hh" 4313821Sgabeblack@google.com#include "sim/stats.hh" 4413821Sgabeblack@google.com#include "mem/mem_object.hh" 4513821Sgabeblack@google.com#include "mem/port.hh" 4613821Sgabeblack@google.com 4713821Sgabeblack@google.comclass Packet; 4813821Sgabeblack@google.comclass MemTest : public MemObject 4913821Sgabeblack@google.com{ 5013821Sgabeblack@google.com public: 5113821Sgabeblack@google.com 5213821Sgabeblack@google.com MemTest(const std::string &name, 5313821Sgabeblack@google.com// MemInterface *_cache_interface, 5413821Sgabeblack@google.com// PhysicalMemory *main_mem, 5513821Sgabeblack@google.com// PhysicalMemory *check_mem, 5613821Sgabeblack@google.com unsigned _memorySize, 5713821Sgabeblack@google.com unsigned _percentReads, 5813821Sgabeblack@google.com// unsigned _percentCopies, 5913821Sgabeblack@google.com unsigned _percentUncacheable, 6013821Sgabeblack@google.com unsigned _progressInterval, 6113821Sgabeblack@google.com unsigned _percentSourceUnaligned, 6213821Sgabeblack@google.com unsigned _percentDestUnaligned, 6313821Sgabeblack@google.com Addr _traceAddr, 6413821Sgabeblack@google.com Counter _max_loads); 6513823Sgabeblack@google.com 6613821Sgabeblack@google.com virtual void init(); 6713821Sgabeblack@google.com 6813821Sgabeblack@google.com // register statistics 6913821Sgabeblack@google.com virtual void regStats(); 7013821Sgabeblack@google.com 7113821Sgabeblack@google.com inline Tick cycles(int numCycles) const { return numCycles; } 7213821Sgabeblack@google.com 7313821Sgabeblack@google.com // main simulation loop (one cycle) 7413821Sgabeblack@google.com void tick(); 7513821Sgabeblack@google.com 7613821Sgabeblack@google.com virtual Port *getPort(const std::string &if_name, int idx = -1); 7713823Sgabeblack@google.com 7813823Sgabeblack@google.com protected: 7913823Sgabeblack@google.com class TickEvent : public Event 8013823Sgabeblack@google.com { 8113823Sgabeblack@google.com private: 8213823Sgabeblack@google.com MemTest *cpu; 8313823Sgabeblack@google.com public: 8413823Sgabeblack@google.com TickEvent(MemTest *c) 8513821Sgabeblack@google.com : Event(&mainEventQueue, CPU_Tick_Pri), cpu(c) {} 8613821Sgabeblack@google.com void process() {cpu->tick();} 8713821Sgabeblack@google.com virtual const char *description() { return "tick event"; } 8813821Sgabeblack@google.com }; 8913821Sgabeblack@google.com 9013821Sgabeblack@google.com TickEvent tickEvent; 9113821Sgabeblack@google.com class CpuPort : public Port 9213821Sgabeblack@google.com { 9313821Sgabeblack@google.com 9413821Sgabeblack@google.com MemTest *memtest; 9513821Sgabeblack@google.com 9613823Sgabeblack@google.com public: 9713821Sgabeblack@google.com 9813821Sgabeblack@google.com CpuPort(const std::string &_name, MemTest *_memtest) 9913821Sgabeblack@google.com : Port(_name), memtest(_memtest) 10013821Sgabeblack@google.com { } 10113821Sgabeblack@google.com 10213821Sgabeblack@google.com protected: 10313821Sgabeblack@google.com 10413821Sgabeblack@google.com virtual bool recvTiming(Packet *pkt); 10513821Sgabeblack@google.com 10613821Sgabeblack@google.com virtual Tick recvAtomic(Packet *pkt); 10713823Sgabeblack@google.com 10813823Sgabeblack@google.com virtual void recvFunctional(Packet *pkt); 10913821Sgabeblack@google.com 11013821Sgabeblack@google.com virtual void recvStatusChange(Status status); 11113821Sgabeblack@google.com 11213821Sgabeblack@google.com virtual void recvRetry(); 11313823Sgabeblack@google.com 11413821Sgabeblack@google.com virtual void getDeviceAddressRanges(AddrRangeList &resp, 11513821Sgabeblack@google.com AddrRangeList &snoop) 11613821Sgabeblack@google.com { resp.clear(); snoop.clear(); } 11713821Sgabeblack@google.com }; 11813821Sgabeblack@google.com 11913821Sgabeblack@google.com CpuPort cachePort; 12013821Sgabeblack@google.com CpuPort funcPort; 12113821Sgabeblack@google.com 12213821Sgabeblack@google.com class MemTestSenderState : public Packet::SenderState 12313821Sgabeblack@google.com { 12413823Sgabeblack@google.com public: 12513823Sgabeblack@google.com /** Constructor. */ 12613823Sgabeblack@google.com MemTestSenderState(uint8_t *_data) 12713821Sgabeblack@google.com : data(_data) 12813821Sgabeblack@google.com { } 12913821Sgabeblack@google.com 13013821Sgabeblack@google.com // Hold onto data pointer 13113821Sgabeblack@google.com uint8_t *data; 13213821Sgabeblack@google.com }; 13313821Sgabeblack@google.com 13413821Sgabeblack@google.com// Request *dataReq; 13513821Sgabeblack@google.com Packet *retryPkt; 13613821Sgabeblack@google.com// MemInterface *cacheInterface; 13713821Sgabeblack@google.com// PhysicalMemory *mainMem; 13813821Sgabeblack@google.com// PhysicalMemory *checkMem; 13913821Sgabeblack@google.com// SimpleThread *thread; 14013821Sgabeblack@google.com 14113821Sgabeblack@google.com bool accessRetry; 14213821Sgabeblack@google.com 14313821Sgabeblack@google.com unsigned size; // size of testing memory region 14413821Sgabeblack@google.com 14513821Sgabeblack@google.com unsigned percentReads; // target percentage of read accesses 14613821Sgabeblack@google.com// unsigned percentCopies; // target percentage of copy accesses 14713821Sgabeblack@google.com unsigned percentUncacheable; 14813821Sgabeblack@google.com 14913821Sgabeblack@google.com int id; 15013821Sgabeblack@google.com 15113821Sgabeblack@google.com std::set<unsigned> outstandingAddrs; 15213821Sgabeblack@google.com 15313821Sgabeblack@google.com unsigned blockSize; 15413821Sgabeblack@google.com 15513821Sgabeblack@google.com Addr blockAddrMask; 15613821Sgabeblack@google.com 15713821Sgabeblack@google.com Addr blockAddr(Addr addr) 15813821Sgabeblack@google.com { 15913821Sgabeblack@google.com return (addr & ~blockAddrMask); 16013821Sgabeblack@google.com } 16113821Sgabeblack@google.com 16213821Sgabeblack@google.com Addr traceBlockAddr; 16313823Sgabeblack@google.com 16413821Sgabeblack@google.com Addr baseAddr1; // fix this to option 16513821Sgabeblack@google.com Addr baseAddr2; // fix this to option 16613823Sgabeblack@google.com Addr uncacheAddr; 16713821Sgabeblack@google.com 16813821Sgabeblack@google.com unsigned progressInterval; // frequency of progress reports 16913821Sgabeblack@google.com Tick nextProgressMessage; // access # for next progress report 17013821Sgabeblack@google.com 17113821Sgabeblack@google.com unsigned percentSourceUnaligned; 17213821Sgabeblack@google.com unsigned percentDestUnaligned; 17313821Sgabeblack@google.com 17413821Sgabeblack@google.com Tick noResponseCycles; 17513821Sgabeblack@google.com 17613821Sgabeblack@google.com uint64_t numReads; 17713821Sgabeblack@google.com uint64_t maxLoads; 17813821Sgabeblack@google.com Stats::Scalar<> numReadsStat; 17913821Sgabeblack@google.com Stats::Scalar<> numWritesStat; 180 Stats::Scalar<> numCopiesStat; 181 182 // called by MemCompleteEvent::process() 183 void completeRequest(Packet *pkt); 184 185 void doRetry(); 186 187 friend class MemCompleteEvent; 188}; 189 190#endif // __CPU_MEMTEST_MEMTEST_HH__ 191 192 193 194