memtest.hh revision 2
1/* 2 * Copyright (c) 2003 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 __MEMTEST_HH__ 30#define __MEMTEST_HH__ 31 32#include "sim_object.hh" 33#include "mem_interface.hh" 34#include "functional_memory.hh" 35#include "base_cpu.hh" 36#include "exec_context.hh" 37 38#include "statistics.hh" 39#include "sim_stats.hh" 40 41class MemTest : public BaseCPU 42{ 43 public: 44 45 MemTest(const std::string &name, 46 MemInterface *_cache_interface, 47 FunctionalMemory *main_mem, 48 FunctionalMemory *check_mem, 49 unsigned _memorySize, 50 unsigned _percentReads, 51 unsigned _percentUncacheable, 52 unsigned _maxReads, 53 unsigned _progressInterval, 54 Addr _traceAddr); 55 56 // register statistics 57 virtual void regStats(); 58 // main simulation loop (one cycle) 59 void tick(); 60 61 protected: 62 class TickEvent : public Event 63 { 64 private: 65 MemTest *cpu; 66 public: 67 TickEvent(MemTest *c) 68 : Event(&mainEventQueue, 100), cpu(c) {} 69 void process() {cpu->tick();} 70 virtual const char *description() { return "tick event"; } 71 }; 72 73 TickEvent tickEvent; 74 75 MemInterface *cacheInterface; 76 FunctionalMemory *mainMem; 77 FunctionalMemory *checkMem; 78 ExecContext *xc; 79 80 unsigned size; // size of testing memory region 81 82 unsigned percentReads; // target percentage of read accesses 83 unsigned percentUncacheable; 84 85 Tick maxReads; // max # of reads to perform (then quit) 86 87 unsigned blockSize; 88 89 Addr blockAddrMask; 90 91 Addr blockAddr(Addr addr) 92 { 93 return (addr & ~blockAddrMask); 94 } 95 96 Addr traceBlockAddr; 97 98 Addr baseAddr1; // fix this to option 99 Addr baseAddr2; // fix this to option 100 Addr uncacheAddr; 101 102 unsigned progressInterval; // frequency of progress reports 103 Tick nextProgressMessage; // access # for next progress report 104 105 Tick noResponseCycles; 106 107 Statistics::Scalar<long long int> numReads; 108 Statistics::Scalar<long long int> numWrites; 109 Statistics::Scalar<long long int> numCopies; 110 111 // called by MemCompleteEvent::process() 112 void completeRequest(MemReqPtr req, uint8_t *data); 113 114 friend class MemCompleteEvent; 115}; 116 117 118class MemCompleteEvent : public Event 119{ 120 MemReqPtr req; 121 uint8_t *data; 122 MemTest *tester; 123 124 public: 125 126 MemCompleteEvent(MemReqPtr _req, uint8_t *_data, MemTest *_tester) 127 : Event(&mainEventQueue), 128 req(_req), data(_data), tester(_tester) 129 { 130 } 131 132 void process(); 133 134 virtual const char *description(); 135}; 136 137#endif // __MEMTEST_HH__ 138 139 140 141