2 * Copyright (c) 2011-2015, 2017, 2019 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 * Copyright (c) 2002-2005 The Regents of The University of Michigan
15 * All rights reserved.
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 * Declaration of a coherent crossbar.
46 #ifndef __MEM_COHERENT_XBAR_HH__
47 #define __MEM_COHERENT_XBAR_HH__
49 #include <unordered_map>
50 #include <unordered_set>
52 #include "mem/snoop_filter.hh"
53 #include "mem/xbar.hh"
54 #include "params/CoherentXBar.hh"
57 * A coherent crossbar connects a number of (potentially) snooping
58 * requestors and responders, and routes the request and response packets
59 * based on the address, and also forwards all requests to the
60 * snoopers and deals with the snoop responses.
62 * The coherent crossbar can be used as a template for modelling QPI,
63 * HyperTransport, ACE and coherent OCP buses, and is typically used
64 * for the L1-to-L2 buses and as the main system interconnect. @sa
65 * \ref gem5MemorySystem "gem5 Memory System"
67 class CoherentXBar : public BaseXBar
73 * Declare the layers of this crossbar, one vector for requests,
74 * one for responses, and one for snoop responses
76 std::vector<ReqLayer*> reqLayers;
77 std::vector<RespLayer*> respLayers;
78 std::vector<SnoopRespLayer*> snoopLayers;
81 * Declaration of the coherent crossbar CPU-side port type, one will
82 * be instantiated for each of the mem_side_ports connecting to the
85 class CoherentXBarResponsePort : public QueuedResponsePort
90 /** A reference to the crossbar to which this port belongs. */
93 /** A normal packet queue used to store responses. */
94 RespPacketQueue queue;
98 CoherentXBarResponsePort(const std::string &_name,
99 CoherentXBar &_xbar, PortID _id)
100 : QueuedResponsePort(_name, &_xbar, queue, _id), xbar(_xbar),
107 recvTimingReq(PacketPtr pkt) override
109 return xbar.recvTimingReq(pkt, id);
113 recvTimingSnoopResp(PacketPtr pkt) override
115 return xbar.recvTimingSnoopResp(pkt, id);
119 recvAtomic(PacketPtr pkt) override
121 return xbar.recvAtomicBackdoor(pkt, id);
125 recvAtomicBackdoor(PacketPtr pkt, MemBackdoorPtr &backdoor) override
127 return xbar.recvAtomicBackdoor(pkt, id, &backdoor);
131 recvFunctional(PacketPtr pkt) override
133 xbar.recvFunctional(pkt, id);
137 getAddrRanges() const override
139 return xbar.getAddrRanges();
145 * Declaration of the coherent crossbar memory-side port type, one will be
146 * instantiated for each of the CPU-side-port interfaces connecting to the
149 class CoherentXBarRequestPort : public RequestPort
152 /** A reference to the crossbar to which this port belongs. */
157 CoherentXBarRequestPort(const std::string &_name,
158 CoherentXBar &_xbar, PortID _id)
159 : RequestPort(_name, &_xbar, _id), xbar(_xbar)
165 * Determine if this port should be considered a snooper. For
166 * a coherent crossbar memory-side port this is always true.
168 * @return a boolean that is true if this port is snooping
170 bool isSnooping() const override { return true; }
173 recvTimingResp(PacketPtr pkt) override
175 return xbar.recvTimingResp(pkt, id);
179 recvTimingSnoopReq(PacketPtr pkt) override
181 return xbar.recvTimingSnoopReq(pkt, id);
185 recvAtomicSnoop(PacketPtr pkt) override
187 return xbar.recvAtomicSnoop(pkt, id);
191 recvFunctionalSnoop(PacketPtr pkt) override
193 xbar.recvFunctionalSnoop(pkt, id);
196 void recvRangeChange() override { xbar.recvRangeChange(id); }
197 void recvReqRetry() override { xbar.recvReqRetry(id); }
202 * Internal class to bridge between an incoming snoop response
203 * from a CPU-side port and forwarding it through an outgoing
204 * CPU-side port. It is effectively a dangling memory-side port.
206 class SnoopRespPort : public RequestPort
211 /** The port which we mirror internally. */
212 QueuedResponsePort& cpuSidePort;
217 * Create a snoop response port that mirrors a given CPU-side port.
219 SnoopRespPort(QueuedResponsePort& cpu_side_port,
220 CoherentXBar& _xbar) :
221 RequestPort(cpu_side_port.name() + ".snoopRespPort", &_xbar),
222 cpuSidePort(cpu_side_port) { }
225 * Override the sending of retries and pass them on through
226 * the mirrored CPU-side port.
229 sendRetryResp() override
231 // forward it as a snoop response retry
232 cpuSidePort.sendRetrySnoopResp();
236 recvReqRetry() override
238 panic("SnoopRespPort should never see retry");
242 recvTimingResp(PacketPtr pkt) override
244 panic("SnoopRespPort should never see timing response");
249 std::vector<SnoopRespPort*> snoopRespPorts;
251 std::vector<QueuedResponsePort*> snoopPorts;
254 * Store the outstanding requests that we are expecting snoop
255 * responses from so we can determine which snoop responses we
256 * generated and which ones were merely forwarded.
258 std::unordered_set<RequestPtr> outstandingSnoop;
261 * Store the outstanding cache maintenance that we are expecting
262 * snoop responses from so we can determine when we received all
263 * snoop responses and if any of the agents satisfied the request.
265 std::unordered_map<PacketId, PacketPtr> outstandingCMO;
268 * Keep a pointer to the system to be allow to querying memory system
273 /** A snoop filter that tracks cache line residency and can restrict the
274 * broadcast needed for probes. NULL denotes an absent filter. */
275 SnoopFilter *snoopFilter;
277 /** Cycles of snoop response latency.*/
278 const Cycles snoopResponseLatency;
280 /** Maximum number of outstading snoops sanity check*/
281 const unsigned int maxOutstandingSnoopCheck;
283 /** Maximum routing table size sanity check*/
284 const unsigned int maxRoutingTableSizeCheck;
286 /** Is this crossbar the point of coherency? **/
287 const bool pointOfCoherency;
289 /** Is this crossbar the point of unification? **/
290 const bool pointOfUnification;
293 * Upstream caches need this packet until true is returned, so
294 * hold it for deletion until a subsequent call
296 std::unique_ptr<Packet> pendingDelete;
298 bool recvTimingReq(PacketPtr pkt, PortID cpu_side_port_id);
299 bool recvTimingResp(PacketPtr pkt, PortID mem_side_port_id);
300 void recvTimingSnoopReq(PacketPtr pkt, PortID mem_side_port_id);
301 bool recvTimingSnoopResp(PacketPtr pkt, PortID cpu_side_port_id);
302 void recvReqRetry(PortID mem_side_port_id);
305 * Forward a timing packet to our snoopers, potentially excluding
306 * one of the connected coherent requestors to avoid sending a packet
307 * back to where it came from.
309 * @param pkt Packet to forward
310 * @param exclude_cpu_side_port_id Id of CPU-side port to exclude
313 forwardTiming(PacketPtr pkt, PortID exclude_cpu_side_port_id)
315 forwardTiming(pkt, exclude_cpu_side_port_id, snoopPorts);
319 * Forward a timing packet to a selected list of snoopers, potentially
320 * excluding one of the connected coherent requestors to avoid sending
321 * a packet back to where it came from.
323 * @param pkt Packet to forward
324 * @param exclude_cpu_side_port_id Id of CPU-side port to exclude
325 * @param dests Vector of destination ports for the forwarded pkt
327 void forwardTiming(PacketPtr pkt, PortID exclude_cpu_side_port_id,
328 const std::vector<QueuedResponsePort*>& dests);
330 Tick recvAtomicBackdoor(PacketPtr pkt, PortID cpu_side_port_id,
331 MemBackdoorPtr *backdoor=nullptr);
332 Tick recvAtomicSnoop(PacketPtr pkt, PortID mem_side_port_id);
335 * Forward an atomic packet to our snoopers, potentially excluding
336 * one of the connected coherent requestors to avoid sending a packet
337 * back to where it came from.
339 * @param pkt Packet to forward
340 * @param exclude_cpu_side_port_id Id of CPU-side port to exclude
342 * @return a pair containing the snoop response and snoop latency
344 std::pair<MemCmd, Tick>
345 forwardAtomic(PacketPtr pkt, PortID exclude_cpu_side_port_id)
347 return forwardAtomic(pkt, exclude_cpu_side_port_id, InvalidPortID,
352 * Forward an atomic packet to a selected list of snoopers, potentially
353 * excluding one of the connected coherent requestors to avoid sending a
354 * packet back to where it came from.
356 * @param pkt Packet to forward
357 * @param exclude_cpu_side_port_id Id of CPU-side port to exclude
358 * @param source_mem_side_port_id Id of the memory-side port for
360 * @param dests Vector of destination ports for the forwarded pkt
362 * @return a pair containing the snoop response and snoop latency
364 std::pair<MemCmd, Tick> forwardAtomic(PacketPtr pkt,
365 PortID exclude_cpu_side_port_id,
366 PortID source_mem_side_port_id,
367 const std::vector<QueuedResponsePort*>&
370 /** Function called by the port when the crossbar is receiving a Functional
372 void recvFunctional(PacketPtr pkt, PortID cpu_side_port_id);
374 /** Function called by the port when the crossbar is receiving a functional
376 void recvFunctionalSnoop(PacketPtr pkt, PortID mem_side_port_id);
379 * Forward a functional packet to our snoopers, potentially
380 * excluding one of the connected coherent requestors to avoid
381 * sending a packet back to where it came from.
383 * @param pkt Packet to forward
384 * @param exclude_cpu_side_port_id Id of CPU-side port to exclude
386 void forwardFunctional(PacketPtr pkt, PortID exclude_cpu_side_port_id);
389 * Determine if the crossbar should sink the packet, as opposed to
390 * forwarding it, or responding.
392 bool sinkPacket(const PacketPtr pkt) const;
395 * Determine if the crossbar should forward the packet, as opposed to
398 bool forwardPacket(const PacketPtr pkt);
401 * Determine if the packet's destination is the memory below
403 * The memory below is the destination for a cache mainteance
404 * operation to the Point of Coherence/Unification if this is the
405 * Point of Coherence/Unification.
407 * @param pkt The processed packet
409 * @return Whether the memory below is the destination for the packet
412 isDestination(const PacketPtr pkt) const
414 return (pkt->req->isToPOC() && pointOfCoherency) ||
415 (pkt->req->isToPOU() && pointOfUnification);
418 Stats::Scalar snoops;
419 Stats::Scalar snoopTraffic;
420 Stats::Distribution snoopFanout;
426 CoherentXBar(const CoherentXBarParams &p);
428 virtual ~CoherentXBar();
430 virtual void regStats();
433 #endif //__MEM_COHERENT_XBAR_HH__