process.hh (12953:ddfd5e4643a9) process.hh (12957:e54f9890363d)
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

--- 17 unchanged lines hidden (view full) ---

26 *
27 * Authors: Gabe Black
28 */
29
30#ifndef __SYSTEMC_CORE_PROCESS_HH__
31#define __SYSTEMC_CORE_PROCESS_HH__
32
33#include <functional>
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

--- 17 unchanged lines hidden (view full) ---

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 <vector>
34
35#include "base/fiber.hh"
35
36#include "base/fiber.hh"
37#include "sim/eventq.hh"
38#include "systemc/core/bindinfo.hh"
36#include "systemc/core/list.hh"
37#include "systemc/core/object.hh"
38#include "systemc/ext/core/sc_event.hh"
39#include "systemc/core/list.hh"
40#include "systemc/core/object.hh"
41#include "systemc/ext/core/sc_event.hh"
42#include "systemc/ext/core/sc_interface.hh"
39#include "systemc/ext/core/sc_module.hh"
43#include "systemc/ext/core/sc_module.hh"
44#include "systemc/ext/core/sc_port.hh"
40#include "systemc/ext/core/sc_process_handle.hh"
41
42namespace sc_gem5
43{
44
45#include "systemc/ext/core/sc_process_handle.hh"
46
47namespace sc_gem5
48{
49
50class Sensitivity
51{
52 protected:
53 Process *process;
54 void satisfy();
55
56 public:
57 Sensitivity(Process *p) : process(p) {}
58 virtual ~Sensitivity() {}
59
60 virtual void notifyWork(Event *e) { satisfy(); }
61 void notify(Event *e);
62 void notify() { notify(nullptr); }
63
64 const std::string name();
65};
66
67class SensitivityTimeout : virtual public Sensitivity
68{
69 private:
70 EventWrapper<Sensitivity, &Sensitivity::notify> timeoutEvent;
71 ::sc_core::sc_time timeout;
72
73 public:
74 SensitivityTimeout(Process *p, ::sc_core::sc_time t);
75 ~SensitivityTimeout();
76};
77
78class SensitivityEvent : virtual public Sensitivity
79{
80 private:
81 const ::sc_core::sc_event *event;
82
83 public:
84 SensitivityEvent(Process *p, const ::sc_core::sc_event *e);
85 ~SensitivityEvent();
86};
87
88//XXX This sensitivity can't be reused. To reset it, it has to be deleted and
89//recreated. That works for dynamic sensitivities, but not for static.
90//Fortunately processes can't be statically sensitive to sc_event_and_lists.
91class SensitivityEventAndList : virtual public Sensitivity
92{
93 private:
94 const ::sc_core::sc_event_and_list *list;
95 int count;
96
97 public:
98 SensitivityEventAndList(
99 Process *p, const ::sc_core::sc_event_and_list *list);
100 ~SensitivityEventAndList();
101
102 virtual void notifyWork(Event *e) override;
103};
104
105class SensitivityEventOrList : virtual public Sensitivity
106{
107 private:
108 const ::sc_core::sc_event_or_list *list;
109
110 public:
111 SensitivityEventOrList(
112 Process *p, const ::sc_core::sc_event_or_list *list);
113 ~SensitivityEventOrList();
114};
115
116// Combined sensitivities. These trigger when any of their parts do.
117
118class SensitivityTimeoutAndEvent :
119 public SensitivityTimeout, public SensitivityEvent
120{
121 public:
122 SensitivityTimeoutAndEvent(
123 Process *p, ::sc_core::sc_time t, const ::sc_core::sc_event *e) :
124 Sensitivity(p), SensitivityTimeout(p, t), SensitivityEvent(p, e)
125 {}
126};
127
128class SensitivityTimeoutAndEventAndList :
129 public SensitivityTimeout, public SensitivityEventAndList
130{
131 public:
132 SensitivityTimeoutAndEventAndList(
133 Process *p, ::sc_core::sc_time t,
134 const ::sc_core::sc_event_and_list *eal) :
135 Sensitivity(p), SensitivityTimeout(p, t),
136 SensitivityEventAndList(p, eal)
137 {}
138};
139
140class SensitivityTimeoutAndEventOrList :
141 public SensitivityTimeout, public SensitivityEventOrList
142{
143 public:
144 SensitivityTimeoutAndEventOrList(
145 Process *p, ::sc_core::sc_time t,
146 const ::sc_core::sc_event_or_list *eol) :
147 Sensitivity(p), SensitivityTimeout(p, t),
148 SensitivityEventOrList(p, eol)
149 {}
150};
151
152typedef std::vector<Sensitivity *> Sensitivities;
153
154
155/*
156 * Pending sensitivities. These are records of sensitivities to install later,
157 * once all the information to configure them is available.
158 */
159
160class PendingSensitivity
161{
162 protected:
163 Process *process;
164
165 public:
166 virtual void finalize(Sensitivities &s) = 0;
167 PendingSensitivity(Process *p) : process(p) {}
168 virtual ~PendingSensitivity() {}
169};
170
171class PendingSensitivityEvent : public PendingSensitivity
172{
173 private:
174 const sc_core::sc_event *event;
175
176 public:
177 PendingSensitivityEvent(Process *p, const sc_core::sc_event *e) :
178 PendingSensitivity(p), event(e) {}
179
180 void
181 finalize(Sensitivities &s) override
182 {
183 s.push_back(new SensitivityEvent(process, event));
184 }
185};
186
187class PendingSensitivityInterface : public PendingSensitivity
188{
189 private:
190 const sc_core::sc_interface *interface;
191
192 public:
193 PendingSensitivityInterface(Process *p, const sc_core::sc_interface *i) :
194 PendingSensitivity(p), interface(i)
195 {}
196
197 void
198 finalize(Sensitivities &s) override
199 {
200 s.push_back(new SensitivityEvent(process,
201 &interface->default_event()));
202 }
203};
204
205class PendingSensitivityPort : public PendingSensitivity
206{
207 private:
208 const sc_core::sc_port_base *port;
209
210 public:
211 PendingSensitivityPort(Process *p, const sc_core::sc_port_base *pb) :
212 PendingSensitivity(p), port(pb)
213 {}
214
215 void
216 finalize(Sensitivities &s) override
217 {
218 for (int i = 0; i < port->size(); i++) {
219 const ::sc_core::sc_event *e =
220 &port->_gem5BindInfo[i]->interface->default_event();
221 s.push_back(new SensitivityEvent(process, e));
222 }
223 }
224};
225
226class PendingSensitivityFinder : public PendingSensitivity
227{
228 private:
229 const sc_core::sc_event_finder *finder;
230
231 public:
232 PendingSensitivityFinder(Process *p, const sc_core::sc_event_finder *f) :
233 PendingSensitivity(p), finder(f)
234 {}
235
236 void
237 finalize(Sensitivities &s) override
238 {
239 s.push_back(new SensitivityEvent(process, &finder->find_event()));
240 }
241};
242
243typedef std::vector<PendingSensitivity *> PendingSensitivities;
244
245
45class Process : public ::sc_core::sc_object, public ListNode
46{
47 public:
48 virtual ::sc_core::sc_curr_proc_kind procKind() const = 0;
49 bool running() const { return _running; }
50 bool dynamic() const { return _dynamic; }
51 bool isUnwinding() const { return _isUnwinding; }
52 bool terminated() const { return _terminated; }

--- 20 unchanged lines hidden (view full) ---

73
74 void incref() { refCount++; }
75 void decref() { refCount--; }
76
77 const ::sc_core::sc_event &resetEvent() { return _resetEvent; }
78 const ::sc_core::sc_event &terminatedEvent() { return _terminatedEvent; }
79
80 // This should only be called before initialization.
246class Process : public ::sc_core::sc_object, public ListNode
247{
248 public:
249 virtual ::sc_core::sc_curr_proc_kind procKind() const = 0;
250 bool running() const { return _running; }
251 bool dynamic() const { return _dynamic; }
252 bool isUnwinding() const { return _isUnwinding; }
253 bool terminated() const { return _terminated; }

--- 20 unchanged lines hidden (view full) ---

274
275 void incref() { refCount++; }
276 void decref() { refCount--; }
277
278 const ::sc_core::sc_event &resetEvent() { return _resetEvent; }
279 const ::sc_core::sc_event &terminatedEvent() { return _terminatedEvent; }
280
281 // This should only be called before initialization.
81 void dontInitialize() { popListNode(); }
282 void dontInitialize();
82
83 void setStackSize(size_t size) { stackSize = size; }
84
283
284 void setStackSize(size_t size) { stackSize = size; }
285
286 void finalize();
287
85 void run();
86
288 void run();
289
290 void addStatic(PendingSensitivity *);
291 void setDynamic(Sensitivity *);
292
87 virtual Fiber *fiber() { return Fiber::primaryFiber(); }
88
89 static Process *newest() { return _newest; }
90
91 protected:
92 Process(const char *name, ProcessFuncWrapper *func, bool _dynamic);
93
94 static Process *_newest;
95
293 virtual Fiber *fiber() { return Fiber::primaryFiber(); }
294
295 static Process *newest() { return _newest; }
296
297 protected:
298 Process(const char *name, ProcessFuncWrapper *func, bool _dynamic);
299
300 static Process *_newest;
301
96 virtual ~Process() { delete func; }
302 virtual ~Process()
303 {
304 delete func;
305 for (auto s: staticSensitivities)
306 delete s;
307 }
97
98 ::sc_core::sc_event _resetEvent;
99 ::sc_core::sc_event _terminatedEvent;
100
101 ProcessFuncWrapper *func;
102 sc_core::sc_curr_proc_kind _procKind;
103 bool _running;
104 bool _dynamic;
105 bool _isUnwinding;
106 bool _terminated;
107
108 bool _suspended;
109 bool _disabled;
110
111 bool _syncReset;
112
113 int refCount;
114
115 size_t stackSize;
308
309 ::sc_core::sc_event _resetEvent;
310 ::sc_core::sc_event _terminatedEvent;
311
312 ProcessFuncWrapper *func;
313 sc_core::sc_curr_proc_kind _procKind;
314 bool _running;
315 bool _dynamic;
316 bool _isUnwinding;
317 bool _terminated;
318
319 bool _suspended;
320 bool _disabled;
321
322 bool _syncReset;
323
324 int refCount;
325
326 size_t stackSize;
327
328 Sensitivities staticSensitivities;
329 PendingSensitivities pendingStaticSensitivities;
330
331 Sensitivity *dynamicSensitivity;
116};
117
332};
333
334inline void
335Sensitivity::notify(Event *e)
336{
337 if (!process->disabled())
338 notifyWork(e);
339}
340
341inline const std::string
342Sensitivity::name()
343{
344 return std::string(process->name()) + ".timeout";
345}
346
118} // namespace sc_gem5
119
120#endif //__SYSTEMC_CORE_PROCESS_HH__
347} // namespace sc_gem5
348
349#endif //__SYSTEMC_CORE_PROCESS_HH__