gem5  v20.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 
58  SimObject(params), t0Event(this, false, EventBase::Default_Pri - 1)
59 {
60  // Install ourselves as the scheduler's event manager.
62 }
63 
64 void
66 {
67  if (scMainFiber.finished())
68  return;
69 
70  if (stopAfterCallbacks)
71  fatal("Simulation called sc_stop during elaboration.\n");
72 
74  for (auto p: allPorts)
75  p->sc_port_base()->before_end_of_elaboration();
76  for (auto m: sc_gem5::allModules)
77  m->beforeEndOfElaboration();
78  for (auto c: sc_gem5::allChannels)
79  c->sc_chan()->before_end_of_elaboration();
80 
82 }
83 
84 void
86 {
87  if (scMainFiber.finished() || stopAfterCallbacks)
88  return;
89 
90  try {
91  for (auto p: allPorts)
92  p->finalize();
93  for (auto p: allPorts)
94  p->regPort();
95 
97  for (auto p: allPorts)
98  p->sc_port_base()->end_of_elaboration();
99  for (auto m: sc_gem5::allModules)
100  m->endOfElaboration();
101  for (auto c: sc_gem5::allChannels)
102  c->sc_chan()->end_of_elaboration();
103  } catch (...) {
105  }
106 }
107 
108 void
110 {
111  if (scMainFiber.finished())
112  return;
113 
115 
116  if (stopAfterCallbacks)
117  return;
118 
119  try {
121  for (auto p: allPorts)
122  p->sc_port_base()->start_of_simulation();
123  for (auto m: sc_gem5::allModules)
124  m->startOfSimulation();
125  for (auto c: sc_gem5::allChannels)
126  c->sc_chan()->start_of_simulation();
127  } catch (...) {
129  }
130 
131  startComplete = true;
132 
133  if (stopAfterCallbacks)
134  stopWork();
135 
137 }
138 
139 void
141 {
142  if (status() < ::sc_core::SC_RUNNING)
143  stopAfterCallbacks = true;
144  else
145  stopWork();
146 }
147 
148 void
150 {
152  try {
153  for (auto p: allPorts)
154  p->sc_port_base()->end_of_simulation();
155  for (auto m: sc_gem5::allModules)
156  m->endOfSimulation();
157  for (auto c: sc_gem5::allChannels)
158  c->sc_chan()->end_of_simulation();
159  } catch (...) {
161  }
162 
163  endComplete = true;
164 
166 }
167 
168 void
170 {
171  if (stopAfterCallbacks) {
172  scheduler.clear();
174  scheduler.scheduleStop(false);
175  } else {
178  }
179 }
180 
182 
183 } // namespace sc_gem5
184 
186 SystemC_KernelParams::create()
187 {
189  "Only one systemc kernel object may be defined.\n");
190  sc_gem5::kernel = new sc_gem5::Kernel(this);
191  return sc_gem5::kernel;
192 }
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:183
port.hh
sc_gem5::Kernel::regStats
void regStats() override
Callback to set stat parameters.
Definition: kernel.cc:85
kernel.hh
SimObject::Params
SimObjectParams Params
Definition: sim_object.hh:113
module.hh
sc_main_fiber.hh
sc_gem5::Scheduler::scheduleStop
void scheduleStop(bool finish_delta)
Definition: scheduler.cc:468
sc_gem5::Kernel::stop
static void stop()
Definition: kernel.cc:140
Fiber::finished
bool finished() const
Returns whether the "main" function of this fiber has finished.
Definition: fiber.hh:100
sc_gem5::Kernel::endOfSimulationComplete
static bool endOfSimulationComplete()
Definition: kernel.cc:52
sc_gem5::Kernel::t0Handler
void t0Handler()
Definition: kernel.cc:169
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:65
sc_gem5::kernel
Kernel * kernel
Definition: kernel.cc:181
sc_gem5::Kernel::Kernel
Kernel(Params *params)
Definition: kernel.cc:57
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
EventManager::schedule
void schedule(Event &event, Tick when)
Definition: eventq.hh:1005
sc_gem5::Scheduler::throwUp
void throwUp()
Definition: scheduler.cc:454
sc_gem5::Kernel::stopWork
static void stopWork()
Definition: kernel.cc:149
sc_gem5::Scheduler::clear
void clear()
Definition: scheduler.cc:67
sc_gem5::Scheduler::initPhase
void initPhase()
Definition: scheduler.cc:110
sc_gem5::Kernel::t0Event
EventWrapper< Kernel, &Kernel::t0Handler > t0Event
Definition: kernel.hh:68
channel.hh
sc_gem5::Kernel::startOfSimulationComplete
static bool startOfSimulationComplete()
Definition: kernel.cc:51
sc_core::SC_START_OF_SIMULATION
@ SC_START_OF_SIMULATION
Definition: sc_main.hh:86
EventManager::eventQueue
EventQueue * eventQueue() const
Definition: eventq.hh:996
sc_core::SC_END_OF_SIMULATION
@ SC_END_OF_SIMULATION
Definition: sc_main.hh:90
sc_gem5::Scheduler::elaborationDone
bool elaborationDone()
Definition: scheduler.hh:354
sc_gem5::scMainFiber
ScMainFiber scMainFiber
Definition: sc_main_fiber.cc:78
sc_gem5::Kernel::startup
void startup() override
startup() is the final initialization call before simulation.
Definition: kernel.cc:109
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:197
sc_core::sc_status
sc_status
Definition: sc_main.hh:81
sc_gem5::allPorts
std::list< Port * > allPorts
Definition: port.cc:167
sc_gem5::Scheduler::setEventQueue
void setEventQueue(EventQueue *_eq)
Definition: scheduler.hh:225
sc_gem5::allModules
std::list< Module * > allModules
Definition: module.cc:211
logging.hh
EventBase
Common base class for Event and GlobalEvent, so they can share flag and priority definitions and acce...
Definition: eventq.hh:91
ArmISA::c
Bitfield< 29 > c
Definition: miscregs_types.hh:50
sc_gem5
Definition: sc_clock.cc:42
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
sc_gem5::scheduler
Scheduler scheduler
Definition: scheduler.cc:489
ArmISA::s
Bitfield< 4 > s
Definition: miscregs_types.hh:556
sc_gem5::Kernel::status
static sc_core::sc_status status()
Definition: kernel.cc:54
sc_core::SC_RUNNING
@ SC_RUNNING
Definition: sc_main.hh:87
scheduler.hh
ArmISA::m
Bitfield< 0 > m
Definition: miscregs_types.hh:389
curTick
Tick curTick()
The current simulated tick.
Definition: core.hh:45
SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:92

Generated on Wed Sep 30 2020 14:02:14 for gem5 by doxygen 1.8.17