sensitivity.hh revision 13206
12SN/A/* 21762SN/A * Copyright 2018 Google, Inc. 32SN/A * 42SN/A * Redistribution and use in source and binary forms, with or without 52SN/A * modification, are permitted provided that the following conditions are 62SN/A * met: redistributions of source code must retain the above copyright 72SN/A * notice, this list of conditions and the following disclaimer; 82SN/A * redistributions in binary form must reproduce the above copyright 92SN/A * notice, this list of conditions and the following disclaimer in the 102SN/A * documentation and/or other materials provided with the distribution; 112SN/A * neither the name of the copyright holders nor the names of its 122SN/A * contributors may be used to endorse or promote products derived from 132SN/A * this software without specific prior written permission. 142SN/A * 152SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 162SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 172SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 182SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 192SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 202SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 212SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 222SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 232SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 242SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 252SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 262SN/A * 272665SN/A * Authors: Gabe Black 282665SN/A */ 292665SN/A 302665SN/A#ifndef __SYSTEMC_CORE_SENSITIVITY_HH__ 312665SN/A#define __SYSTEMC_CORE_SENSITIVITY_HH__ 322SN/A 332SN/A#include <set> 341722SN/A#include <vector> 355480Snate@binkert.org 362SN/A#include "sim/eventq.hh" 372SN/A#include "systemc/core/sched_event.hh" 38146SN/A#include "systemc/ext/core/sc_module.hh" 392SN/A 402SN/Anamespace sc_core 412158SN/A{ 42146SN/A 431805SN/Aclass sc_event; 44146SN/Aclass sc_event_and_list; 451717SN/Aclass sc_event_or_list; 462680SN/Aclass sc_event_finder; 478232Snate@binkert.orgclass sc_export_base; 485480Snate@binkert.orgclass sc_interface; 498741Sgblack@eecs.umich.educlass sc_port_base; 508741Sgblack@eecs.umich.edu 518741Sgblack@eecs.umich.edu} // namespace sc_core 522521SN/A 5356SN/Anamespace sc_gem5 545478SN/A{ 553348SN/A 563348SN/Aclass Process; 572521SN/Aclass Event; 585480Snate@binkert.org 591805SN/A/* 602SN/A * Common sensitivity interface. 612SN/A */ 622107SN/A 632SN/Aclass Sensitivity 645480Snate@binkert.org{ 655478SN/A protected: 668806Sgblack@eecs.umich.edu Process *process; 672SN/A 68545SN/A Sensitivity(Process *p) : process(p) {} 692521SN/A virtual ~Sensitivity() {} 702521SN/A 712521SN/A virtual void addToEvent(const ::sc_core::sc_event *e) = 0; 722521SN/A virtual void delFromEvent(const ::sc_core::sc_event *e) = 0; 732SN/A 742SN/A virtual bool 752SN/A notifyWork(Event *e) 76926SN/A { 77926SN/A satisfy(); 78926SN/A return true; 79926SN/A } 80926SN/A 81926SN/A public: 82926SN/A virtual void finalize() = 0; 834395SN/A virtual void clear() = 0; 841805SN/A 852SN/A void satisfy(); 862SN/A bool notify(Event *e); 871634SN/A 885480Snate@binkert.org virtual bool dynamic() = 0; 891634SN/A}; 902549SN/A 915714Shsul@eecs.umich.edu 921634SN/A/* 931634SN/A * Dynamic vs. static sensitivity. 941634SN/A */ 958931Sandreas.hansson@arm.com 961634SN/Aclass DynamicSensitivity : virtual public Sensitivity 978741Sgblack@eecs.umich.edu{ 988806Sgblack@eecs.umich.edu protected: 998806Sgblack@eecs.umich.edu DynamicSensitivity(Process *p) : Sensitivity(p) {} 1008741Sgblack@eecs.umich.edu 1011634SN/A void addToEvent(const ::sc_core::sc_event *e) override; 1021634SN/A void delFromEvent(const ::sc_core::sc_event *e) override; 1032512SN/A 1045480Snate@binkert.org public: 1052SN/A bool dynamic() override { return true; } 1062SN/A}; 1072512SN/A 1082512SN/Atypedef std::vector<DynamicSensitivity *> DynamicSensitivities; 1092512SN/A 1102512SN/A 111540SN/Aclass StaticSensitivity : virtual public Sensitivity 1122641SN/A{ 1132522SN/A protected: 1142641SN/A StaticSensitivity(Process *p) : Sensitivity(p) {} 1152512SN/A 1162630SN/A void addToEvent(const ::sc_core::sc_event *e) override; 1174986SN/A void delFromEvent(const ::sc_core::sc_event *e) override; 1182521SN/A 1192641SN/A public: 120873SN/A bool dynamic() override { return false; } 121873SN/A}; 122873SN/A 123873SN/Atypedef std::vector<StaticSensitivity *> StaticSensitivities; 124873SN/A 1252630SN/A 126873SN/A/* 127873SN/A * Sensitivity to events, which can be static or dynamic. 1282630SN/A */ 129873SN/A 130873SN/Aclass SensitivityEvent : virtual public Sensitivity 1312630SN/A{ 132873SN/A protected: 133873SN/A const ::sc_core::sc_event *event; 1342630SN/A 135873SN/A SensitivityEvent(Process *p, const ::sc_core::sc_event *e=nullptr) : 136873SN/A Sensitivity(p), event(e) 1372512SN/A {} 1382512SN/A 1392512SN/A public: 1404870SN/A void finalize() override { addToEvent(event); } 141873SN/A void clear() override { delFromEvent(event); } 1425480Snate@binkert.org}; 1432630SN/A 144873SN/A 145873SN/A/* 146873SN/A * Static sensitivities. 147873SN/A */ 148873SN/A 1495478SN/Aclass StaticSensitivityEvent : 150873SN/A public StaticSensitivity, public SensitivityEvent 151873SN/A{ 1522630SN/A public: 153873SN/A StaticSensitivityEvent(Process *p, const sc_core::sc_event *e) : 154873SN/A Sensitivity(p), StaticSensitivity(p), SensitivityEvent(p, e) 1552630SN/A {} 156873SN/A}; 157873SN/A 1582630SN/Aclass StaticSensitivityInterface : 159873SN/A public StaticSensitivity, public SensitivityEvent 160873SN/A{ 1612630SN/A private: 162873SN/A const sc_core::sc_interface *interface; 163873SN/A 1642630SN/A public: 165873SN/A StaticSensitivityInterface(Process *p, const sc_core::sc_interface *i) : 166873SN/A Sensitivity(p), StaticSensitivity(p), SensitivityEvent(p), interface(i) 1672630SN/A {} 168873SN/A 169873SN/A void finalize() override; 1702630SN/A}; 171873SN/A 172873SN/Aclass StaticSensitivityPort : public StaticSensitivity 1732630SN/A{ 174873SN/A private: 175873SN/A const ::sc_core::sc_port_base *port; 1762630SN/A std::set<const ::sc_core::sc_event *> events; 177873SN/A 178873SN/A public: 1792630SN/A StaticSensitivityPort(Process *p, const sc_core::sc_port_base *pb) : 180873SN/A Sensitivity(p), StaticSensitivity(p), port(pb) 181873SN/A {} 1822630SN/A 183873SN/A void finalize() override; 184873SN/A 1852114SN/A void 1862114SN/A clear() override 1872114SN/A { 1882114SN/A for (auto event: events) 1892630SN/A delFromEvent(event); 1902114SN/A } 1912114SN/A}; 192873SN/A 1935480Snate@binkert.orgclass StaticSensitivityExport : 1942630SN/A public StaticSensitivity, public SensitivityEvent 195873SN/A{ 196873SN/A private: 1974870SN/A const sc_core::sc_export_base *exp; 1982SN/A 1992512SN/A public: 2002SN/A StaticSensitivityExport(Process *p, const sc_core::sc_export_base *exp) : 2012SN/A Sensitivity(p), StaticSensitivity(p), SensitivityEvent(p), exp(exp) 2022512SN/A {} 2035480Snate@binkert.org 2042SN/A void finalize() override; 2052641SN/A}; 2062641SN/A 207430SN/Aclass StaticSensitivityFinder : public StaticSensitivity 2082630SN/A{ 2092641SN/A private: 2102SN/A const ::sc_core::sc_event_finder *finder; 211430SN/A std::set<const ::sc_core::sc_event *> events; 212430SN/A 2132SN/A public: 214430SN/A StaticSensitivityFinder(Process *p, const sc_core::sc_event_finder *f) : 2152SN/A Sensitivity(p), StaticSensitivity(p), finder(f) 216430SN/A {} 2172SN/A 218430SN/A void finalize() override; 2192SN/A 220430SN/A void 2212SN/A clear() override 222430SN/A { 2232SN/A for (auto event: events) 224430SN/A delFromEvent(event); 2252SN/A } 226430SN/A}; 2272SN/A 228430SN/A 2292SN/A/* 2302SN/A * Dynamic sensitivities. 2312SN/A */ 2322SN/A 2332SN/Aclass DynamicSensitivityEvent : 2342SN/A public DynamicSensitivity, public SensitivityEvent 235430SN/A{ 2362SN/A public: 237430SN/A DynamicSensitivityEvent(Process *p, const sc_core::sc_event *e) : 2385478SN/A Sensitivity(p), DynamicSensitivity(p), SensitivityEvent(p, e) 239430SN/A {} 2402SN/A}; 241430SN/A 2422114SN/Aclass DynamicSensitivityEventOrList : public DynamicSensitivity 2432114SN/A{ 2447823Ssteve.reinhardt@amd.com private: 2452114SN/A std::set<const ::sc_core::sc_event *> events; 2462114SN/A 2472114SN/A protected: 2482114SN/A bool notifyWork(Event *e) override; 2492114SN/A 2502SN/A public: 2512SN/A DynamicSensitivityEventOrList( 2524870SN/A Process *p, const sc_core::sc_event_or_list *eol); 2532SN/A 2542512SN/A void finalize() override; 255545SN/A void clear() override; 256545SN/A}; 2572SN/A 2585480Snate@binkert.org//XXX This sensitivity can't be reused. To reset it, it has to be deleted and 2592SN/A//recreated. That works for dynamic sensitivities, but not for static. 260222SN/A//Fortunately processes can't be statically sensitive to sc_event_and_lists. 261222SN/Aclass DynamicSensitivityEventAndList : public DynamicSensitivity 262222SN/A{ 263222SN/A private: 264222SN/A std::set<const ::sc_core::sc_event *> events; 265222SN/A 266222SN/A protected: 267222SN/A bool notifyWork(Event *e) override; 268222SN/A 269222SN/A public: 270222SN/A DynamicSensitivityEventAndList( 271222SN/A Process *p, const sc_core::sc_event_and_list *eal); 272222SN/A 273222SN/A void finalize() override; 274222SN/A void clear() override; 275430SN/A}; 2762114SN/A 2772SN/A} // namespace sc_gem5 2782SN/A 2792SN/A#endif //__SYSTEMC_CORE_SENSITIVITY_HH__ 2805480Snate@binkert.org