Giacomo Travaglini has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/12358

Change subject: mem: Implement QoS Round Robin policy
......................................................................

mem: Implement QoS Round Robin policy

This patch is implementing a Round Robin policy. The policy
will get a non empty list of masters from the python world; when
it needs to schedule a packet, it checks the packet's MID with
the current active MID (in the rr algorithm) and choosing
LOW or HIGH priority accordingly.

Change-Id: I61abe5dafb1f724fed9e698a050ad509b56589ed
Signed-off-by: Giacomo Travaglini <giacomo.travagl...@arm.com>
---
M src/mem/qos/QoSPolicy.py
M src/mem/qos/SConscript
A src/mem/qos/policy_round_robin.cc
A src/mem/qos/policy_round_robin.hh
4 files changed, 241 insertions(+), 0 deletions(-)



diff --git a/src/mem/qos/QoSPolicy.py b/src/mem/qos/QoSPolicy.py
index 9ccd985..b69d5c2 100644
--- a/src/mem/qos/QoSPolicy.py
+++ b/src/mem/qos/QoSPolicy.py
@@ -81,3 +81,15 @@
     # default fixed priority value for non-listed Masters
     qos_fixed_prio_default_prio = Param.UInt8(0,
         "Default priority for non-listed Masters")
+
+class QoSRoundRobinPolicy(QoSPolicy):
+    type = 'QoSRoundRobinPolicy'
+    cxx_header = "mem/qos/policy_round_robin.hh"
+    cxx_class = 'QoS::RoundRobinPolicy'
+
+    quantum_size = Param.UInt64(1,
+        "Quantum size: number of packets to be marked as high priority "
+        "before switching to the next MasterID")
+
+    qos_masters = VectorParam.String([],
+        "Policy will round robin over this set of masters")
diff --git a/src/mem/qos/SConscript b/src/mem/qos/SConscript
index 23351ca..fa22ae7 100644
--- a/src/mem/qos/SConscript
+++ b/src/mem/qos/SConscript
@@ -44,6 +44,7 @@

 Source('policy.cc')
 Source('policy_fixed_prio.cc')
+Source('policy_round_robin.cc')
 Source('turnaround_policy_ideal.cc')
 Source('q_policy.cc')
 Source('mem_ctrl.cc')
diff --git a/src/mem/qos/policy_round_robin.cc b/src/mem/qos/policy_round_robin.cc
new file mode 100644
index 0000000..0120791
--- /dev/null
+++ b/src/mem/qos/policy_round_robin.cc
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2018 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder.  You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * 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.
+ *
+ * Author: Giacomo Travaglini
+ */
+
+#include "mem/qos/policy_round_robin.hh"
+
+#include "mem/request.hh"
+
+namespace QoS {
+
+RoundRobinPolicy::RoundRobinPolicy(const Params* p)
+  : Policy(p), quantumSize(p->quantum_size), quantumCounter(0)
+{}
+
+RoundRobinPolicy::~RoundRobinPolicy()
+{}
+
+void
+RoundRobinPolicy::init()
+{
+    const auto& master_list = params()->qos_masters;
+    fatal_if(master_list.empty(),
+        "Empty master list in RoundRobin policy\n");
+
+    for (const auto& master : master_list) {
+        MasterID m_id = memCtrl->system()->lookupMasterId(master);
+
+        assert(m_id != Request::invldMasterId);
+        masters.insert(m_id);
+    }
+
+    selector = masters.begin();
+}
+
+void
+RoundRobinPolicy::advanceSelector()
+{
+    // If we only have 1 master (dummy case) we don't move the selector.
+    if (masters.size() > 1) {
+        if (quantumCounter >= quantumSize) {
+            selector++;
+            quantumCounter = 1;
+
+            // If we hit the end of the set, start from the first element
+            if (selector == masters.end()) {
+                selector = masters.begin();
+            }
+        } else {
+            quantumCounter++;
+        }
+    }
+}
+
+uint8_t
+RoundRobinPolicy::schedule(const MasterID pkt_mid, const uint64_t data)
+{
+    // advance the selector to point to the new masterID
+    advanceSelector();
+
+    MasterID curr_mid = *selector;
+
+    DPRINTF(QOS, "%s: Now serving Master %s (MasterID %d)\n", __func__,
+            memCtrl->system()->getMasterName(curr_mid), curr_mid);
+
+    if (pkt_mid == curr_mid) {
+        return HIGH;
+    } else {
+        return LOW;
+    }
+}
+
+} // namespace QoS
+
+QoS::RoundRobinPolicy *
+QoSRoundRobinPolicyParams::create()
+{
+    return new QoS::RoundRobinPolicy(this);
+}
diff --git a/src/mem/qos/policy_round_robin.hh b/src/mem/qos/policy_round_robin.hh
new file mode 100644
index 0000000..c221ad8
--- /dev/null
+++ b/src/mem/qos/policy_round_robin.hh
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2018 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder.  You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * 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.
+ *
+ * Author: Giacomo Travaglini
+ */
+
+#ifndef __MEM_QOS_POLICY_ROUND_ROBIN_HH__
+#define __MEM_QOS_POLICY_ROUND_ROBIN_HH__
+
+#include "mem/qos/policy.hh"
+#include "params/QoSRoundRobinPolicy.hh"
+
+namespace QoS {
+
+/**
+ * Round Robin QoS Policy
+ *
+ * With this policy every master gets serviced with a round robin
+ * selection criteria. The policy rotates over a set of masters.
+ * When a packet needs to be scheduled, its masterID is compared
+ * with the current selected masterID and if it matches the packet
+ * receive high priority.
+ * After a specific number of packets (quantum), the policy's masterID
+ * moves to to the next one in the list.
+ */
+class RoundRobinPolicy : public Policy
+{
+    using Params = QoSRoundRobinPolicyParams;
+    const Params *params() const
+    { return static_cast<const Params *>(_params); }
+
+    /**
+     * In a round robin policy we only have two priorities:
+     * packets with low priority (0) and packets with high
+     * priority (the packets which are going to be served in
+     * the current quantum)
+     */
+    enum : uint8_t { LOW, HIGH };
+
+  public:
+    RoundRobinPolicy(const Params*);
+    virtual ~RoundRobinPolicy();
+
+    void init() override;
+
+    /**
+     * Schedules a packet based on round robin configuration
+     *
+     * @param m_id master id to schedule
+     * @param data data to schedule
+     * @return QoS priority value
+     */
+    virtual uint8_t schedule(const MasterID, const uint64_t) override;
+
+  protected:
+    /** Helper method used for advancing the selector */
+    void advanceSelector();
+
+  protected:
+    /**
+     * quantumSize represent the number of packets to be scheduled
+     * with high priority from a MasterID before switching
+     * to the next MasterID.
+     */
+    const uint64_t quantumSize;
+
+    /**
+     * quantumCounter gets incremented every time we try to schedule
+     * a packet. When quantumCounter == quantumSize it means we need
+     * to advance the selector and switch to the next MasterID, and
+     * the counter restarts from zero.
+     */
+    uint64_t quantumCounter;
+
+    std::set<MasterID>::iterator selector;
+
+    std::set<MasterID> masters;
+};
+
+} // namespace QoS
+
+#endif // __MEM_QOS_POLICY_ROUND_ROBIN_HH__

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/12358
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I61abe5dafb1f724fed9e698a050ad509b56589ed
Gerrit-Change-Number: 12358
Gerrit-PatchSet: 1
Gerrit-Owner: Giacomo Travaglini <giacomo.travagl...@arm.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to