summaryrefslogtreecommitdiff
path: root/src/systemc/core/sensitivity.hh
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2018-09-14 00:04:22 -0700
committerGabe Black <gabeblack@google.com>2018-10-09 21:49:30 +0000
commit7bc110ce5c12f47105e851a1a54c26a83eba6b87 (patch)
tree67eaaf20063cffc51fbf4dbfb4156737382bfe2a /src/systemc/core/sensitivity.hh
parent8817e547e524cd81b5176cf277ef611920b0815a (diff)
downloadgem5-7bc110ce5c12f47105e851a1a54c26a83eba6b87.tar.xz
systemc: Refactor sensitivities.
Dynamic and Static sensitivities used to be represented by the same classes, even though they're (almost) disjoint in how they worked. Also timeouts, which can be used alongside dynamic sensitivities, were handled by the sensitivities themselves. That meant that the sensitivity mechanism had to mix in more types of behaviors, increasing complexity. Also, the non-standard timed_out function Accellera includes is harder to implement if the path for timeouts and regular sensitivities are mixed together. This change splits up dynamic and static sensitivities and splits out timeouts. It also immitates the ordering Accellera uses when going through sensitivities for an event. Static sensitivities are triggered first in reverse order (why?), and then dynamic sensitivities are triggered in what amounts to reverse order. To delete a sensitivity which has been handled, it's swapped with the one in the last position, and then the vector is truncated to drop it at the end. This has the net effect of stirring the dynamic sensitivities, and isn't easily immitated using a different approach, even if other approaches would be more straightforward. Double check addSensitivity for event.hh Change-Id: I1e73dce386b95f68e9d6737deb8bed70ef717e0d Reviewed-on: https://gem5-review.googlesource.com/c/12805 Reviewed-by: Gabe Black <gabeblack@google.com> Maintainer: Gabe Black <gabeblack@google.com>
Diffstat (limited to 'src/systemc/core/sensitivity.hh')
-rw-r--r--src/systemc/core/sensitivity.hh279
1 files changed, 279 insertions, 0 deletions
diff --git a/src/systemc/core/sensitivity.hh b/src/systemc/core/sensitivity.hh
new file mode 100644
index 000000000..f032630ec
--- /dev/null
+++ b/src/systemc/core/sensitivity.hh
@@ -0,0 +1,279 @@
+/*
+ * Copyright 2018 Google, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Gabe Black
+ */
+
+#ifndef __SYSTEMC_CORE_SENSITIVITY_HH__
+#define __SYSTEMC_CORE_SENSITIVITY_HH__
+
+#include <set>
+#include <vector>
+
+#include "sim/eventq.hh"
+#include "systemc/core/sched_event.hh"
+#include "systemc/ext/core/sc_module.hh"
+
+namespace sc_core
+{
+
+class sc_event;
+class sc_event_and_list;
+class sc_event_or_list;
+class sc_event_finder;
+class sc_export_base;
+class sc_interface;
+class sc_port_base;
+
+} // namespace sc_core
+
+namespace sc_gem5
+{
+
+class Process;
+class Event;
+
+/*
+ * Common sensitivity interface.
+ */
+
+class Sensitivity
+{
+ protected:
+ Process *process;
+
+ Sensitivity(Process *p) : process(p) {}
+ virtual ~Sensitivity() {}
+
+ virtual void addToEvent(const ::sc_core::sc_event *e) = 0;
+ virtual void delFromEvent(const ::sc_core::sc_event *e) = 0;
+
+ virtual bool
+ notifyWork(Event *e)
+ {
+ satisfy();
+ return true;
+ }
+
+ public:
+ virtual void finalize() = 0;
+ virtual void clear() = 0;
+
+ void satisfy();
+ bool notify(Event *e);
+
+ virtual bool dynamic() = 0;
+};
+
+
+/*
+ * Dynamic vs. static sensitivity.
+ */
+
+class DynamicSensitivity : virtual public Sensitivity
+{
+ protected:
+ DynamicSensitivity(Process *p) : Sensitivity(p) {}
+
+ void addToEvent(const ::sc_core::sc_event *e) override;
+ void delFromEvent(const ::sc_core::sc_event *e) override;
+
+ public:
+ bool dynamic() override { return true; }
+};
+
+typedef std::vector<DynamicSensitivity *> DynamicSensitivities;
+
+
+class StaticSensitivity : virtual public Sensitivity
+{
+ protected:
+ StaticSensitivity(Process *p) : Sensitivity(p) {}
+
+ void addToEvent(const ::sc_core::sc_event *e) override;
+ void delFromEvent(const ::sc_core::sc_event *e) override;
+
+ public:
+ bool dynamic() override { return false; }
+};
+
+typedef std::vector<StaticSensitivity *> StaticSensitivities;
+
+
+/*
+ * Sensitivity to events, which can be static or dynamic.
+ */
+
+class SensitivityEvent : virtual public Sensitivity
+{
+ protected:
+ const ::sc_core::sc_event *event;
+
+ SensitivityEvent(Process *p, const ::sc_core::sc_event *e=nullptr) :
+ Sensitivity(p), event(e)
+ {}
+
+ public:
+ void finalize() override { addToEvent(event); }
+ void clear() override { delFromEvent(event); }
+};
+
+
+/*
+ * Static sensitivities.
+ */
+
+class StaticSensitivityEvent :
+ public StaticSensitivity, public SensitivityEvent
+{
+ public:
+ StaticSensitivityEvent(Process *p, const sc_core::sc_event *e) :
+ Sensitivity(p), StaticSensitivity(p), SensitivityEvent(p, e)
+ {}
+};
+
+class StaticSensitivityInterface :
+ public StaticSensitivity, public SensitivityEvent
+{
+ private:
+ const sc_core::sc_interface *interface;
+
+ public:
+ StaticSensitivityInterface(Process *p, const sc_core::sc_interface *i) :
+ Sensitivity(p), StaticSensitivity(p), SensitivityEvent(p), interface(i)
+ {}
+
+ void finalize() override;
+};
+
+class StaticSensitivityPort : public StaticSensitivity
+{
+ private:
+ const ::sc_core::sc_port_base *port;
+ std::set<const ::sc_core::sc_event *> events;
+
+ public:
+ StaticSensitivityPort(Process *p, const sc_core::sc_port_base *pb) :
+ Sensitivity(p), StaticSensitivity(p), port(pb)
+ {}
+
+ void finalize() override;
+
+ void
+ clear() override
+ {
+ for (auto event: events)
+ delFromEvent(event);
+ }
+};
+
+class StaticSensitivityExport :
+ public StaticSensitivity, public SensitivityEvent
+{
+ private:
+ const sc_core::sc_export_base *exp;
+
+ public:
+ StaticSensitivityExport(Process *p, const sc_core::sc_export_base *exp) :
+ Sensitivity(p), StaticSensitivity(p), SensitivityEvent(p), exp(exp)
+ {}
+
+ void finalize() override;
+};
+
+class StaticSensitivityFinder : public StaticSensitivity
+{
+ private:
+ const ::sc_core::sc_event_finder *finder;
+ std::set<const ::sc_core::sc_event *> events;
+
+ public:
+ StaticSensitivityFinder(Process *p, const sc_core::sc_event_finder *f) :
+ Sensitivity(p), StaticSensitivity(p), finder(f)
+ {}
+
+ void finalize() override;
+
+ void
+ clear() override
+ {
+ for (auto event: events)
+ delFromEvent(event);
+ }
+};
+
+
+/*
+ * Dynamic sensitivities.
+ */
+
+class DynamicSensitivityEvent :
+ public DynamicSensitivity, public SensitivityEvent
+{
+ public:
+ DynamicSensitivityEvent(Process *p, const sc_core::sc_event *e) :
+ Sensitivity(p), DynamicSensitivity(p), SensitivityEvent(p, e)
+ {}
+};
+
+class DynamicSensitivityEventOrList : public DynamicSensitivity
+{
+ private:
+ std::set<const ::sc_core::sc_event *> events;
+
+ protected:
+ bool notifyWork(Event *e) override;
+
+ public:
+ DynamicSensitivityEventOrList(
+ Process *p, const sc_core::sc_event_or_list *eol);
+
+ void finalize() override;
+ void clear() override;
+};
+
+//XXX This sensitivity can't be reused. To reset it, it has to be deleted and
+//recreated. That works for dynamic sensitivities, but not for static.
+//Fortunately processes can't be statically sensitive to sc_event_and_lists.
+class DynamicSensitivityEventAndList : public DynamicSensitivity
+{
+ private:
+ std::set<const ::sc_core::sc_event *> events;
+
+ protected:
+ bool notifyWork(Event *e) override;
+
+ public:
+ DynamicSensitivityEventAndList(
+ Process *p, const sc_core::sc_event_and_list *eal);
+
+ void finalize() override;
+ void clear() override;
+};
+
+} // namespace sc_gem5
+
+#endif //__SYSTEMC_CORE_SENSITIVITY_HH__