gem5  v22.0.0.1
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 }
gem5::curTick
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:46
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:190
port.hh
gem5::VegaISA::s
Bitfield< 1 > s
Definition: pagetable.hh:64
sc_gem5::Kernel::regStats
void regStats() override
Callback to set stat parameters.
Definition: kernel.cc:86
kernel.hh
gem5::VegaISA::m
m
Definition: pagetable.hh:52
gem5::EventManager::eventQueue
EventQueue * eventQueue() const
Definition: eventq.hh:1010
module.hh
sc_main_fiber.hh
sc_gem5::Kernel::t0Event
gem5::EventWrapper< Kernel, &Kernel::t0Handler > t0Event
Definition: kernel.hh:68
sc_gem5::Kernel::stop
static void stop()
Definition: kernel.cc:143
sc_gem5::Kernel::endOfSimulationComplete
static bool endOfSimulationComplete()
Definition: kernel.cc:52
sc_gem5::Kernel::t0Handler
void t0Handler()
Definition: kernel.cc:172
sc_gem5::Kernel::init
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: kernel.cc:66
sc_gem5::kernel
Kernel * kernel
Definition: kernel.cc:184
gem5::EventManager::schedule
void schedule(Event &event, Tick when)
Definition: eventq.hh:1019
sc_core::SC_BEFORE_END_OF_ELABORATION
@ SC_BEFORE_END_OF_ELABORATION
Definition: sc_main.hh:84
sc_gem5::allChannels
std::set< Channel * > allChannels
Definition: channel.cc:58
sc_gem5::Kernel
Definition: kernel.hh:45
sc_core::SC_ELABORATION
@ SC_ELABORATION
Definition: sc_main.hh:83
sc_core::SC_END_OF_ELABORATION
@ SC_END_OF_ELABORATION
Definition: sc_main.hh:85
sc_core::SC_STOPPED
@ SC_STOPPED
Definition: sc_main.hh:89
gem5::SimObject::Params
SimObjectParams Params
Definition: sim_object.hh:170
gem5::VegaISA::c
Bitfield< 2 > c
Definition: pagetable.hh:63
gem5::VegaISA::p
Bitfield< 54 > p
Definition: pagetable.hh:70
sc_gem5::Scheduler::throwUp
void throwUp()
Definition: scheduler.cc:459
sc_gem5::Kernel::stopWork
static void stopWork()
Definition: kernel.cc:152
channel.hh
sc_gem5::Kernel::startOfSimulationComplete
static bool startOfSimulationComplete()
Definition: kernel.cc:51
sc_gem5::Scheduler::clear
void clear()
Definition: scheduler.cc:67
sc_core::SC_START_OF_SIMULATION
@ SC_START_OF_SIMULATION
Definition: sc_main.hh:86
sc_core::SC_END_OF_SIMULATION
@ SC_END_OF_SIMULATION
Definition: sc_main.hh:90
sc_gem5::Scheduler::elaborationDone
bool elaborationDone()
Definition: scheduler.hh:378
gem5::statistics::Group::regStats
virtual void regStats()
Callback to set stat parameters.
Definition: group.cc:69
sc_gem5::scMainFiber
ScMainFiber scMainFiber
Definition: sc_main_fiber.cc:81
sc_gem5::Kernel::startup
void startup() override
startup() is the final initialization call before simulation.
Definition: kernel.cc:112
panic_if
#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
gem5::Fiber::finished
bool finished() const
Returns whether the "main" function of this fiber has finished.
Definition: fiber.hh:109
sc_core::sc_status
sc_status
Definition: sc_main.hh:81
sc_gem5::allPorts
std::list< Port * > allPorts
Definition: port.cc:167
sc_gem5::allModules
std::list< Module * > allModules
Definition: module.cc:214
sc_gem5::Scheduler::scheduleStop
void scheduleStop(bool finish_delta)
Definition: scheduler.cc:473
logging.hh
sc_gem5::Scheduler::initPhase
void initPhase()
Definition: scheduler.cc:109
sc_gem5
Definition: sc_clock.cc:41
sc_gem5::scheduler
Scheduler scheduler
Definition: scheduler.cc:494
sc_gem5::Scheduler::setEventQueue
void setEventQueue(gem5::EventQueue *_eq)
Definition: scheduler.hh:240
sc_gem5::Kernel::status
static sc_core::sc_status status()
Definition: kernel.cc:54
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
sc_core::SC_RUNNING
@ SC_RUNNING
Definition: sc_main.hh:87
sc_gem5::Kernel::Kernel
Kernel(const Params &params, int)
Definition: kernel.cc:57
scheduler.hh

Generated on Sat Jun 18 2022 08:12:32 for gem5 by doxygen 1.8.17