gem5  v22.1.0.0
q_policy.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 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 
49 namespace gem5
50 {
51 
52 namespace memory
53 {
54 
56 namespace qos
57 {
58 
59 QueuePolicy*
60 QueuePolicy::create(const QoSMemCtrlParams &p)
61 {
62  switch (p.qos_q_policy) {
63  case enums::QoSQPolicy::fifo:
64  return new FifoQueuePolicy(p);
65  case enums::QoSQPolicy::lrg:
66  return new LrgQueuePolicy(p);
67  case enums::QoSQPolicy::lifo:
68  default:
69  return new LifoQueuePolicy(p);
70  }
71 }
72 
73 QueuePolicy::PacketQueue::iterator
75 {
76  QueuePolicy::PacketQueue::iterator ret = q->end();
77 
78  // Tracks one packet per requestor in the queue
79  std::unordered_map<RequestorID, QueuePolicy::PacketQueue::iterator> track;
80 
81  // Cycle queue only once
82  for (auto pkt_it = q->begin(); pkt_it != q->end(); ++pkt_it) {
83 
84  const auto& pkt = *pkt_it;
85 
86  panic_if(!pkt->req,
87  "QoSQPolicy::lrg detected packet without request");
88 
89  // Get Request RequestorID
90  RequestorID requestor_id = pkt->req->requestorId();
91  DPRINTF(QOS, "QoSQPolicy::lrg checking packet "
92  "from queue with id %d\n", requestor_id);
93 
94  // Check if this is a known requestor.
95  panic_if(memCtrl->hasRequestor(requestor_id),
96  "%s: Unrecognized Requestor\n", __func__);
97 
98  panic_if(toServe.size() > 0,
99  "%s: toServe list is empty\n", __func__);
100 
101  if (toServe.front() == requestor_id) {
102  DPRINTF(QOS, "QoSQPolicy::lrg matched to served "
103  "requestor id %d\n", requestor_id);
104  // This packet matches the RequestorID to be served next
105  // move toServe front to back
106  toServe.push_back(requestor_id);
107  toServe.pop_front();
108 
109  return pkt_it;
110  }
111 
112  // The requestor generating the packet is not first in the toServe list
113  // (Doesn't have the highest priority among requestors)
114  // Check if this is the first packet seen with its requestor id
115  // and remember it. Then keep looping over the remaining packets
116  // in the queue.
117  if (track.find(requestor_id) == track.end()) {
118  track[requestor_id] = pkt_it;
119  DPRINTF(QOS, "QoSQPolicy::lrg tracking a packet for "
120  "requestor id %d\n", requestor_id);
121  }
122  }
123 
124  // If here, the current requestor to be serviced doesn't have a pending
125  // packet in the queue: look for the next requestor in the list.
126  for (const auto& requestorId : toServe) {
127  DPRINTF(QOS, "QoSQPolicy::lrg evaluating alternative "
128  "requestor id %d\n", requestorId);
129 
130  if (track.find(requestorId) != track.end()) {
131  ret = track[requestorId];
132  DPRINTF(QOS, "QoSQPolicy::lrg requestor id "
133  "%d selected for service\n", requestorId);
134 
135  return ret;
136  }
137  }
138 
139  DPRINTF(QOS, "QoSQPolicy::lrg no packet was serviced\n");
140 
141  // Ret will be : packet to serve if any found or queue begin
142  // (end if queue is empty)
143  return ret;
144 }
145 
146 void
148 {
149  RequestorID requestor_id = pkt->requestorId();
150  if (!memCtrl->hasRequestor(requestor_id)) {
151  toServe.push_back(requestor_id);
152  }
153 };
154 
155 } // namespace qos
156 } // namespace memory
157 } // namespace gem5
#define DPRINTF(x,...)
Definition: trace.hh:186
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
RequestorID requestorId() const
Definition: packet.hh:778
First In First Out Queue Policy.
Definition: q_policy.hh:143
Last In First Out Queue Policy.
Definition: q_policy.hh:122
Least Recently Granted Queue Policy It selects packets from the queue with a round robin-like policy:...
Definition: q_policy.hh:169
void enqueuePacket(PacketPtr pkt) override
This method is called by the memory controller after it enqueues a packet.
Definition: q_policy.cc:147
PacketQueue::iterator selectPacket(PacketQueue *queue) override
Implements LRG packet select policy.
Definition: q_policy.cc:74
std::list< RequestorID > toServe
Support structure for lrg algorithms: keeps track of serviced requestors, always serve the front elem...
Definition: q_policy.hh:192
bool hasRequestor(RequestorID id) const
hasRequestor returns true if the selected requestor(ID) has been registered in the memory controller,...
Definition: mem_ctrl.hh:316
static QueuePolicy * create(const QoSMemCtrlParams &p)
This factory method is used for generating the queue policy.
Definition: q_policy.cc:60
MemCtrl * memCtrl
Pointer to parent memory controller implementing the policy.
Definition: q_policy.hh:117
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:204
Bitfield< 27 > q
Definition: misc_types.hh:55
Bitfield< 54 > p
Definition: pagetable.hh:70
GEM5_DEPRECATED_NAMESPACE(QoS, qos)
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
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 Wed Dec 21 2022 10:22:37 for gem5 by doxygen 1.9.1