gem5  v21.1.0.2
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 {
88  if (scMainFiber.finished() || stopAfterCallbacks)
89  return;
90 
91  try {
92  for (auto p: allPorts)
93  p->finalize();
94  for (auto p: allPorts)
95  p->regPort();
96 
98  for (auto p: allPorts)
99  p->sc_port_base()->end_of_elaboration();
100  for (auto m: sc_gem5::allModules)
101  m->endOfElaboration();
102  for (auto c: sc_gem5::allChannels)
103  c->sc_chan()->end_of_elaboration();
104  } catch (...) {
106  }
107 }
108 
109 void
111 {
112  if (scMainFiber.finished())
113  return;
114 
116 
117  if (stopAfterCallbacks)
118  return;
119 
120  try {
122  for (auto p: allPorts)
123  p->sc_port_base()->start_of_simulation();
124  for (auto m: sc_gem5::allModules)
125  m->startOfSimulation();
126  for (auto c: sc_gem5::allChannels)
127  c->sc_chan()->start_of_simulation();
128  } catch (...) {
130  }
131 
132  startComplete = true;
133 
134  if (stopAfterCallbacks)
135  stopWork();
136 
138 }
139 
140 void
142 {
143  if (status() < ::sc_core::SC_RUNNING)
144  stopAfterCallbacks = true;
145  else
146  stopWork();
147 }
148 
149 void
151 {
153  try {
154  for (auto p: allPorts)
155  p->sc_port_base()->end_of_simulation();
156  for (auto m: sc_gem5::allModules)
157  m->endOfSimulation();
158  for (auto c: sc_gem5::allChannels)
159  c->sc_chan()->end_of_simulation();
160  } catch (...) {
162  }
163 
164  endComplete = true;
165 
167 }
168 
169 void
171 {
172  if (stopAfterCallbacks) {
173  scheduler.clear();
175  scheduler.scheduleStop(false);
176  } else {
179  }
180 }
181 
183 
184 } // namespace sc_gem5
185 
187 gem5::SystemC_KernelParams::create() const
188 {
189  using namespace gem5;
191  "Only one systemc kernel object may be defined.\n");
192  sc_gem5::kernel = new sc_gem5::Kernel(*this, 0);
193  return sc_gem5::kernel;
194 }
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:189
port.hh
sc_gem5::Kernel::regStats
void regStats() override
Callback to set stat parameters.
Definition: kernel.cc:86
kernel.hh
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:141
sc_gem5::Kernel::endOfSimulationComplete
static bool endOfSimulationComplete()
Definition: kernel.cc:52
sc_gem5::Kernel::t0Handler
void t0Handler()
Definition: kernel.cc:170
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:182
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::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
sc_gem5::Scheduler::throwUp
void throwUp()
Definition: scheduler.cc:459
gem5::ArmISA::s
Bitfield< 4 > s
Definition: misc_types.hh:561
sc_gem5::Kernel::stopWork
static void stopWork()
Definition: kernel.cc:150
gem5::ArmISA::c
Bitfield< 29 > c
Definition: misc_types.hh:53
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
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:110
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:203
gem5::ArmISA::m
Bitfield< 0 > m
Definition: misc_types.hh:394
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: decoder.cc:40
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 Tue Sep 21 2021 12:25:50 for gem5 by doxygen 1.8.17