gem5  v20.0.0.2
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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:
65  virtual ::sc_core::sc_curr_proc_kind procKind() const = 0;
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 
90  void injectException(ExceptionWrapperBase &exc);
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 
101  ::sc_core::sc_event &resetEvent() { return _resetEvent; }
102  ::sc_core::sc_event &terminatedEvent() { return _terminatedEvent; }
103 
104  void setStackSize(size_t size) { stackSize = size; }
105 
106  void run();
107 
108  void addStatic(StaticSensitivity *);
109  void setDynamic(DynamicSensitivity *);
110  void clearDynamic() { setDynamic(nullptr); }
111  void addReset(Reset *);
112 
114  void setTimeout(::sc_core::sc_time t);
115  void cancelTimeout();
116 
117  void satisfySensitivity(Sensitivity *);
118 
119  void ready();
120 
121  virtual Fiber *fiber() { return Fiber::primaryFiber(); }
122 
123  static Process *newest() { return _newest; }
124 
125  void lastReport(::sc_core::sc_report *report);
126  ::sc_core::sc_report *lastReport() const;
127 
128  bool hasStaticSensitivities() { return !staticSensitivities.empty(); }
129  bool internal() { return _internal; }
130  bool timedOut() { return _timedOut; }
131  bool inReset() { return _syncReset || syncResetCount || asyncResetCount; }
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  }
226  void update() { _process->signalReset(_signal->read() == _value, _sync); }
227 
228  Process *process() { return _process; }
229  const sc_core::sc_signal_in_if<bool> *signal() { return _signal; }
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__
void needsStart(bool ns)
Definition: process.hh:67
count
Definition: misc.hh:703
std::unique_ptr<::sc_core::sc_report > _lastReport
Definition: process.hh:199
Bitfield< 28 > v
const std::string & name()
Definition: trace.cc:50
void waitCount(int count)
Definition: process.hh:138
InternalScEvent _resetEvent
Definition: process.hh:160
bool timedOut()
Definition: process.hh:130
std::vector<::sc_core::sc_join * > joinWaiters
Definition: process.hh:201
bool value()
Definition: process.hh:231
Reset(Process *p, bool s, bool v)
Definition: process.hh:209
size_t stackSize
Definition: process.hh:193
void reset()
Definition: statistics.cc:569
Process * process()
Definition: process.hh:228
void dontInitialize(bool di)
Definition: process.hh:134
static Process * newest()
Definition: process.hh:123
void decref()
Definition: process.hh:99
static Fiber * primaryFiber()
Get a pointer to the primary Fiber.
Definition: fiber.cc:182
bool disabled() const
Definition: process.hh:79
bool dontInitialize()
Definition: process.hh:133
void newReset(const sc_core::sc_port_base *pb, Process *p, bool s, bool v)
Definition: process.cc:425
DynamicSensitivity * dynamicSensitivity
Definition: process.hh:196
STL vector class.
Definition: stl.hh:37
Bitfield< 0 > ns
Bitfield< 11 > enable
Definition: misc.hh:1051
const sc_core::sc_signal_in_if< bool > * _signal
Definition: process.hh:235
Bitfield< 4 > s
UniqueNameGen nameGen
Definition: process.hh:203
void setStackSize(size_t size)
Definition: process.hh:104
bool hasStaticSensitivities()
Definition: process.hh:128
ProcessFuncWrapper * func
Definition: process.hh:163
bool isUnwinding() const
Definition: process.hh:69
const sc_core::sc_signal_in_if< bool > * signal()
Definition: process.hh:229
void update()
Definition: process.hh:226
InternalScEvent _terminatedEvent
Definition: process.hh:161
Process * _process
Definition: process.hh:234
bool _suspendedReady
Definition: process.hh:181
::sc_core::sc_event & resetEvent()
Definition: process.hh:101
std::vector< Reset * > resets
Definition: process.hh:197
ScEvent timeoutEvent
Definition: process.hh:113
::sc_core::sc_event & terminatedEvent()
Definition: process.hh:102
ExceptionWrapperBase * excWrapper
Definition: process.hh:91
void clearDynamic()
Definition: process.hh:110
const char * uniqueName(const char *seed)
Definition: process.hh:140
This class represents a fiber, which is a light weight sort of thread which is cooperatively schedule...
Definition: fiber.hh:62
void isUnwinding(bool v)
Definition: process.hh:70
virtual Fiber * fiber()
Definition: process.hh:121
bool terminated() const
Definition: process.hh:71
bool needsStart() const
Definition: process.hh:66
bool dynamic() const
Definition: process.hh:68
StaticSensitivities staticSensitivities
Definition: process.hh:195
bool scheduled() const
Definition: process.hh:73
virtual ~Process()
Definition: process.hh:149
void joinWait(::sc_core::sc_join *join)
Definition: process.hh:136
static Process * _newest
Definition: process.hh:147
void scheduled(bool new_val)
Definition: process.hh:74
Bitfield< 5 > t
bool sync()
Definition: process.hh:230
Bitfield< 0 > p
void incref()
Definition: process.hh:98
bool install(const sc_core::sc_signal_in_if< bool > *s)
Definition: process.hh:214
bool _dontInitialize
Definition: process.hh:170
bool suspended() const
Definition: process.hh:78
bool inReset()
Definition: process.hh:131
void disable()
Definition: trace.cc:98

Generated on Mon Jun 8 2020 15:34:39 for gem5 by doxygen 1.8.13