2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
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.
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.
31 * Declaration of a memory trace CPU object. Uses a memory trace to drive the
32 * provided memory hierarchy.
35 #include <algorithm> // For min
37 #include "cpu/trace/trace_cpu.hh"
38 #include "cpu/trace/reader/mem_trace_reader.hh"
39 #include "mem/base_mem.hh" // For PARAM constructor
40 #include "mem/mem_interface.hh"
41 #include "sim/builder.hh"
42 #include "sim/sim_events.hh"
46 TraceCPU::TraceCPU(const string
&name
,
47 MemInterface
*icache_interface
,
48 MemInterface
*dcache_interface
,
49 MemTraceReader
*data_trace
)
50 : SimObject(name
), icacheInterface(icache_interface
),
51 dcacheInterface(dcache_interface
),
52 dataTrace(data_trace
), outstandingRequests(0), tickEvent(this)
54 assert(dcacheInterface
);
55 nextCycle
= dataTrace
->getNextReq(nextReq
);
56 tickEvent
.schedule(0);
62 assert(outstandingRequests
>= 0);
63 assert(outstandingRequests
< 1000);
67 while (nextReq
&& curTick
>= nextCycle
) {
68 assert(nextReq
->thread_num
< 4 && "Not enough threads");
69 if (nextReq
->isInstRead() && icacheInterface
) {
70 if (icacheInterface
->isBlocked())
73 nextReq
->time
= curTick
;
74 if (nextReq
->cmd
== Squash
) {
75 icacheInterface
->squash(nextReq
->asid
);
78 if (icacheInterface
->doEvents()) {
79 nextReq
->completionEvent
=
80 new TraceCompleteEvent(nextReq
, this);
81 icacheInterface
->access(nextReq
);
83 icacheInterface
->access(nextReq
);
84 completeRequest(nextReq
);
88 if (dcacheInterface
->isBlocked())
92 nextReq
->time
= curTick
;
93 if (dcacheInterface
->doEvents()) {
94 nextReq
->completionEvent
=
95 new TraceCompleteEvent(nextReq
, this);
96 dcacheInterface
->access(nextReq
);
98 dcacheInterface
->access(nextReq
);
99 completeRequest(nextReq
);
103 nextCycle
= dataTrace
->getNextReq(nextReq
);
107 // No more requests to send. Finish trailing events and exit.
108 if (mainEventQueue
.empty()) {
109 new SimExitEvent("Finshed Memory Trace");
111 tickEvent
.schedule(mainEventQueue
.nextEventTime() + cycles(1));
114 tickEvent
.schedule(max(curTick
+ cycles(1), nextCycle
));
119 TraceCPU::completeRequest(MemReqPtr
& req
)
124 TraceCompleteEvent::process()
126 tester
->completeRequest(req
);
130 TraceCompleteEvent::description()
132 return "trace access complete";
135 TraceCPU::TickEvent::TickEvent(TraceCPU
*c
)
136 : Event(&mainEventQueue
, CPU_Tick_Pri
), cpu(c
)
141 TraceCPU::TickEvent::process()
147 TraceCPU::TickEvent::description()
149 return "TraceCPU tick event";
154 BEGIN_DECLARE_SIM_OBJECT_PARAMS(TraceCPU
)
156 SimObjectParam
<BaseMem
*> icache
;
157 SimObjectParam
<BaseMem
*> dcache
;
158 SimObjectParam
<MemTraceReader
*> data_trace
;
160 END_DECLARE_SIM_OBJECT_PARAMS(TraceCPU
)
162 BEGIN_INIT_SIM_OBJECT_PARAMS(TraceCPU
)
164 INIT_PARAM_DFLT(icache
, "instruction cache", NULL
),
165 INIT_PARAM_DFLT(dcache
, "data cache", NULL
),
166 INIT_PARAM_DFLT(data_trace
, "data trace", NULL
)
168 END_INIT_SIM_OBJECT_PARAMS(TraceCPU
)
170 CREATE_SIM_OBJECT(TraceCPU
)
172 return new TraceCPU(getInstanceName(),
173 (icache
) ? icache
->getInterface() : NULL
,
174 (dcache
) ? dcache
->getInterface() : NULL
,
178 REGISTER_SIM_OBJECT("TraceCPU", TraceCPU
)