fastmodel: Checkpoint the TCs when checkpointing a fast model CPU.
[gem5.git] / src / arch / arm / fastmodel / iris / cpu.cc
1 /*
2 * Copyright 2019 Google, Inc.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met: redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer;
8 * redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution;
11 * neither the name of the copyright holders nor the names of its
12 * contributors may be used to endorse or promote products derived from
13 * this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 * Authors: Gabe Black
28 */
29
30 #include "arch/arm/fastmodel/iris/cpu.hh"
31
32 #include "arch/arm/fastmodel/iris/thread_context.hh"
33 #include "scx/scx.h"
34 #include "sim/serialize.hh"
35
36 namespace Iris
37 {
38
39 BaseCPU::BaseCPU(BaseCPUParams *params, sc_core::sc_module *_evs) :
40 ::BaseCPU::BaseCPU(params), evs(_evs),
41 clockEvent(nullptr), periodAttribute(nullptr)
42 {
43 sc_core::sc_attr_base *base;
44
45 const auto &event_vec = evs->get_child_events();
46 auto event_it = std::find_if(event_vec.begin(), event_vec.end(),
47 [](const sc_core::sc_event *e) -> bool {
48 return e->basename() == ClockEventName; });
49 if (event_it != event_vec.end())
50 clockEvent = *event_it;
51
52 base = evs->get_attribute(PeriodAttributeName);
53 periodAttribute = dynamic_cast<sc_core::sc_attribute<Tick> *>(base);
54 panic_if(base && !periodAttribute,
55 "The EVS clock period attribute is not of type "
56 "sc_attribute<Tick>.");
57
58 base = evs->get_attribute(SendFunctionalAttributeName);
59 sendFunctional =
60 dynamic_cast<sc_core::sc_attribute<PortProxy::SendFunctionalFunc> *>(
61 base);
62 panic_if(base && !sendFunctional,
63 "The EVS send functional attribute is not of type "
64 "sc_attribute<PortProxy::SendFunctionalFunc>.");
65
66 // Make sure fast model knows we're using debugging mechanisms to control
67 // the simulation, and it shouldn't shut down if simulation time stops
68 // for some reason. Despite the misleading name, this doesn't start a CADI
69 // server because it's first parameter is false.
70 scx::scx_start_cadi_server(false, false, true);
71 }
72
73 BaseCPU::~BaseCPU()
74 {
75 for (auto &tc: threadContexts)
76 delete tc;
77 threadContexts.clear();
78 }
79
80 Counter
81 BaseCPU::totalInsts() const
82 {
83 Counter count = 0;
84 for (auto *tc: threadContexts)
85 count += tc->getCurrentInstCount();
86 return count;
87 }
88
89 void
90 BaseCPU::init()
91 {
92 ::BaseCPU::init();
93 for (auto *tc: threadContexts)
94 tc->initMemProxies(tc);
95 }
96
97 void
98 BaseCPU::serializeThread(CheckpointOut &cp, ThreadID tid) const
99 {
100 ::serialize(*threadContexts[tid], cp);
101 }
102
103 } // namespace Iris