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 <vector> 35 36#include "base/fiber.hh" 37#include "sim/eventq.hh" 38#include "systemc/core/bindinfo.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" 43#include "systemc/ext/core/sc_module.hh" 44#include "systemc/ext/core/sc_port.hh" 45#include "systemc/ext/core/sc_process_handle.hh" 46 47namespace sc_gem5 48{ 49 50class Sensitivity 51{ 52 protected: 53 Process *process;
| 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 <vector> 35 36#include "base/fiber.hh" 37#include "sim/eventq.hh" 38#include "systemc/core/bindinfo.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" 43#include "systemc/ext/core/sc_module.hh" 44#include "systemc/ext/core/sc_port.hh" 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
| 54 55 public: 56 Sensitivity(Process *p) : process(p) {} 57 virtual ~Sensitivity() {} 58
|
60 virtual void notifyWork(Event *e) { satisfy(); }
| 59 virtual void notifyWork(Event *e);
|
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 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; } 254 255 void forEachKid(const std::function<void(Process *)> &work); 256 257 bool suspended() const { return _suspended; } 258 bool disabled() const { return _disabled; } 259 260 void suspend(bool inc_kids); 261 void resume(bool inc_kids); 262 void disable(bool inc_kids); 263 void enable(bool inc_kids); 264 265 void kill(bool inc_kids); 266 void reset(bool inc_kids); 267 virtual void throw_it(ExceptionWrapperBase &exc, bool inc_kids); 268 269 void injectException(ExceptionWrapperBase &exc); 270 ExceptionWrapperBase *excWrapper; 271 272 void syncResetOn(bool inc_kids); 273 void syncResetOff(bool inc_kids); 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. 282 void dontInitialize(); 283 284 void setStackSize(size_t size) { stackSize = size; } 285 286 void finalize(); 287 288 void run(); 289 290 void addStatic(PendingSensitivity *); 291 void setDynamic(Sensitivity *); 292
| 60 void notify(Event *e); 61 void notify() { notify(nullptr); } 62 63 const std::string name(); 64}; 65 66class SensitivityTimeout : virtual public Sensitivity 67{ 68 private: 69 EventWrapper<Sensitivity, &Sensitivity::notify> timeoutEvent; 70 ::sc_core::sc_time timeout; 71 72 public: 73 SensitivityTimeout(Process *p, ::sc_core::sc_time t); 74 ~SensitivityTimeout(); 75}; 76 77class SensitivityEvent : virtual public Sensitivity 78{ 79 private: 80 const ::sc_core::sc_event *event; 81 82 public: 83 SensitivityEvent(Process *p, const ::sc_core::sc_event *e); 84 ~SensitivityEvent(); 85}; 86 87//XXX This sensitivity can't be reused. To reset it, it has to be deleted and 88//recreated. That works for dynamic sensitivities, but not for static. 89//Fortunately processes can't be statically sensitive to sc_event_and_lists. 90class SensitivityEventAndList : virtual public Sensitivity 91{ 92 private: 93 const ::sc_core::sc_event_and_list *list; 94 int count; 95 96 public: 97 SensitivityEventAndList( 98 Process *p, const ::sc_core::sc_event_and_list *list); 99 ~SensitivityEventAndList(); 100 101 virtual void notifyWork(Event *e) override; 102}; 103 104class SensitivityEventOrList : virtual public Sensitivity 105{ 106 private: 107 const ::sc_core::sc_event_or_list *list; 108 109 public: 110 SensitivityEventOrList( 111 Process *p, const ::sc_core::sc_event_or_list *list); 112 ~SensitivityEventOrList(); 113}; 114 115// Combined sensitivities. These trigger when any of their parts do. 116 117class SensitivityTimeoutAndEvent : 118 public SensitivityTimeout, public SensitivityEvent 119{ 120 public: 121 SensitivityTimeoutAndEvent( 122 Process *p, ::sc_core::sc_time t, const ::sc_core::sc_event *e) : 123 Sensitivity(p), SensitivityTimeout(p, t), SensitivityEvent(p, e) 124 {} 125}; 126 127class SensitivityTimeoutAndEventAndList : 128 public SensitivityTimeout, public SensitivityEventAndList 129{ 130 public: 131 SensitivityTimeoutAndEventAndList( 132 Process *p, ::sc_core::sc_time t, 133 const ::sc_core::sc_event_and_list *eal) : 134 Sensitivity(p), SensitivityTimeout(p, t), 135 SensitivityEventAndList(p, eal) 136 {} 137}; 138 139class SensitivityTimeoutAndEventOrList : 140 public SensitivityTimeout, public SensitivityEventOrList 141{ 142 public: 143 SensitivityTimeoutAndEventOrList( 144 Process *p, ::sc_core::sc_time t, 145 const ::sc_core::sc_event_or_list *eol) : 146 Sensitivity(p), SensitivityTimeout(p, t), 147 SensitivityEventOrList(p, eol) 148 {} 149}; 150 151typedef std::vector<Sensitivity *> Sensitivities; 152 153 154/* 155 * Pending sensitivities. These are records of sensitivities to install later, 156 * once all the information to configure them is available. 157 */ 158 159class PendingSensitivity 160{ 161 protected: 162 Process *process; 163 164 public: 165 virtual void finalize(Sensitivities &s) = 0; 166 PendingSensitivity(Process *p) : process(p) {} 167 virtual ~PendingSensitivity() {} 168}; 169 170class PendingSensitivityEvent : public PendingSensitivity 171{ 172 private: 173 const sc_core::sc_event *event; 174 175 public: 176 PendingSensitivityEvent(Process *p, const sc_core::sc_event *e) : 177 PendingSensitivity(p), event(e) {} 178 179 void 180 finalize(Sensitivities &s) override 181 { 182 s.push_back(new SensitivityEvent(process, event)); 183 } 184}; 185 186class PendingSensitivityInterface : public PendingSensitivity 187{ 188 private: 189 const sc_core::sc_interface *interface; 190 191 public: 192 PendingSensitivityInterface(Process *p, const sc_core::sc_interface *i) : 193 PendingSensitivity(p), interface(i) 194 {} 195 196 void 197 finalize(Sensitivities &s) override 198 { 199 s.push_back(new SensitivityEvent(process, 200 &interface->default_event())); 201 } 202}; 203 204class PendingSensitivityPort : public PendingSensitivity 205{ 206 private: 207 const sc_core::sc_port_base *port; 208 209 public: 210 PendingSensitivityPort(Process *p, const sc_core::sc_port_base *pb) : 211 PendingSensitivity(p), port(pb) 212 {} 213 214 void 215 finalize(Sensitivities &s) override 216 { 217 for (int i = 0; i < port->size(); i++) { 218 const ::sc_core::sc_event *e = 219 &port->_gem5BindInfo[i]->interface->default_event(); 220 s.push_back(new SensitivityEvent(process, e)); 221 } 222 } 223}; 224 225class PendingSensitivityFinder : public PendingSensitivity 226{ 227 private: 228 const sc_core::sc_event_finder *finder; 229 230 public: 231 PendingSensitivityFinder(Process *p, const sc_core::sc_event_finder *f) : 232 PendingSensitivity(p), finder(f) 233 {} 234 235 void 236 finalize(Sensitivities &s) override 237 { 238 s.push_back(new SensitivityEvent(process, &finder->find_event())); 239 } 240}; 241 242typedef std::vector<PendingSensitivity *> PendingSensitivities; 243 244 245class Process : public ::sc_core::sc_object, public ListNode 246{ 247 public: 248 virtual ::sc_core::sc_curr_proc_kind procKind() const = 0; 249 bool running() const { return _running; } 250 bool dynamic() const { return _dynamic; } 251 bool isUnwinding() const { return _isUnwinding; } 252 bool terminated() const { return _terminated; } 253 254 void forEachKid(const std::function<void(Process *)> &work); 255 256 bool suspended() const { return _suspended; } 257 bool disabled() const { return _disabled; } 258 259 void suspend(bool inc_kids); 260 void resume(bool inc_kids); 261 void disable(bool inc_kids); 262 void enable(bool inc_kids); 263 264 void kill(bool inc_kids); 265 void reset(bool inc_kids); 266 virtual void throw_it(ExceptionWrapperBase &exc, bool inc_kids); 267 268 void injectException(ExceptionWrapperBase &exc); 269 ExceptionWrapperBase *excWrapper; 270 271 void syncResetOn(bool inc_kids); 272 void syncResetOff(bool inc_kids); 273 274 void incref() { refCount++; } 275 void decref() { refCount--; } 276 277 const ::sc_core::sc_event &resetEvent() { return _resetEvent; } 278 const ::sc_core::sc_event &terminatedEvent() { return _terminatedEvent; } 279 280 // This should only be called before initialization. 281 void dontInitialize(); 282 283 void setStackSize(size_t size) { stackSize = size; } 284 285 void finalize(); 286 287 void run(); 288 289 void addStatic(PendingSensitivity *); 290 void setDynamic(Sensitivity *); 291
|
| 292 void satisfySensitivity(Sensitivity *); 293 294 void ready(); 295
|
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 302 virtual ~Process() 303 { 304 delete func; 305 for (auto s: staticSensitivities) 306 delete s; 307 } 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;
| 296 virtual Fiber *fiber() { return Fiber::primaryFiber(); } 297 298 static Process *newest() { return _newest; } 299 300 protected: 301 Process(const char *name, ProcessFuncWrapper *func, bool _dynamic); 302 303 static Process *_newest; 304 305 virtual ~Process() 306 { 307 delete func; 308 for (auto s: staticSensitivities) 309 delete s; 310 } 311 312 ::sc_core::sc_event _resetEvent; 313 ::sc_core::sc_event _terminatedEvent; 314 315 ProcessFuncWrapper *func; 316 sc_core::sc_curr_proc_kind _procKind; 317 bool _running; 318 bool _dynamic; 319 bool _isUnwinding; 320 bool _terminated; 321 322 bool _suspended;
|
| 323 bool _suspendedReady;
|
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; 332}; 333 334inline void
| 324 bool _disabled; 325 326 bool _syncReset; 327 328 int refCount; 329 330 size_t stackSize; 331 332 Sensitivities staticSensitivities; 333 PendingSensitivities pendingStaticSensitivities; 334 335 Sensitivity *dynamicSensitivity; 336}; 337 338inline void
|
| 339Sensitivity::notifyWork(Event *e) 340{ 341 process->satisfySensitivity(this); 342} 343 344inline 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 347} // namespace sc_gem5 348 349#endif //__SYSTEMC_CORE_PROCESS_HH__
| 345Sensitivity::notify(Event *e) 346{ 347 if (!process->disabled()) 348 notifyWork(e); 349} 350 351inline const std::string 352Sensitivity::name() 353{ 354 return std::string(process->name()) + ".timeout"; 355} 356 357} // namespace sc_gem5 358 359#endif //__SYSTEMC_CORE_PROCESS_HH__
|