gem5  v21.1.0.2
process.hh
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 #ifndef __SYSTEMC_CORE_PROCESS_HH__
29 #define __SYSTEMC_CORE_PROCESS_HH__
30 
31 #include <functional>
32 #include <memory>
33 #include <vector>
34 
35 #include "base/fiber.hh"
36 #include "systemc/core/list.hh"
37 #include "systemc/core/module.hh"
38 #include "systemc/core/object.hh"
45 
46 namespace sc_core
47 {
48 
49 class sc_join;
50 
51 } // namespace sc_core
52 
53 namespace sc_gem5
54 {
55 
56 class ScHalt
57 {};
58 
59 class Process;
60 class Reset;
61 
63 {
64  public:
66  bool needsStart() const { return _needsStart; }
67  void needsStart(bool ns) { _needsStart = ns; }
68  bool dynamic() const { return _dynamic; }
69  bool isUnwinding() const { return _isUnwinding; }
70  void isUnwinding(bool v) { _isUnwinding = v; }
71  bool terminated() const { return _terminated; }
72 
73  bool scheduled() const { return _scheduled; }
74  void scheduled(bool new_val) { _scheduled = new_val; }
75 
76  void forEachKid(const std::function<void(Process *)> &work);
77 
78  bool suspended() const { return _suspended; }
79  bool disabled() const { return _disabled; }
80 
81  void suspend(bool inc_kids);
82  void resume(bool inc_kids);
83  void disable(bool inc_kids);
84  void enable(bool inc_kids);
85 
86  void kill(bool inc_kids);
87  void reset(bool inc_kids);
88  void throw_it(ExceptionWrapperBase &exc, bool inc_kids);
89 
92 
93  void syncResetOn(bool inc_kids);
94  void syncResetOff(bool inc_kids);
95 
96  void signalReset(bool set, bool sync);
97 
98  void incref() { refCount++; }
99  void decref() { refCount--; }
100 
103 
104  void setStackSize(size_t size) { stackSize = size; }
105 
106  void run();
107 
110  void clearDynamic() { setDynamic(nullptr); }
111  void addReset(Reset *);
112 
114  void setTimeout(::sc_core::sc_time t);
115  void cancelTimeout();
116 
118 
119  void ready();
120 
121  virtual gem5::Fiber *fiber() { return gem5::Fiber::primaryFiber(); }
122 
123  static Process *newest() { return _newest; }
124 
125  void lastReport(::sc_core::sc_report *report);
127 
128  bool hasStaticSensitivities() { return !staticSensitivities.empty(); }
129  bool internal() { return _internal; }
130  bool timedOut() { return _timedOut; }
132 
133  bool dontInitialize() { return _dontInitialize; }
134  void dontInitialize(bool di) { _dontInitialize = di; }
135 
136  void joinWait(::sc_core::sc_join *join) { joinWaiters.push_back(join); }
137 
138  void waitCount(int count) { _waitCount = count; }
139 
140  const char *uniqueName(const char *seed) { return nameGen.gen(seed); }
141 
142  protected:
143  void timeout();
144 
145  Process(const char *name, ProcessFuncWrapper *func, bool internal=false);
146 
147  static Process *_newest;
148 
149  virtual ~Process()
150  {
151  popListNode();
152  delete func;
153  for (auto s: staticSensitivities) {
154  s->clear();
155  delete s;
156  }
157  clearDynamic();
158  }
159 
162 
164 
165  bool _internal;
166 
167  // Needed to support the deprecated "timed_out" function.
168  bool _timedOut;
169 
171 
173  bool _dynamic;
177 
178  void terminate();
179 
182  bool _disabled;
183 
185 
188 
190 
191  int refCount;
192 
193  size_t stackSize;
194 
198 
199  std::unique_ptr<::sc_core::sc_report> _lastReport;
200 
202 
204 };
205 
206 class Reset
207 {
208  public:
209  Reset(Process *p, bool s, bool v) :
210  _process(p), _signal(nullptr), _sync(s), _value(v)
211  {}
212 
213  bool
215  {
216  _signal = s;
217 
218  if (_signal->_addReset(this)) {
219  _process->addReset(this);
220  if (_signal->read() == _value)
221  update();
222  return true;
223  }
224  return false;
225  }
227 
228  Process *process() { return _process; }
230  bool sync() { return _sync; }
231  bool value() { return _value; }
232 
233  private:
236  bool _sync;
237  bool _value;
238 };
239 
240 void newReset(const sc_core::sc_port_base *pb, Process *p, bool s, bool v);
242  bool s, bool v);
243 
244 } // namespace sc_gem5
245 
246 #endif //__SYSTEMC_CORE_PROCESS_HH__
sc_gem5::Reset::Reset
Reset(Process *p, bool s, bool v)
Definition: process.hh:209
sc_core::sc_port_base
Definition: sc_port.hh:74
sc_gem5::Process::scheduled
bool scheduled() const
Definition: process.hh:73
sc_gem5::Process::forEachKid
void forEachKid(const std::function< void(Process *)> &work)
Definition: process.cc:67
sc_gem5::Process::_needsStart
bool _needsStart
Definition: process.hh:172
sc_gem5::Process::_dontInitialize
bool _dontInitialize
Definition: process.hh:170
sc_core::sc_signal_in_if< bool >::read
virtual const bool & read() const =0
sc_gem5::Process::satisfySensitivity
void satisfySensitivity(Sensitivity *)
Definition: process.cc:332
sc_gem5::Process::needsStart
void needsStart(bool ns)
Definition: process.hh:67
sc_core::sc_signal_in_if< bool >
Definition: sc_signal_in_if.hh:74
sc_gem5::Process::run
void run()
Definition: process.cc:262
sc_gem5::Process::_dynamic
bool _dynamic
Definition: process.hh:173
sc_gem5::Reset::install
bool install(const sc_core::sc_signal_in_if< bool > *s)
Definition: process.hh:214
sc_gem5::Process::_internal
bool _internal
Definition: process.hh:165
sc_gem5::ProcessFuncWrapper
Definition: sc_process_handle.hh:43
module.hh
sc_gem5::Process::_syncReset
bool _syncReset
Definition: process.hh:184
sc_gem5::Process::addReset
void addReset(Reset *)
Definition: process.cc:298
sc_gem5::Process::inReset
bool inReset()
Definition: process.hh:131
sc_gem5::Process::terminated
bool terminated() const
Definition: process.hh:71
sc_gem5::Process::joinWait
void joinWait(::sc_core::sc_join *join)
Definition: process.hh:136
sc_gem5::Process::resetEvent
::sc_core::sc_event & resetEvent()
Definition: process.hh:101
sc_core::sc_signal_in_if< bool >::_addReset
virtual bool _addReset(sc_gem5::Reset *reset) const
Definition: sc_signal_in_if.hh:93
sc_gem5::ListNode
Definition: list.hh:42
sc_gem5::Process::timedOut
bool timedOut()
Definition: process.hh:130
sc_core
Definition: messages.cc:31
sc_gem5::Process::syncResetOn
void syncResetOn(bool inc_kids)
Definition: process.cc:223
sc_gem5::Process::resets
std::vector< Reset * > resets
Definition: process.hh:197
sc_gem5::Process::disable
void disable(bool inc_kids)
Definition: process.cc:112
gem5::ArmISA::ns
Bitfield< 0 > ns
Definition: misc_types.hh:331
sc_gem5::Process::_terminatedEvent
InternalScEvent _terminatedEvent
Definition: process.hh:161
sc_gem5::UniqueNameGen
Definition: module.hh:52
sensitivity.hh
std::vector< StaticSensitivity * >
sc_gem5::Reset
Definition: process.hh:206
gem5::Fiber::primaryFiber
static Fiber * primaryFiber()
Get a pointer to the primary Fiber.
Definition: fiber.cc:186
sc_gem5::Process::reset
void reset(bool inc_kids)
Definition: process.cc:169
sc_gem5::Process::_scheduled
bool _scheduled
Definition: process.hh:176
sc_gem5::Process::incref
void incref()
Definition: process.hh:98
sc_gem5::Process::_disabled
bool _disabled
Definition: process.hh:182
sc_gem5::Reset::value
bool value()
Definition: process.hh:231
sc_gem5::Process::_newest
static Process * _newest
Definition: process.hh:147
sc_gem5::UniqueNameGen::gen
const char * gen(std::string seed)
Definition: module.hh:60
sc_gem5::Process::dynamicSensitivity
DynamicSensitivity * dynamicSensitivity
Definition: process.hh:196
sc_event.hh
sc_gem5::Process::timeoutEvent
ScEvent timeoutEvent
Definition: process.hh:113
sc_gem5::Process::uniqueName
const char * uniqueName(const char *seed)
Definition: process.hh:140
sc_gem5::Process::excWrapper
ExceptionWrapperBase * excWrapper
Definition: process.hh:91
sc_gem5::Process::_waitCount
int _waitCount
Definition: process.hh:189
sc_gem5::InternalScEvent
Definition: sc_event.hh:254
sc_core::sc_process_b
Definition: sc_process_handle.hh:118
sc_gem5::Reset::_sync
bool _sync
Definition: process.hh:236
sc_gem5::DynamicSensitivity
Definition: sensitivity.hh:96
sc_gem5::ListNode::popListNode
void popListNode()
Definition: list.hh:51
gem5::X86ISA::count
count
Definition: misc.hh:709
sc_gem5::Process::syncResetOff
void syncResetOff(bool inc_kids)
Definition: process.cc:232
sc_core::sc_event
Definition: sc_event.hh:169
sc_gem5::Process::staticSensitivities
StaticSensitivities staticSensitivities
Definition: process.hh:195
sc_gem5::Process::cancelTimeout
void cancelTimeout()
Definition: process.cc:304
sc_gem5::StaticSensitivity
Definition: sensitivity.hh:111
gem5::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
sc_gem5::Process::suspend
void suspend(bool inc_kids)
Definition: process.cc:77
sc_gem5::Process::hasStaticSensitivities
bool hasStaticSensitivities()
Definition: process.hh:128
gem5::ArmISA::v
Bitfield< 28 > v
Definition: misc_types.hh:54
gem5::ArmISA::s
Bitfield< 4 > s
Definition: misc_types.hh:561
sc_gem5::Process::scheduled
void scheduled(bool new_val)
Definition: process.hh:74
sc_core::sc_time
Definition: sc_time.hh:49
sc_gem5::ExceptionWrapperBase
Definition: sc_process_handle.hh:61
sched_event.hh
sc_gem5::Process::disabled
bool disabled() const
Definition: process.hh:79
sc_signal_in_if.hh
gem5::Fiber
This class represents a fiber, which is a light weight sort of thread which is cooperatively schedule...
Definition: fiber.hh:71
sc_gem5::Process::terminate
void terminate()
Definition: process.cc:395
sc_gem5::Process::nameGen
UniqueNameGen nameGen
Definition: process.hh:203
sc_gem5::Process::lastReport
::sc_core::sc_report * lastReport() const
Definition: process.cc:376
sc_gem5::Process::refCount
int refCount
Definition: process.hh:191
sc_gem5::ScHalt
Definition: process.hh:56
sc_gem5::Process::addStatic
void addStatic(StaticSensitivity *)
Definition: process.cc:282
sc_gem5::Process::_suspended
bool _suspended
Definition: process.hh:180
sc_gem5::Reset::_signal
const sc_core::sc_signal_in_if< bool > * _signal
Definition: process.hh:235
sc_gem5::Process::timeout
void timeout()
Definition: process.cc:318
sc_core::sc_join
Definition: sc_join.hh:41
sc_gem5::Process::throw_it
void throw_it(ExceptionWrapperBase &exc, bool inc_kids)
Definition: process.cc:198
gem5::ArmISA::t
Bitfield< 5 > t
Definition: misc_types.hh:70
sc_gem5::Process::newest
static Process * newest()
Definition: process.hh:123
sc_gem5::Process::signalReset
void signalReset(bool set, bool sync)
Definition: process.cc:241
sc_gem5::newReset
void newReset(const sc_core::sc_port_base *pb, Process *p, bool s, bool v)
Definition: process.cc:425
sc_gem5::Process::enable
void enable(bool inc_kids)
Definition: process.cc:130
sc_gem5::Process
Definition: process.hh:62
sc_module.hh
sc_gem5::Process::syncResetCount
int syncResetCount
Definition: process.hh:186
sc_core::sc_report
Definition: sc_report.hh:60
sc_gem5::Process::_suspendedReady
bool _suspendedReady
Definition: process.hh:181
sc_gem5::Reset::sync
bool sync()
Definition: process.hh:230
sc_gem5::Process::dynamic
bool dynamic() const
Definition: process.hh:68
sc_gem5::Process::dontInitialize
void dontInitialize(bool di)
Definition: process.hh:134
sc_process_handle.hh
sc_gem5::Process::isUnwinding
void isUnwinding(bool v)
Definition: process.hh:70
sc_gem5::Process::dontInitialize
bool dontInitialize()
Definition: process.hh:133
sc_gem5::Reset::signal
const sc_core::sc_signal_in_if< bool > * signal()
Definition: process.hh:229
sc_gem5::Reset::update
void update()
Definition: process.hh:226
sc_gem5::Process::Process
Process(const char *name, ProcessFuncWrapper *func, bool internal=false)
Definition: process.cc:378
sc_gem5::Process::setTimeout
void setTimeout(::sc_core::sc_time t)
Definition: process.cc:311
sc_gem5::Process::_lastReport
std::unique_ptr<::sc_core::sc_report > _lastReport
Definition: process.hh:199
list.hh
sc_core::sc_object::name
const char * name() const
Definition: sc_object.cc:44
sc_gem5::Process::decref
void decref()
Definition: process.hh:99
object.hh
sc_gem5::Process::suspended
bool suspended() const
Definition: process.hh:78
sc_gem5::Process::injectException
void injectException(ExceptionWrapperBase &exc)
Definition: process.cc:216
sc_gem5::Reset::_process
Process * _process
Definition: process.hh:234
sc_gem5::Process::isUnwinding
bool isUnwinding() const
Definition: process.hh:69
sc_gem5::Process::_resetEvent
InternalScEvent _resetEvent
Definition: process.hh:160
sc_gem5::Process::terminatedEvent
::sc_core::sc_event & terminatedEvent()
Definition: process.hh:102
sc_gem5::Process::asyncResetCount
int asyncResetCount
Definition: process.hh:187
sc_gem5::Process::resume
void resume(bool inc_kids)
Definition: process.cc:98
sc_gem5::Process::procKind
virtual ::sc_core::sc_curr_proc_kind procKind() const =0
sc_gem5
Definition: sc_clock.cc:41
sc_gem5::Process::stackSize
size_t stackSize
Definition: process.hh:193
sc_gem5::Process::setDynamic
void setDynamic(DynamicSensitivity *)
Definition: process.cc:288
sc_gem5::Process::_timedOut
bool _timedOut
Definition: process.hh:168
sc_gem5::Process::_terminated
bool _terminated
Definition: process.hh:175
sc_gem5::Process::_isUnwinding
bool _isUnwinding
Definition: process.hh:174
sc_gem5::Process::joinWaiters
std::vector<::sc_core::sc_join * > joinWaiters
Definition: process.hh:201
sc_gem5::Process::needsStart
bool needsStart() const
Definition: process.hh:66
sc_gem5::Process::setStackSize
void setStackSize(size_t size)
Definition: process.hh:104
sc_gem5::Process::clearDynamic
void clearDynamic()
Definition: process.hh:110
sc_gem5::Process::kill
void kill(bool inc_kids)
Definition: process.cc:141
sc_gem5::Reset::_value
bool _value
Definition: process.hh:237
fiber.hh
sc_gem5::Process::waitCount
void waitCount(int count)
Definition: process.hh:138
sc_gem5::Process::~Process
virtual ~Process()
Definition: process.hh:149
sc_gem5::ScEvent
Definition: sched_event.hh:43
sc_gem5::Process::ready
void ready()
Definition: process.cc:355
sc_gem5::Process::func
ProcessFuncWrapper * func
Definition: process.hh:163
sc_gem5::Process::fiber
virtual gem5::Fiber * fiber()
Definition: process.hh:121
sc_gem5::Sensitivity
Definition: sensitivity.hh:62
sc_gem5::Reset::process
Process * process()
Definition: process.hh:228
sc_core::sc_curr_proc_kind
sc_curr_proc_kind
Definition: sc_process_handle.hh:84

Generated on Tue Sep 21 2021 12:24:36 for gem5 by doxygen 1.8.17