1/*
2 * Copyright (c) 2013, 2015 ARM Limited
3 * All rights reserved.
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software

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

61 warn_once("The frequency of the system counter has already been set");
62 }
63 _freq = freq;
64 _period = (1.0 / freq) * SimClock::Frequency;
65 _resetTick = curTick();
66}
67
68void
69SystemCounter::serialize(std::ostream &os) const
69SystemCounter::serialize(CheckpointOut &cp) const
70{
71 SERIALIZE_SCALAR(_regCntkctl);
72 SERIALIZE_SCALAR(_freq);
73 SERIALIZE_SCALAR(_period);
74 SERIALIZE_SCALAR(_resetTick);
75}
76
77void
78SystemCounter::unserialize(Checkpoint *cp,
79 const std::string &section)
78SystemCounter::unserialize(CheckpointIn &cp)
79{
80 // We didn't handle CNTKCTL in this class before, assume it's zero
81 // if it isn't present.
82 if (!UNSERIALIZE_OPT_SCALAR(_regCntkctl))
83 _regCntkctl = 0;
84 UNSERIALIZE_SCALAR(_freq);
85 UNSERIALIZE_SCALAR(_period);
86 UNSERIALIZE_SCALAR(_resetTick);

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

169
170uint64_t
171ArchTimer::value() const
172{
173 return _systemCounter.value() - _offset;
174}
175
176void
178ArchTimer::serialize(std::ostream &os) const
177ArchTimer::serialize(CheckpointOut &cp) const
178{
180 paramOut(os, "control_serial", _control);
179 paramOut(cp, "control_serial", _control);
180 SERIALIZE_SCALAR(_counterLimit);
181 SERIALIZE_SCALAR(_offset);
182
183 const bool event_scheduled(_counterLimitReachedEvent.scheduled());
184 SERIALIZE_SCALAR(event_scheduled);
185 if (event_scheduled) {
186 const Tick event_time(_counterLimitReachedEvent.when());
187 SERIALIZE_SCALAR(event_time);
188 }
189}
190
191void
193ArchTimer::unserialize(Checkpoint *cp,
194 const std::string &section)
192ArchTimer::unserialize(CheckpointIn &cp)
193{
196 paramIn(cp, section, "control_serial", _control);
194 paramIn(cp, "control_serial", _control);
195 // We didn't serialize an offset before we added support for the
196 // virtual timer. Consider it optional to maintain backwards
197 // compatibility.
198 if (!UNSERIALIZE_OPT_SCALAR(_offset))
199 _offset = 0;
200 bool event_scheduled;
201 UNSERIALIZE_SCALAR(event_scheduled);
202 if (event_scheduled) {

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

233 gic(p->gic),
234 irqPhys(p->int_phys),
235 irqVirt(p->int_virt)
236{
237 dynamic_cast<ArmSystem &>(*p->system).setGenericTimer(this);
238}
239
240void
243GenericTimer::serialize(std::ostream &os)
241GenericTimer::serialize(CheckpointOut &cp) const
242{
245 paramOut(os, "cpu_count", timers.size());
243 paramOut(cp, "cpu_count", timers.size());
244
247 nameOut(os, csprintf("%s.sys_counter", name()));
248 systemCounter.serialize(os);
245 systemCounter.serializeSection(cp, "sys_counter");
246
247 for (int i = 0; i < timers.size(); ++i) {
251 CoreTimers &core(getTimers(i));
248 const CoreTimers &core(*timers[i]);
249
253 nameOut(os, core.phys.name());
254 core.phys.serialize(os);
255
256 nameOut(os, core.virt.name());
257 core.virt.serialize(os);
250 // This should really be phys_timerN, but we are stuck with
251 // arch_timer for backwards compatibility.
252 core.phys.serializeSection(cp, csprintf("arch_timer%d", i));
253 core.virt.serializeSection(cp, csprintf("virt_timer%d", i));
254 }
255}
256
257void
262GenericTimer::unserialize(Checkpoint *cp, const std::string &section)
258GenericTimer::unserialize(CheckpointIn &cp)
259{
264 systemCounter.unserialize(cp, csprintf("%s.sys_counter", section));
260 systemCounter.unserializeSection(cp, "sys_counter");
261
262 // Try to unserialize the CPU count. Old versions of the timer
263 // model assumed a 8 CPUs, so we fall back to that if the field
264 // isn't present.
265 static const unsigned OLD_CPU_MAX = 8;
266 unsigned cpu_count;
267 if (!UNSERIALIZE_OPT_SCALAR(cpu_count)) {
268 warn("Checkpoint does not contain CPU count, assuming %i CPUs\n",
269 OLD_CPU_MAX);
270 cpu_count = OLD_CPU_MAX;
271 }
272
273 for (int i = 0; i < cpu_count; ++i) {
274 CoreTimers &core(getTimers(i));
275 // This should really be phys_timerN, but we are stuck with
276 // arch_timer for backwards compatibility.
281 core.phys.unserialize(cp, csprintf("%s.arch_timer%d", section, i));
282 core.virt.unserialize(cp, csprintf("%s.virt_timer%d", section, i));
277 core.phys.unserializeSection(cp, csprintf("arch_timer%d", i));
278 core.virt.unserializeSection(cp, csprintf("virt_timer%d", i));
279 }
280}
281
282
283GenericTimer::CoreTimers &
284GenericTimer::getTimers(int cpu_id)
285{
286 if (cpu_id >= timers.size())

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

489 ArchTimer::Interrupt(*p->gic, p->int_phys)),
490 virtTimer(csprintf("%s.virt_timer0", name()),
491 *this, systemCounter,
492 ArchTimer::Interrupt(*p->gic, p->int_virt))
493{
494}
495
496void
501GenericTimerMem::serialize(std::ostream &os)
497GenericTimerMem::serialize(CheckpointOut &cp) const
498{
503 paramOut(os, "timer_count", 1);
499 paramOut(cp, "timer_count", 1);
500
505 nameOut(os, csprintf("%s.sys_counter", name()));
506 systemCounter.serialize(os);
501 systemCounter.serializeSection(cp, "sys_counter");
502
508 nameOut(os, physTimer.name());
509 physTimer.serialize(os);
510
511 nameOut(os, virtTimer.name());
512 virtTimer.serialize(os);
503 physTimer.serializeSection(cp, "phys_timer0");
504 virtTimer.serializeSection(cp, "virt_timer0");
505}
506
507void
516GenericTimerMem::unserialize(Checkpoint *cp, const std::string &section)
508GenericTimerMem::unserialize(CheckpointIn &cp)
509{
518 systemCounter.unserialize(cp, csprintf("%s.sys_counter", section));
510 systemCounter.unserializeSection(cp, "sys_counter");
511
512 unsigned timer_count;
513 UNSERIALIZE_SCALAR(timer_count);
514 // The timer count variable is just here for future versions where
515 // we support more than one set of timers.
516 if (timer_count != 1)
517 panic("Incompatible checkpoint: Only one set of timers supported");
518
527 physTimer.unserialize(cp, csprintf("%s.phys_timer0", section));
528 virtTimer.unserialize(cp, csprintf("%s.virt_timer0", section));
519 physTimer.unserializeSection(cp, "phys_timer0");
520 virtTimer.unserializeSection(cp, "virt_timer0");
521}
522
523Tick
524GenericTimerMem::read(PacketPtr pkt)
525{
526 const unsigned size(pkt->getSize());
527 const Addr addr(pkt->getAddr());
528 uint64_t value;

--- 291 unchanged lines hidden ---