sensitivity.hh revision 13208
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#ifndef __SYSTEMC_CORE_SENSITIVITY_HH__
3113206Sgabeblack@google.com#define __SYSTEMC_CORE_SENSITIVITY_HH__
3213206Sgabeblack@google.com
3313206Sgabeblack@google.com#include <set>
3413206Sgabeblack@google.com#include <vector>
3513206Sgabeblack@google.com
3613206Sgabeblack@google.com#include "sim/eventq.hh"
3713206Sgabeblack@google.com#include "systemc/core/sched_event.hh"
3813206Sgabeblack@google.com#include "systemc/ext/core/sc_module.hh"
3913206Sgabeblack@google.com
4013206Sgabeblack@google.comnamespace sc_core
4113206Sgabeblack@google.com{
4213206Sgabeblack@google.com
4313206Sgabeblack@google.comclass sc_event;
4413206Sgabeblack@google.comclass sc_event_and_list;
4513206Sgabeblack@google.comclass sc_event_or_list;
4613206Sgabeblack@google.comclass sc_event_finder;
4713206Sgabeblack@google.comclass sc_export_base;
4813206Sgabeblack@google.comclass sc_interface;
4913206Sgabeblack@google.comclass sc_port_base;
5013206Sgabeblack@google.com
5113206Sgabeblack@google.com} // namespace sc_core
5213206Sgabeblack@google.com
5313206Sgabeblack@google.comnamespace sc_gem5
5413206Sgabeblack@google.com{
5513206Sgabeblack@google.com
5613206Sgabeblack@google.comclass Process;
5713206Sgabeblack@google.comclass Event;
5813206Sgabeblack@google.com
5913206Sgabeblack@google.com/*
6013206Sgabeblack@google.com * Common sensitivity interface.
6113206Sgabeblack@google.com */
6213206Sgabeblack@google.com
6313206Sgabeblack@google.comclass Sensitivity
6413206Sgabeblack@google.com{
6513206Sgabeblack@google.com  protected:
6613206Sgabeblack@google.com    Process *process;
6713206Sgabeblack@google.com
6813206Sgabeblack@google.com    Sensitivity(Process *p) : process(p) {}
6913206Sgabeblack@google.com    virtual ~Sensitivity() {}
7013206Sgabeblack@google.com
7113206Sgabeblack@google.com    virtual void addToEvent(const ::sc_core::sc_event *e) = 0;
7213206Sgabeblack@google.com    virtual void delFromEvent(const ::sc_core::sc_event *e) = 0;
7313206Sgabeblack@google.com
7413206Sgabeblack@google.com    virtual bool
7513206Sgabeblack@google.com    notifyWork(Event *e)
7613206Sgabeblack@google.com    {
7713206Sgabeblack@google.com        satisfy();
7813206Sgabeblack@google.com        return true;
7913206Sgabeblack@google.com    }
8013206Sgabeblack@google.com
8113206Sgabeblack@google.com  public:
8213206Sgabeblack@google.com    virtual void clear() = 0;
8313206Sgabeblack@google.com
8413206Sgabeblack@google.com    void satisfy();
8513206Sgabeblack@google.com    bool notify(Event *e);
8613206Sgabeblack@google.com
8713206Sgabeblack@google.com    virtual bool dynamic() = 0;
8813208Sgabeblack@google.com
8913208Sgabeblack@google.com    bool ofMethod();
9013206Sgabeblack@google.com};
9113206Sgabeblack@google.com
9213206Sgabeblack@google.com
9313206Sgabeblack@google.com/*
9413206Sgabeblack@google.com * Dynamic vs. static sensitivity.
9513206Sgabeblack@google.com */
9613206Sgabeblack@google.com
9713206Sgabeblack@google.comclass DynamicSensitivity : virtual public Sensitivity
9813206Sgabeblack@google.com{
9913206Sgabeblack@google.com  protected:
10013206Sgabeblack@google.com    DynamicSensitivity(Process *p) : Sensitivity(p) {}
10113206Sgabeblack@google.com
10213206Sgabeblack@google.com    void addToEvent(const ::sc_core::sc_event *e) override;
10313206Sgabeblack@google.com    void delFromEvent(const ::sc_core::sc_event *e) override;
10413206Sgabeblack@google.com
10513206Sgabeblack@google.com  public:
10613206Sgabeblack@google.com    bool dynamic() override { return true; }
10713206Sgabeblack@google.com};
10813206Sgabeblack@google.com
10913206Sgabeblack@google.comtypedef std::vector<DynamicSensitivity *> DynamicSensitivities;
11013206Sgabeblack@google.com
11113206Sgabeblack@google.com
11213206Sgabeblack@google.comclass StaticSensitivity : virtual public Sensitivity
11313206Sgabeblack@google.com{
11413206Sgabeblack@google.com  protected:
11513206Sgabeblack@google.com    StaticSensitivity(Process *p) : Sensitivity(p) {}
11613206Sgabeblack@google.com
11713206Sgabeblack@google.com    void addToEvent(const ::sc_core::sc_event *e) override;
11813206Sgabeblack@google.com    void delFromEvent(const ::sc_core::sc_event *e) override;
11913206Sgabeblack@google.com
12013206Sgabeblack@google.com  public:
12113206Sgabeblack@google.com    bool dynamic() override { return false; }
12213206Sgabeblack@google.com};
12313206Sgabeblack@google.com
12413206Sgabeblack@google.comtypedef std::vector<StaticSensitivity *> StaticSensitivities;
12513206Sgabeblack@google.com
12613206Sgabeblack@google.com
12713206Sgabeblack@google.com/*
12813207Sgabeblack@google.com * Sensitivity to an event or events, which can be static or dynamic.
12913206Sgabeblack@google.com */
13013206Sgabeblack@google.com
13113206Sgabeblack@google.comclass SensitivityEvent : virtual public Sensitivity
13213206Sgabeblack@google.com{
13313206Sgabeblack@google.com  protected:
13413206Sgabeblack@google.com    const ::sc_core::sc_event *event;
13513206Sgabeblack@google.com
13613206Sgabeblack@google.com    SensitivityEvent(Process *p, const ::sc_core::sc_event *e=nullptr) :
13713206Sgabeblack@google.com        Sensitivity(p), event(e)
13813206Sgabeblack@google.com    {}
13913206Sgabeblack@google.com
14013206Sgabeblack@google.com  public:
14113206Sgabeblack@google.com    void clear() override { delFromEvent(event); }
14213206Sgabeblack@google.com};
14313206Sgabeblack@google.com
14413207Sgabeblack@google.comclass SensitivityEvents : virtual public Sensitivity
14513207Sgabeblack@google.com{
14613207Sgabeblack@google.com  protected:
14713207Sgabeblack@google.com    std::set<const ::sc_core::sc_event *> events;
14813207Sgabeblack@google.com
14913207Sgabeblack@google.com    SensitivityEvents(Process *p) : Sensitivity(p) {}
15013207Sgabeblack@google.com    SensitivityEvents(
15113207Sgabeblack@google.com            Process *p, const std::set<const ::sc_core::sc_event *> &s) :
15213207Sgabeblack@google.com        Sensitivity(p), events(s)
15313207Sgabeblack@google.com    {}
15413207Sgabeblack@google.com
15513207Sgabeblack@google.com  public:
15613207Sgabeblack@google.com    void
15713207Sgabeblack@google.com    clear() override
15813207Sgabeblack@google.com    {
15913207Sgabeblack@google.com        for (auto event: events)
16013207Sgabeblack@google.com            delFromEvent(event);
16113207Sgabeblack@google.com    }
16213207Sgabeblack@google.com
16313207Sgabeblack@google.com    void
16413207Sgabeblack@google.com    addEvent(const ::sc_core::sc_event *event)
16513207Sgabeblack@google.com    {
16613207Sgabeblack@google.com        events.insert(event);
16713207Sgabeblack@google.com        addToEvent(event);
16813207Sgabeblack@google.com    }
16913207Sgabeblack@google.com};
17013207Sgabeblack@google.com
17113206Sgabeblack@google.com
17213206Sgabeblack@google.com/*
17313206Sgabeblack@google.com * Static sensitivities.
17413206Sgabeblack@google.com */
17513206Sgabeblack@google.com
17613207Sgabeblack@google.comvoid newStaticSensitivityEvent(Process *p, const sc_core::sc_event *e);
17713207Sgabeblack@google.comvoid newStaticSensitivityInterface(Process *p, const sc_core::sc_interface *i);
17813207Sgabeblack@google.comvoid newStaticSensitivityPort(Process *p, const sc_core::sc_port_base *pb);
17913207Sgabeblack@google.comvoid newStaticSensitivityExport(
18013207Sgabeblack@google.com        Process *p, const sc_core::sc_export_base *exp);
18113207Sgabeblack@google.comvoid newStaticSensitivityFinder(
18213207Sgabeblack@google.com        Process *p, const sc_core::sc_event_finder *f);
18313207Sgabeblack@google.com
18413207Sgabeblack@google.com
18513206Sgabeblack@google.comclass StaticSensitivityEvent :
18613206Sgabeblack@google.com    public StaticSensitivity, public SensitivityEvent
18713206Sgabeblack@google.com{
18813207Sgabeblack@google.com    friend void newStaticSensitivityEvent(
18913207Sgabeblack@google.com            Process *p, const sc_core::sc_event *e);
19013207Sgabeblack@google.com
19113207Sgabeblack@google.com  protected:
19213206Sgabeblack@google.com    StaticSensitivityEvent(Process *p, const sc_core::sc_event *e) :
19313206Sgabeblack@google.com        Sensitivity(p), StaticSensitivity(p), SensitivityEvent(p, e)
19413206Sgabeblack@google.com    {}
19513206Sgabeblack@google.com};
19613206Sgabeblack@google.com
19713206Sgabeblack@google.comclass StaticSensitivityInterface :
19813206Sgabeblack@google.com    public StaticSensitivity, public SensitivityEvent
19913206Sgabeblack@google.com{
20013207Sgabeblack@google.com    friend void newStaticSensitivityInterface(
20113207Sgabeblack@google.com            Process *p, const sc_core::sc_interface *i);
20213207Sgabeblack@google.com  protected:
20313207Sgabeblack@google.com    StaticSensitivityInterface(Process *p, const sc_core::sc_interface *i);
20413206Sgabeblack@google.com};
20513206Sgabeblack@google.com
20613207Sgabeblack@google.comclass StaticSensitivityPort :
20713207Sgabeblack@google.com    public StaticSensitivity, public SensitivityEvents
20813206Sgabeblack@google.com{
20913207Sgabeblack@google.com    friend void newStaticSensitivityPort(
21013207Sgabeblack@google.com            Process *p, const sc_core::sc_port_base *pb);
21113206Sgabeblack@google.com
21213207Sgabeblack@google.com  protected:
21313207Sgabeblack@google.com    StaticSensitivityPort(Process *p) :
21413207Sgabeblack@google.com        Sensitivity(p), StaticSensitivity(p), SensitivityEvents(p)
21513206Sgabeblack@google.com    {}
21613206Sgabeblack@google.com};
21713206Sgabeblack@google.com
21813206Sgabeblack@google.comclass StaticSensitivityExport :
21913206Sgabeblack@google.com    public StaticSensitivity, public SensitivityEvent
22013206Sgabeblack@google.com{
22113206Sgabeblack@google.com  private:
22213207Sgabeblack@google.com    friend void newStaticSensitivityExport(
22313207Sgabeblack@google.com            Process *p, const sc_core::sc_export_base *exp);
22413207Sgabeblack@google.com
22513207Sgabeblack@google.com    StaticSensitivityExport(Process *p, const sc_core::sc_export_base *exp);
22613207Sgabeblack@google.com};
22713207Sgabeblack@google.com
22813207Sgabeblack@google.com
22913207Sgabeblack@google.comclass StaticSensitivityFinder :
23013207Sgabeblack@google.com    public StaticSensitivity, public SensitivityEvents
23113207Sgabeblack@google.com{
23213207Sgabeblack@google.com  private:
23313207Sgabeblack@google.com    const sc_core::sc_event_finder *finder;
23413207Sgabeblack@google.com
23513207Sgabeblack@google.com    friend void newStaticSensitivityFinder(
23613207Sgabeblack@google.com            Process *p, const sc_core::sc_event_finder *f);
23713207Sgabeblack@google.com
23813207Sgabeblack@google.com    StaticSensitivityFinder(Process *p, const sc_core::sc_event_finder *f) :
23913207Sgabeblack@google.com        Sensitivity(p), StaticSensitivity(p), SensitivityEvents(p), finder(f)
24013207Sgabeblack@google.com    {}
24113206Sgabeblack@google.com
24213206Sgabeblack@google.com  public:
24313207Sgabeblack@google.com    const ::sc_core::sc_event &find(::sc_core::sc_interface *i);
24413206Sgabeblack@google.com};
24513206Sgabeblack@google.com
24613206Sgabeblack@google.com
24713206Sgabeblack@google.com/*
24813206Sgabeblack@google.com * Dynamic sensitivities.
24913206Sgabeblack@google.com */
25013206Sgabeblack@google.com
25113207Sgabeblack@google.comvoid newDynamicSensitivityEvent(Process *p, const sc_core::sc_event *e);
25213207Sgabeblack@google.comvoid newDynamicSensitivityEventOrList(
25313207Sgabeblack@google.com        Process *p, const sc_core::sc_event_or_list *eol);
25413207Sgabeblack@google.comvoid newDynamicSensitivityEventAndList(
25513207Sgabeblack@google.com        Process *p, const sc_core::sc_event_and_list *eal);
25613207Sgabeblack@google.com
25713206Sgabeblack@google.comclass DynamicSensitivityEvent :
25813206Sgabeblack@google.com    public DynamicSensitivity, public SensitivityEvent
25913206Sgabeblack@google.com{
26013207Sgabeblack@google.com  private:
26113207Sgabeblack@google.com    friend void newDynamicSensitivityEvent(
26213207Sgabeblack@google.com            Process *p, const sc_core::sc_event *e);
26313207Sgabeblack@google.com
26413206Sgabeblack@google.com    DynamicSensitivityEvent(Process *p, const sc_core::sc_event *e) :
26513206Sgabeblack@google.com        Sensitivity(p), DynamicSensitivity(p), SensitivityEvent(p, e)
26613206Sgabeblack@google.com    {}
26713206Sgabeblack@google.com};
26813206Sgabeblack@google.com
26913207Sgabeblack@google.comclass DynamicSensitivityEventOrList :
27013207Sgabeblack@google.com    public DynamicSensitivity, public SensitivityEvents
27113206Sgabeblack@google.com{
27213206Sgabeblack@google.com  private:
27313207Sgabeblack@google.com    friend void newDynamicSensitivityEventOrList(
27413207Sgabeblack@google.com            Process *p, const sc_core::sc_event_or_list *eol);
27513206Sgabeblack@google.com
27613206Sgabeblack@google.com    DynamicSensitivityEventOrList(
27713206Sgabeblack@google.com            Process *p, const sc_core::sc_event_or_list *eol);
27813206Sgabeblack@google.com
27913207Sgabeblack@google.com    bool notifyWork(Event *e) override;
28013206Sgabeblack@google.com};
28113206Sgabeblack@google.com
28213206Sgabeblack@google.com//XXX This sensitivity can't be reused. To reset it, it has to be deleted and
28313206Sgabeblack@google.com//recreated. That works for dynamic sensitivities, but not for static.
28413206Sgabeblack@google.com//Fortunately processes can't be statically sensitive to sc_event_and_lists.
28513207Sgabeblack@google.comclass DynamicSensitivityEventAndList :
28613207Sgabeblack@google.com    public DynamicSensitivity, public SensitivityEvents
28713206Sgabeblack@google.com{
28813206Sgabeblack@google.com  private:
28913207Sgabeblack@google.com    friend void newDynamicSensitivityEventAndList(
29013207Sgabeblack@google.com            Process *p, const sc_core::sc_event_and_list *eal);
29113206Sgabeblack@google.com
29213206Sgabeblack@google.com    DynamicSensitivityEventAndList(
29313206Sgabeblack@google.com            Process *p, const sc_core::sc_event_and_list *eal);
29413206Sgabeblack@google.com
29513207Sgabeblack@google.com    bool notifyWork(Event *e) override;
29613206Sgabeblack@google.com};
29713206Sgabeblack@google.com
29813206Sgabeblack@google.com} // namespace sc_gem5
29913206Sgabeblack@google.com
30013206Sgabeblack@google.com#endif  //__SYSTEMC_CORE_SENSITIVITY_HH__
301