gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
55 namespace qos
56 {
57 
58 QueuePolicy*
59 QueuePolicy::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 
72 QueuePolicy::PacketQueue::iterator
74 {
75  QueuePolicy::PacketQueue::iterator ret = q->end();
76 
77  // Tracks one packet per requestor in the queue
78  std::unordered_map<RequestorID, QueuePolicy::PacketQueue::iterator> track;
79 
80  // Cycle queue only once
81  for (auto pkt_it = q->begin(); pkt_it != q->end(); ++pkt_it) {
82 
83  const auto& pkt = *pkt_it;
84 
85  panic_if(!pkt->req,
86  "QoSQPolicy::lrg detected packet without request");
87 
88  // Get Request RequestorID
89  RequestorID requestor_id = pkt->req->requestorId();
90  DPRINTF(QOS, "QoSQPolicy::lrg checking packet "
91  "from queue with id %d\n", requestor_id);
92 
93  // Check if this is a known requestor.
94  panic_if(memCtrl->hasRequestor(requestor_id),
95  "%s: Unrecognized Requestor\n", __func__);
96 
97  panic_if(toServe.size() > 0,
98  "%s: toServe list is empty\n", __func__);
99 
100  if (toServe.front() == requestor_id) {
101  DPRINTF(QOS, "QoSQPolicy::lrg matched to served "
102  "requestor id %d\n", requestor_id);
103  // This packet matches the RequestorID to be served next
104  // move toServe front to back
105  toServe.push_back(requestor_id);
106  toServe.pop_front();
107 
108  return pkt_it;
109  }
110 
111  // The requestor generating the packet is not first in the toServe list
112  // (Doesn't have the highest priority among requestors)
113  // Check if this is the first packet seen with its requestor id
114  // and remember it. Then keep looping over the remaining packets
115  // in the queue.
116  if (track.find(requestor_id) == track.end()) {
117  track[requestor_id] = pkt_it;
118  DPRINTF(QOS, "QoSQPolicy::lrg tracking a packet for "
119  "requestor id %d\n", requestor_id);
120  }
121  }
122 
123  // If here, the current requestor to be serviced doesn't have a pending
124  // packet in the queue: look for the next requestor in the list.
125  for (const auto& requestorId : toServe) {
126  DPRINTF(QOS, "QoSQPolicy::lrg evaluating alternative "
127  "requestor id %d\n", requestorId);
128 
129  if (track.find(requestorId) != track.end()) {
130  ret = track[requestorId];
131  DPRINTF(QOS, "QoSQPolicy::lrg requestor id "
132  "%d selected for service\n", requestorId);
133 
134  return ret;
135  }
136  }
137 
138  DPRINTF(QOS, "QoSQPolicy::lrg no packet was serviced\n");
139 
140  // Ret will be : packet to serve if any found or queue begin
141  // (end if queue is empty)
142  return ret;
143 }
144 
145 void
147 {
148  RequestorID requestor_id = pkt->requestorId();
149  if (!memCtrl->hasRequestor(requestor_id)) {
150  toServe.push_back(requestor_id);
151  }
152 };
153 
154 } // namespace qos
155 } // namespace memory
156 } // namespace gem5
memory
Definition: mem.h:38
gem5::memory::qos::LrgQueuePolicy::selectPacket
PacketQueue::iterator selectPacket(PacketQueue *queue) override
Implements LRG packet select policy.
Definition: q_policy.cc:73
gem5::memory::qos::QueuePolicy::create
static QueuePolicy * create(const QoSMemCtrlParams &p)
This factory method is used for generating the queue policy.
Definition: q_policy.cc:59
q_policy.hh
gem5::memory::qos::LifoQueuePolicy
Last In First Out Queue Policy.
Definition: q_policy.hh:120
gem5::memory::qos::FifoQueuePolicy
First In First Out Queue Policy.
Definition: q_policy.hh:141
request.hh
gem5::memory::qos::MemCtrl::hasRequestor
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
gem5::Packet::requestorId
RequestorID requestorId() const
Definition: packet.hh:780
gem5::VegaISA::p
Bitfield< 54 > p
Definition: pagetable.hh:70
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:210
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
gem5::memory::qos::QueuePolicy::memCtrl
MemCtrl * memCtrl
Pointer to parent memory controller implementing the policy.
Definition: q_policy.hh:116
gem5::memory::qos::LrgQueuePolicy
Least Recently Granted Queue Policy It selects packets from the queue with a round robin-like policy:...
Definition: q_policy.hh:167
gem5::memory::qos::LrgQueuePolicy::enqueuePacket
void enqueuePacket(PacketPtr pkt) override
This method is called by the memory controller after it enqueues a packet.
Definition: q_policy.cc:146
panic_if
#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
gem5::ArmISA::q
Bitfield< 27 > q
Definition: misc_types.hh:55
std::deque
STL deque class.
Definition: stl.hh:44
logging.hh
gem5::RequestorID
uint16_t RequestorID
Definition: request.hh:95
trace.hh
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::memory::qos::LrgQueuePolicy::toServe
std::list< RequestorID > toServe
Support structure for lrg algorithms: keeps track of serviced requestors, always serve the front elem...
Definition: q_policy.hh:191

Generated on Sun Jul 30 2023 01:56:58 for gem5 by doxygen 1.8.17