sensitivity.hh revision 13208:6703cb024823
112922Sgabeblack@google.com/* 212922Sgabeblack@google.com * Copyright 2018 Google, Inc. 312922Sgabeblack@google.com * 412922Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 512922Sgabeblack@google.com * modification, are permitted provided that the following conditions are 612922Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 712922Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 812922Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 912922Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1012922Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1112922Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1212922Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1312922Sgabeblack@google.com * this software without specific prior written permission. 1412922Sgabeblack@google.com * 1512922Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1612922Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1712922Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1812922Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1912922Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2012922Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2112922Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2212922Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2312922Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2412922Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2512922Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2612922Sgabeblack@google.com * 2712922Sgabeblack@google.com * Authors: Gabe Black 2812922Sgabeblack@google.com */ 2912922Sgabeblack@google.com 3012922Sgabeblack@google.com#ifndef __SYSTEMC_CORE_SENSITIVITY_HH__ 3112922Sgabeblack@google.com#define __SYSTEMC_CORE_SENSITIVITY_HH__ 3212922Sgabeblack@google.com 3312922Sgabeblack@google.com#include <set> 3412922Sgabeblack@google.com#include <vector> 3512922Sgabeblack@google.com 3612922Sgabeblack@google.com#include "sim/eventq.hh" 3712922Sgabeblack@google.com#include "systemc/core/sched_event.hh" 3812922Sgabeblack@google.com#include "systemc/ext/core/sc_module.hh" 3912922Sgabeblack@google.com 4012922Sgabeblack@google.comnamespace sc_core 4112922Sgabeblack@google.com{ 4212922Sgabeblack@google.com 4312922Sgabeblack@google.comclass sc_event; 4412922Sgabeblack@google.comclass sc_event_and_list; 4512922Sgabeblack@google.comclass sc_event_or_list; 4612922Sgabeblack@google.comclass sc_event_finder; 4712922Sgabeblack@google.comclass sc_export_base; 4812922Sgabeblack@google.comclass sc_interface; 4912922Sgabeblack@google.comclass sc_port_base; 5012922Sgabeblack@google.com 5112922Sgabeblack@google.com} // namespace sc_core 5212922Sgabeblack@google.com 5312922Sgabeblack@google.comnamespace sc_gem5 5412922Sgabeblack@google.com{ 5512922Sgabeblack@google.com 5612922Sgabeblack@google.comclass Process; 5712922Sgabeblack@google.comclass Event; 5812922Sgabeblack@google.com 5912922Sgabeblack@google.com/* 6012922Sgabeblack@google.com * Common sensitivity interface. 6112922Sgabeblack@google.com */ 6212922Sgabeblack@google.com 6312922Sgabeblack@google.comclass Sensitivity 6412922Sgabeblack@google.com{ 6512922Sgabeblack@google.com protected: 6612922Sgabeblack@google.com Process *process; 6712922Sgabeblack@google.com 6812922Sgabeblack@google.com Sensitivity(Process *p) : process(p) {} 6912922Sgabeblack@google.com virtual ~Sensitivity() {} 7012922Sgabeblack@google.com 7112922Sgabeblack@google.com virtual void addToEvent(const ::sc_core::sc_event *e) = 0; 7212922Sgabeblack@google.com virtual void delFromEvent(const ::sc_core::sc_event *e) = 0; 7312922Sgabeblack@google.com 7412922Sgabeblack@google.com virtual bool 7512922Sgabeblack@google.com notifyWork(Event *e) 7612922Sgabeblack@google.com { 7712922Sgabeblack@google.com satisfy(); 7812922Sgabeblack@google.com return true; 7912922Sgabeblack@google.com } 8012922Sgabeblack@google.com 8112922Sgabeblack@google.com public: 8212922Sgabeblack@google.com virtual void clear() = 0; 8312922Sgabeblack@google.com 8412922Sgabeblack@google.com void satisfy(); 8512922Sgabeblack@google.com bool notify(Event *e); 8612922Sgabeblack@google.com 8712922Sgabeblack@google.com virtual bool dynamic() = 0; 8812922Sgabeblack@google.com 8912922Sgabeblack@google.com bool ofMethod(); 9012922Sgabeblack@google.com}; 9112922Sgabeblack@google.com 9212922Sgabeblack@google.com 9312922Sgabeblack@google.com/* 9412922Sgabeblack@google.com * Dynamic vs. static sensitivity. 9512922Sgabeblack@google.com */ 9612922Sgabeblack@google.com 9712922Sgabeblack@google.comclass DynamicSensitivity : virtual public Sensitivity 9812922Sgabeblack@google.com{ 9912922Sgabeblack@google.com protected: 10012922Sgabeblack@google.com DynamicSensitivity(Process *p) : Sensitivity(p) {} 10112922Sgabeblack@google.com 10212922Sgabeblack@google.com void addToEvent(const ::sc_core::sc_event *e) override; 10312922Sgabeblack@google.com void delFromEvent(const ::sc_core::sc_event *e) override; 10412922Sgabeblack@google.com 10512922Sgabeblack@google.com public: 10612922Sgabeblack@google.com bool dynamic() override { return true; } 10712922Sgabeblack@google.com}; 10812922Sgabeblack@google.com 10912922Sgabeblack@google.comtypedef std::vector<DynamicSensitivity *> DynamicSensitivities; 11012922Sgabeblack@google.com 11112922Sgabeblack@google.com 11212922Sgabeblack@google.comclass StaticSensitivity : virtual public Sensitivity 11312922Sgabeblack@google.com{ 11412922Sgabeblack@google.com protected: 11512922Sgabeblack@google.com StaticSensitivity(Process *p) : Sensitivity(p) {} 11612922Sgabeblack@google.com 11712922Sgabeblack@google.com void addToEvent(const ::sc_core::sc_event *e) override; 11812922Sgabeblack@google.com void delFromEvent(const ::sc_core::sc_event *e) override; 11912922Sgabeblack@google.com 12012922Sgabeblack@google.com public: 12112922Sgabeblack@google.com bool dynamic() override { return false; } 12212922Sgabeblack@google.com}; 12312922Sgabeblack@google.com 12412922Sgabeblack@google.comtypedef std::vector<StaticSensitivity *> StaticSensitivities; 12512922Sgabeblack@google.com 12612922Sgabeblack@google.com 12712922Sgabeblack@google.com/* 12812922Sgabeblack@google.com * Sensitivity to an event or events, which can be static or dynamic. 12912922Sgabeblack@google.com */ 13012922Sgabeblack@google.com 13112922Sgabeblack@google.comclass SensitivityEvent : virtual public Sensitivity 13212922Sgabeblack@google.com{ 13312922Sgabeblack@google.com protected: 13412922Sgabeblack@google.com const ::sc_core::sc_event *event; 13512922Sgabeblack@google.com 13612922Sgabeblack@google.com SensitivityEvent(Process *p, const ::sc_core::sc_event *e=nullptr) : 13712922Sgabeblack@google.com Sensitivity(p), event(e) 13812922Sgabeblack@google.com {} 13912922Sgabeblack@google.com 14012922Sgabeblack@google.com public: 14112922Sgabeblack@google.com void clear() override { delFromEvent(event); } 14212922Sgabeblack@google.com}; 14312922Sgabeblack@google.com 14412922Sgabeblack@google.comclass SensitivityEvents : virtual public Sensitivity 14512922Sgabeblack@google.com{ 14612922Sgabeblack@google.com protected: 14712922Sgabeblack@google.com std::set<const ::sc_core::sc_event *> events; 14812922Sgabeblack@google.com 14912922Sgabeblack@google.com SensitivityEvents(Process *p) : Sensitivity(p) {} 15012922Sgabeblack@google.com SensitivityEvents( 15112922Sgabeblack@google.com Process *p, const std::set<const ::sc_core::sc_event *> &s) : 15212922Sgabeblack@google.com Sensitivity(p), events(s) 15312922Sgabeblack@google.com {} 15412922Sgabeblack@google.com 15512922Sgabeblack@google.com public: 15612922Sgabeblack@google.com void 15712922Sgabeblack@google.com clear() override 15812922Sgabeblack@google.com { 15912922Sgabeblack@google.com for (auto event: events) 16012922Sgabeblack@google.com delFromEvent(event); 16112922Sgabeblack@google.com } 16212922Sgabeblack@google.com 16312922Sgabeblack@google.com void 16412922Sgabeblack@google.com addEvent(const ::sc_core::sc_event *event) 16512922Sgabeblack@google.com { 16612922Sgabeblack@google.com events.insert(event); 16712922Sgabeblack@google.com addToEvent(event); 16812922Sgabeblack@google.com } 16912922Sgabeblack@google.com}; 17012922Sgabeblack@google.com 17112922Sgabeblack@google.com 17212922Sgabeblack@google.com/* 17312922Sgabeblack@google.com * Static sensitivities. 17412922Sgabeblack@google.com */ 17512922Sgabeblack@google.com 17612922Sgabeblack@google.comvoid newStaticSensitivityEvent(Process *p, const sc_core::sc_event *e); 17712922Sgabeblack@google.comvoid newStaticSensitivityInterface(Process *p, const sc_core::sc_interface *i); 17812922Sgabeblack@google.comvoid newStaticSensitivityPort(Process *p, const sc_core::sc_port_base *pb); 17912922Sgabeblack@google.comvoid newStaticSensitivityExport( 18012922Sgabeblack@google.com Process *p, const sc_core::sc_export_base *exp); 18112922Sgabeblack@google.comvoid newStaticSensitivityFinder( 18212922Sgabeblack@google.com Process *p, const sc_core::sc_event_finder *f); 18312922Sgabeblack@google.com 18412922Sgabeblack@google.com 18512922Sgabeblack@google.comclass StaticSensitivityEvent : 18612922Sgabeblack@google.com public StaticSensitivity, public SensitivityEvent 18712922Sgabeblack@google.com{ 18812922Sgabeblack@google.com friend void newStaticSensitivityEvent( 18912922Sgabeblack@google.com Process *p, const sc_core::sc_event *e); 19012922Sgabeblack@google.com 19112922Sgabeblack@google.com protected: 19212922Sgabeblack@google.com StaticSensitivityEvent(Process *p, const sc_core::sc_event *e) : 19312922Sgabeblack@google.com Sensitivity(p), StaticSensitivity(p), SensitivityEvent(p, e) 19412922Sgabeblack@google.com {} 19512922Sgabeblack@google.com}; 19612922Sgabeblack@google.com 19712922Sgabeblack@google.comclass StaticSensitivityInterface : 19812922Sgabeblack@google.com public StaticSensitivity, public SensitivityEvent 19912922Sgabeblack@google.com{ 20012922Sgabeblack@google.com friend void newStaticSensitivityInterface( 20112922Sgabeblack@google.com Process *p, const sc_core::sc_interface *i); 20212922Sgabeblack@google.com protected: 20312922Sgabeblack@google.com StaticSensitivityInterface(Process *p, const sc_core::sc_interface *i); 20412922Sgabeblack@google.com}; 20512922Sgabeblack@google.com 20612922Sgabeblack@google.comclass StaticSensitivityPort : 20712922Sgabeblack@google.com public StaticSensitivity, public SensitivityEvents 20812922Sgabeblack@google.com{ 20912922Sgabeblack@google.com friend void newStaticSensitivityPort( 21012922Sgabeblack@google.com Process *p, const sc_core::sc_port_base *pb); 21112922Sgabeblack@google.com 212 protected: 213 StaticSensitivityPort(Process *p) : 214 Sensitivity(p), StaticSensitivity(p), SensitivityEvents(p) 215 {} 216}; 217 218class StaticSensitivityExport : 219 public StaticSensitivity, public SensitivityEvent 220{ 221 private: 222 friend void newStaticSensitivityExport( 223 Process *p, const sc_core::sc_export_base *exp); 224 225 StaticSensitivityExport(Process *p, const sc_core::sc_export_base *exp); 226}; 227 228 229class StaticSensitivityFinder : 230 public StaticSensitivity, public SensitivityEvents 231{ 232 private: 233 const sc_core::sc_event_finder *finder; 234 235 friend void newStaticSensitivityFinder( 236 Process *p, const sc_core::sc_event_finder *f); 237 238 StaticSensitivityFinder(Process *p, const sc_core::sc_event_finder *f) : 239 Sensitivity(p), StaticSensitivity(p), SensitivityEvents(p), finder(f) 240 {} 241 242 public: 243 const ::sc_core::sc_event &find(::sc_core::sc_interface *i); 244}; 245 246 247/* 248 * Dynamic sensitivities. 249 */ 250 251void newDynamicSensitivityEvent(Process *p, const sc_core::sc_event *e); 252void newDynamicSensitivityEventOrList( 253 Process *p, const sc_core::sc_event_or_list *eol); 254void newDynamicSensitivityEventAndList( 255 Process *p, const sc_core::sc_event_and_list *eal); 256 257class DynamicSensitivityEvent : 258 public DynamicSensitivity, public SensitivityEvent 259{ 260 private: 261 friend void newDynamicSensitivityEvent( 262 Process *p, const sc_core::sc_event *e); 263 264 DynamicSensitivityEvent(Process *p, const sc_core::sc_event *e) : 265 Sensitivity(p), DynamicSensitivity(p), SensitivityEvent(p, e) 266 {} 267}; 268 269class DynamicSensitivityEventOrList : 270 public DynamicSensitivity, public SensitivityEvents 271{ 272 private: 273 friend void newDynamicSensitivityEventOrList( 274 Process *p, const sc_core::sc_event_or_list *eol); 275 276 DynamicSensitivityEventOrList( 277 Process *p, const sc_core::sc_event_or_list *eol); 278 279 bool notifyWork(Event *e) override; 280}; 281 282//XXX This sensitivity can't be reused. To reset it, it has to be deleted and 283//recreated. That works for dynamic sensitivities, but not for static. 284//Fortunately processes can't be statically sensitive to sc_event_and_lists. 285class DynamicSensitivityEventAndList : 286 public DynamicSensitivity, public SensitivityEvents 287{ 288 private: 289 friend void newDynamicSensitivityEventAndList( 290 Process *p, const sc_core::sc_event_and_list *eal); 291 292 DynamicSensitivityEventAndList( 293 Process *p, const sc_core::sc_event_and_list *eal); 294 295 bool notifyWork(Event *e) override; 296}; 297 298} // namespace sc_gem5 299 300#endif //__SYSTEMC_CORE_SENSITIVITY_HH__ 301