base.cc (2670:9107b8bd08cd) base.cc (2680:246e7104f744)
1/*
2 * Copyright (c) 2002-2005 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;

--- 25 unchanged lines hidden (view full) ---

34#include <sstream>
35
36#include "base/cprintf.hh"
37#include "base/loader/symtab.hh"
38#include "base/misc.hh"
39#include "base/output.hh"
40#include "cpu/base.hh"
41#include "cpu/cpuevent.hh"
1/*
2 * Copyright (c) 2002-2005 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;

--- 25 unchanged lines hidden (view full) ---

34#include <sstream>
35
36#include "base/cprintf.hh"
37#include "base/loader/symtab.hh"
38#include "base/misc.hh"
39#include "base/output.hh"
40#include "cpu/base.hh"
41#include "cpu/cpuevent.hh"
42#include "cpu/exec_context.hh"
42#include "cpu/thread_context.hh"
43#include "cpu/profile.hh"
44#include "cpu/sampler/sampler.hh"
45#include "sim/param.hh"
46#include "sim/process.hh"
47#include "sim/sim_events.hh"
48#include "sim/system.hh"
49
50#include "base/trace.hh"

--- 123 unchanged lines hidden (view full) ---

174BaseCPU::~BaseCPU()
175{
176}
177
178void
179BaseCPU::init()
180{
181 if (!params->deferRegistration)
43#include "cpu/profile.hh"
44#include "cpu/sampler/sampler.hh"
45#include "sim/param.hh"
46#include "sim/process.hh"
47#include "sim/sim_events.hh"
48#include "sim/system.hh"
49
50#include "base/trace.hh"

--- 123 unchanged lines hidden (view full) ---

174BaseCPU::~BaseCPU()
175{
176}
177
178void
179BaseCPU::init()
180{
181 if (!params->deferRegistration)
182 registerExecContexts();
182 registerThreadContexts();
183}
184
185void
186BaseCPU::startup()
187{
188#if FULL_SYSTEM
189 if (!params->deferRegistration && profileEvent)
190 profileEvent->schedule(curTick);

--- 6 unchanged lines hidden (view full) ---

197{
198 using namespace Stats;
199
200 numCycles
201 .name(name() + ".numCycles")
202 .desc("number of cpu cycles simulated")
203 ;
204
183}
184
185void
186BaseCPU::startup()
187{
188#if FULL_SYSTEM
189 if (!params->deferRegistration && profileEvent)
190 profileEvent->schedule(curTick);

--- 6 unchanged lines hidden (view full) ---

197{
198 using namespace Stats;
199
200 numCycles
201 .name(name() + ".numCycles")
202 .desc("number of cpu cycles simulated")
203 ;
204
205 int size = execContexts.size();
205 int size = threadContexts.size();
206 if (size > 1) {
207 for (int i = 0; i < size; ++i) {
208 stringstream namestr;
209 ccprintf(namestr, "%s.ctx%d", name(), i);
206 if (size > 1) {
207 for (int i = 0; i < size; ++i) {
208 stringstream namestr;
209 ccprintf(namestr, "%s.ctx%d", name(), i);
210 execContexts[i]->regStats(namestr.str());
210 threadContexts[i]->regStats(namestr.str());
211 }
212 } else if (size == 1)
211 }
212 } else if (size == 1)
213 execContexts[0]->regStats(name());
213 threadContexts[0]->regStats(name());
214
215#if FULL_SYSTEM
216#endif
217}
218
219
220void
214
215#if FULL_SYSTEM
216#endif
217}
218
219
220void
221BaseCPU::registerExecContexts()
221BaseCPU::registerThreadContexts()
222{
222{
223 for (int i = 0; i < execContexts.size(); ++i) {
224 ExecContext *xc = execContexts[i];
223 for (int i = 0; i < threadContexts.size(); ++i) {
224 ThreadContext *tc = threadContexts[i];
225
226#if FULL_SYSTEM
227 int id = params->cpu_id;
228 if (id != -1)
229 id += i;
230
225
226#if FULL_SYSTEM
227 int id = params->cpu_id;
228 if (id != -1)
229 id += i;
230
231 xc->setCpuId(system->registerExecContext(xc, id));
231 tc->setCpuId(system->registerThreadContext(tc, id));
232#else
232#else
233 xc->setCpuId(xc->getProcessPtr()->registerExecContext(xc));
233 tc->setCpuId(tc->getProcessPtr()->registerThreadContext(tc));
234#endif
235 }
236}
237
238
239void
240BaseCPU::switchOut(Sampler *sampler)
241{
242 panic("This CPU doesn't support sampling!");
243}
244
245void
246BaseCPU::takeOverFrom(BaseCPU *oldCPU)
247{
234#endif
235 }
236}
237
238
239void
240BaseCPU::switchOut(Sampler *sampler)
241{
242 panic("This CPU doesn't support sampling!");
243}
244
245void
246BaseCPU::takeOverFrom(BaseCPU *oldCPU)
247{
248 assert(execContexts.size() == oldCPU->execContexts.size());
248 assert(threadContexts.size() == oldCPU->threadContexts.size());
249
249
250 for (int i = 0; i < execContexts.size(); ++i) {
251 ExecContext *newXC = execContexts[i];
252 ExecContext *oldXC = oldCPU->execContexts[i];
250 for (int i = 0; i < threadContexts.size(); ++i) {
251 ThreadContext *newTC = threadContexts[i];
252 ThreadContext *oldTC = oldCPU->threadContexts[i];
253
253
254 newXC->takeOverFrom(oldXC);
254 newTC->takeOverFrom(oldTC);
255
255
256 CpuEvent::replaceExecContext(oldXC, newXC);
256 CpuEvent::replaceThreadContext(oldTC, newTC);
257
257
258 assert(newXC->readCpuId() == oldXC->readCpuId());
258 assert(newTC->readCpuId() == oldTC->readCpuId());
259#if FULL_SYSTEM
259#if FULL_SYSTEM
260 system->replaceExecContext(newXC, newXC->readCpuId());
260 system->replaceThreadContext(newTC, newTC->readCpuId());
261#else
261#else
262 assert(newXC->getProcessPtr() == oldXC->getProcessPtr());
263 newXC->getProcessPtr()->replaceExecContext(newXC, newXC->readCpuId());
262 assert(newTC->getProcessPtr() == oldTC->getProcessPtr());
263 newTC->getProcessPtr()->replaceThreadContext(newTC, newTC->readCpuId());
264#endif
265 }
266
267#if FULL_SYSTEM
268 for (int i = 0; i < TheISA::NumInterruptLevels; ++i)
269 interrupts[i] = oldCPU->interrupts[i];
270 intstatus = oldCPU->intstatus;
271
264#endif
265 }
266
267#if FULL_SYSTEM
268 for (int i = 0; i < TheISA::NumInterruptLevels; ++i)
269 interrupts[i] = oldCPU->interrupts[i];
270 intstatus = oldCPU->intstatus;
271
272 for (int i = 0; i < execContexts.size(); ++i)
273 execContexts[i]->profileClear();
272 for (int i = 0; i < threadContexts.size(); ++i)
273 threadContexts[i]->profileClear();
274
275 if (profileEvent)
276 profileEvent->schedule(curTick);
277#endif
278}
279
280
281#if FULL_SYSTEM
282BaseCPU::ProfileEvent::ProfileEvent(BaseCPU *_cpu, int _interval)
283 : Event(&mainEventQueue), cpu(_cpu), interval(_interval)
284{ }
285
286void
287BaseCPU::ProfileEvent::process()
288{
274
275 if (profileEvent)
276 profileEvent->schedule(curTick);
277#endif
278}
279
280
281#if FULL_SYSTEM
282BaseCPU::ProfileEvent::ProfileEvent(BaseCPU *_cpu, int _interval)
283 : Event(&mainEventQueue), cpu(_cpu), interval(_interval)
284{ }
285
286void
287BaseCPU::ProfileEvent::process()
288{
289 for (int i = 0, size = cpu->execContexts.size(); i < size; ++i) {
290 ExecContext *xc = cpu->execContexts[i];
291 xc->profileSample();
289 for (int i = 0, size = cpu->threadContexts.size(); i < size; ++i) {
290 ThreadContext *tc = cpu->threadContexts[i];
291 tc->profileSample();
292 }
293
294 schedule(curTick + interval);
295}
296
297void
298BaseCPU::post_interrupt(int int_num, int index)
299{

--- 84 unchanged lines hidden ---
292 }
293
294 schedule(curTick + interval);
295}
296
297void
298BaseCPU::post_interrupt(int int_num, int index)
299{

--- 84 unchanged lines hidden ---