memtest.hh revision 3402
1545SN/A/* 21762SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 3545SN/A * All rights reserved. 4545SN/A * 5545SN/A * Redistribution and use in source and binary forms, with or without 6545SN/A * modification, are permitted provided that the following conditions are 7545SN/A * met: redistributions of source code must retain the above copyright 8545SN/A * notice, this list of conditions and the following disclaimer; 9545SN/A * redistributions in binary form must reproduce the above copyright 10545SN/A * notice, this list of conditions and the following disclaimer in the 11545SN/A * documentation and/or other materials provided with the distribution; 12545SN/A * neither the name of the copyright holders nor the names of its 13545SN/A * contributors may be used to endorse or promote products derived from 14545SN/A * this software without specific prior written permission. 15545SN/A * 16545SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17545SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18545SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19545SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20545SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21545SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22545SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23545SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24545SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25545SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26545SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Erik Hallnor 292665Ssaidi@eecs.umich.edu * Steve Reinhardt 30545SN/A */ 31545SN/A 321310SN/A#ifndef __CPU_MEMTEST_MEMTEST_HH__ 331310SN/A#define __CPU_MEMTEST_MEMTEST_HH__ 34545SN/A 352542SN/A#include <set> 362592SN/A 372489SN/A#include "base/statistics.hh" 382914Ssaidi@eecs.umich.edu//#include "mem/functional/functional.hh" 39545SN/A//#include "mem/mem_interface.hh" 403090Sstever@eecs.umich.edu#include "sim/eventq.hh" 411310SN/A#include "sim/sim_exit.hh" 422384SN/A#include "sim/sim_object.hh" 432489SN/A#include "sim/stats.hh" 442522SN/A#include "mem/mem_object.hh" 45545SN/A#include "mem/port.hh" 462489SN/A 472489SN/Aclass Packet; 482489SN/Aclass MemTest : public MemObject 492489SN/A{ 502489SN/A public: 513090Sstever@eecs.umich.edu 523090Sstever@eecs.umich.edu MemTest(const std::string &name, 532914Ssaidi@eecs.umich.edu// MemInterface *_cache_interface, 54545SN/A// PhysicalMemory *main_mem, 55545SN/A// PhysicalMemory *check_mem, 562489SN/A unsigned _memorySize, 572384SN/A unsigned _percentReads, 582384SN/A unsigned _percentFunctional, 592630SN/A unsigned _percentUncacheable, 602384SN/A unsigned _progressInterval, 613090Sstever@eecs.umich.edu unsigned _percentSourceUnaligned, 623090Sstever@eecs.umich.edu unsigned _percentDestUnaligned, 632384SN/A Addr _traceAddr, 642384SN/A Counter _max_loads, 653091Sstever@eecs.umich.edu bool _atomic); 662901Ssaidi@eecs.umich.edu 672384SN/A virtual void init(); 682384SN/A 692565SN/A // register statistics 702384SN/A virtual void regStats(); 712384SN/A 722384SN/A inline Tick cycles(int numCycles) const { return numCycles; } 732784Ssaidi@eecs.umich.edu 742784Ssaidi@eecs.umich.edu // main simulation loop (one cycle) 752784Ssaidi@eecs.umich.edu void tick(); 762784Ssaidi@eecs.umich.edu 772784Ssaidi@eecs.umich.edu virtual Port *getPort(const std::string &if_name, int idx = -1); 782784Ssaidi@eecs.umich.edu 792784Ssaidi@eecs.umich.edu protected: 802784Ssaidi@eecs.umich.edu class TickEvent : public Event 812784Ssaidi@eecs.umich.edu { 822784Ssaidi@eecs.umich.edu private: 832784Ssaidi@eecs.umich.edu MemTest *cpu; 842784Ssaidi@eecs.umich.edu public: 852784Ssaidi@eecs.umich.edu TickEvent(MemTest *c) 862784Ssaidi@eecs.umich.edu : Event(&mainEventQueue, CPU_Tick_Pri), cpu(c) {} 872784Ssaidi@eecs.umich.edu void process() {cpu->tick();} 882784Ssaidi@eecs.umich.edu virtual const char *description() { return "tick event"; } 892784Ssaidi@eecs.umich.edu }; 902784Ssaidi@eecs.umich.edu 912784Ssaidi@eecs.umich.edu TickEvent tickEvent; 922784Ssaidi@eecs.umich.edu class CpuPort : public Port 932565SN/A { 942384SN/A 952384SN/A MemTest *memtest; 962901Ssaidi@eecs.umich.edu 972565SN/A public: 982901Ssaidi@eecs.umich.edu 992565SN/A CpuPort(const std::string &_name, MemTest *_memtest) 1002565SN/A : Port(_name, _memtest), memtest(_memtest) 1012565SN/A { } 1022384SN/A 1032901Ssaidi@eecs.umich.edu protected: 1042901Ssaidi@eecs.umich.edu 1052901Ssaidi@eecs.umich.edu virtual bool recvTiming(PacketPtr pkt); 1062901Ssaidi@eecs.umich.edu 1072901Ssaidi@eecs.umich.edu virtual Tick recvAtomic(PacketPtr pkt); 1082901Ssaidi@eecs.umich.edu 1092901Ssaidi@eecs.umich.edu virtual void recvFunctional(PacketPtr pkt); 1102630SN/A 1112630SN/A virtual void recvStatusChange(Status status); 1122384SN/A 1132630SN/A virtual void recvRetry(); 1142384SN/A 1152384SN/A virtual void getDeviceAddressRanges(AddrRangeList &resp, 1162384SN/A AddrRangeList &snoop) 1172384SN/A { resp.clear(); snoop.clear(); snoop.push_back(RangeSize(0,-1)); } 1182384SN/A }; 1192657Ssaidi@eecs.umich.edu 1202384SN/A CpuPort cachePort; 1213090Sstever@eecs.umich.edu CpuPort funcPort; 1223090Sstever@eecs.umich.edu 1232521SN/A class MemTestSenderState : public Packet::SenderState 1242384SN/A { 1252685Ssaidi@eecs.umich.edu public: 1262489SN/A /** Constructor. */ 1272384SN/A MemTestSenderState(uint8_t *_data) 1282901Ssaidi@eecs.umich.edu : data(_data) 1292565SN/A { } 1302641Sstever@eecs.umich.edu 1312641Sstever@eecs.umich.edu // Hold onto data pointer 1322565SN/A uint8_t *data; 1332565SN/A }; 1342384SN/A 1352901Ssaidi@eecs.umich.edu// Request *dataReq; 1362384SN/A PacketPtr retryPkt; 1372384SN/A// MemInterface *cacheInterface; 1382489SN/A// PhysicalMemory *mainMem; 1392489SN/A// PhysicalMemory *checkMem; 1402489SN/A// SimpleThread *thread; 1412489SN/A 1422489SN/A bool accessRetry; 1432489SN/A 1442489SN/A unsigned size; // size of testing memory region 1452542SN/A 1462384SN/A unsigned percentReads; // target percentage of read accesses 1472384SN/A unsigned percentFunctional; // target percentage of functional accesses 1482384SN/A unsigned percentUncacheable; 1492489SN/A 1502489SN/A int id; 1511310SN/A 1522384SN/A std::set<unsigned> outstandingAddrs; 1532901Ssaidi@eecs.umich.edu 1542901Ssaidi@eecs.umich.edu unsigned blockSize; 1552489SN/A 1562489SN/A Addr blockAddrMask; 1572384SN/A 1582384SN/A Addr blockAddr(Addr addr) 1592521SN/A { 1602384SN/A return (addr & ~blockAddrMask); 1613090Sstever@eecs.umich.edu } 1623090Sstever@eecs.umich.edu 1632523SN/A Addr traceBlockAddr; 1642523SN/A 1652523SN/A Addr baseAddr1; // fix this to option 1662630SN/A Addr baseAddr2; // fix this to option 1672384SN/A Addr uncacheAddr; 1682489SN/A 1692523SN/A unsigned progressInterval; // frequency of progress reports 1702523SN/A Tick nextProgressMessage; // access # for next progress report 1712523SN/A 1722523SN/A unsigned percentSourceUnaligned; 1732630SN/A unsigned percentDestUnaligned; 174545SN/A 175545SN/A Tick noResponseCycles; 1763090Sstever@eecs.umich.edu 1773090Sstever@eecs.umich.edu uint64_t numReads; 1783090Sstever@eecs.umich.edu uint64_t maxLoads; 1792512SN/A 1802512SN/A bool atomic; 1812512SN/A 1822512SN/A Stats::Scalar<> numReadsStat; 1832522SN/A Stats::Scalar<> numWritesStat; 1842512SN/A Stats::Scalar<> numCopiesStat; 1852521SN/A 1862512SN/A // called by MemCompleteEvent::process() 1872512SN/A void completeRequest(PacketPtr pkt); 1882512SN/A 1892512SN/A void sendPkt(PacketPtr pkt); 1902512SN/A 1912512SN/A void doRetry(); 1922521SN/A 1932901Ssaidi@eecs.umich.edu friend class MemCompleteEvent; 1942901Ssaidi@eecs.umich.edu}; 1952512SN/A 1962384SN/A#endif // __CPU_MEMTEST_MEMTEST_HH__ 197545SN/A 1982384SN/A 1992541SN/A 2002541SN/A