memtest.hh revision 1298
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 __MEMTEST_HH__
30#define __MEMTEST_HH__
31
32#include <set>
33
34#include "base/statistics.hh"
35#include "cpu/base_cpu.hh"
36#include "cpu/exec_context.hh"
37#include "mem/functional_mem/functional_memory.hh"
38#include "mem/mem_interface.hh"
39#include "sim/sim_object.hh"
40#include "sim/stats.hh"
41
42class MemTest : public BaseCPU
43{
44  public:
45
46    MemTest(const std::string &name,
47            MemInterface *_cache_interface,
48            FunctionalMemory *main_mem,
49            FunctionalMemory *check_mem,
50            unsigned _memorySize,
51            unsigned _percentReads,
52            unsigned _percentCopies,
53            unsigned _percentUncacheable,
54            unsigned _progressInterval,
55            unsigned _percentSourceUnaligned,
56            unsigned _percentDestUnaligned,
57            Addr _traceAddr,
58            Counter max_loads_any_thread,
59            Counter max_loads_all_threads);
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    Stats::Scalar<> numReadsStat;
120    Stats::Scalar<> numWritesStat;
121    Stats::Scalar<> numCopiesStat;
122
123    // called by MemCompleteEvent::process()
124    void completeRequest(MemReqPtr &req, uint8_t *data);
125
126    friend class MemCompleteEvent;
127};
128
129
130class MemCompleteEvent : public Event
131{
132    MemReqPtr req;
133    uint8_t *data;
134    MemTest *tester;
135
136  public:
137
138    MemCompleteEvent(MemReqPtr &_req, uint8_t *_data, MemTest *_tester)
139        : Event(&mainEventQueue),
140          req(_req), data(_data), tester(_tester)
141    {
142    }
143
144    void process();
145
146    virtual const char *description();
147};
148
149#endif // __MEMTEST_HH__
150
151
152
153