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#include "systemc/core/sensitivity.hh" 3113206Sgabeblack@google.com 3213206Sgabeblack@google.com#include "systemc/core/event.hh" 3313207Sgabeblack@google.com#include "systemc/core/port.hh" 3413208Sgabeblack@google.com#include "systemc/core/process.hh" 3513206Sgabeblack@google.com#include "systemc/core/scheduler.hh" 3613260Sgabeblack@google.com#include "systemc/ext/channel/sc_in.hh" 3713260Sgabeblack@google.com#include "systemc/ext/channel/sc_inout.hh" 3813260Sgabeblack@google.com#include "systemc/ext/channel/sc_out.hh" 3913317Sgabeblack@google.com#include "systemc/ext/core/messages.hh" 4013206Sgabeblack@google.com#include "systemc/ext/core/sc_export.hh" 4113206Sgabeblack@google.com#include "systemc/ext/core/sc_interface.hh" 4213206Sgabeblack@google.com#include "systemc/ext/core/sc_port.hh" 4313206Sgabeblack@google.com 4413206Sgabeblack@google.comnamespace sc_gem5 4513206Sgabeblack@google.com{ 4613206Sgabeblack@google.com 4713207Sgabeblack@google.com/* 4813207Sgabeblack@google.com * Common sensitivity interface. 4913207Sgabeblack@google.com */ 5013207Sgabeblack@google.com 5113206Sgabeblack@google.comvoid 5213206Sgabeblack@google.comSensitivity::satisfy() 5313206Sgabeblack@google.com{ 5413206Sgabeblack@google.com process->satisfySensitivity(this); 5513206Sgabeblack@google.com} 5613206Sgabeblack@google.com 5713206Sgabeblack@google.combool 5813304Sgabeblack@google.comSensitivity::notifyWork(Event *e) 5913304Sgabeblack@google.com{ 6013304Sgabeblack@google.com satisfy(); 6113304Sgabeblack@google.com return true; 6213304Sgabeblack@google.com} 6313304Sgabeblack@google.com 6413304Sgabeblack@google.combool 6513206Sgabeblack@google.comSensitivity::notify(Event *e) 6613206Sgabeblack@google.com{ 6713304Sgabeblack@google.com if (scheduler.current() == process) { 6813304Sgabeblack@google.com static bool warned = false; 6913304Sgabeblack@google.com if (!warned) { 7013317Sgabeblack@google.com SC_REPORT_WARNING(sc_core::SC_ID_IMMEDIATE_SELF_NOTIFICATION_, 7113317Sgabeblack@google.com process->name()); 7213304Sgabeblack@google.com warned = true; 7313304Sgabeblack@google.com } 7413304Sgabeblack@google.com return false; 7513304Sgabeblack@google.com } 7613304Sgabeblack@google.com 7713206Sgabeblack@google.com if (process->disabled()) 7813206Sgabeblack@google.com return false; 7913304Sgabeblack@google.com 8013304Sgabeblack@google.com return notifyWork(e); 8113206Sgabeblack@google.com} 8213206Sgabeblack@google.com 8313208Sgabeblack@google.combool 8413208Sgabeblack@google.comSensitivity::ofMethod() 8513208Sgabeblack@google.com{ 8613208Sgabeblack@google.com return process->procKind() == sc_core::SC_METHOD_PROC_; 8713208Sgabeblack@google.com} 8813208Sgabeblack@google.com 8913206Sgabeblack@google.com 9013207Sgabeblack@google.com/* 9113207Sgabeblack@google.com * Dynamic vs. static sensitivity. 9213207Sgabeblack@google.com */ 9313207Sgabeblack@google.com 9413206Sgabeblack@google.comvoid 9513206Sgabeblack@google.comDynamicSensitivity::addToEvent(const ::sc_core::sc_event *e) 9613206Sgabeblack@google.com{ 9713206Sgabeblack@google.com Event::getFromScEvent(e)->addSensitivity(this); 9813206Sgabeblack@google.com} 9913206Sgabeblack@google.com 10013206Sgabeblack@google.comvoid 10113206Sgabeblack@google.comDynamicSensitivity::delFromEvent(const ::sc_core::sc_event *e) 10213206Sgabeblack@google.com{ 10313206Sgabeblack@google.com Event::getFromScEvent(e)->delSensitivity(this); 10413206Sgabeblack@google.com} 10513206Sgabeblack@google.com 10613206Sgabeblack@google.comvoid 10713206Sgabeblack@google.comStaticSensitivity::addToEvent(const ::sc_core::sc_event *e) 10813206Sgabeblack@google.com{ 10913206Sgabeblack@google.com Event::getFromScEvent(e)->addSensitivity(this); 11013206Sgabeblack@google.com} 11113206Sgabeblack@google.com 11213206Sgabeblack@google.comvoid 11313206Sgabeblack@google.comStaticSensitivity::delFromEvent(const ::sc_core::sc_event *e) 11413206Sgabeblack@google.com{ 11513206Sgabeblack@google.com Event::getFromScEvent(e)->delSensitivity(this); 11613206Sgabeblack@google.com} 11713206Sgabeblack@google.com 11813207Sgabeblack@google.com 11913207Sgabeblack@google.com/* 12013207Sgabeblack@google.com * Static sensitivities. 12113207Sgabeblack@google.com */ 12213207Sgabeblack@google.com 12313206Sgabeblack@google.comvoid 12413207Sgabeblack@google.comnewStaticSensitivityEvent(Process *p, const sc_core::sc_event *e) 12513206Sgabeblack@google.com{ 12613207Sgabeblack@google.com auto s = new StaticSensitivityEvent(p, e); 12713207Sgabeblack@google.com s->addToEvent(s->event); 12813207Sgabeblack@google.com p->addStatic(s); 12913206Sgabeblack@google.com} 13013206Sgabeblack@google.com 13113206Sgabeblack@google.comvoid 13213207Sgabeblack@google.comnewStaticSensitivityInterface(Process *p, const sc_core::sc_interface *i) 13313206Sgabeblack@google.com{ 13413207Sgabeblack@google.com auto s = new StaticSensitivityInterface(p, i); 13513207Sgabeblack@google.com s->addToEvent(s->event); 13613207Sgabeblack@google.com p->addStatic(s); 13713206Sgabeblack@google.com} 13813206Sgabeblack@google.com 13913206Sgabeblack@google.comvoid 14013207Sgabeblack@google.comnewStaticSensitivityPort(Process *p, const sc_core::sc_port_base *pb) 14113206Sgabeblack@google.com{ 14213207Sgabeblack@google.com auto s = new StaticSensitivityPort(p); 14313207Sgabeblack@google.com Port *port = Port::fromPort(pb); 14413207Sgabeblack@google.com port->sensitive(s); 14513207Sgabeblack@google.com p->addStatic(s); 14613206Sgabeblack@google.com} 14713206Sgabeblack@google.com 14813206Sgabeblack@google.comvoid 14913207Sgabeblack@google.comnewStaticSensitivityExport(Process *p, const sc_core::sc_export_base *exp) 15013206Sgabeblack@google.com{ 15113207Sgabeblack@google.com auto s = new StaticSensitivityExport(p, exp); 15213207Sgabeblack@google.com s->addToEvent(s->event); 15313207Sgabeblack@google.com p->addStatic(s); 15413206Sgabeblack@google.com} 15513206Sgabeblack@google.com 15613207Sgabeblack@google.comvoid 15713207Sgabeblack@google.comnewStaticSensitivityFinder(Process *p, const sc_core::sc_event_finder *f) 15813207Sgabeblack@google.com{ 15913207Sgabeblack@google.com auto s = new StaticSensitivityFinder(p, f); 16013207Sgabeblack@google.com Port *port = Port::fromPort(f->port()); 16113207Sgabeblack@google.com port->sensitive(s); 16213207Sgabeblack@google.com p->addStatic(s); 16313207Sgabeblack@google.com} 16413207Sgabeblack@google.com 16513207Sgabeblack@google.com 16613207Sgabeblack@google.comStaticSensitivityInterface::StaticSensitivityInterface( 16713207Sgabeblack@google.com Process *p, const sc_core::sc_interface *i) : 16813207Sgabeblack@google.com Sensitivity(p), StaticSensitivity(p), 16913207Sgabeblack@google.com SensitivityEvent(p, &i->default_event()) 17013207Sgabeblack@google.com{} 17113207Sgabeblack@google.com 17213207Sgabeblack@google.comStaticSensitivityExport::StaticSensitivityExport( 17313207Sgabeblack@google.com Process *p, const sc_core::sc_export_base *exp) : 17413207Sgabeblack@google.com Sensitivity(p), StaticSensitivity(p), 17513207Sgabeblack@google.com SensitivityEvent(p, &exp->get_interface()->default_event()) 17613207Sgabeblack@google.com{} 17713207Sgabeblack@google.com 17813207Sgabeblack@google.comconst ::sc_core::sc_event & 17913207Sgabeblack@google.comStaticSensitivityFinder::find(::sc_core::sc_interface *i) 18013207Sgabeblack@google.com{ 18113207Sgabeblack@google.com return finder->find_event(i); 18213207Sgabeblack@google.com} 18313207Sgabeblack@google.com 18413207Sgabeblack@google.com 18513207Sgabeblack@google.com/* 18613207Sgabeblack@google.com * Dynamic sensitivities. 18713207Sgabeblack@google.com */ 18813207Sgabeblack@google.com 18913207Sgabeblack@google.comvoid 19013207Sgabeblack@google.comnewDynamicSensitivityEvent(Process *p, const sc_core::sc_event *e) 19113207Sgabeblack@google.com{ 19213207Sgabeblack@google.com auto s = new DynamicSensitivityEvent(p, e); 19313207Sgabeblack@google.com s->addToEvent(s->event); 19413207Sgabeblack@google.com p->setDynamic(s); 19513207Sgabeblack@google.com} 19613207Sgabeblack@google.com 19713207Sgabeblack@google.comvoid 19813207Sgabeblack@google.comnewDynamicSensitivityEventOrList( 19913207Sgabeblack@google.com Process *p, const sc_core::sc_event_or_list *eol) 20013207Sgabeblack@google.com{ 20113207Sgabeblack@google.com auto s = new DynamicSensitivityEventOrList(p, eol); 20213207Sgabeblack@google.com for (auto event: s->events) 20313207Sgabeblack@google.com s->addToEvent(event); 20413207Sgabeblack@google.com p->setDynamic(s); 20513207Sgabeblack@google.com} 20613207Sgabeblack@google.com 20713207Sgabeblack@google.comvoid newDynamicSensitivityEventAndList( 20813207Sgabeblack@google.com Process *p, const sc_core::sc_event_and_list *eal) 20913207Sgabeblack@google.com{ 21013207Sgabeblack@google.com auto s = new DynamicSensitivityEventAndList(p, eal); 21113207Sgabeblack@google.com for (auto event: s->events) 21213207Sgabeblack@google.com s->addToEvent(event); 21313207Sgabeblack@google.com p->setDynamic(s); 21413207Sgabeblack@google.com} 21513207Sgabeblack@google.com 21613207Sgabeblack@google.com 21713207Sgabeblack@google.comDynamicSensitivityEventOrList::DynamicSensitivityEventOrList( 21813207Sgabeblack@google.com Process *p, const sc_core::sc_event_or_list *eol) : 21913207Sgabeblack@google.com Sensitivity(p), DynamicSensitivity(p), SensitivityEvents(p, eol->events) 22013207Sgabeblack@google.com{} 22113207Sgabeblack@google.com 22213206Sgabeblack@google.combool 22313304Sgabeblack@google.comDynamicSensitivityEventOrList::notifyWork(Event *e) 22413206Sgabeblack@google.com{ 22513206Sgabeblack@google.com events.erase(e->sc_event()); 22613206Sgabeblack@google.com 22713206Sgabeblack@google.com // All the other events need this deleted from their lists since this 22813206Sgabeblack@google.com // sensitivity has been satisfied without them triggering. 22913206Sgabeblack@google.com for (auto le: events) 23013206Sgabeblack@google.com delFromEvent(le); 23113206Sgabeblack@google.com 23213206Sgabeblack@google.com satisfy(); 23313206Sgabeblack@google.com return true; 23413206Sgabeblack@google.com} 23513206Sgabeblack@google.com 23613207Sgabeblack@google.comDynamicSensitivityEventAndList::DynamicSensitivityEventAndList( 23713207Sgabeblack@google.com Process *p, const sc_core::sc_event_and_list *eal) : 23813207Sgabeblack@google.com Sensitivity(p), DynamicSensitivity(p), SensitivityEvents(p, eal->events) 23913206Sgabeblack@google.com{} 24013206Sgabeblack@google.com 24113206Sgabeblack@google.combool 24213304Sgabeblack@google.comDynamicSensitivityEventAndList::notifyWork(Event *e) 24313206Sgabeblack@google.com{ 24413206Sgabeblack@google.com events.erase(e->sc_event()); 24513206Sgabeblack@google.com 24613206Sgabeblack@google.com // This sensitivity is satisfied if all events have triggered. 24713206Sgabeblack@google.com if (events.empty()) 24813206Sgabeblack@google.com satisfy(); 24913206Sgabeblack@google.com 25013206Sgabeblack@google.com return true; 25113206Sgabeblack@google.com} 25213206Sgabeblack@google.com 25313206Sgabeblack@google.com} // namespace sc_gem5 254