2 * Copyright (c) 2018 ARM Limited
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 * Author: Matteo Andreozzi
40 #ifndef __MEM_QOS_Q_POLICY_HH__
41 #define __MEM_QOS_Q_POLICY_HH__
44 #include <unordered_set>
46 #include "mem/packet.hh"
47 #include "params/QoSMemCtrl.hh"
56 * The QoS Queue Policy class implements algorithms to schedule packets
57 * within the same QoS priority queue
62 typedef std::deque<PacketPtr> PacketQueue;
65 * This factory method is used for generating the queue policy. It takes
66 * the memory controller params as an argument and returns the related
67 * QueuePolicy object. If no particular QueuePolicy has been specified in
68 * the QoSMemCtrlParams, the method will default to a LIFO queue policy.
70 * @param p QoS::MemCtrl parameter variable
71 * @return Pointer to the QueuePolicy
73 static QueuePolicy* create(const QoSMemCtrlParams* p);
76 * This method is called by the memory controller after it enqueues a
77 * packet. It is a way for the queue policy to hook into the packet
78 * enqueuing and update relevant metadata. This will then be used once
79 * the QueuePolicy::selectPacket will be called.
81 * @param pkt Enqueued packet
83 virtual void enqueuePacket(PacketPtr pkt) {};
87 * The implementation of this virtual method selects the packet
88 * to be serviced from the packet queue passed as an argument.
90 * @param queue Packet queue
91 * @return Iterator pointing to the packet in the queue to be
94 virtual PacketQueue::iterator selectPacket(PacketQueue* queue) = 0;
97 * Setting a pointer to the Memory Controller implementing
100 void setMemCtrl(MemCtrl* mem) { memCtrl = mem; };
103 QueuePolicy(const QoSMemCtrlParams* p)
107 /** Pointer to parent memory controller implementing the policy */
111 /** Last In First Out Queue Policy */
112 class LifoQueuePolicy : public QueuePolicy
115 LifoQueuePolicy(const QoSMemCtrlParams* p)
120 * Implements LIFO packet select policy
122 * @param queue The queue in which to select a packet
123 * @return Iterator to the selected packet
125 PacketQueue::iterator
126 selectPacket(PacketQueue* queue) override
132 /** First In First Out Queue Policy */
133 class FifoQueuePolicy : public QueuePolicy
136 FifoQueuePolicy(const QoSMemCtrlParams* p)
141 * Implements FCFS packet select policy
143 * @param queue The queue in which to select a packet
144 * @return Iterator to the selected packet
146 PacketQueue::iterator
147 selectPacket(PacketQueue* queue) override
149 return queue->begin();
154 * Least Recently Granted Queue Policy
155 * It selects packets from the queue with a round
156 * robin-like policy: using the master id as a switching
157 * parameter rather than switching over a time quantum.
159 class LrgQueuePolicy : public QueuePolicy
162 LrgQueuePolicy(const QoSMemCtrlParams* p)
166 void enqueuePacket(PacketPtr pkt) override;
169 * Implements LRG packet select policy
171 * @param queue The queue in which to select a packet
172 * @return Iterator to the selected packet
174 PacketQueue::iterator
175 selectPacket(PacketQueue* queue) override;
179 * Support structure for lrg algorithms:
180 * keeps track of serviced masters,
181 * always serve the front element.
183 std::list<MasterID> toServe;
188 #endif /* __MEM_QOS_Q_POLICY_HH__ */