sensitivity.cc revision 13317:36c574a4036e
110515SN/A/*
210515SN/A * Copyright 2018 Google, Inc.
310515SN/A *
410515SN/A * Redistribution and use in source and binary forms, with or without
510515SN/A * modification, are permitted provided that the following conditions are
610515SN/A * met: redistributions of source code must retain the above copyright
710515SN/A * notice, this list of conditions and the following disclaimer;
810515SN/A * redistributions in binary form must reproduce the above copyright
910515SN/A * notice, this list of conditions and the following disclaimer in the
1010515SN/A * documentation and/or other materials provided with the distribution;
1110515SN/A * neither the name of the copyright holders nor the names of its
1210515SN/A * contributors may be used to endorse or promote products derived from
1310515SN/A * this software without specific prior written permission.
1410515SN/A *
1511570SCurtis.Dunham@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1610515SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1710515SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1810515SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1911570SCurtis.Dunham@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2011570SCurtis.Dunham@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2110515SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2210515SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2310515SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2411570SCurtis.Dunham@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2510515SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2610515SN/A *
2710515SN/A * Authors: Gabe Black
2811570SCurtis.Dunham@arm.com */
2910515SN/A
3010515SN/A#include "systemc/core/sensitivity.hh"
3110515SN/A
3210515SN/A#include "base/logging.hh"
3311570SCurtis.Dunham@arm.com#include "systemc/core/event.hh"
3410515SN/A#include "systemc/core/port.hh"
3510515SN/A#include "systemc/core/process.hh"
3610515SN/A#include "systemc/core/scheduler.hh"
3710515SN/A#include "systemc/ext/channel/sc_in.hh"
3810515SN/A#include "systemc/ext/channel/sc_inout.hh"
3910515SN/A#include "systemc/ext/channel/sc_out.hh"
4010515SN/A#include "systemc/ext/core/messages.hh"
4110736SN/A#include "systemc/ext/core/sc_export.hh"
4210515SN/A#include "systemc/ext/core/sc_interface.hh"
4311167Sjthestness@gmail.com#include "systemc/ext/core/sc_port.hh"
4410515SN/A
4511570SCurtis.Dunham@arm.comnamespace sc_gem5
4611570SCurtis.Dunham@arm.com{
4711570SCurtis.Dunham@arm.com
4810515SN/A/*
4910515SN/A * Common sensitivity interface.
5010515SN/A */
5111570SCurtis.Dunham@arm.com
5211570SCurtis.Dunham@arm.comvoid
5310515SN/ASensitivity::satisfy()
5410515SN/A{
5511570SCurtis.Dunham@arm.com    process->satisfySensitivity(this);
5611570SCurtis.Dunham@arm.com}
5710515SN/A
5810515SN/Abool
5910515SN/ASensitivity::notifyWork(Event *e)
6010515SN/A{
6110515SN/A    satisfy();
6210515SN/A    return true;
6310515SN/A}
6410515SN/A
6510515SN/Abool
6610515SN/ASensitivity::notify(Event *e)
6710515SN/A{
6810515SN/A    if (scheduler.current() == process) {
6911570SCurtis.Dunham@arm.com        static bool warned = false;
7010515SN/A        if (!warned) {
7110515SN/A            SC_REPORT_WARNING(sc_core::SC_ID_IMMEDIATE_SELF_NOTIFICATION_,
7211570SCurtis.Dunham@arm.com                    process->name());
7311570SCurtis.Dunham@arm.com            warned = true;
7411570SCurtis.Dunham@arm.com        }
7511570SCurtis.Dunham@arm.com        return false;
7610515SN/A    }
7710515SN/A
7810515SN/A    if (process->disabled())
7910515SN/A        return false;
8010515SN/A
8110515SN/A    return notifyWork(e);
8210515SN/A}
8310515SN/A
8410515SN/Abool
8510515SN/ASensitivity::ofMethod()
8610515SN/A{
8710515SN/A    return process->procKind() == sc_core::SC_METHOD_PROC_;
8810515SN/A}
8910515SN/A
9010515SN/A
9110515SN/A/*
9210515SN/A * Dynamic vs. static sensitivity.
9310515SN/A */
9410515SN/A
9510515SN/Avoid
9610515SN/ADynamicSensitivity::addToEvent(const ::sc_core::sc_event *e)
9710515SN/A{
9810515SN/A    Event::getFromScEvent(e)->addSensitivity(this);
9910515SN/A}
10010515SN/A
10110515SN/Avoid
10211570SCurtis.Dunham@arm.comDynamicSensitivity::delFromEvent(const ::sc_core::sc_event *e)
10310515SN/A{
10410515SN/A    Event::getFromScEvent(e)->delSensitivity(this);
10510515SN/A}
10610515SN/A
10710515SN/Avoid
10810515SN/AStaticSensitivity::addToEvent(const ::sc_core::sc_event *e)
10910515SN/A{
11010515SN/A    Event::getFromScEvent(e)->addSensitivity(this);
11110515SN/A}
11210515SN/A
11310515SN/Avoid
11410515SN/AStaticSensitivity::delFromEvent(const ::sc_core::sc_event *e)
11510515SN/A{
11610515SN/A    Event::getFromScEvent(e)->delSensitivity(this);
11710515SN/A}
11810515SN/A
11910515SN/A
12011570SCurtis.Dunham@arm.com/*
12110515SN/A * Static sensitivities.
12210515SN/A */
12310515SN/A
12410515SN/Avoid
12510515SN/AnewStaticSensitivityEvent(Process *p, const sc_core::sc_event *e)
12610515SN/A{
12710515SN/A    auto s = new StaticSensitivityEvent(p, e);
12810515SN/A    s->addToEvent(s->event);
12910515SN/A    p->addStatic(s);
13010515SN/A}
13110515SN/A
13210515SN/Avoid
13310515SN/AnewStaticSensitivityInterface(Process *p, const sc_core::sc_interface *i)
13410515SN/A{
13510515SN/A    auto s = new StaticSensitivityInterface(p, i);
13610515SN/A    s->addToEvent(s->event);
13710515SN/A    p->addStatic(s);
13810515SN/A}
13911570SCurtis.Dunham@arm.com
14011570SCurtis.Dunham@arm.comvoid
14111570SCurtis.Dunham@arm.comnewStaticSensitivityPort(Process *p, const sc_core::sc_port_base *pb)
14211570SCurtis.Dunham@arm.com{
14310515SN/A    auto s = new StaticSensitivityPort(p);
14410515SN/A    Port *port = Port::fromPort(pb);
14510515SN/A    port->sensitive(s);
14610515SN/A    p->addStatic(s);
14710515SN/A}
14810515SN/A
14910515SN/Avoid
15010515SN/AnewStaticSensitivityExport(Process *p, const sc_core::sc_export_base *exp)
15110515SN/A{
15210515SN/A    auto s = new StaticSensitivityExport(p, exp);
15310515SN/A    s->addToEvent(s->event);
15410515SN/A    p->addStatic(s);
15510515SN/A}
15610515SN/A
15710515SN/Avoid
15811103Snilay@cs.wisc.edunewStaticSensitivityFinder(Process *p, const sc_core::sc_event_finder *f)
15910515SN/A{
16010515SN/A    auto s = new StaticSensitivityFinder(p, f);
16110515SN/A    Port *port = Port::fromPort(f->port());
16210515SN/A    port->sensitive(s);
16311239Sandreas.sandberg@arm.com    p->addStatic(s);
16411570SCurtis.Dunham@arm.com}
16510636SN/A
16610515SN/A
16710515SN/AStaticSensitivityInterface::StaticSensitivityInterface(
16810900Snilay@cs.wisc.edu        Process *p, const sc_core::sc_interface *i) :
16910515SN/A    Sensitivity(p), StaticSensitivity(p),
17010515SN/A    SensitivityEvent(p, &i->default_event())
17111570SCurtis.Dunham@arm.com{}
17211570SCurtis.Dunham@arm.com
17311570SCurtis.Dunham@arm.comStaticSensitivityExport::StaticSensitivityExport(
17411570SCurtis.Dunham@arm.com        Process *p, const sc_core::sc_export_base *exp) :
17510515SN/A    Sensitivity(p), StaticSensitivity(p),
17610515SN/A    SensitivityEvent(p, &exp->get_interface()->default_event())
17710515SN/A{}
17810515SN/A
17910515SN/Aconst ::sc_core::sc_event &
18010515SN/AStaticSensitivityFinder::find(::sc_core::sc_interface *i)
18110515SN/A{
18210515SN/A    return finder->find_event(i);
18310515SN/A}
18411239Sandreas.sandberg@arm.com
18510515SN/A
18610515SN/A/*
18710515SN/A * Dynamic sensitivities.
18810515SN/A */
18910515SN/A
19010515SN/Avoid
19110515SN/AnewDynamicSensitivityEvent(Process *p, const sc_core::sc_event *e)
19210515SN/A{
19311570SCurtis.Dunham@arm.com    auto s = new DynamicSensitivityEvent(p, e);
19410515SN/A    s->addToEvent(s->event);
19510515SN/A    p->setDynamic(s);
19611570SCurtis.Dunham@arm.com}
19711570SCurtis.Dunham@arm.com
19811570SCurtis.Dunham@arm.comvoid
19911570SCurtis.Dunham@arm.comnewDynamicSensitivityEventOrList(
20010515SN/A        Process *p, const sc_core::sc_event_or_list *eol)
20110515SN/A{
20210515SN/A    auto s = new DynamicSensitivityEventOrList(p, eol);
20310515SN/A    for (auto event: s->events)
20410515SN/A        s->addToEvent(event);
20510515SN/A    p->setDynamic(s);
20610515SN/A}
20710515SN/A
20810736SN/Avoid newDynamicSensitivityEventAndList(
20910515SN/A        Process *p, const sc_core::sc_event_and_list *eal)
21010515SN/A{
21110515SN/A    auto s = new DynamicSensitivityEventAndList(p, eal);
21210515SN/A    for (auto event: s->events)
21310515SN/A        s->addToEvent(event);
21410515SN/A    p->setDynamic(s);
21510515SN/A}
21610515SN/A
21710515SN/A
21810515SN/ADynamicSensitivityEventOrList::DynamicSensitivityEventOrList(
21910515SN/A        Process *p, const sc_core::sc_event_or_list *eol) :
22010515SN/A    Sensitivity(p), DynamicSensitivity(p), SensitivityEvents(p, eol->events)
22110515SN/A{}
22211570SCurtis.Dunham@arm.com
22310515SN/Abool
22410515SN/ADynamicSensitivityEventOrList::notifyWork(Event *e)
22510515SN/A{
22611570SCurtis.Dunham@arm.com    events.erase(e->sc_event());
22711570SCurtis.Dunham@arm.com
22811570SCurtis.Dunham@arm.com    // All the other events need this deleted from their lists since this
22911570SCurtis.Dunham@arm.com    // sensitivity has been satisfied without them triggering.
23010515SN/A    for (auto le: events)
23110515SN/A        delFromEvent(le);
23210515SN/A
23310515SN/A    satisfy();
23410515SN/A    return true;
23510515SN/A}
23610515SN/A
23710515SN/ADynamicSensitivityEventAndList::DynamicSensitivityEventAndList(
23810515SN/A        Process *p, const sc_core::sc_event_and_list *eal) :
23910515SN/A    Sensitivity(p), DynamicSensitivity(p), SensitivityEvents(p, eal->events)
24010515SN/A{}
24110515SN/A
24210515SN/Abool
24311570SCurtis.Dunham@arm.comDynamicSensitivityEventAndList::notifyWork(Event *e)
24410515SN/A{
24510515SN/A    events.erase(e->sc_event());
24610515SN/A
24711570SCurtis.Dunham@arm.com    // This sensitivity is satisfied if all events have triggered.
24811570SCurtis.Dunham@arm.com    if (events.empty())
24911570SCurtis.Dunham@arm.com        satisfy();
25011570SCurtis.Dunham@arm.com
25110515SN/A    return true;
25210515SN/A}
25310515SN/A
25410515SN/A} // namespace sc_gem5
25511103Snilay@cs.wisc.edu