sensitivity.cc revision 13317
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
3213288Sgabeblack@google.com#include "base/logging.hh"
3313206Sgabeblack@google.com#include "systemc/core/event.hh"
3413207Sgabeblack@google.com#include "systemc/core/port.hh"
3513208Sgabeblack@google.com#include "systemc/core/process.hh"
3613206Sgabeblack@google.com#include "systemc/core/scheduler.hh"
3713260Sgabeblack@google.com#include "systemc/ext/channel/sc_in.hh"
3813260Sgabeblack@google.com#include "systemc/ext/channel/sc_inout.hh"
3913260Sgabeblack@google.com#include "systemc/ext/channel/sc_out.hh"
4013317Sgabeblack@google.com#include "systemc/ext/core/messages.hh"
4113206Sgabeblack@google.com#include "systemc/ext/core/sc_export.hh"
4213206Sgabeblack@google.com#include "systemc/ext/core/sc_interface.hh"
4313206Sgabeblack@google.com#include "systemc/ext/core/sc_port.hh"
4413206Sgabeblack@google.com
4513206Sgabeblack@google.comnamespace sc_gem5
4613206Sgabeblack@google.com{
4713206Sgabeblack@google.com
4813207Sgabeblack@google.com/*
4913207Sgabeblack@google.com * Common sensitivity interface.
5013207Sgabeblack@google.com */
5113207Sgabeblack@google.com
5213206Sgabeblack@google.comvoid
5313206Sgabeblack@google.comSensitivity::satisfy()
5413206Sgabeblack@google.com{
5513206Sgabeblack@google.com    process->satisfySensitivity(this);
5613206Sgabeblack@google.com}
5713206Sgabeblack@google.com
5813206Sgabeblack@google.combool
5913304Sgabeblack@google.comSensitivity::notifyWork(Event *e)
6013304Sgabeblack@google.com{
6113304Sgabeblack@google.com    satisfy();
6213304Sgabeblack@google.com    return true;
6313304Sgabeblack@google.com}
6413304Sgabeblack@google.com
6513304Sgabeblack@google.combool
6613206Sgabeblack@google.comSensitivity::notify(Event *e)
6713206Sgabeblack@google.com{
6813304Sgabeblack@google.com    if (scheduler.current() == process) {
6913304Sgabeblack@google.com        static bool warned = false;
7013304Sgabeblack@google.com        if (!warned) {
7113317Sgabeblack@google.com            SC_REPORT_WARNING(sc_core::SC_ID_IMMEDIATE_SELF_NOTIFICATION_,
7213317Sgabeblack@google.com                    process->name());
7313304Sgabeblack@google.com            warned = true;
7413304Sgabeblack@google.com        }
7513304Sgabeblack@google.com        return false;
7613304Sgabeblack@google.com    }
7713304Sgabeblack@google.com
7813206Sgabeblack@google.com    if (process->disabled())
7913206Sgabeblack@google.com        return false;
8013304Sgabeblack@google.com
8113304Sgabeblack@google.com    return notifyWork(e);
8213206Sgabeblack@google.com}
8313206Sgabeblack@google.com
8413208Sgabeblack@google.combool
8513208Sgabeblack@google.comSensitivity::ofMethod()
8613208Sgabeblack@google.com{
8713208Sgabeblack@google.com    return process->procKind() == sc_core::SC_METHOD_PROC_;
8813208Sgabeblack@google.com}
8913208Sgabeblack@google.com
9013206Sgabeblack@google.com
9113207Sgabeblack@google.com/*
9213207Sgabeblack@google.com * Dynamic vs. static sensitivity.
9313207Sgabeblack@google.com */
9413207Sgabeblack@google.com
9513206Sgabeblack@google.comvoid
9613206Sgabeblack@google.comDynamicSensitivity::addToEvent(const ::sc_core::sc_event *e)
9713206Sgabeblack@google.com{
9813206Sgabeblack@google.com    Event::getFromScEvent(e)->addSensitivity(this);
9913206Sgabeblack@google.com}
10013206Sgabeblack@google.com
10113206Sgabeblack@google.comvoid
10213206Sgabeblack@google.comDynamicSensitivity::delFromEvent(const ::sc_core::sc_event *e)
10313206Sgabeblack@google.com{
10413206Sgabeblack@google.com    Event::getFromScEvent(e)->delSensitivity(this);
10513206Sgabeblack@google.com}
10613206Sgabeblack@google.com
10713206Sgabeblack@google.comvoid
10813206Sgabeblack@google.comStaticSensitivity::addToEvent(const ::sc_core::sc_event *e)
10913206Sgabeblack@google.com{
11013206Sgabeblack@google.com    Event::getFromScEvent(e)->addSensitivity(this);
11113206Sgabeblack@google.com}
11213206Sgabeblack@google.com
11313206Sgabeblack@google.comvoid
11413206Sgabeblack@google.comStaticSensitivity::delFromEvent(const ::sc_core::sc_event *e)
11513206Sgabeblack@google.com{
11613206Sgabeblack@google.com    Event::getFromScEvent(e)->delSensitivity(this);
11713206Sgabeblack@google.com}
11813206Sgabeblack@google.com
11913207Sgabeblack@google.com
12013207Sgabeblack@google.com/*
12113207Sgabeblack@google.com * Static sensitivities.
12213207Sgabeblack@google.com */
12313207Sgabeblack@google.com
12413206Sgabeblack@google.comvoid
12513207Sgabeblack@google.comnewStaticSensitivityEvent(Process *p, const sc_core::sc_event *e)
12613206Sgabeblack@google.com{
12713207Sgabeblack@google.com    auto s = new StaticSensitivityEvent(p, e);
12813207Sgabeblack@google.com    s->addToEvent(s->event);
12913207Sgabeblack@google.com    p->addStatic(s);
13013206Sgabeblack@google.com}
13113206Sgabeblack@google.com
13213206Sgabeblack@google.comvoid
13313207Sgabeblack@google.comnewStaticSensitivityInterface(Process *p, const sc_core::sc_interface *i)
13413206Sgabeblack@google.com{
13513207Sgabeblack@google.com    auto s = new StaticSensitivityInterface(p, i);
13613207Sgabeblack@google.com    s->addToEvent(s->event);
13713207Sgabeblack@google.com    p->addStatic(s);
13813206Sgabeblack@google.com}
13913206Sgabeblack@google.com
14013206Sgabeblack@google.comvoid
14113207Sgabeblack@google.comnewStaticSensitivityPort(Process *p, const sc_core::sc_port_base *pb)
14213206Sgabeblack@google.com{
14313207Sgabeblack@google.com    auto s = new StaticSensitivityPort(p);
14413207Sgabeblack@google.com    Port *port = Port::fromPort(pb);
14513207Sgabeblack@google.com    port->sensitive(s);
14613207Sgabeblack@google.com    p->addStatic(s);
14713206Sgabeblack@google.com}
14813206Sgabeblack@google.com
14913206Sgabeblack@google.comvoid
15013207Sgabeblack@google.comnewStaticSensitivityExport(Process *p, const sc_core::sc_export_base *exp)
15113206Sgabeblack@google.com{
15213207Sgabeblack@google.com    auto s = new StaticSensitivityExport(p, exp);
15313207Sgabeblack@google.com    s->addToEvent(s->event);
15413207Sgabeblack@google.com    p->addStatic(s);
15513206Sgabeblack@google.com}
15613206Sgabeblack@google.com
15713207Sgabeblack@google.comvoid
15813207Sgabeblack@google.comnewStaticSensitivityFinder(Process *p, const sc_core::sc_event_finder *f)
15913207Sgabeblack@google.com{
16013207Sgabeblack@google.com    auto s = new StaticSensitivityFinder(p, f);
16113207Sgabeblack@google.com    Port *port = Port::fromPort(f->port());
16213207Sgabeblack@google.com    port->sensitive(s);
16313207Sgabeblack@google.com    p->addStatic(s);
16413207Sgabeblack@google.com}
16513207Sgabeblack@google.com
16613207Sgabeblack@google.com
16713207Sgabeblack@google.comStaticSensitivityInterface::StaticSensitivityInterface(
16813207Sgabeblack@google.com        Process *p, const sc_core::sc_interface *i) :
16913207Sgabeblack@google.com    Sensitivity(p), StaticSensitivity(p),
17013207Sgabeblack@google.com    SensitivityEvent(p, &i->default_event())
17113207Sgabeblack@google.com{}
17213207Sgabeblack@google.com
17313207Sgabeblack@google.comStaticSensitivityExport::StaticSensitivityExport(
17413207Sgabeblack@google.com        Process *p, const sc_core::sc_export_base *exp) :
17513207Sgabeblack@google.com    Sensitivity(p), StaticSensitivity(p),
17613207Sgabeblack@google.com    SensitivityEvent(p, &exp->get_interface()->default_event())
17713207Sgabeblack@google.com{}
17813207Sgabeblack@google.com
17913207Sgabeblack@google.comconst ::sc_core::sc_event &
18013207Sgabeblack@google.comStaticSensitivityFinder::find(::sc_core::sc_interface *i)
18113207Sgabeblack@google.com{
18213207Sgabeblack@google.com    return finder->find_event(i);
18313207Sgabeblack@google.com}
18413207Sgabeblack@google.com
18513207Sgabeblack@google.com
18613207Sgabeblack@google.com/*
18713207Sgabeblack@google.com * Dynamic sensitivities.
18813207Sgabeblack@google.com */
18913207Sgabeblack@google.com
19013207Sgabeblack@google.comvoid
19113207Sgabeblack@google.comnewDynamicSensitivityEvent(Process *p, const sc_core::sc_event *e)
19213207Sgabeblack@google.com{
19313207Sgabeblack@google.com    auto s = new DynamicSensitivityEvent(p, e);
19413207Sgabeblack@google.com    s->addToEvent(s->event);
19513207Sgabeblack@google.com    p->setDynamic(s);
19613207Sgabeblack@google.com}
19713207Sgabeblack@google.com
19813207Sgabeblack@google.comvoid
19913207Sgabeblack@google.comnewDynamicSensitivityEventOrList(
20013207Sgabeblack@google.com        Process *p, const sc_core::sc_event_or_list *eol)
20113207Sgabeblack@google.com{
20213207Sgabeblack@google.com    auto s = new DynamicSensitivityEventOrList(p, eol);
20313207Sgabeblack@google.com    for (auto event: s->events)
20413207Sgabeblack@google.com        s->addToEvent(event);
20513207Sgabeblack@google.com    p->setDynamic(s);
20613207Sgabeblack@google.com}
20713207Sgabeblack@google.com
20813207Sgabeblack@google.comvoid newDynamicSensitivityEventAndList(
20913207Sgabeblack@google.com        Process *p, const sc_core::sc_event_and_list *eal)
21013207Sgabeblack@google.com{
21113207Sgabeblack@google.com    auto s = new DynamicSensitivityEventAndList(p, eal);
21213207Sgabeblack@google.com    for (auto event: s->events)
21313207Sgabeblack@google.com        s->addToEvent(event);
21413207Sgabeblack@google.com    p->setDynamic(s);
21513207Sgabeblack@google.com}
21613207Sgabeblack@google.com
21713207Sgabeblack@google.com
21813207Sgabeblack@google.comDynamicSensitivityEventOrList::DynamicSensitivityEventOrList(
21913207Sgabeblack@google.com        Process *p, const sc_core::sc_event_or_list *eol) :
22013207Sgabeblack@google.com    Sensitivity(p), DynamicSensitivity(p), SensitivityEvents(p, eol->events)
22113207Sgabeblack@google.com{}
22213207Sgabeblack@google.com
22313206Sgabeblack@google.combool
22413304Sgabeblack@google.comDynamicSensitivityEventOrList::notifyWork(Event *e)
22513206Sgabeblack@google.com{
22613206Sgabeblack@google.com    events.erase(e->sc_event());
22713206Sgabeblack@google.com
22813206Sgabeblack@google.com    // All the other events need this deleted from their lists since this
22913206Sgabeblack@google.com    // sensitivity has been satisfied without them triggering.
23013206Sgabeblack@google.com    for (auto le: events)
23113206Sgabeblack@google.com        delFromEvent(le);
23213206Sgabeblack@google.com
23313206Sgabeblack@google.com    satisfy();
23413206Sgabeblack@google.com    return true;
23513206Sgabeblack@google.com}
23613206Sgabeblack@google.com
23713207Sgabeblack@google.comDynamicSensitivityEventAndList::DynamicSensitivityEventAndList(
23813207Sgabeblack@google.com        Process *p, const sc_core::sc_event_and_list *eal) :
23913207Sgabeblack@google.com    Sensitivity(p), DynamicSensitivity(p), SensitivityEvents(p, eal->events)
24013206Sgabeblack@google.com{}
24113206Sgabeblack@google.com
24213206Sgabeblack@google.combool
24313304Sgabeblack@google.comDynamicSensitivityEventAndList::notifyWork(Event *e)
24413206Sgabeblack@google.com{
24513206Sgabeblack@google.com    events.erase(e->sc_event());
24613206Sgabeblack@google.com
24713206Sgabeblack@google.com    // This sensitivity is satisfied if all events have triggered.
24813206Sgabeblack@google.com    if (events.empty())
24913206Sgabeblack@google.com        satisfy();
25013206Sgabeblack@google.com
25113206Sgabeblack@google.com    return true;
25213206Sgabeblack@google.com}
25313206Sgabeblack@google.com
25413206Sgabeblack@google.com} // namespace sc_gem5
255