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; };
102 virtual ~QueuePolicy() {};
105 QueuePolicy(const QoSMemCtrlParams &p)
109 /** Pointer to parent memory controller implementing the policy */
113 /** Last In First Out Queue Policy */
114 class LifoQueuePolicy : public QueuePolicy
117 LifoQueuePolicy(const QoSMemCtrlParams &p)
122 * Implements LIFO packet select policy
124 * @param queue The queue in which to select a packet
125 * @return Iterator to the selected packet
127 PacketQueue::iterator
128 selectPacket(PacketQueue* queue) override
134 /** First In First Out Queue Policy */
135 class FifoQueuePolicy : public QueuePolicy
138 FifoQueuePolicy(const QoSMemCtrlParams &p)
143 * Implements FCFS packet select policy
145 * @param queue The queue in which to select a packet
146 * @return Iterator to the selected packet
148 PacketQueue::iterator
149 selectPacket(PacketQueue* queue) override
151 return queue->begin();
156 * Least Recently Granted Queue Policy
157 * It selects packets from the queue with a round
158 * robin-like policy: using the requestor id as a switching
159 * parameter rather than switching over a time quantum.
161 class LrgQueuePolicy : public QueuePolicy
164 LrgQueuePolicy(const QoSMemCtrlParams &p)
168 void enqueuePacket(PacketPtr pkt) override;
171 * Implements LRG packet select policy
173 * @param queue The queue in which to select a packet
174 * @return Iterator to the selected packet
176 PacketQueue::iterator
177 selectPacket(PacketQueue* queue) override;
181 * Support structure for lrg algorithms:
182 * keeps track of serviced requestors,
183 * always serve the front element.
185 std::list<RequestorID> toServe;
190 #endif /* __MEM_QOS_Q_POLICY_HH__ */