base.cc (3520:4f4a2054fd85) base.cc (3541:d74340b852f6)
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;
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 * Authors: Steve Reinhardt
29 * Nathan Binkert
30 */
31
32#include <iostream>
33#include <string>
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/thread_context.hh"
43#include "cpu/profile.hh"
44#include "sim/sim_exit.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"
51
52// Hack
53#include "sim/stat_control.hh"
54
55using namespace std;
56
57vector<BaseCPU *> BaseCPU::cpuList;
58
59// This variable reflects the max number of threads in any CPU. Be
60// careful to only use it once all the CPUs that you care about have
61// been initialized
62int maxThreadsPerCPU = 1;
63
64CPUProgressEvent::CPUProgressEvent(EventQueue *q, Tick ival,
65 BaseCPU *_cpu)
66 : Event(q, Event::Stat_Event_Pri), interval(ival),
67 lastNumInst(0), cpu(_cpu)
68{
69 if (interval)
70 schedule(curTick + interval);
71}
72
73void
74CPUProgressEvent::process()
75{
76 Counter temp = cpu->totalInstructions();
77#ifndef NDEBUG
78 double ipc = double(temp - lastNumInst) / (interval / cpu->cycles(1));
79
80 DPRINTFN("%s progress event, instructions committed: %lli, IPC: %0.8d\n",
81 cpu->name(), temp - lastNumInst, ipc);
82 ipc = 0.0;
83#else
84 cprintf("%lli: %s progress event, instructions committed: %lli\n",
85 curTick, cpu->name(), temp - lastNumInst);
86#endif
87 lastNumInst = temp;
88 schedule(curTick + interval);
89}
90
91const char *
92CPUProgressEvent::description()
93{
94 return "CPU Progress event";
95}
96
97#if FULL_SYSTEM
98BaseCPU::BaseCPU(Params *p)
99 : MemObject(p->name), clock(p->clock), checkInterrupts(true),
100 params(p), number_of_threads(p->numberOfThreads), system(p->system)
101#else
102BaseCPU::BaseCPU(Params *p)
103 : MemObject(p->name), clock(p->clock), params(p),
104 number_of_threads(p->numberOfThreads), system(p->system)
105#endif
106{
107// currentTick = curTick;
108 DPRINTF(FullCPU, "BaseCPU: Creating object, mem address %#x.\n", this);
109
110 // add self to global list of CPUs
111 cpuList.push_back(this);
112
113 DPRINTF(FullCPU, "BaseCPU: CPU added to cpuList, mem address %#x.\n",
114 this);
115
116 if (number_of_threads > maxThreadsPerCPU)
117 maxThreadsPerCPU = number_of_threads;
118
119 // allocate per-thread instruction-based event queues
120 comInstEventQueue = new EventQueue *[number_of_threads];
121 for (int i = 0; i < number_of_threads; ++i)
122 comInstEventQueue[i] = new EventQueue("instruction-based event queue");
123
124 //
125 // set up instruction-count-based termination events, if any
126 //
127 if (p->max_insts_any_thread != 0)
128 for (int i = 0; i < number_of_threads; ++i)
129 schedExitSimLoop("a thread reached the max instruction count",
130 p->max_insts_any_thread, 0,
131 comInstEventQueue[i]);
132
133 if (p->max_insts_all_threads != 0) {
134 // allocate & initialize shared downcounter: each event will
135 // decrement this when triggered; simulation will terminate
136 // when counter reaches 0
137 int *counter = new int;
138 *counter = number_of_threads;
139 for (int i = 0; i < number_of_threads; ++i)
140 new CountedExitEvent(comInstEventQueue[i],
141 "all threads reached the max instruction count",
142 p->max_insts_all_threads, *counter);
143 }
144
145 // allocate per-thread load-based event queues
146 comLoadEventQueue = new EventQueue *[number_of_threads];
147 for (int i = 0; i < number_of_threads; ++i)
148 comLoadEventQueue[i] = new EventQueue("load-based event queue");
149
150 //
151 // set up instruction-count-based termination events, if any
152 //
153 if (p->max_loads_any_thread != 0)
154 for (int i = 0; i < number_of_threads; ++i)
155 schedExitSimLoop("a thread reached the max load count",
156 p->max_loads_any_thread, 0,
157 comLoadEventQueue[i]);
158
159 if (p->max_loads_all_threads != 0) {
160 // allocate & initialize shared downcounter: each event will
161 // decrement this when triggered; simulation will terminate
162 // when counter reaches 0
163 int *counter = new int;
164 *counter = number_of_threads;
165 for (int i = 0; i < number_of_threads; ++i)
166 new CountedExitEvent(comLoadEventQueue[i],
167 "all threads reached the max load count",
168 p->max_loads_all_threads, *counter);
169 }
170
171 functionTracingEnabled = false;
172 if (p->functionTrace) {
173 functionTraceStream = simout.find(csprintf("ftrace.%s", name()));
174 currentFunctionStart = currentFunctionEnd = 0;
175 functionEntryTick = p->functionTraceStart;
176
177 if (p->functionTraceStart == 0) {
178 functionTracingEnabled = true;
179 } else {
180 Event *e =
181 new EventWrapper<BaseCPU, &BaseCPU::enableFunctionTrace>(this,
182 true);
183 e->schedule(p->functionTraceStart);
184 }
185 }
186#if FULL_SYSTEM
187 profileEvent = NULL;
188 if (params->profile)
189 profileEvent = new ProfileEvent(this, params->profile);
190#endif
191}
192
193BaseCPU::Params::Params()
194{
195#if FULL_SYSTEM
196 profile = false;
197#endif
198 checker = NULL;
199}
200
201void
202BaseCPU::enableFunctionTrace()
203{
204 functionTracingEnabled = true;
205}
206
207BaseCPU::~BaseCPU()
208{
209}
210
211void
212BaseCPU::init()
213{
214 if (!params->deferRegistration)
215 registerThreadContexts();
216}
217
218void
219BaseCPU::startup()
220{
221#if FULL_SYSTEM
222 if (!params->deferRegistration && profileEvent)
223 profileEvent->schedule(curTick);
224#endif
225
226 if (params->progress_interval) {
227 new CPUProgressEvent(&mainEventQueue, params->progress_interval,
228 this);
229 }
230}
231
232
233void
234BaseCPU::regStats()
235{
236 using namespace Stats;
237
238 numCycles
239 .name(name() + ".numCycles")
240 .desc("number of cpu cycles simulated")
241 ;
242
243 int size = threadContexts.size();
244 if (size > 1) {
245 for (int i = 0; i < size; ++i) {
246 stringstream namestr;
247 ccprintf(namestr, "%s.ctx%d", name(), i);
248 threadContexts[i]->regStats(namestr.str());
249 }
250 } else if (size == 1)
251 threadContexts[0]->regStats(name());
252
253#if FULL_SYSTEM
254#endif
255}
256
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;
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 * Authors: Steve Reinhardt
29 * Nathan Binkert
30 */
31
32#include <iostream>
33#include <string>
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/thread_context.hh"
43#include "cpu/profile.hh"
44#include "sim/sim_exit.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"
51
52// Hack
53#include "sim/stat_control.hh"
54
55using namespace std;
56
57vector<BaseCPU *> BaseCPU::cpuList;
58
59// This variable reflects the max number of threads in any CPU. Be
60// careful to only use it once all the CPUs that you care about have
61// been initialized
62int maxThreadsPerCPU = 1;
63
64CPUProgressEvent::CPUProgressEvent(EventQueue *q, Tick ival,
65 BaseCPU *_cpu)
66 : Event(q, Event::Stat_Event_Pri), interval(ival),
67 lastNumInst(0), cpu(_cpu)
68{
69 if (interval)
70 schedule(curTick + interval);
71}
72
73void
74CPUProgressEvent::process()
75{
76 Counter temp = cpu->totalInstructions();
77#ifndef NDEBUG
78 double ipc = double(temp - lastNumInst) / (interval / cpu->cycles(1));
79
80 DPRINTFN("%s progress event, instructions committed: %lli, IPC: %0.8d\n",
81 cpu->name(), temp - lastNumInst, ipc);
82 ipc = 0.0;
83#else
84 cprintf("%lli: %s progress event, instructions committed: %lli\n",
85 curTick, cpu->name(), temp - lastNumInst);
86#endif
87 lastNumInst = temp;
88 schedule(curTick + interval);
89}
90
91const char *
92CPUProgressEvent::description()
93{
94 return "CPU Progress event";
95}
96
97#if FULL_SYSTEM
98BaseCPU::BaseCPU(Params *p)
99 : MemObject(p->name), clock(p->clock), checkInterrupts(true),
100 params(p), number_of_threads(p->numberOfThreads), system(p->system)
101#else
102BaseCPU::BaseCPU(Params *p)
103 : MemObject(p->name), clock(p->clock), params(p),
104 number_of_threads(p->numberOfThreads), system(p->system)
105#endif
106{
107// currentTick = curTick;
108 DPRINTF(FullCPU, "BaseCPU: Creating object, mem address %#x.\n", this);
109
110 // add self to global list of CPUs
111 cpuList.push_back(this);
112
113 DPRINTF(FullCPU, "BaseCPU: CPU added to cpuList, mem address %#x.\n",
114 this);
115
116 if (number_of_threads > maxThreadsPerCPU)
117 maxThreadsPerCPU = number_of_threads;
118
119 // allocate per-thread instruction-based event queues
120 comInstEventQueue = new EventQueue *[number_of_threads];
121 for (int i = 0; i < number_of_threads; ++i)
122 comInstEventQueue[i] = new EventQueue("instruction-based event queue");
123
124 //
125 // set up instruction-count-based termination events, if any
126 //
127 if (p->max_insts_any_thread != 0)
128 for (int i = 0; i < number_of_threads; ++i)
129 schedExitSimLoop("a thread reached the max instruction count",
130 p->max_insts_any_thread, 0,
131 comInstEventQueue[i]);
132
133 if (p->max_insts_all_threads != 0) {
134 // allocate & initialize shared downcounter: each event will
135 // decrement this when triggered; simulation will terminate
136 // when counter reaches 0
137 int *counter = new int;
138 *counter = number_of_threads;
139 for (int i = 0; i < number_of_threads; ++i)
140 new CountedExitEvent(comInstEventQueue[i],
141 "all threads reached the max instruction count",
142 p->max_insts_all_threads, *counter);
143 }
144
145 // allocate per-thread load-based event queues
146 comLoadEventQueue = new EventQueue *[number_of_threads];
147 for (int i = 0; i < number_of_threads; ++i)
148 comLoadEventQueue[i] = new EventQueue("load-based event queue");
149
150 //
151 // set up instruction-count-based termination events, if any
152 //
153 if (p->max_loads_any_thread != 0)
154 for (int i = 0; i < number_of_threads; ++i)
155 schedExitSimLoop("a thread reached the max load count",
156 p->max_loads_any_thread, 0,
157 comLoadEventQueue[i]);
158
159 if (p->max_loads_all_threads != 0) {
160 // allocate & initialize shared downcounter: each event will
161 // decrement this when triggered; simulation will terminate
162 // when counter reaches 0
163 int *counter = new int;
164 *counter = number_of_threads;
165 for (int i = 0; i < number_of_threads; ++i)
166 new CountedExitEvent(comLoadEventQueue[i],
167 "all threads reached the max load count",
168 p->max_loads_all_threads, *counter);
169 }
170
171 functionTracingEnabled = false;
172 if (p->functionTrace) {
173 functionTraceStream = simout.find(csprintf("ftrace.%s", name()));
174 currentFunctionStart = currentFunctionEnd = 0;
175 functionEntryTick = p->functionTraceStart;
176
177 if (p->functionTraceStart == 0) {
178 functionTracingEnabled = true;
179 } else {
180 Event *e =
181 new EventWrapper<BaseCPU, &BaseCPU::enableFunctionTrace>(this,
182 true);
183 e->schedule(p->functionTraceStart);
184 }
185 }
186#if FULL_SYSTEM
187 profileEvent = NULL;
188 if (params->profile)
189 profileEvent = new ProfileEvent(this, params->profile);
190#endif
191}
192
193BaseCPU::Params::Params()
194{
195#if FULL_SYSTEM
196 profile = false;
197#endif
198 checker = NULL;
199}
200
201void
202BaseCPU::enableFunctionTrace()
203{
204 functionTracingEnabled = true;
205}
206
207BaseCPU::~BaseCPU()
208{
209}
210
211void
212BaseCPU::init()
213{
214 if (!params->deferRegistration)
215 registerThreadContexts();
216}
217
218void
219BaseCPU::startup()
220{
221#if FULL_SYSTEM
222 if (!params->deferRegistration && profileEvent)
223 profileEvent->schedule(curTick);
224#endif
225
226 if (params->progress_interval) {
227 new CPUProgressEvent(&mainEventQueue, params->progress_interval,
228 this);
229 }
230}
231
232
233void
234BaseCPU::regStats()
235{
236 using namespace Stats;
237
238 numCycles
239 .name(name() + ".numCycles")
240 .desc("number of cpu cycles simulated")
241 ;
242
243 int size = threadContexts.size();
244 if (size > 1) {
245 for (int i = 0; i < size; ++i) {
246 stringstream namestr;
247 ccprintf(namestr, "%s.ctx%d", name(), i);
248 threadContexts[i]->regStats(namestr.str());
249 }
250 } else if (size == 1)
251 threadContexts[0]->regStats(name());
252
253#if FULL_SYSTEM
254#endif
255}
256
257Tick
258BaseCPU::nextCycle()
259{
260 Tick next_tick = curTick + clock - 1;
261 next_tick -= (next_tick % clock);
262 return next_tick;
263}
257
264
265Tick
266BaseCPU::nextCycle(Tick begin_tick)
267{
268 Tick next_tick = begin_tick;
269
270 while (next_tick < curTick)
271 next_tick += clock;
272
273 next_tick -= (next_tick % clock);
274 assert(next_tick >= curTick);
275 return next_tick;
276}
277
258void
259BaseCPU::registerThreadContexts()
260{
261 for (int i = 0; i < threadContexts.size(); ++i) {
262 ThreadContext *tc = threadContexts[i];
263
264#if FULL_SYSTEM
265 int id = params->cpu_id;
266 if (id != -1)
267 id += i;
268
269 tc->setCpuId(system->registerThreadContext(tc, id));
270#else
271 tc->setCpuId(tc->getProcessPtr()->registerThreadContext(tc));
272#endif
273 }
274}
275
276
277void
278BaseCPU::switchOut()
279{
280// panic("This CPU doesn't support sampling!");
281#if FULL_SYSTEM
282 if (profileEvent && profileEvent->scheduled())
283 profileEvent->deschedule();
284#endif
285}
286
287void
288BaseCPU::takeOverFrom(BaseCPU *oldCPU)
289{
290 assert(threadContexts.size() == oldCPU->threadContexts.size());
291
292 for (int i = 0; i < threadContexts.size(); ++i) {
293 ThreadContext *newTC = threadContexts[i];
294 ThreadContext *oldTC = oldCPU->threadContexts[i];
295
296 newTC->takeOverFrom(oldTC);
297
298 CpuEvent::replaceThreadContext(oldTC, newTC);
299
300 assert(newTC->readCpuId() == oldTC->readCpuId());
301#if FULL_SYSTEM
302 system->replaceThreadContext(newTC, newTC->readCpuId());
303#else
304 assert(newTC->getProcessPtr() == oldTC->getProcessPtr());
305 newTC->getProcessPtr()->replaceThreadContext(newTC, newTC->readCpuId());
306#endif
307
308// TheISA::compareXCs(oldXC, newXC);
309 }
310
311#if FULL_SYSTEM
312 interrupts = oldCPU->interrupts;
313 checkInterrupts = oldCPU->checkInterrupts;
314
315 for (int i = 0; i < threadContexts.size(); ++i)
316 threadContexts[i]->profileClear();
317
318 // The Sampler must take care of this!
319// if (profileEvent)
320// profileEvent->schedule(curTick);
321#endif
322}
323
324
325#if FULL_SYSTEM
326BaseCPU::ProfileEvent::ProfileEvent(BaseCPU *_cpu, int _interval)
327 : Event(&mainEventQueue), cpu(_cpu), interval(_interval)
328{ }
329
330void
331BaseCPU::ProfileEvent::process()
332{
333 for (int i = 0, size = cpu->threadContexts.size(); i < size; ++i) {
334 ThreadContext *tc = cpu->threadContexts[i];
335 tc->profileSample();
336 }
337
338 schedule(curTick + interval);
339}
340
341void
342BaseCPU::post_interrupt(int int_num, int index)
343{
344 checkInterrupts = true;
345 interrupts.post(int_num, index);
346}
347
348void
349BaseCPU::clear_interrupt(int int_num, int index)
350{
351 interrupts.clear(int_num, index);
352}
353
354void
355BaseCPU::clear_interrupts()
356{
357 interrupts.clear_all();
358}
359
360
361void
362BaseCPU::serialize(std::ostream &os)
363{
364 interrupts.serialize(os);
365}
366
367void
368BaseCPU::unserialize(Checkpoint *cp, const std::string &section)
369{
370 interrupts.unserialize(cp, section);
371}
372
373#endif // FULL_SYSTEM
374
375void
376BaseCPU::traceFunctionsInternal(Addr pc)
377{
378 if (!debugSymbolTable)
379 return;
380
381 // if pc enters different function, print new function symbol and
382 // update saved range. Otherwise do nothing.
383 if (pc < currentFunctionStart || pc >= currentFunctionEnd) {
384 string sym_str;
385 bool found = debugSymbolTable->findNearestSymbol(pc, sym_str,
386 currentFunctionStart,
387 currentFunctionEnd);
388
389 if (!found) {
390 // no symbol found: use addr as label
391 sym_str = csprintf("0x%x", pc);
392 currentFunctionStart = pc;
393 currentFunctionEnd = pc + 1;
394 }
395
396 ccprintf(*functionTraceStream, " (%d)\n%d: %s",
397 curTick - functionEntryTick, curTick, sym_str);
398 functionEntryTick = curTick;
399 }
400}
401
402
403DEFINE_SIM_OBJECT_CLASS_NAME("BaseCPU", BaseCPU)
278void
279BaseCPU::registerThreadContexts()
280{
281 for (int i = 0; i < threadContexts.size(); ++i) {
282 ThreadContext *tc = threadContexts[i];
283
284#if FULL_SYSTEM
285 int id = params->cpu_id;
286 if (id != -1)
287 id += i;
288
289 tc->setCpuId(system->registerThreadContext(tc, id));
290#else
291 tc->setCpuId(tc->getProcessPtr()->registerThreadContext(tc));
292#endif
293 }
294}
295
296
297void
298BaseCPU::switchOut()
299{
300// panic("This CPU doesn't support sampling!");
301#if FULL_SYSTEM
302 if (profileEvent && profileEvent->scheduled())
303 profileEvent->deschedule();
304#endif
305}
306
307void
308BaseCPU::takeOverFrom(BaseCPU *oldCPU)
309{
310 assert(threadContexts.size() == oldCPU->threadContexts.size());
311
312 for (int i = 0; i < threadContexts.size(); ++i) {
313 ThreadContext *newTC = threadContexts[i];
314 ThreadContext *oldTC = oldCPU->threadContexts[i];
315
316 newTC->takeOverFrom(oldTC);
317
318 CpuEvent::replaceThreadContext(oldTC, newTC);
319
320 assert(newTC->readCpuId() == oldTC->readCpuId());
321#if FULL_SYSTEM
322 system->replaceThreadContext(newTC, newTC->readCpuId());
323#else
324 assert(newTC->getProcessPtr() == oldTC->getProcessPtr());
325 newTC->getProcessPtr()->replaceThreadContext(newTC, newTC->readCpuId());
326#endif
327
328// TheISA::compareXCs(oldXC, newXC);
329 }
330
331#if FULL_SYSTEM
332 interrupts = oldCPU->interrupts;
333 checkInterrupts = oldCPU->checkInterrupts;
334
335 for (int i = 0; i < threadContexts.size(); ++i)
336 threadContexts[i]->profileClear();
337
338 // The Sampler must take care of this!
339// if (profileEvent)
340// profileEvent->schedule(curTick);
341#endif
342}
343
344
345#if FULL_SYSTEM
346BaseCPU::ProfileEvent::ProfileEvent(BaseCPU *_cpu, int _interval)
347 : Event(&mainEventQueue), cpu(_cpu), interval(_interval)
348{ }
349
350void
351BaseCPU::ProfileEvent::process()
352{
353 for (int i = 0, size = cpu->threadContexts.size(); i < size; ++i) {
354 ThreadContext *tc = cpu->threadContexts[i];
355 tc->profileSample();
356 }
357
358 schedule(curTick + interval);
359}
360
361void
362BaseCPU::post_interrupt(int int_num, int index)
363{
364 checkInterrupts = true;
365 interrupts.post(int_num, index);
366}
367
368void
369BaseCPU::clear_interrupt(int int_num, int index)
370{
371 interrupts.clear(int_num, index);
372}
373
374void
375BaseCPU::clear_interrupts()
376{
377 interrupts.clear_all();
378}
379
380
381void
382BaseCPU::serialize(std::ostream &os)
383{
384 interrupts.serialize(os);
385}
386
387void
388BaseCPU::unserialize(Checkpoint *cp, const std::string &section)
389{
390 interrupts.unserialize(cp, section);
391}
392
393#endif // FULL_SYSTEM
394
395void
396BaseCPU::traceFunctionsInternal(Addr pc)
397{
398 if (!debugSymbolTable)
399 return;
400
401 // if pc enters different function, print new function symbol and
402 // update saved range. Otherwise do nothing.
403 if (pc < currentFunctionStart || pc >= currentFunctionEnd) {
404 string sym_str;
405 bool found = debugSymbolTable->findNearestSymbol(pc, sym_str,
406 currentFunctionStart,
407 currentFunctionEnd);
408
409 if (!found) {
410 // no symbol found: use addr as label
411 sym_str = csprintf("0x%x", pc);
412 currentFunctionStart = pc;
413 currentFunctionEnd = pc + 1;
414 }
415
416 ccprintf(*functionTraceStream, " (%d)\n%d: %s",
417 curTick - functionEntryTick, curTick, sym_str);
418 functionEntryTick = curTick;
419 }
420}
421
422
423DEFINE_SIM_OBJECT_CLASS_NAME("BaseCPU", BaseCPU)