memtest.hh revision 5543
16657Snate@binkert.org/* 26657Snate@binkert.org * Copyright (c) 2002-2005 The Regents of The University of Michigan 36657Snate@binkert.org * All rights reserved. 46657Snate@binkert.org * 56657Snate@binkert.org * Redistribution and use in source and binary forms, with or without 66657Snate@binkert.org * modification, are permitted provided that the following conditions are 76657Snate@binkert.org * met: redistributions of source code must retain the above copyright 86657Snate@binkert.org * notice, this list of conditions and the following disclaimer; 96657Snate@binkert.org * redistributions in binary form must reproduce the above copyright 106657Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 116657Snate@binkert.org * documentation and/or other materials provided with the distribution; 126657Snate@binkert.org * neither the name of the copyright holders nor the names of its 136657Snate@binkert.org * contributors may be used to endorse or promote products derived from 146657Snate@binkert.org * this software without specific prior written permission. 156657Snate@binkert.org * 166657Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176657Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186657Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196657Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206657Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216657Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226657Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236657Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246657Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256657Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266657Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276657Snate@binkert.org * 286657Snate@binkert.org * Authors: Erik Hallnor 296657Snate@binkert.org * Steve Reinhardt 306657Snate@binkert.org */ 316657Snate@binkert.org 326657Snate@binkert.org#ifndef __CPU_MEMTEST_MEMTEST_HH__ 336657Snate@binkert.org#define __CPU_MEMTEST_MEMTEST_HH__ 346657Snate@binkert.org 356657Snate@binkert.org#include <set> 366657Snate@binkert.org 376657Snate@binkert.org#include "base/statistics.hh" 386657Snate@binkert.org#include "base/fast_alloc.hh" 396657Snate@binkert.org#include "params/MemTest.hh" 406657Snate@binkert.org#include "sim/eventq.hh" 416657Snate@binkert.org#include "sim/sim_exit.hh" 426657Snate@binkert.org#include "sim/sim_object.hh" 436657Snate@binkert.org#include "sim/stats.hh" 446657Snate@binkert.org#include "mem/mem_object.hh" 456657Snate@binkert.org#include "mem/port.hh" 466657Snate@binkert.org 476657Snate@binkert.orgclass Packet; 486657Snate@binkert.orgclass MemTest : public MemObject 496657Snate@binkert.org{ 506657Snate@binkert.org public: 516657Snate@binkert.org typedef MemTestParams Params; 526657Snate@binkert.org MemTest(const Params *p); 536657Snate@binkert.org 546657Snate@binkert.org virtual void init(); 556657Snate@binkert.org 566657Snate@binkert.org // register statistics 576657Snate@binkert.org virtual void regStats(); 586657Snate@binkert.org 596657Snate@binkert.org inline Tick ticks(int numCycles) const { return numCycles; } 606657Snate@binkert.org 616657Snate@binkert.org // main simulation loop (one cycle) 626657Snate@binkert.org void tick(); 636657Snate@binkert.org 646657Snate@binkert.org virtual Port *getPort(const std::string &if_name, int idx = -1); 656657Snate@binkert.org 666657Snate@binkert.org /** 676657Snate@binkert.org * Print state of address in memory system via PrintReq (for 686657Snate@binkert.org * debugging). 696657Snate@binkert.org */ 706657Snate@binkert.org void printAddr(Addr a); 716657Snate@binkert.org 726657Snate@binkert.org protected: 73 class TickEvent : public Event 74 { 75 private: 76 MemTest *cpu; 77 public: 78 TickEvent(MemTest *c) 79 : Event(&mainEventQueue, CPU_Tick_Pri), cpu(c) {} 80 void process() {cpu->tick();} 81 virtual const char *description() const { return "MemTest tick"; } 82 }; 83 84 TickEvent tickEvent; 85 86 class CpuPort : public Port 87 { 88 MemTest *memtest; 89 90 public: 91 92 CpuPort(const std::string &_name, MemTest *_memtest) 93 : Port(_name, _memtest), memtest(_memtest) 94 { } 95 96 bool snoopRangeSent; 97 98 protected: 99 100 virtual bool recvTiming(PacketPtr pkt); 101 102 virtual Tick recvAtomic(PacketPtr pkt); 103 104 virtual void recvFunctional(PacketPtr pkt); 105 106 virtual void recvStatusChange(Status status); 107 108 virtual void recvRetry(); 109 110 virtual void getDeviceAddressRanges(AddrRangeList &resp, 111 bool &snoop) 112 { resp.clear(); snoop = false; } 113 }; 114 115 CpuPort cachePort; 116 CpuPort funcPort; 117 118 bool snoopRangeSent; 119 120 class MemTestSenderState : public Packet::SenderState, public FastAlloc 121 { 122 public: 123 /** Constructor. */ 124 MemTestSenderState(uint8_t *_data) 125 : data(_data) 126 { } 127 128 // Hold onto data pointer 129 uint8_t *data; 130 }; 131 132 PacketPtr retryPkt; 133 134 bool accessRetry; 135 136 unsigned size; // size of testing memory region 137 138 unsigned percentReads; // target percentage of read accesses 139 unsigned percentFunctional; // target percentage of functional accesses 140 unsigned percentUncacheable; 141 142 int id; 143 144 std::set<unsigned> outstandingAddrs; 145 146 unsigned blockSize; 147 148 Addr blockAddrMask; 149 150 Addr blockAddr(Addr addr) 151 { 152 return (addr & ~blockAddrMask); 153 } 154 155 Addr traceBlockAddr; 156 157 Addr baseAddr1; // fix this to option 158 Addr baseAddr2; // fix this to option 159 Addr uncacheAddr; 160 161 unsigned progressInterval; // frequency of progress reports 162 Tick nextProgressMessage; // access # for next progress report 163 164 unsigned percentSourceUnaligned; 165 unsigned percentDestUnaligned; 166 167 Tick noResponseCycles; 168 169 uint64_t numReads; 170 uint64_t maxLoads; 171 172 bool atomic; 173 174 Stats::Scalar<> numReadsStat; 175 Stats::Scalar<> numWritesStat; 176 Stats::Scalar<> numCopiesStat; 177 178 // called by MemCompleteEvent::process() 179 void completeRequest(PacketPtr pkt); 180 181 void sendPkt(PacketPtr pkt); 182 183 void doRetry(); 184 185 friend class MemCompleteEvent; 186}; 187 188#endif // __CPU_MEMTEST_MEMTEST_HH__ 189 190 191 192