mem: Consistently use ISO prefixes
[gem5.git] / src / mem / coherent_xbar.hh
1 /*
2 * Copyright (c) 2011-2015, 2017, 2019 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 * Copyright (c) 2002-2005 The Regents of The University of Michigan
15 * All rights reserved.
16 *
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.
27 *
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.
39 */
40
41 /**
42 * @file
43 * Declaration of a coherent crossbar.
44 */
45
46 #ifndef __MEM_COHERENT_XBAR_HH__
47 #define __MEM_COHERENT_XBAR_HH__
48
49 #include <unordered_map>
50 #include <unordered_set>
51
52 #include "mem/snoop_filter.hh"
53 #include "mem/xbar.hh"
54 #include "params/CoherentXBar.hh"
55
56 /**
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.
61 *
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"
66 */
67 class CoherentXBar : public BaseXBar
68 {
69
70 protected:
71
72 /**
73 * Declare the layers of this crossbar, one vector for requests,
74 * one for responses, and one for snoop responses
75 */
76 std::vector<ReqLayer*> reqLayers;
77 std::vector<RespLayer*> respLayers;
78 std::vector<SnoopRespLayer*> snoopLayers;
79
80 /**
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
83 * crossbar.
84 */
85 class CoherentXBarResponsePort : public QueuedResponsePort
86 {
87
88 private:
89
90 /** A reference to the crossbar to which this port belongs. */
91 CoherentXBar &xbar;
92
93 /** A normal packet queue used to store responses. */
94 RespPacketQueue queue;
95
96 public:
97
98 CoherentXBarResponsePort(const std::string &_name,
99 CoherentXBar &_xbar, PortID _id)
100 : QueuedResponsePort(_name, &_xbar, queue, _id), xbar(_xbar),
101 queue(_xbar, *this)
102 { }
103
104 protected:
105
106 bool
107 recvTimingReq(PacketPtr pkt) override
108 {
109 return xbar.recvTimingReq(pkt, id);
110 }
111
112 bool
113 recvTimingSnoopResp(PacketPtr pkt) override
114 {
115 return xbar.recvTimingSnoopResp(pkt, id);
116 }
117
118 Tick
119 recvAtomic(PacketPtr pkt) override
120 {
121 return xbar.recvAtomicBackdoor(pkt, id);
122 }
123
124 Tick
125 recvAtomicBackdoor(PacketPtr pkt, MemBackdoorPtr &backdoor) override
126 {
127 return xbar.recvAtomicBackdoor(pkt, id, &backdoor);
128 }
129
130 void
131 recvFunctional(PacketPtr pkt) override
132 {
133 xbar.recvFunctional(pkt, id);
134 }
135
136 AddrRangeList
137 getAddrRanges() const override
138 {
139 return xbar.getAddrRanges();
140 }
141
142 };
143
144 /**
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
147 * crossbar.
148 */
149 class CoherentXBarRequestPort : public RequestPort
150 {
151 private:
152 /** A reference to the crossbar to which this port belongs. */
153 CoherentXBar &xbar;
154
155 public:
156
157 CoherentXBarRequestPort(const std::string &_name,
158 CoherentXBar &_xbar, PortID _id)
159 : RequestPort(_name, &_xbar, _id), xbar(_xbar)
160 { }
161
162 protected:
163
164 /**
165 * Determine if this port should be considered a snooper. For
166 * a coherent crossbar memory-side port this is always true.
167 *
168 * @return a boolean that is true if this port is snooping
169 */
170 bool isSnooping() const override { return true; }
171
172 bool
173 recvTimingResp(PacketPtr pkt) override
174 {
175 return xbar.recvTimingResp(pkt, id);
176 }
177
178 void
179 recvTimingSnoopReq(PacketPtr pkt) override
180 {
181 return xbar.recvTimingSnoopReq(pkt, id);
182 }
183
184 Tick
185 recvAtomicSnoop(PacketPtr pkt) override
186 {
187 return xbar.recvAtomicSnoop(pkt, id);
188 }
189
190 void
191 recvFunctionalSnoop(PacketPtr pkt) override
192 {
193 xbar.recvFunctionalSnoop(pkt, id);
194 }
195
196 void recvRangeChange() override { xbar.recvRangeChange(id); }
197 void recvReqRetry() override { xbar.recvReqRetry(id); }
198
199 };
200
201 /**
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.
205 */
206 class SnoopRespPort : public RequestPort
207 {
208
209 private:
210
211 /** The port which we mirror internally. */
212 QueuedResponsePort& cpuSidePort;
213
214 public:
215
216 /**
217 * Create a snoop response port that mirrors a given CPU-side port.
218 */
219 SnoopRespPort(QueuedResponsePort& cpu_side_port,
220 CoherentXBar& _xbar) :
221 RequestPort(cpu_side_port.name() + ".snoopRespPort", &_xbar),
222 cpuSidePort(cpu_side_port) { }
223
224 /**
225 * Override the sending of retries and pass them on through
226 * the mirrored CPU-side port.
227 */
228 void
229 sendRetryResp() override
230 {
231 // forward it as a snoop response retry
232 cpuSidePort.sendRetrySnoopResp();
233 }
234
235 void
236 recvReqRetry() override
237 {
238 panic("SnoopRespPort should never see retry");
239 }
240
241 bool
242 recvTimingResp(PacketPtr pkt) override
243 {
244 panic("SnoopRespPort should never see timing response");
245 }
246
247 };
248
249 std::vector<SnoopRespPort*> snoopRespPorts;
250
251 std::vector<QueuedResponsePort*> snoopPorts;
252
253 /**
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.
257 */
258 std::unordered_set<RequestPtr> outstandingSnoop;
259
260 /**
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.
264 */
265 std::unordered_map<PacketId, PacketPtr> outstandingCMO;
266
267 /**
268 * Keep a pointer to the system to be allow to querying memory system
269 * properties.
270 */
271 System *system;
272
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;
276
277 /** Cycles of snoop response latency.*/
278 const Cycles snoopResponseLatency;
279
280 /** Maximum number of outstading snoops sanity check*/
281 const unsigned int maxOutstandingSnoopCheck;
282
283 /** Maximum routing table size sanity check*/
284 const unsigned int maxRoutingTableSizeCheck;
285
286 /** Is this crossbar the point of coherency? **/
287 const bool pointOfCoherency;
288
289 /** Is this crossbar the point of unification? **/
290 const bool pointOfUnification;
291
292 /**
293 * Upstream caches need this packet until true is returned, so
294 * hold it for deletion until a subsequent call
295 */
296 std::unique_ptr<Packet> pendingDelete;
297
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);
303
304 /**
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.
308 *
309 * @param pkt Packet to forward
310 * @param exclude_cpu_side_port_id Id of CPU-side port to exclude
311 */
312 void
313 forwardTiming(PacketPtr pkt, PortID exclude_cpu_side_port_id)
314 {
315 forwardTiming(pkt, exclude_cpu_side_port_id, snoopPorts);
316 }
317
318 /**
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.
322 *
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
326 */
327 void forwardTiming(PacketPtr pkt, PortID exclude_cpu_side_port_id,
328 const std::vector<QueuedResponsePort*>& dests);
329
330 Tick recvAtomicBackdoor(PacketPtr pkt, PortID cpu_side_port_id,
331 MemBackdoorPtr *backdoor=nullptr);
332 Tick recvAtomicSnoop(PacketPtr pkt, PortID mem_side_port_id);
333
334 /**
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.
338 *
339 * @param pkt Packet to forward
340 * @param exclude_cpu_side_port_id Id of CPU-side port to exclude
341 *
342 * @return a pair containing the snoop response and snoop latency
343 */
344 std::pair<MemCmd, Tick>
345 forwardAtomic(PacketPtr pkt, PortID exclude_cpu_side_port_id)
346 {
347 return forwardAtomic(pkt, exclude_cpu_side_port_id, InvalidPortID,
348 snoopPorts);
349 }
350
351 /**
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.
355 *
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
359 * snoops from below
360 * @param dests Vector of destination ports for the forwarded pkt
361 *
362 * @return a pair containing the snoop response and snoop latency
363 */
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*>&
368 dests);
369
370 /** Function called by the port when the crossbar is receiving a Functional
371 transaction.*/
372 void recvFunctional(PacketPtr pkt, PortID cpu_side_port_id);
373
374 /** Function called by the port when the crossbar is receiving a functional
375 snoop transaction.*/
376 void recvFunctionalSnoop(PacketPtr pkt, PortID mem_side_port_id);
377
378 /**
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.
382 *
383 * @param pkt Packet to forward
384 * @param exclude_cpu_side_port_id Id of CPU-side port to exclude
385 */
386 void forwardFunctional(PacketPtr pkt, PortID exclude_cpu_side_port_id);
387
388 /**
389 * Determine if the crossbar should sink the packet, as opposed to
390 * forwarding it, or responding.
391 */
392 bool sinkPacket(const PacketPtr pkt) const;
393
394 /**
395 * Determine if the crossbar should forward the packet, as opposed to
396 * responding to it.
397 */
398 bool forwardPacket(const PacketPtr pkt);
399
400 /**
401 * Determine if the packet's destination is the memory below
402 *
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.
406 *
407 * @param pkt The processed packet
408 *
409 * @return Whether the memory below is the destination for the packet
410 */
411 bool
412 isDestination(const PacketPtr pkt) const
413 {
414 return (pkt->req->isToPOC() && pointOfCoherency) ||
415 (pkt->req->isToPOU() && pointOfUnification);
416 }
417
418 Stats::Scalar snoops;
419 Stats::Scalar snoopTraffic;
420 Stats::Distribution snoopFanout;
421
422 public:
423
424 virtual void init();
425
426 CoherentXBar(const CoherentXBarParams &p);
427
428 virtual ~CoherentXBar();
429
430 virtual void regStats();
431 };
432
433 #endif //__MEM_COHERENT_XBAR_HH__