memtest.hh revision 1400
1/* 2 * Copyright (c) 2002-2004 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#ifndef __CPU_MEMTEST_MEMTEST_HH__ 30#define __CPU_MEMTEST_MEMTEST_HH__ 31 32#include <set> 33 34#include "base/statistics.hh" 35#include "mem/functional_mem/functional_memory.hh" 36#include "mem/mem_interface.hh" 37#include "sim/eventq.hh" 38#include "sim/sim_exit.hh" 39#include "sim/sim_object.hh" 40#include "sim/stats.hh" 41 42class ExecContext; 43class MemTest : public SimObject 44{ 45 public: 46 47 MemTest(const std::string &name, 48 MemInterface *_cache_interface, 49 FunctionalMemory *main_mem, 50 FunctionalMemory *check_mem, 51 unsigned _memorySize, 52 unsigned _percentReads, 53 unsigned _percentCopies, 54 unsigned _percentUncacheable, 55 unsigned _progressInterval, 56 unsigned _percentSourceUnaligned, 57 unsigned _percentDestUnaligned, 58 Addr _traceAddr, 59 Counter _max_loads); 60 61 // register statistics 62 virtual void regStats(); 63 // main simulation loop (one cycle) 64 void tick(); 65 66 protected: 67 class TickEvent : public Event 68 { 69 private: 70 MemTest *cpu; 71 public: 72 TickEvent(MemTest *c) 73 : Event(&mainEventQueue, CPU_Tick_Pri), cpu(c) {} 74 void process() {cpu->tick();} 75 virtual const char *description() { return "tick event"; } 76 }; 77 78 TickEvent tickEvent; 79 80 MemInterface *cacheInterface; 81 FunctionalMemory *mainMem; 82 FunctionalMemory *checkMem; 83 ExecContext *xc; 84 85 unsigned size; // size of testing memory region 86 87 unsigned percentReads; // target percentage of read accesses 88 unsigned percentCopies; // target percentage of copy accesses 89 unsigned percentUncacheable; 90 91 int id; 92 93 std::set<unsigned> outstandingAddrs; 94 95 unsigned blockSize; 96 97 Addr blockAddrMask; 98 99 Addr blockAddr(Addr addr) 100 { 101 return (addr & ~blockAddrMask); 102 } 103 104 Addr traceBlockAddr; 105 106 Addr baseAddr1; // fix this to option 107 Addr baseAddr2; // fix this to option 108 Addr uncacheAddr; 109 110 unsigned progressInterval; // frequency of progress reports 111 Tick nextProgressMessage; // access # for next progress report 112 113 unsigned percentSourceUnaligned; 114 unsigned percentDestUnaligned; 115 116 Tick noResponseCycles; 117 118 uint64_t numReads; 119 uint64_t maxLoads; 120 Stats::Scalar<> numReadsStat; 121 Stats::Scalar<> numWritesStat; 122 Stats::Scalar<> numCopiesStat; 123 124 // called by MemCompleteEvent::process() 125 void completeRequest(MemReqPtr &req, uint8_t *data); 126 127 friend class MemCompleteEvent; 128}; 129 130 131class MemCompleteEvent : public Event 132{ 133 MemReqPtr req; 134 uint8_t *data; 135 MemTest *tester; 136 137 public: 138 139 MemCompleteEvent(MemReqPtr &_req, uint8_t *_data, MemTest *_tester) 140 : Event(&mainEventQueue), 141 req(_req), data(_data), tester(_tester) 142 { 143 } 144 145 void process(); 146 147 virtual const char *description(); 148}; 149 150#endif // __CPU_MEMTEST_MEMTEST_HH__ 151 152 153 154