process.hh revision 13308:30e825b4fd46
112841Sgabeblack@google.com/* 212841Sgabeblack@google.com * Copyright 2018 Google, Inc. 312841Sgabeblack@google.com * 412841Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 512841Sgabeblack@google.com * modification, are permitted provided that the following conditions are 612841Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 712841Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 812841Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 912841Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1012841Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1112841Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1212841Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1312841Sgabeblack@google.com * this software without specific prior written permission. 1412841Sgabeblack@google.com * 1512841Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1612841Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1712841Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1812841Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1912841Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2012841Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2112841Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2212841Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2312841Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2412841Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2512841Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2612841Sgabeblack@google.com * 2712841Sgabeblack@google.com * Authors: Gabe Black 2812841Sgabeblack@google.com */ 2912841Sgabeblack@google.com 3012841Sgabeblack@google.com#ifndef __SYSTEMC_CORE_PROCESS_HH__ 3112841Sgabeblack@google.com#define __SYSTEMC_CORE_PROCESS_HH__ 3212841Sgabeblack@google.com 3313123Sgabeblack@google.com#include <functional> 3413123Sgabeblack@google.com#include <memory> 3512841Sgabeblack@google.com#include <vector> 3612841Sgabeblack@google.com 3712841Sgabeblack@google.com#include "base/fiber.hh" 3812841Sgabeblack@google.com#include "systemc/core/list.hh" 3912841Sgabeblack@google.com#include "systemc/core/module.hh" 4012841Sgabeblack@google.com#include "systemc/core/object.hh" 4112841Sgabeblack@google.com#include "systemc/core/sched_event.hh" 4212841Sgabeblack@google.com#include "systemc/core/sensitivity.hh" 4312841Sgabeblack@google.com#include "systemc/ext/channel/sc_signal_in_if.hh" 4412841Sgabeblack@google.com#include "systemc/ext/core/sc_event.hh" 4512841Sgabeblack@google.com#include "systemc/ext/core/sc_module.hh" 4612841Sgabeblack@google.com#include "systemc/ext/core/sc_process_handle.hh" 4712841Sgabeblack@google.com 4812841Sgabeblack@google.comnamespace sc_core 4912841Sgabeblack@google.com{ 5012841Sgabeblack@google.com 5112841Sgabeblack@google.comclass sc_join; 5212841Sgabeblack@google.com 5312841Sgabeblack@google.com} // namespace sc_core 5412841Sgabeblack@google.com 5513123Sgabeblack@google.comnamespace sc_gem5 5613123Sgabeblack@google.com{ 5712841Sgabeblack@google.com 5812841Sgabeblack@google.comclass ScHalt 5912841Sgabeblack@google.com{}; 6013123Sgabeblack@google.com 6112841Sgabeblack@google.comclass Process; 6212841Sgabeblack@google.comclass Reset; 6312841Sgabeblack@google.com 6412841Sgabeblack@google.comclass Process : public ::sc_core::sc_process_b, public ListNode 6512841Sgabeblack@google.com{ 6612841Sgabeblack@google.com public: 6712841Sgabeblack@google.com virtual ::sc_core::sc_curr_proc_kind procKind() const = 0; 6812841Sgabeblack@google.com bool needsStart() const { return _needsStart; } 6912841Sgabeblack@google.com void needsStart(bool ns) { _needsStart = ns; } 7012841Sgabeblack@google.com bool dynamic() const { return _dynamic; } 7113123Sgabeblack@google.com bool isUnwinding() const { return _isUnwinding; } 7212841Sgabeblack@google.com void isUnwinding(bool v) { _isUnwinding = v; } 7313123Sgabeblack@google.com bool terminated() const { return _terminated; } 7413123Sgabeblack@google.com 7513123Sgabeblack@google.com void forEachKid(const std::function<void(Process *)> &work); 7613123Sgabeblack@google.com 7713123Sgabeblack@google.com bool suspended() const { return _suspended; } 7813123Sgabeblack@google.com bool disabled() const { return _disabled; } 7912841Sgabeblack@google.com 8012841Sgabeblack@google.com void suspend(bool inc_kids); 8112841Sgabeblack@google.com void resume(bool inc_kids); 8212841Sgabeblack@google.com void disable(bool inc_kids); 8313123Sgabeblack@google.com void enable(bool inc_kids); 8413123Sgabeblack@google.com 8513123Sgabeblack@google.com void kill(bool inc_kids); 8612841Sgabeblack@google.com void reset(bool inc_kids); 8712841Sgabeblack@google.com void throw_it(ExceptionWrapperBase &exc, bool inc_kids); 8813123Sgabeblack@google.com 8912841Sgabeblack@google.com void injectException(ExceptionWrapperBase &exc); 9013123Sgabeblack@google.com ExceptionWrapperBase *excWrapper; 9113123Sgabeblack@google.com 9213123Sgabeblack@google.com void syncResetOn(bool inc_kids); 9313123Sgabeblack@google.com void syncResetOff(bool inc_kids); 9413123Sgabeblack@google.com 9513123Sgabeblack@google.com void signalReset(bool set, bool sync); 9612841Sgabeblack@google.com 9713123Sgabeblack@google.com void incref() { refCount++; } 9812841Sgabeblack@google.com void decref() { refCount--; } 9912841Sgabeblack@google.com 10013123Sgabeblack@google.com ::sc_core::sc_event &resetEvent() { return _resetEvent; } 10112841Sgabeblack@google.com ::sc_core::sc_event &terminatedEvent() { return _terminatedEvent; } 10213123Sgabeblack@google.com 10313123Sgabeblack@google.com void setStackSize(size_t size) { stackSize = size; } 10413123Sgabeblack@google.com 10513123Sgabeblack@google.com void run(); 10612841Sgabeblack@google.com 10712841Sgabeblack@google.com void addStatic(StaticSensitivity *); 10813123Sgabeblack@google.com void setDynamic(DynamicSensitivity *); 10912841Sgabeblack@google.com void clearDynamic() { setDynamic(nullptr); } 11013123Sgabeblack@google.com void addReset(Reset *); 11113123Sgabeblack@google.com 11213123Sgabeblack@google.com ScEvent timeoutEvent; 11313123Sgabeblack@google.com void setTimeout(::sc_core::sc_time t); 11413123Sgabeblack@google.com void cancelTimeout(); 11513123Sgabeblack@google.com 11612841Sgabeblack@google.com void satisfySensitivity(Sensitivity *); 11712841Sgabeblack@google.com 11813123Sgabeblack@google.com void ready(); 11912841Sgabeblack@google.com 12013123Sgabeblack@google.com virtual Fiber *fiber() { return Fiber::primaryFiber(); } 12112841Sgabeblack@google.com 12212841Sgabeblack@google.com static Process *newest() { return _newest; } 12312841Sgabeblack@google.com 12412841Sgabeblack@google.com void lastReport(::sc_core::sc_report *report); 12512853Sgabeblack@google.com ::sc_core::sc_report *lastReport() const; 12612841Sgabeblack@google.com 12713123Sgabeblack@google.com bool hasStaticSensitivities() { return !staticSensitivities.empty(); } 12812841Sgabeblack@google.com bool internal() { return _internal; } 12912841Sgabeblack@google.com bool timedOut() { return _timedOut; } 13012841Sgabeblack@google.com bool inReset() { return _syncReset || syncResetCount || asyncResetCount; } 13112841Sgabeblack@google.com 13213123Sgabeblack@google.com bool dontInitialize() { return _dontInitialize; } 13312841Sgabeblack@google.com void dontInitialize(bool di) { _dontInitialize = di; } 13412841Sgabeblack@google.com 13513123Sgabeblack@google.com void joinWait(::sc_core::sc_join *join) { joinWaiters.push_back(join); } 13612841Sgabeblack@google.com 13712841Sgabeblack@google.com void waitCount(int count) { _waitCount = count; } 13812841Sgabeblack@google.com 13913123Sgabeblack@google.com const char *uniqueName(const char *seed) { return nameGen.gen(seed); } 14012841Sgabeblack@google.com 14112841Sgabeblack@google.com protected: 14212841Sgabeblack@google.com void timeout(); 14313123Sgabeblack@google.com 14412841Sgabeblack@google.com Process(const char *name, ProcessFuncWrapper *func, bool internal=false); 14513143Sgabeblack@google.com 14613143Sgabeblack@google.com static Process *_newest; 14713143Sgabeblack@google.com 14813143Sgabeblack@google.com virtual ~Process() 14913123Sgabeblack@google.com { 15013123Sgabeblack@google.com popListNode(); 15113123Sgabeblack@google.com delete func; 15213123Sgabeblack@google.com for (auto s: staticSensitivities) { 15312841Sgabeblack@google.com s->clear(); 15412841Sgabeblack@google.com delete s; 15513143Sgabeblack@google.com } 15612841Sgabeblack@google.com clearDynamic(); 15713143Sgabeblack@google.com } 15813143Sgabeblack@google.com 15913143Sgabeblack@google.com InternalScEvent _resetEvent; 16013143Sgabeblack@google.com InternalScEvent _terminatedEvent; 16113143Sgabeblack@google.com 16213143Sgabeblack@google.com ProcessFuncWrapper *func; 16313143Sgabeblack@google.com 16413143Sgabeblack@google.com bool _internal; 16513143Sgabeblack@google.com 16613143Sgabeblack@google.com // Needed to support the deprecated "timed_out" function. 16712841Sgabeblack@google.com bool _timedOut; 16812841Sgabeblack@google.com 16912841Sgabeblack@google.com bool _dontInitialize; 17012841Sgabeblack@google.com 17112841Sgabeblack@google.com bool _needsStart; 17212841Sgabeblack@google.com bool _dynamic; 17312841Sgabeblack@google.com bool _isUnwinding; 17413123Sgabeblack@google.com bool _terminated; 17513123Sgabeblack@google.com 17613123Sgabeblack@google.com void terminate(); 17713123Sgabeblack@google.com 17813123Sgabeblack@google.com bool _suspended; 17913123Sgabeblack@google.com bool _suspendedReady; 18013123Sgabeblack@google.com bool _disabled; 18113123Sgabeblack@google.com 18213123Sgabeblack@google.com bool _syncReset; 18312841Sgabeblack@google.com 18412841Sgabeblack@google.com int syncResetCount; 18512841Sgabeblack@google.com int asyncResetCount; 18612841Sgabeblack@google.com 18712841Sgabeblack@google.com int _waitCount; 18812841Sgabeblack@google.com 18912841Sgabeblack@google.com int refCount; 19012841Sgabeblack@google.com 19113123Sgabeblack@google.com size_t stackSize; 19213123Sgabeblack@google.com 19313123Sgabeblack@google.com StaticSensitivities staticSensitivities; 19413123Sgabeblack@google.com DynamicSensitivity *dynamicSensitivity; 19513123Sgabeblack@google.com std::vector<Reset *> resets; 19613123Sgabeblack@google.com 19713123Sgabeblack@google.com std::unique_ptr<::sc_core::sc_report> _lastReport; 19813123Sgabeblack@google.com 19912841Sgabeblack@google.com std::vector<::sc_core::sc_join *> joinWaiters; 20012841Sgabeblack@google.com 20112841Sgabeblack@google.com UniqueNameGen nameGen; 20212841Sgabeblack@google.com}; 20313143Sgabeblack@google.com 20412841Sgabeblack@google.comclass Reset 20513143Sgabeblack@google.com{ 20612841Sgabeblack@google.com public: 20712841Sgabeblack@google.com Reset(Process *p, bool s, bool v) : 20812841Sgabeblack@google.com _process(p), _signal(nullptr), _sync(s), _value(v) 20912841Sgabeblack@google.com {} 21012841Sgabeblack@google.com 21112841Sgabeblack@google.com 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__ 245