memtest.hh revision 695
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/sim_object.hh"
33#include "mem/mem_interface.hh"
34#include "mem/functional_mem/functional_memory.hh"
35#include "cpu/base_cpu.hh"
36#include "cpu/exec_context.hh"
37
38#include "base/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 _percentCopies,
52            unsigned _percentUncacheable,
53            unsigned _progressInterval,
54            unsigned _percentSourceUnaligned,
55            unsigned _percentDestUnaligned,
56            Addr _traceAddr,
57            Counter max_loads_any_thread,
58            Counter max_loads_all_threads);
59
60    // register statistics
61    virtual void regStats();
62    // main simulation loop (one cycle)
63    void tick();
64
65  protected:
66    class TickEvent : public Event
67    {
68      private:
69        MemTest *cpu;
70      public:
71        TickEvent(MemTest *c)
72            : Event(&mainEventQueue, CPU_Tick_Pri), cpu(c) {}
73        void process() {cpu->tick();}
74        virtual const char *description() { return "tick event"; }
75    };
76
77    TickEvent tickEvent;
78
79    MemInterface *cacheInterface;
80    FunctionalMemory *mainMem;
81    FunctionalMemory *checkMem;
82    ExecContext *xc;
83
84    unsigned size;		// size of testing memory region
85
86    unsigned percentReads;	// target percentage of read accesses
87    unsigned percentCopies;	// target percentage of copy accesses
88    unsigned percentUncacheable;
89
90    unsigned blockSize;
91
92    Addr blockAddrMask;
93
94    Addr blockAddr(Addr addr)
95    {
96        return (addr & ~blockAddrMask);
97    }
98
99    Addr traceBlockAddr;
100
101    Addr baseAddr1;		// fix this to option
102    Addr baseAddr2;		// fix this to option
103    Addr uncacheAddr;
104
105    unsigned progressInterval;	// frequency of progress reports
106    Tick nextProgressMessage;	// access # for next progress report
107
108    unsigned percentSourceUnaligned;
109    unsigned percentDestUnaligned;
110
111    Tick noResponseCycles;
112
113    uint64_t numReads;
114    Statistics::Scalar<> numReadsStat;
115    Statistics::Scalar<> numWritesStat;
116    Statistics::Scalar<> numCopiesStat;
117
118    // called by MemCompleteEvent::process()
119    void completeRequest(MemReqPtr &req, uint8_t *data);
120
121    friend class MemCompleteEvent;
122};
123
124
125class MemCompleteEvent : public Event
126{
127    MemReqPtr req;
128    uint8_t *data;
129    MemTest *tester;
130
131  public:
132
133    MemCompleteEvent(MemReqPtr &_req, uint8_t *_data, MemTest *_tester)
134        : Event(&mainEventQueue),
135          req(_req), data(_data), tester(_tester)
136    {
137    }
138
139    void process();
140
141    virtual const char *description();
142};
143
144#endif // __MEMTEST_HH__
145
146
147
148