sensitivity.cc revision 13208
113821Sgabeblack@google.com/* 213821Sgabeblack@google.com * Copyright 2018 Google, Inc. 313821Sgabeblack@google.com * 413821Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 513821Sgabeblack@google.com * modification, are permitted provided that the following conditions are 613821Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 713821Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 813821Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 913821Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1013821Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1113821Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1213821Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1313821Sgabeblack@google.com * this software without specific prior written permission. 1413821Sgabeblack@google.com * 1513821Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1613821Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1713821Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1813821Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1913821Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2013821Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2113821Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2213821Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2313821Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2413821Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2513821Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2613821Sgabeblack@google.com * 2713821Sgabeblack@google.com * Authors: Gabe Black 2813821Sgabeblack@google.com */ 2913821Sgabeblack@google.com 3013821Sgabeblack@google.com#include "systemc/core/sensitivity.hh" 3113821Sgabeblack@google.com 3213821Sgabeblack@google.com#include "systemc/core/event.hh" 3313821Sgabeblack@google.com#include "systemc/core/port.hh" 3413821Sgabeblack@google.com#include "systemc/core/process.hh" 3513821Sgabeblack@google.com#include "systemc/core/scheduler.hh" 3613821Sgabeblack@google.com#include "systemc/ext/core/sc_export.hh" 3713821Sgabeblack@google.com#include "systemc/ext/core/sc_interface.hh" 3813821Sgabeblack@google.com#include "systemc/ext/core/sc_port.hh" 3913821Sgabeblack@google.com 4013821Sgabeblack@google.comnamespace sc_gem5 4113821Sgabeblack@google.com{ 4213821Sgabeblack@google.com 4313821Sgabeblack@google.com/* 4413821Sgabeblack@google.com * Common sensitivity interface. 4513821Sgabeblack@google.com */ 4613821Sgabeblack@google.com 4713821Sgabeblack@google.comvoid 4813821Sgabeblack@google.comSensitivity::satisfy() 4913821Sgabeblack@google.com{ 5013821Sgabeblack@google.com process->satisfySensitivity(this); 5113821Sgabeblack@google.com} 5213821Sgabeblack@google.com 5313821Sgabeblack@google.combool 5413821Sgabeblack@google.comSensitivity::notify(Event *e) 5513821Sgabeblack@google.com{ 5613821Sgabeblack@google.com if (process->disabled()) 5713821Sgabeblack@google.com return false; 5813821Sgabeblack@google.com return notifyWork(e); 5913821Sgabeblack@google.com} 6013821Sgabeblack@google.com 6113821Sgabeblack@google.combool 6213821Sgabeblack@google.comSensitivity::ofMethod() 6313821Sgabeblack@google.com{ 6413821Sgabeblack@google.com return process->procKind() == sc_core::SC_METHOD_PROC_; 6513821Sgabeblack@google.com} 6613823Sgabeblack@google.com 6713823Sgabeblack@google.com 6813821Sgabeblack@google.com/* 6913821Sgabeblack@google.com * Dynamic vs. static sensitivity. 7013821Sgabeblack@google.com */ 7113821Sgabeblack@google.com 7213821Sgabeblack@google.comvoid 7313821Sgabeblack@google.comDynamicSensitivity::addToEvent(const ::sc_core::sc_event *e) 7413821Sgabeblack@google.com{ 7513821Sgabeblack@google.com Event::getFromScEvent(e)->addSensitivity(this); 7613821Sgabeblack@google.com} 7713821Sgabeblack@google.com 7813821Sgabeblack@google.comvoid 7913821Sgabeblack@google.comDynamicSensitivity::delFromEvent(const ::sc_core::sc_event *e) 8013821Sgabeblack@google.com{ 8113821Sgabeblack@google.com Event::getFromScEvent(e)->delSensitivity(this); 8213821Sgabeblack@google.com} 8313846Sgabeblack@google.com 8413821Sgabeblack@google.comvoid 8513846Sgabeblack@google.comStaticSensitivity::addToEvent(const ::sc_core::sc_event *e) 8613846Sgabeblack@google.com{ 8713821Sgabeblack@google.com Event::getFromScEvent(e)->addSensitivity(this); 8813846Sgabeblack@google.com} 8913846Sgabeblack@google.com 9013846Sgabeblack@google.comvoid 9113846Sgabeblack@google.comStaticSensitivity::delFromEvent(const ::sc_core::sc_event *e) 9213821Sgabeblack@google.com{ 9313821Sgabeblack@google.com Event::getFromScEvent(e)->delSensitivity(this); 9413846Sgabeblack@google.com} 9513821Sgabeblack@google.com 9613821Sgabeblack@google.com 9713821Sgabeblack@google.com/* 9813821Sgabeblack@google.com * Static sensitivities. 9913846Sgabeblack@google.com */ 10013846Sgabeblack@google.com 10113846Sgabeblack@google.comvoid 10213821Sgabeblack@google.comnewStaticSensitivityEvent(Process *p, const sc_core::sc_event *e) 10313846Sgabeblack@google.com{ 10413846Sgabeblack@google.com auto s = new StaticSensitivityEvent(p, e); 10513846Sgabeblack@google.com s->addToEvent(s->event); 10613846Sgabeblack@google.com p->addStatic(s); 10713846Sgabeblack@google.com} 10813821Sgabeblack@google.com 10913821Sgabeblack@google.comvoid 11013846Sgabeblack@google.comnewStaticSensitivityInterface(Process *p, const sc_core::sc_interface *i) 11113821Sgabeblack@google.com{ 11213846Sgabeblack@google.com auto s = new StaticSensitivityInterface(p, i); 11313821Sgabeblack@google.com s->addToEvent(s->event); 11413821Sgabeblack@google.com p->addStatic(s); 11513821Sgabeblack@google.com} 11613846Sgabeblack@google.com 11713846Sgabeblack@google.comvoid 11813846Sgabeblack@google.comnewStaticSensitivityPort(Process *p, const sc_core::sc_port_base *pb) 11913846Sgabeblack@google.com{ 12013846Sgabeblack@google.com auto s = new StaticSensitivityPort(p); 12113846Sgabeblack@google.com Port *port = Port::fromPort(pb); 12213821Sgabeblack@google.com port->sensitive(s); 12313821Sgabeblack@google.com p->addStatic(s); 12413823Sgabeblack@google.com} 12513821Sgabeblack@google.com 12613823Sgabeblack@google.comvoid 12713823Sgabeblack@google.comnewStaticSensitivityExport(Process *p, const sc_core::sc_export_base *exp) 12813821Sgabeblack@google.com{ 12913821Sgabeblack@google.com auto s = new StaticSensitivityExport(p, exp); 13013821Sgabeblack@google.com s->addToEvent(s->event); 13113821Sgabeblack@google.com p->addStatic(s); 13213821Sgabeblack@google.com} 13313821Sgabeblack@google.com 13413821Sgabeblack@google.comvoid 13513821Sgabeblack@google.comnewStaticSensitivityFinder(Process *p, const sc_core::sc_event_finder *f) 13613821Sgabeblack@google.com{ 13713821Sgabeblack@google.com auto s = new StaticSensitivityFinder(p, f); 13813821Sgabeblack@google.com Port *port = Port::fromPort(f->port()); 13913821Sgabeblack@google.com port->sensitive(s); 14013821Sgabeblack@google.com p->addStatic(s); 14113821Sgabeblack@google.com} 14213821Sgabeblack@google.com 14313821Sgabeblack@google.com 14413821Sgabeblack@google.comStaticSensitivityInterface::StaticSensitivityInterface( 14513821Sgabeblack@google.com Process *p, const sc_core::sc_interface *i) : 14613821Sgabeblack@google.com Sensitivity(p), StaticSensitivity(p), 14713821Sgabeblack@google.com SensitivityEvent(p, &i->default_event()) 14813821Sgabeblack@google.com{} 14913821Sgabeblack@google.com 15013821Sgabeblack@google.comStaticSensitivityExport::StaticSensitivityExport( 15113821Sgabeblack@google.com Process *p, const sc_core::sc_export_base *exp) : 15213821Sgabeblack@google.com Sensitivity(p), StaticSensitivity(p), 15313821Sgabeblack@google.com SensitivityEvent(p, &exp->get_interface()->default_event()) 15413821Sgabeblack@google.com{} 15513821Sgabeblack@google.com 15613821Sgabeblack@google.comconst ::sc_core::sc_event & 15713821Sgabeblack@google.comStaticSensitivityFinder::find(::sc_core::sc_interface *i) 15813821Sgabeblack@google.com{ 15913821Sgabeblack@google.com return finder->find_event(i); 16013821Sgabeblack@google.com} 16113821Sgabeblack@google.com 16213821Sgabeblack@google.com 16313821Sgabeblack@google.com/* 16413821Sgabeblack@google.com * Dynamic sensitivities. 16513821Sgabeblack@google.com */ 16613821Sgabeblack@google.com 16713821Sgabeblack@google.comvoid 16813821Sgabeblack@google.comnewDynamicSensitivityEvent(Process *p, const sc_core::sc_event *e) 16913821Sgabeblack@google.com{ 17013821Sgabeblack@google.com auto s = new DynamicSensitivityEvent(p, e); 17113821Sgabeblack@google.com s->addToEvent(s->event); 17213821Sgabeblack@google.com p->setDynamic(s); 17313821Sgabeblack@google.com} 17413821Sgabeblack@google.com 17513821Sgabeblack@google.comvoid 17613821Sgabeblack@google.comnewDynamicSensitivityEventOrList( 17713821Sgabeblack@google.com Process *p, const sc_core::sc_event_or_list *eol) 17813821Sgabeblack@google.com{ 17913821Sgabeblack@google.com auto s = new DynamicSensitivityEventOrList(p, eol); 18013821Sgabeblack@google.com for (auto event: s->events) 18113821Sgabeblack@google.com s->addToEvent(event); 18213846Sgabeblack@google.com p->setDynamic(s); 18313846Sgabeblack@google.com} 18413846Sgabeblack@google.com 18513846Sgabeblack@google.comvoid newDynamicSensitivityEventAndList( 18613846Sgabeblack@google.com Process *p, const sc_core::sc_event_and_list *eal) 18713846Sgabeblack@google.com{ 18813846Sgabeblack@google.com auto s = new DynamicSensitivityEventAndList(p, eal); 18913846Sgabeblack@google.com for (auto event: s->events) 19013846Sgabeblack@google.com s->addToEvent(event); 19113846Sgabeblack@google.com p->setDynamic(s); 19213846Sgabeblack@google.com} 19313846Sgabeblack@google.com 19413846Sgabeblack@google.com 19513846Sgabeblack@google.comDynamicSensitivityEventOrList::DynamicSensitivityEventOrList( 19613846Sgabeblack@google.com Process *p, const sc_core::sc_event_or_list *eol) : 19713846Sgabeblack@google.com Sensitivity(p), DynamicSensitivity(p), SensitivityEvents(p, eol->events) 19813846Sgabeblack@google.com{} 19913846Sgabeblack@google.com 20013846Sgabeblack@google.combool 20113846Sgabeblack@google.comDynamicSensitivityEventOrList::notifyWork(Event *e) 20213846Sgabeblack@google.com{ 20313846Sgabeblack@google.com events.erase(e->sc_event()); 20413846Sgabeblack@google.com 20513846Sgabeblack@google.com // All the other events need this deleted from their lists since this 20613846Sgabeblack@google.com // sensitivity has been satisfied without them triggering. 20713846Sgabeblack@google.com for (auto le: events) 20813846Sgabeblack@google.com delFromEvent(le); 20913846Sgabeblack@google.com 21013846Sgabeblack@google.com satisfy(); 21113846Sgabeblack@google.com return true; 21213846Sgabeblack@google.com} 21313821Sgabeblack@google.com 21413823Sgabeblack@google.comDynamicSensitivityEventAndList::DynamicSensitivityEventAndList( 21513821Sgabeblack@google.com Process *p, const sc_core::sc_event_and_list *eal) : 21613823Sgabeblack@google.com Sensitivity(p), DynamicSensitivity(p), SensitivityEvents(p, eal->events) 21713821Sgabeblack@google.com{} 21813821Sgabeblack@google.com 21913821Sgabeblack@google.combool 22013821Sgabeblack@google.comDynamicSensitivityEventAndList::notifyWork(Event *e) 22113846Sgabeblack@google.com{ 22213846Sgabeblack@google.com events.erase(e->sc_event()); 22313846Sgabeblack@google.com 22413846Sgabeblack@google.com // This sensitivity is satisfied if all events have triggered. 22513846Sgabeblack@google.com if (events.empty()) 22613846Sgabeblack@google.com satisfy(); 22713846Sgabeblack@google.com 22813846Sgabeblack@google.com return true; 22913846Sgabeblack@google.com} 23013846Sgabeblack@google.com 23113846Sgabeblack@google.com} // namespace sc_gem5 23213846Sgabeblack@google.com