gem5 v24.0.0.0
Loading...
Searching...
No Matches
q_policy.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018,2024 ARM Limited
3 * All rights reserved
4 *
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.
13 *
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.
24 *
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.
36 */
37
38#include "mem/qos/q_policy.hh"
39
40#include <unordered_map>
41#include <utility>
42
43#include "base/logging.hh"
44#include "base/trace.hh"
45#include "debug/QOS.hh"
46#include "enums/QoSQPolicy.hh"
47#include "mem/request.hh"
48
49namespace gem5
50{
51
52namespace memory
53{
54
55namespace qos
56{
57
58QueuePolicy*
59QueuePolicy::create(const QoSMemCtrlParams &p)
60{
61 switch (p.qos_q_policy) {
62 case enums::QoSQPolicy::fifo:
63 return new FifoQueuePolicy(p);
64 case enums::QoSQPolicy::lrg:
65 return new LrgQueuePolicy(p);
66 case enums::QoSQPolicy::lifo:
67 default:
68 return new LifoQueuePolicy(p);
69 }
70}
71
72QueuePolicy::PacketQueue::iterator
74{
75 panic_if(queue->empty(),
76 "Provided packet queue is not usable by queue policy");
77 return queue->begin();
78}
79
80QueuePolicy::PacketQueue::iterator
82{
83 panic_if(queue->empty(),
84 "Provided packet queue is not usable by queue policy");
85 return std::prev(queue->end());
86}
87
88QueuePolicy::PacketQueue::iterator
90{
91 panic_if(q->empty(),
92 "Provided packet queue is not usable by queue policy");
93 QueuePolicy::PacketQueue::iterator ret = q->end();
94
95 // Tracks one packet per requestor in the queue
96 std::unordered_map<RequestorID, QueuePolicy::PacketQueue::iterator> track;
97
98 // Cycle queue only once
99 for (auto pkt_it = q->begin(); pkt_it != q->end(); ++pkt_it) {
100
101 const auto& pkt = *pkt_it;
102
103 panic_if(!pkt->req,
104 "QoSQPolicy::lrg detected packet without request");
105
106 // Get Request RequestorID
107 RequestorID requestor_id = pkt->req->requestorId();
108 DPRINTF(QOS, "QoSQPolicy::lrg checking packet "
109 "from queue with id %d\n", requestor_id);
110
111 // Check if this is a known requestor.
112 panic_if(!memCtrl->hasRequestor(requestor_id),
113 "%s: Unrecognized Requestor\n", __func__);
114
115 panic_if(toServe.size() <= 0,
116 "%s: toServe list is empty\n", __func__);
117
118 if (toServe.front() == requestor_id) {
119 DPRINTF(QOS, "QoSQPolicy::lrg matched to served "
120 "requestor id %d\n", requestor_id);
121 // This packet matches the RequestorID to be served next
122 // move toServe front to back
123 toServe.push_back(requestor_id);
124 toServe.pop_front();
125
126 return pkt_it;
127 }
128
129 // The requestor generating the packet is not first in the toServe list
130 // (Doesn't have the highest priority among requestors)
131 // Check if this is the first packet seen with its requestor id
132 // and remember it. Then keep looping over the remaining packets
133 // in the queue.
134 if (track.find(requestor_id) == track.end()) {
135 track[requestor_id] = pkt_it;
136 DPRINTF(QOS, "QoSQPolicy::lrg tracking a packet for "
137 "requestor id %d\n", requestor_id);
138 }
139 }
140
141 // If here, the current requestor to be serviced doesn't have a pending
142 // packet in the queue: look for the next requestor in the list.
143 for (const auto& requestorId : toServe) {
144 DPRINTF(QOS, "QoSQPolicy::lrg evaluating alternative "
145 "requestor id %d\n", requestorId);
146
147 if (track.find(requestorId) != track.end()) {
148 ret = track[requestorId];
149 DPRINTF(QOS, "QoSQPolicy::lrg requestor id "
150 "%d selected for service\n", requestorId);
151
152 return ret;
153 }
154 }
155
156 DPRINTF(QOS, "QoSQPolicy::lrg no packet was serviced\n");
157
158 // Ret will be : packet to serve
159 return ret;
160}
161
162void
164{
165 RequestorID requestor_id = pkt->requestorId();
166 if (!memCtrl->hasRequestor(requestor_id)) {
167 toServe.push_back(requestor_id);
168 }
169};
170
171} // namespace qos
172} // namespace memory
173} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:210
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
RequestorID requestorId() const
Definition packet.hh:780
First In First Out Queue Policy.
Definition q_policy.hh:139
PacketQueue::iterator selectPacket(PacketQueue *queue) override
Implements FCFS packet select policy.
Definition q_policy.cc:73
Last In First Out Queue Policy.
Definition q_policy.hh:121
PacketQueue::iterator selectPacket(PacketQueue *queue) override
Implements LIFO packet select policy.
Definition q_policy.cc:81
Least Recently Granted Queue Policy It selects packets from the queue with a round robin-like policy:...
Definition q_policy.hh:162
void enqueuePacket(PacketPtr pkt) override
This method is called by the memory controller after it enqueues a packet.
Definition q_policy.cc:163
PacketQueue::iterator selectPacket(PacketQueue *queue) override
Implements LRG packet select policy.
Definition q_policy.cc:89
std::list< RequestorID > toServe
Support structure for lrg algorithms: keeps track of serviced requestors, always serve the front elem...
Definition q_policy.hh:185
bool hasRequestor(RequestorID id) const
hasRequestor returns true if the selected requestor(ID) has been registered in the memory controller,...
Definition mem_ctrl.hh:315
static QueuePolicy * create(const QoSMemCtrlParams &p)
This factory method is used for generating the queue policy.
Definition q_policy.cc:59
MemCtrl * memCtrl
Pointer to parent memory controller implementing the policy.
Definition q_policy.hh:116
STL deque class.
Definition stl.hh:44
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition logging.hh:214
Bitfield< 27 > q
Definition misc_types.hh:55
Bitfield< 0 > p
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
uint16_t RequestorID
Definition request.hh:95
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
Definition mem.h:38

Generated on Tue Jun 18 2024 16:24:05 for gem5 by doxygen 1.11.0