sensitivity.cc revision 13207
11782SN/A/* 21782SN/A * Copyright 2018 Google, Inc. 31782SN/A * 41782SN/A * Redistribution and use in source and binary forms, with or without 51782SN/A * modification, are permitted provided that the following conditions are 61782SN/A * met: redistributions of source code must retain the above copyright 71782SN/A * notice, this list of conditions and the following disclaimer; 81782SN/A * redistributions in binary form must reproduce the above copyright 91782SN/A * notice, this list of conditions and the following disclaimer in the 101782SN/A * documentation and/or other materials provided with the distribution; 111782SN/A * neither the name of the copyright holders nor the names of its 121782SN/A * contributors may be used to endorse or promote products derived from 131782SN/A * this software without specific prior written permission. 141782SN/A * 151782SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 161782SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 171782SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 181782SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 191782SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 201782SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 211782SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 221782SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 231782SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 241782SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 251782SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 261782SN/A * 272665Ssaidi@eecs.umich.edu * Authors: Gabe Black 282665Ssaidi@eecs.umich.edu */ 291782SN/A 301782SN/A#include "systemc/core/sensitivity.hh" 311782SN/A 321782SN/A#include "systemc/core/event.hh" 331835SN/A#include "systemc/core/port.hh" 341835SN/A#include "systemc/core/scheduler.hh" 351782SN/A#include "systemc/ext/core/sc_export.hh" 361782SN/A#include "systemc/ext/core/sc_interface.hh" 371782SN/A#include "systemc/ext/core/sc_port.hh" 384762Snate@binkert.org 3911793Sbrandon.potter@amd.comnamespace sc_gem5 402158SN/A{ 414762Snate@binkert.org 424762Snate@binkert.org/* 431782SN/A * Common sensitivity interface. 442680Sktlim@umich.edu */ 458706Sandreas.hansson@arm.com 462036SN/Avoid 471782SN/ASensitivity::satisfy() 481847SN/A{ 491847SN/A process->satisfySensitivity(this); 501782SN/A} 512212SN/A 521782SN/Abool 532212SN/ASensitivity::notify(Event *e) 542158SN/A{ 551782SN/A if (process->disabled()) 561782SN/A return false; 571823SN/A return notifyWork(e); 581885SN/A} 591782SN/A 601885SN/A 611885SN/A/* 621885SN/A * Dynamic vs. static sensitivity. 631782SN/A */ 641782SN/A 652212SN/Avoid 661782SN/ADynamicSensitivity::addToEvent(const ::sc_core::sc_event *e) 671782SN/A{ 681821SN/A Event::getFromScEvent(e)->addSensitivity(this); 691821SN/A} 701821SN/A 711821SN/Avoid 722680Sktlim@umich.eduDynamicSensitivity::delFromEvent(const ::sc_core::sc_event *e) 731821SN/A{ 741821SN/A Event::getFromScEvent(e)->delSensitivity(this); 751821SN/A} 761821SN/A 775958Sgblack@eecs.umich.eduvoid 785958Sgblack@eecs.umich.eduStaticSensitivity::addToEvent(const ::sc_core::sc_event *e) 791821SN/A{ 808852Sandreas.hansson@arm.com Event::getFromScEvent(e)->addSensitivity(this); 818852Sandreas.hansson@arm.com} 821782SN/A 831782SN/Avoid 841885SN/AStaticSensitivity::delFromEvent(const ::sc_core::sc_event *e) 852680Sktlim@umich.edu{ 861885SN/A Event::getFromScEvent(e)->delSensitivity(this); 872680Sktlim@umich.edu} 882680Sktlim@umich.edu 891885SN/A 901885SN/A/* 914762Snate@binkert.org * Static sensitivities. 924762Snate@binkert.org */ 931782SN/A 944762Snate@binkert.orgvoid 951782SN/AnewStaticSensitivityEvent(Process *p, const sc_core::sc_event *e) 96{ 97 auto s = new StaticSensitivityEvent(p, e); 98 s->addToEvent(s->event); 99 p->addStatic(s); 100} 101 102void 103newStaticSensitivityInterface(Process *p, const sc_core::sc_interface *i) 104{ 105 auto s = new StaticSensitivityInterface(p, i); 106 s->addToEvent(s->event); 107 p->addStatic(s); 108} 109 110void 111newStaticSensitivityPort(Process *p, const sc_core::sc_port_base *pb) 112{ 113 auto s = new StaticSensitivityPort(p); 114 Port *port = Port::fromPort(pb); 115 port->sensitive(s); 116 p->addStatic(s); 117} 118 119void 120newStaticSensitivityExport(Process *p, const sc_core::sc_export_base *exp) 121{ 122 auto s = new StaticSensitivityExport(p, exp); 123 s->addToEvent(s->event); 124 p->addStatic(s); 125} 126 127void 128newStaticSensitivityFinder(Process *p, const sc_core::sc_event_finder *f) 129{ 130 auto s = new StaticSensitivityFinder(p, f); 131 Port *port = Port::fromPort(f->port()); 132 port->sensitive(s); 133 p->addStatic(s); 134} 135 136 137StaticSensitivityInterface::StaticSensitivityInterface( 138 Process *p, const sc_core::sc_interface *i) : 139 Sensitivity(p), StaticSensitivity(p), 140 SensitivityEvent(p, &i->default_event()) 141{} 142 143StaticSensitivityExport::StaticSensitivityExport( 144 Process *p, const sc_core::sc_export_base *exp) : 145 Sensitivity(p), StaticSensitivity(p), 146 SensitivityEvent(p, &exp->get_interface()->default_event()) 147{} 148 149const ::sc_core::sc_event & 150StaticSensitivityFinder::find(::sc_core::sc_interface *i) 151{ 152 return finder->find_event(i); 153} 154 155 156/* 157 * Dynamic sensitivities. 158 */ 159 160void 161newDynamicSensitivityEvent(Process *p, const sc_core::sc_event *e) 162{ 163 auto s = new DynamicSensitivityEvent(p, e); 164 s->addToEvent(s->event); 165 p->setDynamic(s); 166} 167 168void 169newDynamicSensitivityEventOrList( 170 Process *p, const sc_core::sc_event_or_list *eol) 171{ 172 auto s = new DynamicSensitivityEventOrList(p, eol); 173 for (auto event: s->events) 174 s->addToEvent(event); 175 p->setDynamic(s); 176} 177 178void newDynamicSensitivityEventAndList( 179 Process *p, const sc_core::sc_event_and_list *eal) 180{ 181 auto s = new DynamicSensitivityEventAndList(p, eal); 182 for (auto event: s->events) 183 s->addToEvent(event); 184 p->setDynamic(s); 185} 186 187 188DynamicSensitivityEventOrList::DynamicSensitivityEventOrList( 189 Process *p, const sc_core::sc_event_or_list *eol) : 190 Sensitivity(p), DynamicSensitivity(p), SensitivityEvents(p, eol->events) 191{} 192 193bool 194DynamicSensitivityEventOrList::notifyWork(Event *e) 195{ 196 events.erase(e->sc_event()); 197 198 // All the other events need this deleted from their lists since this 199 // sensitivity has been satisfied without them triggering. 200 for (auto le: events) 201 delFromEvent(le); 202 203 satisfy(); 204 return true; 205} 206 207DynamicSensitivityEventAndList::DynamicSensitivityEventAndList( 208 Process *p, const sc_core::sc_event_and_list *eal) : 209 Sensitivity(p), DynamicSensitivity(p), SensitivityEvents(p, eal->events) 210{} 211 212bool 213DynamicSensitivityEventAndList::notifyWork(Event *e) 214{ 215 events.erase(e->sc_event()); 216 217 // This sensitivity is satisfied if all events have triggered. 218 if (events.empty()) 219 satisfy(); 220 221 return true; 222} 223 224} // namespace sc_gem5 225