sensitivity.cc revision 13206
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" 3313206Sgabeblack@google.com#include "systemc/core/scheduler.hh" 3413206Sgabeblack@google.com#include "systemc/ext/core/sc_export.hh" 3513206Sgabeblack@google.com#include "systemc/ext/core/sc_interface.hh" 3613206Sgabeblack@google.com#include "systemc/ext/core/sc_port.hh" 3713206Sgabeblack@google.com 3813206Sgabeblack@google.comnamespace sc_gem5 3913206Sgabeblack@google.com{ 4013206Sgabeblack@google.com 4113206Sgabeblack@google.comvoid 4213206Sgabeblack@google.comSensitivity::satisfy() 4313206Sgabeblack@google.com{ 4413206Sgabeblack@google.com process->satisfySensitivity(this); 4513206Sgabeblack@google.com} 4613206Sgabeblack@google.com 4713206Sgabeblack@google.combool 4813206Sgabeblack@google.comSensitivity::notify(Event *e) 4913206Sgabeblack@google.com{ 5013206Sgabeblack@google.com if (process->disabled()) 5113206Sgabeblack@google.com return false; 5213206Sgabeblack@google.com return notifyWork(e); 5313206Sgabeblack@google.com} 5413206Sgabeblack@google.com 5513206Sgabeblack@google.com 5613206Sgabeblack@google.comvoid 5713206Sgabeblack@google.comDynamicSensitivity::addToEvent(const ::sc_core::sc_event *e) 5813206Sgabeblack@google.com{ 5913206Sgabeblack@google.com Event::getFromScEvent(e)->addSensitivity(this); 6013206Sgabeblack@google.com} 6113206Sgabeblack@google.com 6213206Sgabeblack@google.comvoid 6313206Sgabeblack@google.comDynamicSensitivity::delFromEvent(const ::sc_core::sc_event *e) 6413206Sgabeblack@google.com{ 6513206Sgabeblack@google.com Event::getFromScEvent(e)->delSensitivity(this); 6613206Sgabeblack@google.com} 6713206Sgabeblack@google.com 6813206Sgabeblack@google.comvoid 6913206Sgabeblack@google.comStaticSensitivity::addToEvent(const ::sc_core::sc_event *e) 7013206Sgabeblack@google.com{ 7113206Sgabeblack@google.com Event::getFromScEvent(e)->addSensitivity(this); 7213206Sgabeblack@google.com} 7313206Sgabeblack@google.com 7413206Sgabeblack@google.comvoid 7513206Sgabeblack@google.comStaticSensitivity::delFromEvent(const ::sc_core::sc_event *e) 7613206Sgabeblack@google.com{ 7713206Sgabeblack@google.com Event::getFromScEvent(e)->delSensitivity(this); 7813206Sgabeblack@google.com} 7913206Sgabeblack@google.com 8013206Sgabeblack@google.comvoid 8113206Sgabeblack@google.comStaticSensitivityInterface::finalize() 8213206Sgabeblack@google.com{ 8313206Sgabeblack@google.com event = &interface->default_event(); 8413206Sgabeblack@google.com SensitivityEvent::finalize(); 8513206Sgabeblack@google.com} 8613206Sgabeblack@google.com 8713206Sgabeblack@google.comvoid 8813206Sgabeblack@google.comStaticSensitivityPort::finalize() 8913206Sgabeblack@google.com{ 9013206Sgabeblack@google.com for (int i = 0; i < port->size(); i++) { 9113206Sgabeblack@google.com const ::sc_core::sc_event *event = 9213206Sgabeblack@google.com &port->_gem5Interface(i)->default_event(); 9313206Sgabeblack@google.com events.insert(event); 9413206Sgabeblack@google.com addToEvent(event); 9513206Sgabeblack@google.com } 9613206Sgabeblack@google.com} 9713206Sgabeblack@google.com 9813206Sgabeblack@google.comvoid 9913206Sgabeblack@google.comStaticSensitivityExport::finalize() 10013206Sgabeblack@google.com{ 10113206Sgabeblack@google.com event = &exp->get_interface()->default_event(); 10213206Sgabeblack@google.com SensitivityEvent::finalize(); 10313206Sgabeblack@google.com} 10413206Sgabeblack@google.com 10513206Sgabeblack@google.comvoid 10613206Sgabeblack@google.comStaticSensitivityFinder::finalize() 10713206Sgabeblack@google.com{ 10813206Sgabeblack@google.com const ::sc_core::sc_port_base *port = finder->port(); 10913206Sgabeblack@google.com int size = port->size(); 11013206Sgabeblack@google.com for (int i = 0; i < size; i++) { 11113206Sgabeblack@google.com ::sc_core::sc_interface *interface = port->_gem5Interface(i); 11213206Sgabeblack@google.com const ::sc_core::sc_event *event = &finder->find_event(interface); 11313206Sgabeblack@google.com events.insert(event); 11413206Sgabeblack@google.com addToEvent(event); 11513206Sgabeblack@google.com } 11613206Sgabeblack@google.com} 11713206Sgabeblack@google.com 11813206Sgabeblack@google.combool 11913206Sgabeblack@google.comDynamicSensitivityEventOrList::notifyWork(Event *e) 12013206Sgabeblack@google.com{ 12113206Sgabeblack@google.com events.erase(e->sc_event()); 12213206Sgabeblack@google.com 12313206Sgabeblack@google.com // All the other events need this deleted from their lists since this 12413206Sgabeblack@google.com // sensitivity has been satisfied without them triggering. 12513206Sgabeblack@google.com for (auto le: events) 12613206Sgabeblack@google.com delFromEvent(le); 12713206Sgabeblack@google.com 12813206Sgabeblack@google.com satisfy(); 12913206Sgabeblack@google.com return true; 13013206Sgabeblack@google.com} 13113206Sgabeblack@google.com 13213206Sgabeblack@google.comDynamicSensitivityEventOrList::DynamicSensitivityEventOrList( 13313206Sgabeblack@google.com Process *p, const sc_core::sc_event_or_list *eol) : 13413206Sgabeblack@google.com Sensitivity(p), DynamicSensitivity(p), events(eol->events) 13513206Sgabeblack@google.com{} 13613206Sgabeblack@google.com 13713206Sgabeblack@google.comvoid 13813206Sgabeblack@google.comDynamicSensitivityEventOrList::finalize() 13913206Sgabeblack@google.com{ 14013206Sgabeblack@google.com for (auto e: events) 14113206Sgabeblack@google.com addToEvent(e); 14213206Sgabeblack@google.com} 14313206Sgabeblack@google.com 14413206Sgabeblack@google.comvoid 14513206Sgabeblack@google.comDynamicSensitivityEventOrList::clear() 14613206Sgabeblack@google.com{ 14713206Sgabeblack@google.com for (auto e: events) 14813206Sgabeblack@google.com delFromEvent(e); 14913206Sgabeblack@google.com} 15013206Sgabeblack@google.com 15113206Sgabeblack@google.combool 15213206Sgabeblack@google.comDynamicSensitivityEventAndList::notifyWork(Event *e) 15313206Sgabeblack@google.com{ 15413206Sgabeblack@google.com events.erase(e->sc_event()); 15513206Sgabeblack@google.com 15613206Sgabeblack@google.com // This sensitivity is satisfied if all events have triggered. 15713206Sgabeblack@google.com if (events.empty()) 15813206Sgabeblack@google.com satisfy(); 15913206Sgabeblack@google.com 16013206Sgabeblack@google.com return true; 16113206Sgabeblack@google.com} 16213206Sgabeblack@google.com 16313206Sgabeblack@google.comDynamicSensitivityEventAndList::DynamicSensitivityEventAndList( 16413206Sgabeblack@google.com Process *p, const sc_core::sc_event_and_list *eal) : 16513206Sgabeblack@google.com Sensitivity(p), DynamicSensitivity(p), events(eal->events) 16613206Sgabeblack@google.com{} 16713206Sgabeblack@google.com 16813206Sgabeblack@google.comvoid 16913206Sgabeblack@google.comDynamicSensitivityEventAndList::finalize() 17013206Sgabeblack@google.com{ 17113206Sgabeblack@google.com for (auto e: events) 17213206Sgabeblack@google.com addToEvent(e); 17313206Sgabeblack@google.com} 17413206Sgabeblack@google.com 17513206Sgabeblack@google.comvoid 17613206Sgabeblack@google.comDynamicSensitivityEventAndList::clear() 17713206Sgabeblack@google.com{ 17813206Sgabeblack@google.com for (auto e: events) 17913206Sgabeblack@google.com delFromEvent(e); 18013206Sgabeblack@google.com} 18113206Sgabeblack@google.com 18213206Sgabeblack@google.com} // namespace sc_gem5 183