2 * Copyright (c) 2011-2015 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) 2006 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.
47 * Definition of a crossbar object.
50 #include "base/misc.hh"
51 #include "base/trace.hh"
52 #include "debug/AddrRanges.hh"
53 #include "debug/CoherentXBar.hh"
54 #include "mem/coherent_xbar.hh"
55 #include "sim/system.hh"
57 CoherentXBar::CoherentXBar(const CoherentXBarParams
*p
)
58 : BaseXBar(p
), system(p
->system
), snoopFilter(p
->snoop_filter
),
59 snoopResponseLatency(p
->snoop_response_latency
)
61 // create the ports based on the size of the master and slave
62 // vector ports, and the presence of the default port, the ports
63 // are enumerated starting from zero
64 for (int i
= 0; i
< p
->port_master_connection_count
; ++i
) {
65 std::string portName
= csprintf("%s.master[%d]", name(), i
);
66 MasterPort
* bp
= new CoherentXBarMasterPort(portName
, *this, i
);
67 masterPorts
.push_back(bp
);
68 reqLayers
.push_back(new ReqLayer(*bp
, *this,
69 csprintf(".reqLayer%d", i
)));
70 snoopLayers
.push_back(new SnoopRespLayer(*bp
, *this,
71 csprintf(".snoopLayer%d", i
)));
74 // see if we have a default slave device connected and if so add
75 // our corresponding master port
76 if (p
->port_default_connection_count
) {
77 defaultPortID
= masterPorts
.size();
78 std::string portName
= name() + ".default";
79 MasterPort
* bp
= new CoherentXBarMasterPort(portName
, *this,
81 masterPorts
.push_back(bp
);
82 reqLayers
.push_back(new ReqLayer(*bp
, *this, csprintf(".reqLayer%d",
84 snoopLayers
.push_back(new SnoopRespLayer(*bp
, *this,
85 csprintf(".snoopLayer%d",
89 // create the slave ports, once again starting at zero
90 for (int i
= 0; i
< p
->port_slave_connection_count
; ++i
) {
91 std::string portName
= csprintf("%s.slave[%d]", name(), i
);
92 QueuedSlavePort
* bp
= new CoherentXBarSlavePort(portName
, *this, i
);
93 slavePorts
.push_back(bp
);
94 respLayers
.push_back(new RespLayer(*bp
, *this,
95 csprintf(".respLayer%d", i
)));
96 snoopRespPorts
.push_back(new SnoopRespPort(*bp
, *this));
102 CoherentXBar::~CoherentXBar()
104 for (auto l
: reqLayers
)
106 for (auto l
: respLayers
)
108 for (auto l
: snoopLayers
)
110 for (auto p
: snoopRespPorts
)
117 // the base class is responsible for determining the block size
120 // iterate over our slave ports and determine which of our
121 // neighbouring master ports are snooping and add them as snoopers
122 for (const auto& p
: slavePorts
) {
123 // check if the connected master port is snooping
124 if (p
->isSnooping()) {
125 DPRINTF(AddrRanges
, "Adding snooping master %s\n",
126 p
->getMasterPort().name());
127 snoopPorts
.push_back(p
);
131 if (snoopPorts
.empty())
132 warn("CoherentXBar %s has no snooping ports attached!\n", name());
134 // inform the snoop filter about the slave ports so it can create
135 // its own internal representation
137 snoopFilter
->setSlavePorts(slavePorts
);
141 CoherentXBar::recvTimingReq(PacketPtr pkt
, PortID slave_port_id
)
143 // determine the source port based on the id
144 SlavePort
*src_port
= slavePorts
[slave_port_id
];
146 // remember if the packet is an express snoop
147 bool is_express_snoop
= pkt
->isExpressSnoop();
148 bool is_inhibited
= pkt
->memInhibitAsserted();
149 // for normal requests, going downstream, the express snoop flag
150 // and the inhibited flag should always be the same
151 assert(is_express_snoop
== is_inhibited
);
153 // determine the destination based on the address
154 PortID master_port_id
= findPort(pkt
->getAddr());
156 // test if the crossbar should be considered occupied for the current
157 // port, and exclude express snoops from the check
158 if (!is_express_snoop
&& !reqLayers
[master_port_id
]->tryTiming(src_port
)) {
159 DPRINTF(CoherentXBar
, "recvTimingReq: src %s %s 0x%x BUSY\n",
160 src_port
->name(), pkt
->cmdString(), pkt
->getAddr());
164 DPRINTF(CoherentXBar
, "recvTimingReq: src %s %s expr %d 0x%x\n",
165 src_port
->name(), pkt
->cmdString(), is_express_snoop
,
168 // store size and command as they might be modified when
169 // forwarding the packet
170 unsigned int pkt_size
= pkt
->hasData() ? pkt
->getSize() : 0;
171 unsigned int pkt_cmd
= pkt
->cmdToIndex();
173 // store the old header delay so we can restore it if needed
174 Tick old_header_delay
= pkt
->headerDelay
;
176 // a request sees the frontend and forward latency
177 Tick xbar_delay
= (frontendLatency
+ forwardLatency
) * clockPeriod();
179 // set the packet header and payload delay
180 calcPacketTiming(pkt
, xbar_delay
);
182 // determine how long to be crossbar layer is busy
183 Tick packetFinishTime
= clockEdge(Cycles(1)) + pkt
->payloadDelay
;
185 if (!system
->bypassCaches()) {
186 assert(pkt
->snoopDelay
== 0);
188 // the packet is a memory-mapped request and should be
189 // broadcasted to our snoopers but the source
191 // check with the snoop filter where to forward this packet
192 auto sf_res
= snoopFilter
->lookupRequest(pkt
, *src_port
);
193 // the time required by a packet to be delivered through
194 // the xbar has to be charged also with to lookup latency
195 // of the snoop filter
196 pkt
->headerDelay
+= sf_res
.second
* clockPeriod();
197 DPRINTF(CoherentXBar
, "recvTimingReq: src %s %s 0x%x"\
198 " SF size: %i lat: %i\n", src_port
->name(),
199 pkt
->cmdString(), pkt
->getAddr(), sf_res
.first
.size(),
202 if (pkt
->isEviction()) {
203 // for block-evicting packets, i.e. writebacks and
204 // clean evictions, there is no need to snoop up, as
205 // all we do is determine if the block is cached or
206 // not, instead just set it here based on the snoop
208 if (!sf_res
.first
.empty())
209 pkt
->setBlockCached();
211 forwardTiming(pkt
, slave_port_id
, sf_res
.first
);
214 forwardTiming(pkt
, slave_port_id
);
217 // add the snoop delay to our header delay, and then reset it
218 pkt
->headerDelay
+= pkt
->snoopDelay
;
222 // forwardTiming snooped into peer caches of the sender, and if
223 // this is a clean evict or clean writeback, but the packet is
224 // found in a cache, do not forward it
225 if ((pkt
->cmd
== MemCmd::CleanEvict
||
226 pkt
->cmd
== MemCmd::WritebackClean
) && pkt
->isBlockCached()) {
227 DPRINTF(CoherentXBar
, "Clean evict/writeback %#llx still cached, "
228 "not forwarding\n", pkt
->getAddr());
230 // update the layer state and schedule an idle event
231 reqLayers
[master_port_id
]->succeededTiming(packetFinishTime
);
233 // queue the packet for deletion
234 pendingDelete
.reset(pkt
);
239 // remember if the packet will generate a snoop response
240 const bool expect_snoop_resp
= !is_inhibited
&& pkt
->memInhibitAsserted();
241 const bool expect_response
= pkt
->needsResponse() &&
242 !pkt
->memInhibitAsserted();
244 // since it is a normal request, attempt to send the packet
245 bool success
= masterPorts
[master_port_id
]->sendTimingReq(pkt
);
247 if (snoopFilter
&& !system
->bypassCaches()) {
248 // Let the snoop filter know about the success of the send operation
249 snoopFilter
->finishRequest(!success
, pkt
);
252 // check if we were successful in sending the packet onwards
254 // express snoops and inhibited packets should never be forced
256 assert(!is_express_snoop
);
257 assert(!pkt
->memInhibitAsserted());
259 // restore the header delay
260 pkt
->headerDelay
= old_header_delay
;
262 DPRINTF(CoherentXBar
, "recvTimingReq: src %s %s 0x%x RETRY\n",
263 src_port
->name(), pkt
->cmdString(), pkt
->getAddr());
265 // update the layer state and schedule an idle event
266 reqLayers
[master_port_id
]->failedTiming(src_port
,
267 clockEdge(Cycles(1)));
269 // express snoops currently bypass the crossbar state entirely
270 if (!is_express_snoop
) {
271 // if this particular request will generate a snoop
273 if (expect_snoop_resp
) {
274 // we should never have an exsiting request outstanding
275 assert(outstandingSnoop
.find(pkt
->req
) ==
276 outstandingSnoop
.end());
277 outstandingSnoop
.insert(pkt
->req
);
279 // basic sanity check on the outstanding snoops
280 panic_if(outstandingSnoop
.size() > 512,
281 "Outstanding snoop requests exceeded 512\n");
284 // remember where to route the normal response to
285 if (expect_response
|| expect_snoop_resp
) {
286 assert(routeTo
.find(pkt
->req
) == routeTo
.end());
287 routeTo
[pkt
->req
] = slave_port_id
;
289 panic_if(routeTo
.size() > 512,
290 "Routing table exceeds 512 packets\n");
293 // update the layer state and schedule an idle event
294 reqLayers
[master_port_id
]->succeededTiming(packetFinishTime
);
297 // stats updates only consider packets that were successfully sent
298 pktCount
[slave_port_id
][master_port_id
]++;
299 pktSize
[slave_port_id
][master_port_id
] += pkt_size
;
300 transDist
[pkt_cmd
]++;
302 if (is_express_snoop
)
310 CoherentXBar::recvTimingResp(PacketPtr pkt
, PortID master_port_id
)
312 // determine the source port based on the id
313 MasterPort
*src_port
= masterPorts
[master_port_id
];
315 // determine the destination
316 const auto route_lookup
= routeTo
.find(pkt
->req
);
317 assert(route_lookup
!= routeTo
.end());
318 const PortID slave_port_id
= route_lookup
->second
;
319 assert(slave_port_id
!= InvalidPortID
);
320 assert(slave_port_id
< respLayers
.size());
322 // test if the crossbar should be considered occupied for the
324 if (!respLayers
[slave_port_id
]->tryTiming(src_port
)) {
325 DPRINTF(CoherentXBar
, "recvTimingResp: src %s %s 0x%x BUSY\n",
326 src_port
->name(), pkt
->cmdString(), pkt
->getAddr());
330 DPRINTF(CoherentXBar
, "recvTimingResp: src %s %s 0x%x\n",
331 src_port
->name(), pkt
->cmdString(), pkt
->getAddr());
333 // store size and command as they might be modified when
334 // forwarding the packet
335 unsigned int pkt_size
= pkt
->hasData() ? pkt
->getSize() : 0;
336 unsigned int pkt_cmd
= pkt
->cmdToIndex();
338 // a response sees the response latency
339 Tick xbar_delay
= responseLatency
* clockPeriod();
341 // set the packet header and payload delay
342 calcPacketTiming(pkt
, xbar_delay
);
344 // determine how long to be crossbar layer is busy
345 Tick packetFinishTime
= clockEdge(Cycles(1)) + pkt
->payloadDelay
;
347 if (snoopFilter
&& !system
->bypassCaches()) {
348 // let the snoop filter inspect the response and update its state
349 snoopFilter
->updateResponse(pkt
, *slavePorts
[slave_port_id
]);
352 // send the packet through the destination slave port and pay for
353 // any outstanding header delay
354 Tick latency
= pkt
->headerDelay
;
355 pkt
->headerDelay
= 0;
356 slavePorts
[slave_port_id
]->schedTimingResp(pkt
, curTick() + latency
);
358 // remove the request from the routing table
359 routeTo
.erase(route_lookup
);
361 respLayers
[slave_port_id
]->succeededTiming(packetFinishTime
);
364 pktCount
[slave_port_id
][master_port_id
]++;
365 pktSize
[slave_port_id
][master_port_id
] += pkt_size
;
366 transDist
[pkt_cmd
]++;
372 CoherentXBar::recvTimingSnoopReq(PacketPtr pkt
, PortID master_port_id
)
374 DPRINTF(CoherentXBar
, "recvTimingSnoopReq: src %s %s 0x%x\n",
375 masterPorts
[master_port_id
]->name(), pkt
->cmdString(),
378 // update stats here as we know the forwarding will succeed
379 transDist
[pkt
->cmdToIndex()]++;
382 // we should only see express snoops from caches
383 assert(pkt
->isExpressSnoop());
385 // set the packet header and payload delay, for now use forward latency
386 // @todo Assess the choice of latency further
387 calcPacketTiming(pkt
, forwardLatency
* clockPeriod());
389 // remeber if the packet is inhibited so we can see if it changes
390 const bool is_inhibited
= pkt
->memInhibitAsserted();
392 assert(pkt
->snoopDelay
== 0);
395 // let the Snoop Filter work its magic and guide probing
396 auto sf_res
= snoopFilter
->lookupSnoop(pkt
);
397 // the time required by a packet to be delivered through
398 // the xbar has to be charged also with to lookup latency
399 // of the snoop filter
400 pkt
->headerDelay
+= sf_res
.second
* clockPeriod();
401 DPRINTF(CoherentXBar
, "recvTimingSnoopReq: src %s %s 0x%x"\
402 " SF size: %i lat: %i\n", masterPorts
[master_port_id
]->name(),
403 pkt
->cmdString(), pkt
->getAddr(), sf_res
.first
.size(),
406 // forward to all snoopers
407 forwardTiming(pkt
, InvalidPortID
, sf_res
.first
);
409 forwardTiming(pkt
, InvalidPortID
);
412 // add the snoop delay to our header delay, and then reset it
413 pkt
->headerDelay
+= pkt
->snoopDelay
;
416 // if we can expect a response, remember how to route it
417 if (!is_inhibited
&& pkt
->memInhibitAsserted()) {
418 assert(routeTo
.find(pkt
->req
) == routeTo
.end());
419 routeTo
[pkt
->req
] = master_port_id
;
422 // a snoop request came from a connected slave device (one of
423 // our master ports), and if it is not coming from the slave
424 // device responsible for the address range something is
425 // wrong, hence there is nothing further to do as the packet
426 // would be going back to where it came from
427 assert(master_port_id
== findPort(pkt
->getAddr()));
431 CoherentXBar::recvTimingSnoopResp(PacketPtr pkt
, PortID slave_port_id
)
433 // determine the source port based on the id
434 SlavePort
* src_port
= slavePorts
[slave_port_id
];
436 // get the destination
437 const auto route_lookup
= routeTo
.find(pkt
->req
);
438 assert(route_lookup
!= routeTo
.end());
439 const PortID dest_port_id
= route_lookup
->second
;
440 assert(dest_port_id
!= InvalidPortID
);
442 // determine if the response is from a snoop request we
443 // created as the result of a normal request (in which case it
444 // should be in the outstandingSnoop), or if we merely forwarded
445 // someone else's snoop request
446 const bool forwardAsSnoop
= outstandingSnoop
.find(pkt
->req
) ==
447 outstandingSnoop
.end();
449 // test if the crossbar should be considered occupied for the
450 // current port, note that the check is bypassed if the response
451 // is being passed on as a normal response since this is occupying
452 // the response layer rather than the snoop response layer
453 if (forwardAsSnoop
) {
454 assert(dest_port_id
< snoopLayers
.size());
455 if (!snoopLayers
[dest_port_id
]->tryTiming(src_port
)) {
456 DPRINTF(CoherentXBar
, "recvTimingSnoopResp: src %s %s 0x%x BUSY\n",
457 src_port
->name(), pkt
->cmdString(), pkt
->getAddr());
461 // get the master port that mirrors this slave port internally
462 MasterPort
* snoop_port
= snoopRespPorts
[slave_port_id
];
463 assert(dest_port_id
< respLayers
.size());
464 if (!respLayers
[dest_port_id
]->tryTiming(snoop_port
)) {
465 DPRINTF(CoherentXBar
, "recvTimingSnoopResp: src %s %s 0x%x BUSY\n",
466 snoop_port
->name(), pkt
->cmdString(), pkt
->getAddr());
471 DPRINTF(CoherentXBar
, "recvTimingSnoopResp: src %s %s 0x%x\n",
472 src_port
->name(), pkt
->cmdString(), pkt
->getAddr());
474 // store size and command as they might be modified when
475 // forwarding the packet
476 unsigned int pkt_size
= pkt
->hasData() ? pkt
->getSize() : 0;
477 unsigned int pkt_cmd
= pkt
->cmdToIndex();
479 // responses are never express snoops
480 assert(!pkt
->isExpressSnoop());
482 // a snoop response sees the snoop response latency, and if it is
483 // forwarded as a normal response, the response latency
485 (forwardAsSnoop
? snoopResponseLatency
: responseLatency
) *
488 // set the packet header and payload delay
489 calcPacketTiming(pkt
, xbar_delay
);
491 // determine how long to be crossbar layer is busy
492 Tick packetFinishTime
= clockEdge(Cycles(1)) + pkt
->payloadDelay
;
494 // forward it either as a snoop response or a normal response
495 if (forwardAsSnoop
) {
496 // this is a snoop response to a snoop request we forwarded,
497 // e.g. coming from the L1 and going to the L2, and it should
498 // be forwarded as a snoop response
501 // update the probe filter so that it can properly track the line
502 snoopFilter
->updateSnoopForward(pkt
, *slavePorts
[slave_port_id
],
503 *masterPorts
[dest_port_id
]);
506 bool success M5_VAR_USED
=
507 masterPorts
[dest_port_id
]->sendTimingSnoopResp(pkt
);
508 pktCount
[slave_port_id
][dest_port_id
]++;
509 pktSize
[slave_port_id
][dest_port_id
] += pkt_size
;
512 snoopLayers
[dest_port_id
]->succeededTiming(packetFinishTime
);
514 // we got a snoop response on one of our slave ports,
515 // i.e. from a coherent master connected to the crossbar, and
516 // since we created the snoop request as part of recvTiming,
517 // this should now be a normal response again
518 outstandingSnoop
.erase(pkt
->req
);
520 // this is a snoop response from a coherent master, hence it
521 // should never go back to where the snoop response came from,
522 // but instead to where the original request came from
523 assert(slave_port_id
!= dest_port_id
);
526 // update the probe filter so that it can properly track the line
527 snoopFilter
->updateSnoopResponse(pkt
, *slavePorts
[slave_port_id
],
528 *slavePorts
[dest_port_id
]);
531 DPRINTF(CoherentXBar
, "recvTimingSnoopResp: src %s %s 0x%x"\
532 " FWD RESP\n", src_port
->name(), pkt
->cmdString(),
535 // as a normal response, it should go back to a master through
536 // one of our slave ports, we also pay for any outstanding
538 Tick latency
= pkt
->headerDelay
;
539 pkt
->headerDelay
= 0;
540 slavePorts
[dest_port_id
]->schedTimingResp(pkt
, curTick() + latency
);
542 respLayers
[dest_port_id
]->succeededTiming(packetFinishTime
);
545 // remove the request from the routing table
546 routeTo
.erase(route_lookup
);
549 transDist
[pkt_cmd
]++;
557 CoherentXBar::forwardTiming(PacketPtr pkt
, PortID exclude_slave_port_id
,
558 const std::vector
<QueuedSlavePort
*>& dests
)
560 DPRINTF(CoherentXBar
, "%s for %s address %x size %d\n", __func__
,
561 pkt
->cmdString(), pkt
->getAddr(), pkt
->getSize());
563 // snoops should only happen if the system isn't bypassing caches
564 assert(!system
->bypassCaches());
568 for (const auto& p
: dests
) {
569 // we could have gotten this request from a snooping master
570 // (corresponding to our own slave port that is also in
571 // snoopPorts) and should not send it back to where it came
573 if (exclude_slave_port_id
== InvalidPortID
||
574 p
->getId() != exclude_slave_port_id
) {
575 // cache is not allowed to refuse snoop
576 p
->sendTimingSnoopReq(pkt
);
581 // Stats for fanout of this forward operation
582 snoopFanout
.sample(fanout
);
586 CoherentXBar::recvReqRetry(PortID master_port_id
)
588 // responses and snoop responses never block on forwarding them,
589 // so the retry will always be coming from a port to which we
590 // tried to forward a request
591 reqLayers
[master_port_id
]->recvRetry();
595 CoherentXBar::recvAtomic(PacketPtr pkt
, PortID slave_port_id
)
597 DPRINTF(CoherentXBar
, "recvAtomic: packet src %s addr 0x%x cmd %s\n",
598 slavePorts
[slave_port_id
]->name(), pkt
->getAddr(),
601 unsigned int pkt_size
= pkt
->hasData() ? pkt
->getSize() : 0;
602 unsigned int pkt_cmd
= pkt
->cmdToIndex();
604 MemCmd snoop_response_cmd
= MemCmd::InvalidCmd
;
605 Tick snoop_response_latency
= 0;
607 if (!system
->bypassCaches()) {
608 // forward to all snoopers but the source
609 std::pair
<MemCmd
, Tick
> snoop_result
;
611 // check with the snoop filter where to forward this packet
613 snoopFilter
->lookupRequest(pkt
, *slavePorts
[slave_port_id
]);
614 snoop_response_latency
+= sf_res
.second
* clockPeriod();
615 DPRINTF(CoherentXBar
, "%s: src %s %s 0x%x"\
616 " SF size: %i lat: %i\n", __func__
,
617 slavePorts
[slave_port_id
]->name(), pkt
->cmdString(),
618 pkt
->getAddr(), sf_res
.first
.size(), sf_res
.second
);
620 // let the snoop filter know about the success of the send
621 // operation, and do it even before sending it onwards to
622 // avoid situations where atomic upward snoops sneak in
623 // between and change the filter state
624 snoopFilter
->finishRequest(false, pkt
);
626 snoop_result
= forwardAtomic(pkt
, slave_port_id
, InvalidPortID
,
629 snoop_result
= forwardAtomic(pkt
, slave_port_id
);
631 snoop_response_cmd
= snoop_result
.first
;
632 snoop_response_latency
+= snoop_result
.second
;
635 // forwardAtomic snooped into peer caches of the sender, and if
636 // this is a clean evict, but the packet is found in a cache, do
638 if ((pkt
->cmd
== MemCmd::CleanEvict
||
639 pkt
->cmd
== MemCmd::WritebackClean
) && pkt
->isBlockCached()) {
640 DPRINTF(CoherentXBar
, "Clean evict/writeback %#llx still cached, "
641 "not forwarding\n", pkt
->getAddr());
645 // even if we had a snoop response, we must continue and also
646 // perform the actual request at the destination
647 PortID master_port_id
= findPort(pkt
->getAddr());
649 // stats updates for the request
650 pktCount
[slave_port_id
][master_port_id
]++;
651 pktSize
[slave_port_id
][master_port_id
] += pkt_size
;
652 transDist
[pkt_cmd
]++;
654 // forward the request to the appropriate destination
655 Tick response_latency
= masterPorts
[master_port_id
]->sendAtomic(pkt
);
657 // if lower levels have replied, tell the snoop filter
658 if (!system
->bypassCaches() && snoopFilter
&& pkt
->isResponse()) {
659 snoopFilter
->updateResponse(pkt
, *slavePorts
[slave_port_id
]);
662 // if we got a response from a snooper, restore it here
663 if (snoop_response_cmd
!= MemCmd::InvalidCmd
) {
664 // no one else should have responded
665 assert(!pkt
->isResponse());
666 pkt
->cmd
= snoop_response_cmd
;
667 response_latency
= snoop_response_latency
;
670 // add the response data
671 if (pkt
->isResponse()) {
672 pkt_size
= pkt
->hasData() ? pkt
->getSize() : 0;
673 pkt_cmd
= pkt
->cmdToIndex();
676 pktCount
[slave_port_id
][master_port_id
]++;
677 pktSize
[slave_port_id
][master_port_id
] += pkt_size
;
678 transDist
[pkt_cmd
]++;
681 // @todo: Not setting header time
682 pkt
->payloadDelay
= response_latency
;
683 return response_latency
;
687 CoherentXBar::recvAtomicSnoop(PacketPtr pkt
, PortID master_port_id
)
689 DPRINTF(CoherentXBar
, "recvAtomicSnoop: packet src %s addr 0x%x cmd %s\n",
690 masterPorts
[master_port_id
]->name(), pkt
->getAddr(),
693 // add the request snoop data
696 // forward to all snoopers
697 std::pair
<MemCmd
, Tick
> snoop_result
;
698 Tick snoop_response_latency
= 0;
700 auto sf_res
= snoopFilter
->lookupSnoop(pkt
);
701 snoop_response_latency
+= sf_res
.second
* clockPeriod();
702 DPRINTF(CoherentXBar
, "%s: src %s %s 0x%x SF size: %i lat: %i\n",
703 __func__
, masterPorts
[master_port_id
]->name(), pkt
->cmdString(),
704 pkt
->getAddr(), sf_res
.first
.size(), sf_res
.second
);
705 snoop_result
= forwardAtomic(pkt
, InvalidPortID
, master_port_id
,
708 snoop_result
= forwardAtomic(pkt
, InvalidPortID
);
710 MemCmd snoop_response_cmd
= snoop_result
.first
;
711 snoop_response_latency
+= snoop_result
.second
;
713 if (snoop_response_cmd
!= MemCmd::InvalidCmd
)
714 pkt
->cmd
= snoop_response_cmd
;
716 // add the response snoop data
717 if (pkt
->isResponse()) {
721 // @todo: Not setting header time
722 pkt
->payloadDelay
= snoop_response_latency
;
723 return snoop_response_latency
;
726 std::pair
<MemCmd
, Tick
>
727 CoherentXBar::forwardAtomic(PacketPtr pkt
, PortID exclude_slave_port_id
,
728 PortID source_master_port_id
,
729 const std::vector
<QueuedSlavePort
*>& dests
)
731 // the packet may be changed on snoops, record the original
732 // command to enable us to restore it between snoops so that
733 // additional snoops can take place properly
734 MemCmd orig_cmd
= pkt
->cmd
;
735 MemCmd snoop_response_cmd
= MemCmd::InvalidCmd
;
736 Tick snoop_response_latency
= 0;
738 // snoops should only happen if the system isn't bypassing caches
739 assert(!system
->bypassCaches());
743 for (const auto& p
: dests
) {
744 // we could have gotten this request from a snooping master
745 // (corresponding to our own slave port that is also in
746 // snoopPorts) and should not send it back to where it came
748 if (exclude_slave_port_id
!= InvalidPortID
&&
749 p
->getId() == exclude_slave_port_id
)
752 Tick latency
= p
->sendAtomicSnoop(pkt
);
755 // in contrast to a functional access, we have to keep on
756 // going as all snoopers must be updated even if we get a
758 if (!pkt
->isResponse())
761 // response from snoop agent
762 assert(pkt
->cmd
!= orig_cmd
);
763 assert(pkt
->memInhibitAsserted());
764 // should only happen once
765 assert(snoop_response_cmd
== MemCmd::InvalidCmd
);
766 // save response state
767 snoop_response_cmd
= pkt
->cmd
;
768 snoop_response_latency
= latency
;
771 // Handle responses by the snoopers and differentiate between
772 // responses to requests from above and snoops from below
773 if (source_master_port_id
!= InvalidPortID
) {
774 // Getting a response for a snoop from below
775 assert(exclude_slave_port_id
== InvalidPortID
);
776 snoopFilter
->updateSnoopForward(pkt
, *p
,
777 *masterPorts
[source_master_port_id
]);
779 // Getting a response for a request from above
780 assert(source_master_port_id
== InvalidPortID
);
781 snoopFilter
->updateSnoopResponse(pkt
, *p
,
782 *slavePorts
[exclude_slave_port_id
]);
785 // restore original packet state for remaining snoopers
790 snoopFanout
.sample(fanout
);
792 // the packet is restored as part of the loop and any potential
793 // snoop response is part of the returned pair
794 return std::make_pair(snoop_response_cmd
, snoop_response_latency
);
798 CoherentXBar::recvFunctional(PacketPtr pkt
, PortID slave_port_id
)
800 if (!pkt
->isPrint()) {
801 // don't do DPRINTFs on PrintReq as it clutters up the output
802 DPRINTF(CoherentXBar
,
803 "recvFunctional: packet src %s addr 0x%x cmd %s\n",
804 slavePorts
[slave_port_id
]->name(), pkt
->getAddr(),
808 if (!system
->bypassCaches()) {
809 // forward to all snoopers but the source
810 forwardFunctional(pkt
, slave_port_id
);
813 // there is no need to continue if the snooping has found what we
814 // were looking for and the packet is already a response
815 if (!pkt
->isResponse()) {
816 // since our slave ports are queued ports we need to check them as well
817 for (const auto& p
: slavePorts
) {
818 // if we find a response that has the data, then the
819 // downstream caches/memories may be out of date, so simply stop
821 if (p
->checkFunctional(pkt
)) {
822 if (pkt
->needsResponse())
828 PortID dest_id
= findPort(pkt
->getAddr());
830 masterPorts
[dest_id
]->sendFunctional(pkt
);
835 CoherentXBar::recvFunctionalSnoop(PacketPtr pkt
, PortID master_port_id
)
837 if (!pkt
->isPrint()) {
838 // don't do DPRINTFs on PrintReq as it clutters up the output
839 DPRINTF(CoherentXBar
,
840 "recvFunctionalSnoop: packet src %s addr 0x%x cmd %s\n",
841 masterPorts
[master_port_id
]->name(), pkt
->getAddr(),
845 for (const auto& p
: slavePorts
) {
846 if (p
->checkFunctional(pkt
)) {
847 if (pkt
->needsResponse())
853 // forward to all snoopers
854 forwardFunctional(pkt
, InvalidPortID
);
858 CoherentXBar::forwardFunctional(PacketPtr pkt
, PortID exclude_slave_port_id
)
860 // snoops should only happen if the system isn't bypassing caches
861 assert(!system
->bypassCaches());
863 for (const auto& p
: snoopPorts
) {
864 // we could have gotten this request from a snooping master
865 // (corresponding to our own slave port that is also in
866 // snoopPorts) and should not send it back to where it came
868 if (exclude_slave_port_id
== InvalidPortID
||
869 p
->getId() != exclude_slave_port_id
)
870 p
->sendFunctionalSnoop(pkt
);
872 // if we get a response we are done
873 if (pkt
->isResponse()) {
880 CoherentXBar::regStats()
882 // register the stats of the base class and our layers
883 BaseXBar::regStats();
884 for (auto l
: reqLayers
)
886 for (auto l
: respLayers
)
888 for (auto l
: snoopLayers
)
892 .name(name() + ".snoops")
893 .desc("Total snoops (count)")
897 .init(0, snoopPorts
.size(), 1)
898 .name(name() + ".snoop_fanout")
899 .desc("Request fanout histogram")
904 CoherentXBarParams::create()
906 return new CoherentXBar(this);