sensitivity.hh revision 13207
113206Sgabeblack@google.com/* 213206Sgabeblack@google.com * Copyright 2018 Google, Inc. 313206Sgabeblack@google.com * 413206Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 513206Sgabeblack@google.com * modification, are permitted provided that the following conditions are 613206Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 713206Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 813206Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 913206Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1013206Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1113206Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1213206Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1313206Sgabeblack@google.com * this software without specific prior written permission. 1413206Sgabeblack@google.com * 1513206Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1613206Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1713206Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1813206Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1913206Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2013206Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2113206Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2213206Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2313206Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2413206Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2513206Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2613206Sgabeblack@google.com * 2713206Sgabeblack@google.com * Authors: Gabe Black 2813206Sgabeblack@google.com */ 2913206Sgabeblack@google.com 3013206Sgabeblack@google.com#ifndef __SYSTEMC_CORE_SENSITIVITY_HH__ 3113206Sgabeblack@google.com#define __SYSTEMC_CORE_SENSITIVITY_HH__ 3213206Sgabeblack@google.com 3313206Sgabeblack@google.com#include <set> 3413206Sgabeblack@google.com#include <vector> 3513206Sgabeblack@google.com 3613206Sgabeblack@google.com#include "sim/eventq.hh" 3713206Sgabeblack@google.com#include "systemc/core/sched_event.hh" 3813206Sgabeblack@google.com#include "systemc/ext/core/sc_module.hh" 3913206Sgabeblack@google.com 4013206Sgabeblack@google.comnamespace sc_core 4113206Sgabeblack@google.com{ 4213206Sgabeblack@google.com 4313206Sgabeblack@google.comclass sc_event; 4413206Sgabeblack@google.comclass sc_event_and_list; 4513206Sgabeblack@google.comclass sc_event_or_list; 4613206Sgabeblack@google.comclass sc_event_finder; 4713206Sgabeblack@google.comclass sc_export_base; 4813206Sgabeblack@google.comclass sc_interface; 4913206Sgabeblack@google.comclass sc_port_base; 5013206Sgabeblack@google.com 5113206Sgabeblack@google.com} // namespace sc_core 5213206Sgabeblack@google.com 5313206Sgabeblack@google.comnamespace sc_gem5 5413206Sgabeblack@google.com{ 5513206Sgabeblack@google.com 5613206Sgabeblack@google.comclass Process; 5713206Sgabeblack@google.comclass Event; 5813206Sgabeblack@google.com 5913206Sgabeblack@google.com/* 6013206Sgabeblack@google.com * Common sensitivity interface. 6113206Sgabeblack@google.com */ 6213206Sgabeblack@google.com 6313206Sgabeblack@google.comclass Sensitivity 6413206Sgabeblack@google.com{ 6513206Sgabeblack@google.com protected: 6613206Sgabeblack@google.com Process *process; 6713206Sgabeblack@google.com 6813206Sgabeblack@google.com Sensitivity(Process *p) : process(p) {} 6913206Sgabeblack@google.com virtual ~Sensitivity() {} 7013206Sgabeblack@google.com 7113206Sgabeblack@google.com virtual void addToEvent(const ::sc_core::sc_event *e) = 0; 7213206Sgabeblack@google.com virtual void delFromEvent(const ::sc_core::sc_event *e) = 0; 7313206Sgabeblack@google.com 7413206Sgabeblack@google.com virtual bool 7513206Sgabeblack@google.com notifyWork(Event *e) 7613206Sgabeblack@google.com { 7713206Sgabeblack@google.com satisfy(); 7813206Sgabeblack@google.com return true; 7913206Sgabeblack@google.com } 8013206Sgabeblack@google.com 8113206Sgabeblack@google.com public: 8213206Sgabeblack@google.com virtual void clear() = 0; 8313206Sgabeblack@google.com 8413206Sgabeblack@google.com void satisfy(); 8513206Sgabeblack@google.com bool notify(Event *e); 8613206Sgabeblack@google.com 8713206Sgabeblack@google.com virtual bool dynamic() = 0; 8813206Sgabeblack@google.com}; 8913206Sgabeblack@google.com 9013206Sgabeblack@google.com 9113206Sgabeblack@google.com/* 9213206Sgabeblack@google.com * Dynamic vs. static sensitivity. 9313206Sgabeblack@google.com */ 9413206Sgabeblack@google.com 9513206Sgabeblack@google.comclass DynamicSensitivity : virtual public Sensitivity 9613206Sgabeblack@google.com{ 9713206Sgabeblack@google.com protected: 9813206Sgabeblack@google.com DynamicSensitivity(Process *p) : Sensitivity(p) {} 9913206Sgabeblack@google.com 10013206Sgabeblack@google.com void addToEvent(const ::sc_core::sc_event *e) override; 10113206Sgabeblack@google.com void delFromEvent(const ::sc_core::sc_event *e) override; 10213206Sgabeblack@google.com 10313206Sgabeblack@google.com public: 10413206Sgabeblack@google.com bool dynamic() override { return true; } 10513206Sgabeblack@google.com}; 10613206Sgabeblack@google.com 10713206Sgabeblack@google.comtypedef std::vector<DynamicSensitivity *> DynamicSensitivities; 10813206Sgabeblack@google.com 10913206Sgabeblack@google.com 11013206Sgabeblack@google.comclass StaticSensitivity : virtual public Sensitivity 11113206Sgabeblack@google.com{ 11213206Sgabeblack@google.com protected: 11313206Sgabeblack@google.com StaticSensitivity(Process *p) : Sensitivity(p) {} 11413206Sgabeblack@google.com 11513206Sgabeblack@google.com void addToEvent(const ::sc_core::sc_event *e) override; 11613206Sgabeblack@google.com void delFromEvent(const ::sc_core::sc_event *e) override; 11713206Sgabeblack@google.com 11813206Sgabeblack@google.com public: 11913206Sgabeblack@google.com bool dynamic() override { return false; } 12013206Sgabeblack@google.com}; 12113206Sgabeblack@google.com 12213206Sgabeblack@google.comtypedef std::vector<StaticSensitivity *> StaticSensitivities; 12313206Sgabeblack@google.com 12413206Sgabeblack@google.com 12513206Sgabeblack@google.com/* 12613207Sgabeblack@google.com * Sensitivity to an event or events, which can be static or dynamic. 12713206Sgabeblack@google.com */ 12813206Sgabeblack@google.com 12913206Sgabeblack@google.comclass SensitivityEvent : virtual public Sensitivity 13013206Sgabeblack@google.com{ 13113206Sgabeblack@google.com protected: 13213206Sgabeblack@google.com const ::sc_core::sc_event *event; 13313206Sgabeblack@google.com 13413206Sgabeblack@google.com SensitivityEvent(Process *p, const ::sc_core::sc_event *e=nullptr) : 13513206Sgabeblack@google.com Sensitivity(p), event(e) 13613206Sgabeblack@google.com {} 13713206Sgabeblack@google.com 13813206Sgabeblack@google.com public: 13913206Sgabeblack@google.com void clear() override { delFromEvent(event); } 14013206Sgabeblack@google.com}; 14113206Sgabeblack@google.com 14213207Sgabeblack@google.comclass SensitivityEvents : virtual public Sensitivity 14313207Sgabeblack@google.com{ 14413207Sgabeblack@google.com protected: 14513207Sgabeblack@google.com std::set<const ::sc_core::sc_event *> events; 14613207Sgabeblack@google.com 14713207Sgabeblack@google.com SensitivityEvents(Process *p) : Sensitivity(p) {} 14813207Sgabeblack@google.com SensitivityEvents( 14913207Sgabeblack@google.com Process *p, const std::set<const ::sc_core::sc_event *> &s) : 15013207Sgabeblack@google.com Sensitivity(p), events(s) 15113207Sgabeblack@google.com {} 15213207Sgabeblack@google.com 15313207Sgabeblack@google.com public: 15413207Sgabeblack@google.com void 15513207Sgabeblack@google.com clear() override 15613207Sgabeblack@google.com { 15713207Sgabeblack@google.com for (auto event: events) 15813207Sgabeblack@google.com delFromEvent(event); 15913207Sgabeblack@google.com } 16013207Sgabeblack@google.com 16113207Sgabeblack@google.com void 16213207Sgabeblack@google.com addEvent(const ::sc_core::sc_event *event) 16313207Sgabeblack@google.com { 16413207Sgabeblack@google.com events.insert(event); 16513207Sgabeblack@google.com addToEvent(event); 16613207Sgabeblack@google.com } 16713207Sgabeblack@google.com}; 16813207Sgabeblack@google.com 16913206Sgabeblack@google.com 17013206Sgabeblack@google.com/* 17113206Sgabeblack@google.com * Static sensitivities. 17213206Sgabeblack@google.com */ 17313206Sgabeblack@google.com 17413207Sgabeblack@google.comvoid newStaticSensitivityEvent(Process *p, const sc_core::sc_event *e); 17513207Sgabeblack@google.comvoid newStaticSensitivityInterface(Process *p, const sc_core::sc_interface *i); 17613207Sgabeblack@google.comvoid newStaticSensitivityPort(Process *p, const sc_core::sc_port_base *pb); 17713207Sgabeblack@google.comvoid newStaticSensitivityExport( 17813207Sgabeblack@google.com Process *p, const sc_core::sc_export_base *exp); 17913207Sgabeblack@google.comvoid newStaticSensitivityFinder( 18013207Sgabeblack@google.com Process *p, const sc_core::sc_event_finder *f); 18113207Sgabeblack@google.com 18213207Sgabeblack@google.com 18313206Sgabeblack@google.comclass StaticSensitivityEvent : 18413206Sgabeblack@google.com public StaticSensitivity, public SensitivityEvent 18513206Sgabeblack@google.com{ 18613207Sgabeblack@google.com friend void newStaticSensitivityEvent( 18713207Sgabeblack@google.com Process *p, const sc_core::sc_event *e); 18813207Sgabeblack@google.com 18913207Sgabeblack@google.com protected: 19013206Sgabeblack@google.com StaticSensitivityEvent(Process *p, const sc_core::sc_event *e) : 19113206Sgabeblack@google.com Sensitivity(p), StaticSensitivity(p), SensitivityEvent(p, e) 19213206Sgabeblack@google.com {} 19313206Sgabeblack@google.com}; 19413206Sgabeblack@google.com 19513206Sgabeblack@google.comclass StaticSensitivityInterface : 19613206Sgabeblack@google.com public StaticSensitivity, public SensitivityEvent 19713206Sgabeblack@google.com{ 19813207Sgabeblack@google.com friend void newStaticSensitivityInterface( 19913207Sgabeblack@google.com Process *p, const sc_core::sc_interface *i); 20013207Sgabeblack@google.com protected: 20113207Sgabeblack@google.com StaticSensitivityInterface(Process *p, const sc_core::sc_interface *i); 20213206Sgabeblack@google.com}; 20313206Sgabeblack@google.com 20413207Sgabeblack@google.comclass StaticSensitivityPort : 20513207Sgabeblack@google.com public StaticSensitivity, public SensitivityEvents 20613206Sgabeblack@google.com{ 20713207Sgabeblack@google.com friend void newStaticSensitivityPort( 20813207Sgabeblack@google.com Process *p, const sc_core::sc_port_base *pb); 20913206Sgabeblack@google.com 21013207Sgabeblack@google.com protected: 21113207Sgabeblack@google.com StaticSensitivityPort(Process *p) : 21213207Sgabeblack@google.com Sensitivity(p), StaticSensitivity(p), SensitivityEvents(p) 21313206Sgabeblack@google.com {} 21413206Sgabeblack@google.com}; 21513206Sgabeblack@google.com 21613206Sgabeblack@google.comclass StaticSensitivityExport : 21713206Sgabeblack@google.com public StaticSensitivity, public SensitivityEvent 21813206Sgabeblack@google.com{ 21913206Sgabeblack@google.com private: 22013207Sgabeblack@google.com friend void newStaticSensitivityExport( 22113207Sgabeblack@google.com Process *p, const sc_core::sc_export_base *exp); 22213207Sgabeblack@google.com 22313207Sgabeblack@google.com StaticSensitivityExport(Process *p, const sc_core::sc_export_base *exp); 22413207Sgabeblack@google.com}; 22513207Sgabeblack@google.com 22613207Sgabeblack@google.com 22713207Sgabeblack@google.comclass StaticSensitivityFinder : 22813207Sgabeblack@google.com public StaticSensitivity, public SensitivityEvents 22913207Sgabeblack@google.com{ 23013207Sgabeblack@google.com private: 23113207Sgabeblack@google.com const sc_core::sc_event_finder *finder; 23213207Sgabeblack@google.com 23313207Sgabeblack@google.com friend void newStaticSensitivityFinder( 23413207Sgabeblack@google.com Process *p, const sc_core::sc_event_finder *f); 23513207Sgabeblack@google.com 23613207Sgabeblack@google.com StaticSensitivityFinder(Process *p, const sc_core::sc_event_finder *f) : 23713207Sgabeblack@google.com Sensitivity(p), StaticSensitivity(p), SensitivityEvents(p), finder(f) 23813207Sgabeblack@google.com {} 23913206Sgabeblack@google.com 24013206Sgabeblack@google.com public: 24113207Sgabeblack@google.com const ::sc_core::sc_event &find(::sc_core::sc_interface *i); 24213206Sgabeblack@google.com}; 24313206Sgabeblack@google.com 24413206Sgabeblack@google.com 24513206Sgabeblack@google.com/* 24613206Sgabeblack@google.com * Dynamic sensitivities. 24713206Sgabeblack@google.com */ 24813206Sgabeblack@google.com 24913207Sgabeblack@google.comvoid newDynamicSensitivityEvent(Process *p, const sc_core::sc_event *e); 25013207Sgabeblack@google.comvoid newDynamicSensitivityEventOrList( 25113207Sgabeblack@google.com Process *p, const sc_core::sc_event_or_list *eol); 25213207Sgabeblack@google.comvoid newDynamicSensitivityEventAndList( 25313207Sgabeblack@google.com Process *p, const sc_core::sc_event_and_list *eal); 25413207Sgabeblack@google.com 25513206Sgabeblack@google.comclass DynamicSensitivityEvent : 25613206Sgabeblack@google.com public DynamicSensitivity, public SensitivityEvent 25713206Sgabeblack@google.com{ 25813207Sgabeblack@google.com private: 25913207Sgabeblack@google.com friend void newDynamicSensitivityEvent( 26013207Sgabeblack@google.com Process *p, const sc_core::sc_event *e); 26113207Sgabeblack@google.com 26213206Sgabeblack@google.com DynamicSensitivityEvent(Process *p, const sc_core::sc_event *e) : 26313206Sgabeblack@google.com Sensitivity(p), DynamicSensitivity(p), SensitivityEvent(p, e) 26413206Sgabeblack@google.com {} 26513206Sgabeblack@google.com}; 26613206Sgabeblack@google.com 26713207Sgabeblack@google.comclass DynamicSensitivityEventOrList : 26813207Sgabeblack@google.com public DynamicSensitivity, public SensitivityEvents 26913206Sgabeblack@google.com{ 27013206Sgabeblack@google.com private: 27113207Sgabeblack@google.com friend void newDynamicSensitivityEventOrList( 27213207Sgabeblack@google.com Process *p, const sc_core::sc_event_or_list *eol); 27313206Sgabeblack@google.com 27413206Sgabeblack@google.com DynamicSensitivityEventOrList( 27513206Sgabeblack@google.com Process *p, const sc_core::sc_event_or_list *eol); 27613206Sgabeblack@google.com 27713207Sgabeblack@google.com bool notifyWork(Event *e) override; 27813206Sgabeblack@google.com}; 27913206Sgabeblack@google.com 28013206Sgabeblack@google.com//XXX This sensitivity can't be reused. To reset it, it has to be deleted and 28113206Sgabeblack@google.com//recreated. That works for dynamic sensitivities, but not for static. 28213206Sgabeblack@google.com//Fortunately processes can't be statically sensitive to sc_event_and_lists. 28313207Sgabeblack@google.comclass DynamicSensitivityEventAndList : 28413207Sgabeblack@google.com public DynamicSensitivity, public SensitivityEvents 28513206Sgabeblack@google.com{ 28613206Sgabeblack@google.com private: 28713207Sgabeblack@google.com friend void newDynamicSensitivityEventAndList( 28813207Sgabeblack@google.com Process *p, const sc_core::sc_event_and_list *eal); 28913206Sgabeblack@google.com 29013206Sgabeblack@google.com DynamicSensitivityEventAndList( 29113206Sgabeblack@google.com Process *p, const sc_core::sc_event_and_list *eal); 29213206Sgabeblack@google.com 29313207Sgabeblack@google.com bool notifyWork(Event *e) override; 29413206Sgabeblack@google.com}; 29513206Sgabeblack@google.com 29613206Sgabeblack@google.com} // namespace sc_gem5 29713206Sgabeblack@google.com 29813206Sgabeblack@google.com#endif //__SYSTEMC_CORE_SENSITIVITY_HH__ 299