gem5  v22.1.0.0
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 
28 #include "systemc/core/kernel.hh"
29 
30 #include "base/logging.hh"
31 #include "systemc/core/channel.hh"
32 #include "systemc/core/module.hh"
33 #include "systemc/core/port.hh"
36 
37 namespace sc_gem5
38 {
39 
40 namespace
41 {
42 
43 bool stopAfterCallbacks = false;
44 bool startComplete = false;
45 bool endComplete = false;
46 
48 
49 } // anonymous namespace
50 
51 bool Kernel::startOfSimulationComplete() { return startComplete; }
52 bool Kernel::endOfSimulationComplete() { return endComplete; }
53 
54 sc_core::sc_status Kernel::status() { return _status; }
55 void Kernel::status(sc_core::sc_status s) { _status = s; }
56 
57 Kernel::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 
65 void
67 {
68  if (scMainFiber.finished())
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 
85 void
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 
111 void
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 
142 void
144 {
145  if (status() < ::sc_core::SC_RUNNING)
146  stopAfterCallbacks = true;
147  else
148  stopWork();
149 }
150 
151 void
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 
171 void
173 {
174  if (stopAfterCallbacks) {
175  scheduler.clear();
177  scheduler.scheduleStop(false);
178  } else {
181  }
182 }
183 
185 
186 } // namespace sc_gem5
187 
189 gem5::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 }
SimObjectParams Params
Definition: sim_object.hh:170
gem5::EventWrapper< Kernel, &Kernel::t0Handler > t0Event
Definition: kernel.hh:68
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
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
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
bool elaborationDone()
Definition: scheduler.hh:378
void setEventQueue(gem5::EventQueue *_eq)
Definition: scheduler.hh:240
EventQueue * eventQueue() const
Definition: eventq.hh:1010
void schedule(Event &event, Tick when)
Definition: eventq.hh:1019
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:190
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:204
virtual void regStats()
Callback to set stat parameters.
Definition: group.cc:69
Bitfield< 1 > s
Definition: pagetable.hh:64
Bitfield< 2 > c
Definition: pagetable.hh:63
Bitfield< 54 > p
Definition: pagetable.hh:70
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:46
sc_status
Definition: sc_main.hh:82
@ 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 Wed Dec 21 2022 10:22:40 for gem5 by doxygen 1.9.1