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

Generated on Fri Feb 28 2020 16:26:56 for gem5 by doxygen 1.8.13