7c2b32a93ba2aa3da35bcdcbde9dc2ac820a1ffe
2 * Copyright (c) 2001-2006 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 #include "arch/isa_traits.hh"
32 #include "cpu/base.hh"
33 #include "cpu/cpu_exec_context.hh"
34 #include "cpu/exec_context.hh"
37 #include "base/callback.hh"
38 #include "base/cprintf.hh"
39 #include "base/output.hh"
40 #include "base/trace.hh"
41 #include "cpu/profile.hh"
42 #include "cpu/quiesce_event.hh"
43 #include "kern/kernel_stats.hh"
44 #include "sim/serialize.hh"
45 #include "sim/sim_exit.hh"
46 #include "arch/stacktrace.hh"
48 #include "sim/process.hh"
49 #include "sim/system.hh"
50 #include "mem/translating_port.hh"
57 CPUExecContext::CPUExecContext(BaseCPU
*_cpu
, int _thread_num
, System
*_sys
,
58 AlphaITB
*_itb
, AlphaDTB
*_dtb
,
59 bool use_kernel_stats
)
60 : _status(ExecContext::Unallocated
), cpu(_cpu
), thread_num(_thread_num
),
61 cpu_id(-1), lastActivate(0), lastSuspend(0), system(_sys
), itb(_itb
),
62 dtb(_dtb
), profile(NULL
), func_exe_inst(0), storeCondFailures(0)
65 proxy
= new ProxyExecContext
<CPUExecContext
>(this);
67 quiesceEvent
= new EndQuiesceEvent(proxy
);
71 if (cpu
->params
->profile
) {
72 profile
= new FunctionProfile(system
->kernelSymtab
);
74 new MakeCallback
<CPUExecContext
,
75 &CPUExecContext::dumpFuncProfile
>(this);
76 registerExitCallback(cb
);
79 // let's fill with a dummy node for now so we don't get a segfault
80 // on the first cycle when there's no node available.
81 static ProfileNode dummyNode
;
82 profileNode
= &dummyNode
;
86 if (use_kernel_stats
) {
87 kernelStats
= new Kernel::Statistics(system
);
92 physPort
= new FunctionalPort(csprintf("%s-%d-funcport",
93 cpu
->name(), thread_num
));
94 mem_port
= system
->physmem
->getPort("functional");
95 mem_port
->setPeer(physPort
);
96 physPort
->setPeer(mem_port
);
98 virtPort
= new VirtualPort(csprintf("%s-%d-vport",
99 cpu
->name(), thread_num
));
100 mem_port
= system
->physmem
->getPort("functional");
101 mem_port
->setPeer(virtPort
);
102 virtPort
->setPeer(mem_port
);
105 CPUExecContext::CPUExecContext(BaseCPU
*_cpu
, int _thread_num
,
106 Process
*_process
, int _asid
, MemObject
* memobj
)
107 : _status(ExecContext::Unallocated
),
108 cpu(_cpu
), thread_num(_thread_num
), cpu_id(-1), lastActivate(0),
109 lastSuspend(0), process(_process
), asid(_asid
),
110 func_exe_inst(0), storeCondFailures(0)
112 /* Use this port to for syscall emulation writes to memory. */
114 port
= new TranslatingPort(csprintf("%s-%d-funcport",
115 cpu
->name(), thread_num
),
116 process
->pTable
, false);
117 mem_port
= memobj
->getPort("functional");
118 mem_port
->setPeer(port
);
119 port
->setPeer(mem_port
);
122 proxy
= new ProxyExecContext
<CPUExecContext
>(this);
125 CPUExecContext::CPUExecContext(RegFile
*regFile
)
126 : cpu(NULL
), thread_num(-1), process(NULL
), asid(-1),
127 func_exe_inst(0), storeCondFailures(0)
130 proxy
= new ProxyExecContext
<CPUExecContext
>(this);
135 CPUExecContext::~CPUExecContext()
142 CPUExecContext::dumpFuncProfile()
144 std::ostream
*os
= simout
.create(csprintf("profile.%s.dat", cpu
->name()));
145 profile
->dump(proxy
, *os
);
149 CPUExecContext::profileClear()
156 CPUExecContext::profileSample()
159 profile
->sample(profileNode
, profilePC
);
165 CPUExecContext::takeOverFrom(ExecContext
*oldContext
)
167 // some things should already be set up
169 assert(system
== oldContext
->getSystemPtr());
171 assert(process
== oldContext
->getProcessPtr());
174 // copy over functional state
175 _status
= oldContext
->status();
176 copyArchRegs(oldContext
);
177 cpu_id
= oldContext
->readCpuId();
179 func_exe_inst
= oldContext
->readFuncExeInst();
181 EndQuiesceEvent
*quiesce
= oldContext
->getQuiesceEvent();
183 // Point the quiesce event's XC at this XC so that it wakes up
188 quiesceEvent
->xc
= proxy
;
192 storeCondFailures
= 0;
194 oldContext
->setStatus(ExecContext::Unallocated
);
198 CPUExecContext::serialize(ostream
&os
)
200 SERIALIZE_ENUM(_status
);
202 // thread_num and cpu_id are deterministic from the config
203 SERIALIZE_SCALAR(func_exe_inst
);
204 SERIALIZE_SCALAR(inst
);
207 Tick quiesceEndTick
= 0;
208 if (quiesceEvent
->scheduled())
209 quiesceEndTick
= quiesceEvent
->when();
210 SERIALIZE_SCALAR(quiesceEndTick
);
212 kernelStats
->serialize(os
);
218 CPUExecContext::unserialize(Checkpoint
*cp
, const std::string
§ion
)
220 UNSERIALIZE_ENUM(_status
);
221 regs
.unserialize(cp
, section
);
222 // thread_num and cpu_id are deterministic from the config
223 UNSERIALIZE_SCALAR(func_exe_inst
);
224 UNSERIALIZE_SCALAR(inst
);
228 UNSERIALIZE_SCALAR(quiesceEndTick
);
230 quiesceEvent
->schedule(quiesceEndTick
);
232 kernelStats
->unserialize(cp
, section
);
238 CPUExecContext::activate(int delay
)
240 if (status() == ExecContext::Active
)
243 lastActivate
= curTick
;
245 if (status() == ExecContext::Unallocated
) {
246 cpu
->activateWhenReady(thread_num
);
250 _status
= ExecContext::Active
;
252 // status() == Suspended
253 cpu
->activateContext(thread_num
, delay
);
257 CPUExecContext::suspend()
259 if (status() == ExecContext::Suspended
)
262 lastActivate
= curTick
;
263 lastSuspend
= curTick
;
266 // Don't change the status from active if there are pending interrupts
267 if (cpu->check_interrupts()) {
268 assert(status() == ExecContext::Active);
273 _status
= ExecContext::Suspended
;
274 cpu
->suspendContext(thread_num
);
278 CPUExecContext::deallocate()
280 if (status() == ExecContext::Unallocated
)
283 _status
= ExecContext::Unallocated
;
284 cpu
->deallocateContext(thread_num
);
288 CPUExecContext::halt()
290 if (status() == ExecContext::Halted
)
293 _status
= ExecContext::Halted
;
294 cpu
->haltContext(thread_num
);
299 CPUExecContext::regStats(const string
&name
)
303 kernelStats
->regStats(name
+ ".kern");
308 CPUExecContext::copyArchRegs(ExecContext
*xc
)
310 TheISA::copyRegs(xc
, proxy
);
315 CPUExecContext::getVirtPort(ExecContext
*xc
)
323 vp
= new VirtualPort("xc-vport", xc
);
324 mem_port
= system
->physmem
->getPort("functional");
325 mem_port
->setPeer(vp
);
326 vp
->setPeer(mem_port
);
331 CPUExecContext::delVirtPort(VirtualPort
*vp
)
333 // assert(!vp->nullExecContext());
334 delete vp
->getPeer();