sensitivity.cc revision 13317
12139SN/A/*
22139SN/A * Copyright 2018 Google, Inc.
313610Sgiacomo.gabrielli@arm.com *
412109SRekai.GonzalezAlberquilla@arm.com * Redistribution and use in source and binary forms, with or without
512109SRekai.GonzalezAlberquilla@arm.com * modification, are permitted provided that the following conditions are
612109SRekai.GonzalezAlberquilla@arm.com * met: redistributions of source code must retain the above copyright
712109SRekai.GonzalezAlberquilla@arm.com * notice, this list of conditions and the following disclaimer;
812109SRekai.GonzalezAlberquilla@arm.com * redistributions in binary form must reproduce the above copyright
912109SRekai.GonzalezAlberquilla@arm.com * notice, this list of conditions and the following disclaimer in the
1012109SRekai.GonzalezAlberquilla@arm.com * documentation and/or other materials provided with the distribution;
1112109SRekai.GonzalezAlberquilla@arm.com * neither the name of the copyright holders nor the names of its
1212109SRekai.GonzalezAlberquilla@arm.com * contributors may be used to endorse or promote products derived from
1312109SRekai.GonzalezAlberquilla@arm.com * this software without specific prior written permission.
1412109SRekai.GonzalezAlberquilla@arm.com *
152139SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
162139SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
172139SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
182139SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
192139SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
202139SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
212139SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
222139SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
232139SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
242139SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
252139SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
262139SN/A *
272139SN/A * Authors: Gabe Black
282139SN/A */
292139SN/A
302139SN/A#include "systemc/core/sensitivity.hh"
312139SN/A
322139SN/A#include "base/logging.hh"
332139SN/A#include "systemc/core/event.hh"
342139SN/A#include "systemc/core/port.hh"
352139SN/A#include "systemc/core/process.hh"
362139SN/A#include "systemc/core/scheduler.hh"
372139SN/A#include "systemc/ext/channel/sc_in.hh"
382139SN/A#include "systemc/ext/channel/sc_inout.hh"
392139SN/A#include "systemc/ext/channel/sc_out.hh"
402665Ssaidi@eecs.umich.edu#include "systemc/ext/core/messages.hh"
412665Ssaidi@eecs.umich.edu#include "systemc/ext/core/sc_export.hh"
422139SN/A#include "systemc/ext/core/sc_interface.hh"
434202Sbinkertn@umich.edu#include "systemc/ext/core/sc_port.hh"
448961Sgblack@eecs.umich.edu
4510196SCurtis.Dunham@arm.comnamespace sc_gem5
462139SN/A{
4712246Sgabeblack@google.com
4812246Sgabeblack@google.com/*
494202Sbinkertn@umich.edu * Common sensitivity interface.
502152SN/A */
512152SN/A
522139SN/Avoid
532139SN/ASensitivity::satisfy()
542139SN/A{
552139SN/A    process->satisfySensitivity(this);
562139SN/A}
572152SN/A
582152SN/Abool
592139SN/ASensitivity::notifyWork(Event *e)
6012015Sgabeblack@google.com{
6112015Sgabeblack@google.com    satisfy();
629020Sgblack@eecs.umich.edu    return true;
634781Snate@binkert.org}
647799Sgblack@eecs.umich.edu
654781Snate@binkert.orgbool
664781Snate@binkert.orgSensitivity::notify(Event *e)
673170Sstever@eecs.umich.edu{
685664Sgblack@eecs.umich.edu    if (scheduler.current() == process) {
698105Sgblack@eecs.umich.edu        static bool warned = false;
706179Sksewell@umich.edu        if (!warned) {
714781Snate@binkert.org            SC_REPORT_WARNING(sc_core::SC_ID_IMMEDIATE_SELF_NOTIFICATION_,
7210553Salexandru.dutu@amd.com                    process->name());
736329Sgblack@eecs.umich.edu            warned = true;
744781Snate@binkert.org        }
754781Snate@binkert.org        return false;
764781Snate@binkert.org    }
774781Snate@binkert.org
784781Snate@binkert.org    if (process->disabled())
7912015Sgabeblack@google.com        return false;
8012015Sgabeblack@google.com
812152SN/A    return notifyWork(e);
8211308Santhony.gutierrez@amd.com}
8312016Sgabeblack@google.com
8412016Sgabeblack@google.combool
8511308Santhony.gutierrez@amd.comSensitivity::ofMethod()
8611696Santhony.gutierrez@amd.com{
8711308Santhony.gutierrez@amd.com    return process->procKind() == sc_core::SC_METHOD_PROC_;
8812016Sgabeblack@google.com}
8912016Sgabeblack@google.com
9011308Santhony.gutierrez@amd.com
912152SN/A/*
922152SN/A * Dynamic vs. static sensitivity.
932152SN/A */
942152SN/A
952152SN/Avoid
962152SN/ADynamicSensitivity::addToEvent(const ::sc_core::sc_event *e)
972152SN/A{
982152SN/A    Event::getFromScEvent(e)->addSensitivity(this);
992152SN/A}
1002152SN/A
10112222Sgabeblack@google.comvoid
1022152SN/ADynamicSensitivity::delFromEvent(const ::sc_core::sc_event *e)
10312222Sgabeblack@google.com{
10412222Sgabeblack@google.com    Event::getFromScEvent(e)->delSensitivity(this);
10512222Sgabeblack@google.com}
10612222Sgabeblack@google.com
1072152SN/Avoid
10812222Sgabeblack@google.comStaticSensitivity::addToEvent(const ::sc_core::sc_event *e)
10912222Sgabeblack@google.com{
11012222Sgabeblack@google.com    Event::getFromScEvent(e)->addSensitivity(this);
11112222Sgabeblack@google.com}
1122152SN/A
1132152SN/Avoid
1142152SN/AStaticSensitivity::delFromEvent(const ::sc_core::sc_event *e)
1152152SN/A{
1162152SN/A    Event::getFromScEvent(e)->delSensitivity(this);
1172152SN/A}
11812222Sgabeblack@google.com
11912222Sgabeblack@google.com
1206993Snate@binkert.org/*
1216998Snate@binkert.org * Static sensitivities.
1226998Snate@binkert.org */
1236998Snate@binkert.org
12412222Sgabeblack@google.comvoid
12512222Sgabeblack@google.comnewStaticSensitivityEvent(Process *p, const sc_core::sc_event *e)
12612222Sgabeblack@google.com{
1276993Snate@binkert.org    auto s = new StaticSensitivityEvent(p, e);
1286993Snate@binkert.org    s->addToEvent(s->event);
12910319SAndreas.Sandberg@ARM.com    p->addStatic(s);
1306993Snate@binkert.org}
1312152SN/A
13212222Sgabeblack@google.comvoid
1332152SN/AnewStaticSensitivityInterface(Process *p, const sc_core::sc_interface *i)
13412222Sgabeblack@google.com{
1355944Sgblack@eecs.umich.edu    auto s = new StaticSensitivityInterface(p, i);
13610196SCurtis.Dunham@arm.com    s->addToEvent(s->event);
13712222Sgabeblack@google.com    p->addStatic(s);
13812222Sgabeblack@google.com}
13912222Sgabeblack@google.com
14012222Sgabeblack@google.comvoid
14110196SCurtis.Dunham@arm.comnewStaticSensitivityPort(Process *p, const sc_core::sc_port_base *pb)
14212222Sgabeblack@google.com{
14312222Sgabeblack@google.com    auto s = new StaticSensitivityPort(p);
14412222Sgabeblack@google.com    Port *port = Port::fromPort(pb);
14512222Sgabeblack@google.com    port->sensitive(s);
14610196SCurtis.Dunham@arm.com    p->addStatic(s);
14712222Sgabeblack@google.com}
14812222Sgabeblack@google.com
14912222Sgabeblack@google.comvoid
15012222Sgabeblack@google.comnewStaticSensitivityExport(Process *p, const sc_core::sc_export_base *exp)
15112222Sgabeblack@google.com{
15212222Sgabeblack@google.com    auto s = new StaticSensitivityExport(p, exp);
15310196SCurtis.Dunham@arm.com    s->addToEvent(s->event);
15412222Sgabeblack@google.com    p->addStatic(s);
15512222Sgabeblack@google.com}
15612222Sgabeblack@google.com
15712222Sgabeblack@google.comvoid
15812222Sgabeblack@google.comnewStaticSensitivityFinder(Process *p, const sc_core::sc_event_finder *f)
15912222Sgabeblack@google.com{
16012222Sgabeblack@google.com    auto s = new StaticSensitivityFinder(p, f);
16110196SCurtis.Dunham@arm.com    Port *port = Port::fromPort(f->port());
16212222Sgabeblack@google.com    port->sensitive(s);
16312222Sgabeblack@google.com    p->addStatic(s);
16412222Sgabeblack@google.com}
16512222Sgabeblack@google.com
16612222Sgabeblack@google.com
16712222Sgabeblack@google.comStaticSensitivityInterface::StaticSensitivityInterface(
16810196SCurtis.Dunham@arm.com        Process *p, const sc_core::sc_interface *i) :
16912222Sgabeblack@google.com    Sensitivity(p), StaticSensitivity(p),
17012222Sgabeblack@google.com    SensitivityEvent(p, &i->default_event())
17112222Sgabeblack@google.com{}
17212222Sgabeblack@google.com
17312222Sgabeblack@google.comStaticSensitivityExport::StaticSensitivityExport(
17412222Sgabeblack@google.com        Process *p, const sc_core::sc_export_base *exp) :
17512222Sgabeblack@google.com    Sensitivity(p), StaticSensitivity(p),
17612222Sgabeblack@google.com    SensitivityEvent(p, &exp->get_interface()->default_event())
17712222Sgabeblack@google.com{}
17812222Sgabeblack@google.com
17912222Sgabeblack@google.comconst ::sc_core::sc_event &
18010196SCurtis.Dunham@arm.comStaticSensitivityFinder::find(::sc_core::sc_interface *i)
18112222Sgabeblack@google.com{
18212222Sgabeblack@google.com    return finder->find_event(i);
18312222Sgabeblack@google.com}
18412222Sgabeblack@google.com
18512222Sgabeblack@google.com
18612222Sgabeblack@google.com/*
18712222Sgabeblack@google.com * Dynamic sensitivities.
18812222Sgabeblack@google.com */
18912222Sgabeblack@google.com
19012222Sgabeblack@google.comvoid
19112222Sgabeblack@google.comnewDynamicSensitivityEvent(Process *p, const sc_core::sc_event *e)
19212222Sgabeblack@google.com{
19312222Sgabeblack@google.com    auto s = new DynamicSensitivityEvent(p, e);
19412222Sgabeblack@google.com    s->addToEvent(s->event);
19512222Sgabeblack@google.com    p->setDynamic(s);
19612222Sgabeblack@google.com}
19712222Sgabeblack@google.com
19812222Sgabeblack@google.comvoid
19912222Sgabeblack@google.comnewDynamicSensitivityEventOrList(
20012222Sgabeblack@google.com        Process *p, const sc_core::sc_event_or_list *eol)
20112222Sgabeblack@google.com{
20212222Sgabeblack@google.com    auto s = new DynamicSensitivityEventOrList(p, eol);
20312222Sgabeblack@google.com    for (auto event: s->events)
20412222Sgabeblack@google.com        s->addToEvent(event);
20512222Sgabeblack@google.com    p->setDynamic(s);
20612222Sgabeblack@google.com}
20712222Sgabeblack@google.com
20812222Sgabeblack@google.comvoid newDynamicSensitivityEventAndList(
20912222Sgabeblack@google.com        Process *p, const sc_core::sc_event_and_list *eal)
21012222Sgabeblack@google.com{
21112222Sgabeblack@google.com    auto s = new DynamicSensitivityEventAndList(p, eal);
21212222Sgabeblack@google.com    for (auto event: s->events)
21312222Sgabeblack@google.com        s->addToEvent(event);
21412222Sgabeblack@google.com    p->setDynamic(s);
21512222Sgabeblack@google.com}
21612222Sgabeblack@google.com
21712222Sgabeblack@google.com
21812222Sgabeblack@google.comDynamicSensitivityEventOrList::DynamicSensitivityEventOrList(
21912222Sgabeblack@google.com        Process *p, const sc_core::sc_event_or_list *eol) :
22012222Sgabeblack@google.com    Sensitivity(p), DynamicSensitivity(p), SensitivityEvents(p, eol->events)
22112222Sgabeblack@google.com{}
22212222Sgabeblack@google.com
22312222Sgabeblack@google.combool
22412222Sgabeblack@google.comDynamicSensitivityEventOrList::notifyWork(Event *e)
22510196SCurtis.Dunham@arm.com{
2268335Snate@binkert.org    events.erase(e->sc_event());
2278335Snate@binkert.org
22812109SRekai.GonzalezAlberquilla@arm.com    // All the other events need this deleted from their lists since this
22913610Sgiacomo.gabrielli@arm.com    // sensitivity has been satisfied without them triggering.
2309920Syasuko.eckert@amd.com    for (auto le: events)
2318335Snate@binkert.org        delFromEvent(le);
23213610Sgiacomo.gabrielli@arm.com
23313610Sgiacomo.gabrielli@arm.com    satisfy();
234    return true;
235}
236
237DynamicSensitivityEventAndList::DynamicSensitivityEventAndList(
238        Process *p, const sc_core::sc_event_and_list *eal) :
239    Sensitivity(p), DynamicSensitivity(p), SensitivityEvents(p, eal->events)
240{}
241
242bool
243DynamicSensitivityEventAndList::notifyWork(Event *e)
244{
245    events.erase(e->sc_event());
246
247    // This sensitivity is satisfied if all events have triggered.
248    if (events.empty())
249        satisfy();
250
251    return true;
252}
253
254} // namespace sc_gem5
255