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
41 #ifndef __MEM_QOS_MEM_SINK_HH__
42 #define __MEM_QOS_MEM_SINK_HH__
44 #include "mem/qos/mem_ctrl.hh"
45 #include "mem/qport.hh"
46 #include "params/QoSMemSinkCtrl.hh"
53 * The QoS Memory Sink is a lightweight memory controller with QoS
54 * support. It is meant to provide a QoS aware simple memory system
55 * without the need of using a complex DRAM memory controller
57 class MemSinkCtrl : public MemCtrl
61 * The Request packets are store in a multiple dequeue structure,
62 * based on their QoS priority
64 using PacketQueue = std::deque<PacketPtr>;
67 class MemoryPort : public QueuedSlavePort
70 /** reference to parent memory object */
73 /** Outgoing packet responses queue */
74 RespPacketQueue queue;
81 * @param m reference to ProfileGen parent object
83 MemoryPort(const std::string&, MemSinkCtrl&);
87 * Receive a Packet in Atomic mode
89 * @param pkt pointer to memory packet
90 * @return packet access latency in ticks
92 Tick recvAtomic(PacketPtr pkt);
95 * Receive a Packet in Functional mode
97 * @param pkt pointer to memory packet
99 void recvFunctional(PacketPtr pkt);
102 * Receive a Packet in Timing mode
104 * @param pkt pointer to memory packet
105 * @return true if the request was accepted
107 bool recvTimingReq(PacketPtr pkt);
110 * Gets the configured address ranges for this port
111 * @return the configured address ranges for this port
113 AddrRangeList getAddrRanges() const;
119 * QoS Memory Sink Constructor
121 * @param p QoS Memory Sink configuration parameters
123 MemSinkCtrl(const QoSMemSinkCtrlParams*);
125 virtual ~MemSinkCtrl();
128 * Checks and return the Drain state of this SimObject
129 * @return current Drain state
131 DrainState drain() override;
134 * Getter method to access this memory's slave port
136 * @param if_name interface name
137 * @param idx port ID number
138 * @return reference to this memory's slave port
140 Port &getPort(const std::string &if_name, PortID=InvalidPortID) override;
143 * Initializes this object
145 void init() override;
148 /** Memory between requests latency (ticks) */
149 const Tick requestLatency;
151 /** Memory response latency (ticks) */
152 const Tick responseLatency;
154 /** Memory packet size in bytes */
155 const uint64_t memoryPacketSize;
157 /** Read request packets queue buffer size in #packets */
158 const uint64_t readBufferSize;
160 /** Write request packets queue buffer size in #packets */
161 const uint64_t writeBufferSize;
163 /** Memory slave port */
166 /** Read request pending */
169 /** Write request pending */
172 /** Next request service time */
175 /** Count the number of read retries */
176 Stats::Scalar numReadRetries;
178 /** Count the number of write retries */
179 Stats::Scalar numWriteRetries;
182 * QoS-aware (per priority) incoming read requests packets queue
184 std::vector<PacketQueue> readQueue;
187 * QoS-aware (per priority) incoming read requests packets queue
189 std::vector<PacketQueue> writeQueue;
192 * Processes the next Request event according to configured
195 void processNextReqEvent();
197 /** Event wrapper to schedule next request handler function */
200 &MemSinkCtrl::processNextReqEvent> nextReqEvent;
203 * Check if the read queue has room for more entries
205 * @param packets The number of entries needed in the read queue
206 * @return true if read queue is full, false otherwise
208 inline bool readQueueFull(const uint64_t packets) const;
211 * Check if the write queue has room for more entries
213 * @param packets The number of entries needed in the write queue
214 * @return true if write queue is full, false otherwise
216 inline bool writeQueueFull(const uint64_t packets) const;
219 * Receive a Packet in Atomic mode
221 * @param pkt pointer to memory packet
222 * @return packet access latency in ticks
224 Tick recvAtomic(PacketPtr pkt);
227 * Receive a Packet in Functional mode
229 * @param pkt pointer to memory packet
231 void recvFunctional(PacketPtr pkt);
234 * Receive a Packet in Timing mode
236 * @param pkt pointer to memory packet
237 * @return true if the request was accepted
239 bool recvTimingReq(PacketPtr pkt);
241 /** Registers statistics */
242 void regStats() override;
247 #endif /* __MEM_QOS_MEM_SINK_HH__ */