gem5 v24.0.0.0
Loading...
Searching...
No Matches
kernel.cc
Go to the documentation of this file.
1/*
2 * Copyright 2018 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
29
30#include "base/logging.hh"
33#include "systemc/core/port.hh"
36
37namespace sc_gem5
38{
39
40namespace
41{
42
43bool stopAfterCallbacks = false;
44bool startComplete = false;
45bool endComplete = false;
46
48
49} // anonymous namespace
50
51bool Kernel::startOfSimulationComplete() { return startComplete; }
52bool Kernel::endOfSimulationComplete() { return endComplete; }
53
55void Kernel::status(sc_core::sc_status s) { _status = s; }
56
57Kernel::Kernel(const Params &params, int) :
58 gem5::SimObject(params),
59 t0Event(*this, false, gem5::EventBase::Default_Pri - 1)
60{
61 // Install ourselves as the scheduler's event manager.
63}
64
65void
67{
69 return;
70
71 if (stopAfterCallbacks)
72 fatal("Simulation called sc_stop during elaboration.\n");
73
75 for (auto p: allPorts)
76 p->sc_port_base()->before_end_of_elaboration();
77 for (auto m: sc_gem5::allModules)
78 m->beforeEndOfElaboration();
79 for (auto c: sc_gem5::allChannels)
80 c->sc_chan()->before_end_of_elaboration();
81
83}
84
85void
87{
89
90 if (scMainFiber.finished() || stopAfterCallbacks)
91 return;
92
93 try {
94 for (auto p: allPorts)
95 p->finalize();
96 for (auto p: allPorts)
97 p->regPort();
98
100 for (auto p: allPorts)
101 p->sc_port_base()->end_of_elaboration();
102 for (auto m: sc_gem5::allModules)
103 m->endOfElaboration();
104 for (auto c: sc_gem5::allChannels)
105 c->sc_chan()->end_of_elaboration();
106 } catch (...) {
108 }
109}
110
111void
113{
114 if (scMainFiber.finished())
115 return;
116
118
119 if (stopAfterCallbacks)
120 return;
121
122 try {
124 for (auto p: allPorts)
125 p->sc_port_base()->start_of_simulation();
126 for (auto m: sc_gem5::allModules)
127 m->startOfSimulation();
128 for (auto c: sc_gem5::allChannels)
129 c->sc_chan()->start_of_simulation();
130 } catch (...) {
132 }
133
134 startComplete = true;
135
136 if (stopAfterCallbacks)
137 stopWork();
138
140}
141
142void
144{
146 stopAfterCallbacks = true;
147 else
148 stopWork();
149}
150
151void
153{
155 try {
156 for (auto p: allPorts)
157 p->sc_port_base()->end_of_simulation();
158 for (auto m: sc_gem5::allModules)
159 m->endOfSimulation();
160 for (auto c: sc_gem5::allChannels)
161 c->sc_chan()->end_of_simulation();
162 } catch (...) {
164 }
165
166 endComplete = true;
167
169}
170
171void
173{
174 if (stopAfterCallbacks) {
177 scheduler.scheduleStop(false);
178 } else {
181 }
182}
183
185
186} // namespace sc_gem5
187
189gem5::SystemC_KernelParams::create() const
190{
191 using namespace gem5;
193 "Only one systemc kernel object may be defined.\n");
194 sc_gem5::kernel = new sc_gem5::Kernel(*this, 0);
195 return sc_gem5::kernel;
196}
void startup() override
startup() is the final initialization call before simulation.
Definition kernel.cc:112
static sc_core::sc_status status()
Definition kernel.cc:54
void t0Handler()
Definition kernel.cc:172
gem5::SystemC_KernelParams Params
Definition kernel.hh:48
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition kernel.cc:66
static bool endOfSimulationComplete()
Definition kernel.cc:52
gem5::MemberEventWrapper<&Kernel::t0Handler > t0Event
Definition kernel.hh:68
static void stopWork()
Definition kernel.cc:152
void regStats() override
Callback to set stat parameters.
Definition kernel.cc:86
static bool startOfSimulationComplete()
Definition kernel.cc:51
static void stop()
Definition kernel.cc:143
Kernel(const Params &params, int)
Definition kernel.cc:57
void scheduleStop(bool finish_delta)
Definition scheduler.cc:473
void setEventQueue(gem5::EventQueue *_eq)
Definition scheduler.hh:240
SwitchingFiber c
void schedule(Event &event, Tick when)
Definition eventq.hh:1012
EventQueue * eventQueue() const
Definition eventq.hh:1003
bool finished() const
Returns whether the "main" function of this fiber has finished.
Definition fiber.hh:109
#define fatal(...)
This implements a cprintf based fatal() function.
Definition logging.hh:200
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition logging.hh:214
virtual void regStats()
Callback to set stat parameters.
Definition group.cc:68
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
Tick curTick()
The universal simulation clock.
Definition cur_tick.hh:46
@ SC_END_OF_ELABORATION
Definition sc_main.hh:85
@ SC_END_OF_SIMULATION
Definition sc_main.hh:90
@ SC_ELABORATION
Definition sc_main.hh:83
@ SC_STOPPED
Definition sc_main.hh:89
@ SC_RUNNING
Definition sc_main.hh:87
@ SC_BEFORE_END_OF_ELABORATION
Definition sc_main.hh:84
@ SC_START_OF_SIMULATION
Definition sc_main.hh:86
ScMainFiber scMainFiber
std::list< Port * > allPorts
Definition port.cc:167
Scheduler scheduler
Definition scheduler.cc:494
Kernel * kernel
Definition kernel.cc:184
std::set< Channel * > allChannels
Definition channel.cc:58
std::list< Module * > allModules
Definition module.cc:214

Generated on Tue Jun 18 2024 16:24:06 for gem5 by doxygen 1.11.0