process.hh (13308:30e825b4fd46) process.hh (13328:d5f4e801436a)
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"
41#include "systemc/core/sched_event.hh"
42#include "systemc/core/sensitivity.hh"
43#include "systemc/ext/channel/sc_signal_in_if.hh"
44#include "systemc/ext/core/sc_event.hh"
45#include "systemc/ext/core/sc_module.hh"
46#include "systemc/ext/core/sc_process_handle.hh"
47
48namespace sc_core
49{
50
51class sc_join;
52
53} // namespace sc_core
54
55namespace sc_gem5
56{
57
58class ScHalt
59{};
60
61class Process;
62class Reset;
63
64class Process : public ::sc_core::sc_process_b, public ListNode
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
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"
41#include "systemc/core/sched_event.hh"
42#include "systemc/core/sensitivity.hh"
43#include "systemc/ext/channel/sc_signal_in_if.hh"
44#include "systemc/ext/core/sc_event.hh"
45#include "systemc/ext/core/sc_module.hh"
46#include "systemc/ext/core/sc_process_handle.hh"
47
48namespace sc_core
49{
50
51class sc_join;
52
53} // namespace sc_core
54
55namespace sc_gem5
56{
57
58class ScHalt
59{};
60
61class Process;
62class Reset;
63
64class Process : public ::sc_core::sc_process_b, public ListNode
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
75 void forEachKid(const std::function<void(Process *)> &work);
76
77 bool suspended() const { return _suspended; }
78 bool disabled() const { return _disabled; }
79
80 void suspend(bool inc_kids);
81 void resume(bool inc_kids);
82 void disable(bool inc_kids);
83 void enable(bool inc_kids);
84
85 void kill(bool inc_kids);
86 void reset(bool inc_kids);
87 void throw_it(ExceptionWrapperBase &exc, bool inc_kids);
88
89 void injectException(ExceptionWrapperBase &exc);
90 ExceptionWrapperBase *excWrapper;
91
92 void syncResetOn(bool inc_kids);
93 void syncResetOff(bool inc_kids);
94
95 void signalReset(bool set, bool sync);
96
97 void incref() { refCount++; }
98 void decref() { refCount--; }
99
100 ::sc_core::sc_event &resetEvent() { return _resetEvent; }
101 ::sc_core::sc_event &terminatedEvent() { return _terminatedEvent; }
102
103 void setStackSize(size_t size) { stackSize = size; }
104
105 void run();
106
107 void addStatic(StaticSensitivity *);
108 void setDynamic(DynamicSensitivity *);
109 void clearDynamic() { setDynamic(nullptr); }
110 void addReset(Reset *);
111
112 ScEvent timeoutEvent;
113 void setTimeout(::sc_core::sc_time t);
114 void cancelTimeout();
115
116 void satisfySensitivity(Sensitivity *);
117
118 void ready();
119
120 virtual Fiber *fiber() { return Fiber::primaryFiber(); }
121
122 static Process *newest() { return _newest; }
123
124 void lastReport(::sc_core::sc_report *report);
125 ::sc_core::sc_report *lastReport() const;
126
127 bool hasStaticSensitivities() { return !staticSensitivities.empty(); }
128 bool internal() { return _internal; }
129 bool timedOut() { return _timedOut; }
130 bool inReset() { return _syncReset || syncResetCount || asyncResetCount; }
131
132 bool dontInitialize() { return _dontInitialize; }
133 void dontInitialize(bool di) { _dontInitialize = di; }
134
135 void joinWait(::sc_core::sc_join *join) { joinWaiters.push_back(join); }
136
137 void waitCount(int count) { _waitCount = count; }
138
139 const char *uniqueName(const char *seed) { return nameGen.gen(seed); }
140
141 protected:
142 void timeout();
143
144 Process(const char *name, ProcessFuncWrapper *func, bool internal=false);
145
146 static Process *_newest;
147
148 virtual ~Process()
149 {
150 popListNode();
151 delete func;
152 for (auto s: staticSensitivities) {
153 s->clear();
154 delete s;
155 }
156 clearDynamic();
157 }
158
159 InternalScEvent _resetEvent;
160 InternalScEvent _terminatedEvent;
161
162 ProcessFuncWrapper *func;
163
164 bool _internal;
165
166 // Needed to support the deprecated "timed_out" function.
167 bool _timedOut;
168
169 bool _dontInitialize;
170
171 bool _needsStart;
172 bool _dynamic;
173 bool _isUnwinding;
174 bool _terminated;
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);
93 ExceptionWrapperBase *excWrapper;
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
115 ScEvent timeoutEvent;
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
162 InternalScEvent _resetEvent;
163 InternalScEvent _terminatedEvent;
164
165 ProcessFuncWrapper *func;
166
167 bool _internal;
168
169 // Needed to support the deprecated "timed_out" function.
170 bool _timedOut;
171
172 bool _dontInitialize;
173
174 bool _needsStart;
175 bool _dynamic;
176 bool _isUnwinding;
177 bool _terminated;
178 bool _scheduled;
175
176 void terminate();
177
178 bool _suspended;
179 bool _suspendedReady;
180 bool _disabled;
181
182 bool _syncReset;
183
184 int syncResetCount;
185 int asyncResetCount;
186
187 int _waitCount;
188
189 int refCount;
190
191 size_t stackSize;
192
193 StaticSensitivities staticSensitivities;
194 DynamicSensitivity *dynamicSensitivity;
195 std::vector<Reset *> resets;
196
197 std::unique_ptr<::sc_core::sc_report> _lastReport;
198
199 std::vector<::sc_core::sc_join *> joinWaiters;
200
201 UniqueNameGen nameGen;
202};
203
204class Reset
205{
206 public:
207 Reset(Process *p, bool s, bool v) :
208 _process(p), _signal(nullptr), _sync(s), _value(v)
209 {}
210
211 bool
212 install(const sc_core::sc_signal_in_if<bool> *s)
213 {
214 _signal = s;
215
216 if (_signal->_addReset(this)) {
217 _process->addReset(this);
218 if (_signal->read() == _value)
219 update();
220 return true;
221 }
222 return false;
223 }
224 void update() { _process->signalReset(_signal->read() == _value, _sync); }
225
226 Process *process() { return _process; }
227 const sc_core::sc_signal_in_if<bool> *signal() { return _signal; }
228 bool sync() { return _sync; }
229 bool value() { return _value; }
230
231 private:
232 Process *_process;
233 const sc_core::sc_signal_in_if<bool> *_signal;
234 bool _sync;
235 bool _value;
236};
237
238void newReset(const sc_core::sc_port_base *pb, Process *p, bool s, bool v);
239void newReset(const sc_core::sc_signal_in_if<bool> *sig, Process *p,
240 bool s, bool v);
241
242} // namespace sc_gem5
243
244#endif //__SYSTEMC_CORE_PROCESS_HH__
179
180 void terminate();
181
182 bool _suspended;
183 bool _suspendedReady;
184 bool _disabled;
185
186 bool _syncReset;
187
188 int syncResetCount;
189 int asyncResetCount;
190
191 int _waitCount;
192
193 int refCount;
194
195 size_t stackSize;
196
197 StaticSensitivities staticSensitivities;
198 DynamicSensitivity *dynamicSensitivity;
199 std::vector<Reset *> resets;
200
201 std::unique_ptr<::sc_core::sc_report> _lastReport;
202
203 std::vector<::sc_core::sc_join *> joinWaiters;
204
205 UniqueNameGen nameGen;
206};
207
208class 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
216 install(const sc_core::sc_signal_in_if<bool> *s)
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:
236 Process *_process;
237 const sc_core::sc_signal_in_if<bool> *_signal;
238 bool _sync;
239 bool _value;
240};
241
242void newReset(const sc_core::sc_port_base *pb, Process *p, bool s, bool v);
243void newReset(const sc_core::sc_signal_in_if<bool> *sig, Process *p,
244 bool s, bool v);
245
246} // namespace sc_gem5
247
248#endif //__SYSTEMC_CORE_PROCESS_HH__