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 cache_responding
= pkt
->cacheResponding();
149 // for normal requests, going downstream, the express snoop flag
150 // and the cache responding flag should always be the same
151 assert(is_express_snoop
== cache_responding
);
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 by
240 // checking if a cache set the cacheResponding flag during the
242 const bool expect_snoop_resp
= !cache_responding
&& pkt
->cacheResponding();
243 const bool expect_response
= pkt
->needsResponse() &&
244 !pkt
->cacheResponding();
246 // since it is a normal request, attempt to send the packet
247 bool success
= masterPorts
[master_port_id
]->sendTimingReq(pkt
);
249 if (snoopFilter
&& !system
->bypassCaches()) {
250 // Let the snoop filter know about the success of the send operation
251 snoopFilter
->finishRequest(!success
, pkt
);
254 // check if we were successful in sending the packet onwards
256 // express snoops should never be forced to retry
257 assert(!is_express_snoop
);
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 // remember if a cache has already committed to responding so we
390 // can see if it changes during the snooping
391 const bool cache_responding
= pkt
->cacheResponding();
393 assert(pkt
->snoopDelay
== 0);
396 // let the Snoop Filter work its magic and guide probing
397 auto sf_res
= snoopFilter
->lookupSnoop(pkt
);
398 // the time required by a packet to be delivered through
399 // the xbar has to be charged also with to lookup latency
400 // of the snoop filter
401 pkt
->headerDelay
+= sf_res
.second
* clockPeriod();
402 DPRINTF(CoherentXBar
, "recvTimingSnoopReq: src %s %s 0x%x"\
403 " SF size: %i lat: %i\n", masterPorts
[master_port_id
]->name(),
404 pkt
->cmdString(), pkt
->getAddr(), sf_res
.first
.size(),
407 // forward to all snoopers
408 forwardTiming(pkt
, InvalidPortID
, sf_res
.first
);
410 forwardTiming(pkt
, InvalidPortID
);
413 // add the snoop delay to our header delay, and then reset it
414 pkt
->headerDelay
+= pkt
->snoopDelay
;
417 // if we can expect a response, remember how to route it
418 if (!cache_responding
&& pkt
->cacheResponding()) {
419 assert(routeTo
.find(pkt
->req
) == routeTo
.end());
420 routeTo
[pkt
->req
] = master_port_id
;
423 // a snoop request came from a connected slave device (one of
424 // our master ports), and if it is not coming from the slave
425 // device responsible for the address range something is
426 // wrong, hence there is nothing further to do as the packet
427 // would be going back to where it came from
428 assert(master_port_id
== findPort(pkt
->getAddr()));
432 CoherentXBar::recvTimingSnoopResp(PacketPtr pkt
, PortID slave_port_id
)
434 // determine the source port based on the id
435 SlavePort
* src_port
= slavePorts
[slave_port_id
];
437 // get the destination
438 const auto route_lookup
= routeTo
.find(pkt
->req
);
439 assert(route_lookup
!= routeTo
.end());
440 const PortID dest_port_id
= route_lookup
->second
;
441 assert(dest_port_id
!= InvalidPortID
);
443 // determine if the response is from a snoop request we
444 // created as the result of a normal request (in which case it
445 // should be in the outstandingSnoop), or if we merely forwarded
446 // someone else's snoop request
447 const bool forwardAsSnoop
= outstandingSnoop
.find(pkt
->req
) ==
448 outstandingSnoop
.end();
450 // test if the crossbar should be considered occupied for the
451 // current port, note that the check is bypassed if the response
452 // is being passed on as a normal response since this is occupying
453 // the response layer rather than the snoop response layer
454 if (forwardAsSnoop
) {
455 assert(dest_port_id
< snoopLayers
.size());
456 if (!snoopLayers
[dest_port_id
]->tryTiming(src_port
)) {
457 DPRINTF(CoherentXBar
, "recvTimingSnoopResp: src %s %s 0x%x BUSY\n",
458 src_port
->name(), pkt
->cmdString(), pkt
->getAddr());
462 // get the master port that mirrors this slave port internally
463 MasterPort
* snoop_port
= snoopRespPorts
[slave_port_id
];
464 assert(dest_port_id
< respLayers
.size());
465 if (!respLayers
[dest_port_id
]->tryTiming(snoop_port
)) {
466 DPRINTF(CoherentXBar
, "recvTimingSnoopResp: src %s %s 0x%x BUSY\n",
467 snoop_port
->name(), pkt
->cmdString(), pkt
->getAddr());
472 DPRINTF(CoherentXBar
, "recvTimingSnoopResp: src %s %s 0x%x\n",
473 src_port
->name(), pkt
->cmdString(), pkt
->getAddr());
475 // store size and command as they might be modified when
476 // forwarding the packet
477 unsigned int pkt_size
= pkt
->hasData() ? pkt
->getSize() : 0;
478 unsigned int pkt_cmd
= pkt
->cmdToIndex();
480 // responses are never express snoops
481 assert(!pkt
->isExpressSnoop());
483 // a snoop response sees the snoop response latency, and if it is
484 // forwarded as a normal response, the response latency
486 (forwardAsSnoop
? snoopResponseLatency
: responseLatency
) *
489 // set the packet header and payload delay
490 calcPacketTiming(pkt
, xbar_delay
);
492 // determine how long to be crossbar layer is busy
493 Tick packetFinishTime
= clockEdge(Cycles(1)) + pkt
->payloadDelay
;
495 // forward it either as a snoop response or a normal response
496 if (forwardAsSnoop
) {
497 // this is a snoop response to a snoop request we forwarded,
498 // e.g. coming from the L1 and going to the L2, and it should
499 // be forwarded as a snoop response
502 // update the probe filter so that it can properly track the line
503 snoopFilter
->updateSnoopForward(pkt
, *slavePorts
[slave_port_id
],
504 *masterPorts
[dest_port_id
]);
507 bool success M5_VAR_USED
=
508 masterPorts
[dest_port_id
]->sendTimingSnoopResp(pkt
);
509 pktCount
[slave_port_id
][dest_port_id
]++;
510 pktSize
[slave_port_id
][dest_port_id
] += pkt_size
;
513 snoopLayers
[dest_port_id
]->succeededTiming(packetFinishTime
);
515 // we got a snoop response on one of our slave ports,
516 // i.e. from a coherent master connected to the crossbar, and
517 // since we created the snoop request as part of recvTiming,
518 // this should now be a normal response again
519 outstandingSnoop
.erase(pkt
->req
);
521 // this is a snoop response from a coherent master, hence it
522 // should never go back to where the snoop response came from,
523 // but instead to where the original request came from
524 assert(slave_port_id
!= dest_port_id
);
527 // update the probe filter so that it can properly track the line
528 snoopFilter
->updateSnoopResponse(pkt
, *slavePorts
[slave_port_id
],
529 *slavePorts
[dest_port_id
]);
532 DPRINTF(CoherentXBar
, "recvTimingSnoopResp: src %s %s 0x%x"\
533 " FWD RESP\n", src_port
->name(), pkt
->cmdString(),
536 // as a normal response, it should go back to a master through
537 // one of our slave ports, we also pay for any outstanding
539 Tick latency
= pkt
->headerDelay
;
540 pkt
->headerDelay
= 0;
541 slavePorts
[dest_port_id
]->schedTimingResp(pkt
, curTick() + latency
);
543 respLayers
[dest_port_id
]->succeededTiming(packetFinishTime
);
546 // remove the request from the routing table
547 routeTo
.erase(route_lookup
);
550 transDist
[pkt_cmd
]++;
558 CoherentXBar::forwardTiming(PacketPtr pkt
, PortID exclude_slave_port_id
,
559 const std::vector
<QueuedSlavePort
*>& dests
)
561 DPRINTF(CoherentXBar
, "%s for %s address %x size %d\n", __func__
,
562 pkt
->cmdString(), pkt
->getAddr(), pkt
->getSize());
564 // snoops should only happen if the system isn't bypassing caches
565 assert(!system
->bypassCaches());
569 for (const auto& p
: dests
) {
570 // we could have gotten this request from a snooping master
571 // (corresponding to our own slave port that is also in
572 // snoopPorts) and should not send it back to where it came
574 if (exclude_slave_port_id
== InvalidPortID
||
575 p
->getId() != exclude_slave_port_id
) {
576 // cache is not allowed to refuse snoop
577 p
->sendTimingSnoopReq(pkt
);
582 // Stats for fanout of this forward operation
583 snoopFanout
.sample(fanout
);
587 CoherentXBar::recvReqRetry(PortID master_port_id
)
589 // responses and snoop responses never block on forwarding them,
590 // so the retry will always be coming from a port to which we
591 // tried to forward a request
592 reqLayers
[master_port_id
]->recvRetry();
596 CoherentXBar::recvAtomic(PacketPtr pkt
, PortID slave_port_id
)
598 DPRINTF(CoherentXBar
, "recvAtomic: packet src %s addr 0x%x cmd %s\n",
599 slavePorts
[slave_port_id
]->name(), pkt
->getAddr(),
602 unsigned int pkt_size
= pkt
->hasData() ? pkt
->getSize() : 0;
603 unsigned int pkt_cmd
= pkt
->cmdToIndex();
605 MemCmd snoop_response_cmd
= MemCmd::InvalidCmd
;
606 Tick snoop_response_latency
= 0;
608 if (!system
->bypassCaches()) {
609 // forward to all snoopers but the source
610 std::pair
<MemCmd
, Tick
> snoop_result
;
612 // check with the snoop filter where to forward this packet
614 snoopFilter
->lookupRequest(pkt
, *slavePorts
[slave_port_id
]);
615 snoop_response_latency
+= sf_res
.second
* clockPeriod();
616 DPRINTF(CoherentXBar
, "%s: src %s %s 0x%x"\
617 " SF size: %i lat: %i\n", __func__
,
618 slavePorts
[slave_port_id
]->name(), pkt
->cmdString(),
619 pkt
->getAddr(), sf_res
.first
.size(), sf_res
.second
);
621 // let the snoop filter know about the success of the send
622 // operation, and do it even before sending it onwards to
623 // avoid situations where atomic upward snoops sneak in
624 // between and change the filter state
625 snoopFilter
->finishRequest(false, pkt
);
627 snoop_result
= forwardAtomic(pkt
, slave_port_id
, InvalidPortID
,
630 snoop_result
= forwardAtomic(pkt
, slave_port_id
);
632 snoop_response_cmd
= snoop_result
.first
;
633 snoop_response_latency
+= snoop_result
.second
;
636 // forwardAtomic snooped into peer caches of the sender, and if
637 // this is a clean evict, but the packet is found in a cache, do
639 if ((pkt
->cmd
== MemCmd::CleanEvict
||
640 pkt
->cmd
== MemCmd::WritebackClean
) && pkt
->isBlockCached()) {
641 DPRINTF(CoherentXBar
, "Clean evict/writeback %#llx still cached, "
642 "not forwarding\n", pkt
->getAddr());
646 // even if we had a snoop response, we must continue and also
647 // perform the actual request at the destination
648 PortID master_port_id
= findPort(pkt
->getAddr());
650 // stats updates for the request
651 pktCount
[slave_port_id
][master_port_id
]++;
652 pktSize
[slave_port_id
][master_port_id
] += pkt_size
;
653 transDist
[pkt_cmd
]++;
655 // forward the request to the appropriate destination
656 Tick response_latency
= masterPorts
[master_port_id
]->sendAtomic(pkt
);
658 // if lower levels have replied, tell the snoop filter
659 if (!system
->bypassCaches() && snoopFilter
&& pkt
->isResponse()) {
660 snoopFilter
->updateResponse(pkt
, *slavePorts
[slave_port_id
]);
663 // if we got a response from a snooper, restore it here
664 if (snoop_response_cmd
!= MemCmd::InvalidCmd
) {
665 // no one else should have responded
666 assert(!pkt
->isResponse());
667 pkt
->cmd
= snoop_response_cmd
;
668 response_latency
= snoop_response_latency
;
671 // add the response data
672 if (pkt
->isResponse()) {
673 pkt_size
= pkt
->hasData() ? pkt
->getSize() : 0;
674 pkt_cmd
= pkt
->cmdToIndex();
677 pktCount
[slave_port_id
][master_port_id
]++;
678 pktSize
[slave_port_id
][master_port_id
] += pkt_size
;
679 transDist
[pkt_cmd
]++;
682 // @todo: Not setting header time
683 pkt
->payloadDelay
= response_latency
;
684 return response_latency
;
688 CoherentXBar::recvAtomicSnoop(PacketPtr pkt
, PortID master_port_id
)
690 DPRINTF(CoherentXBar
, "recvAtomicSnoop: packet src %s addr 0x%x cmd %s\n",
691 masterPorts
[master_port_id
]->name(), pkt
->getAddr(),
694 // add the request snoop data
697 // forward to all snoopers
698 std::pair
<MemCmd
, Tick
> snoop_result
;
699 Tick snoop_response_latency
= 0;
701 auto sf_res
= snoopFilter
->lookupSnoop(pkt
);
702 snoop_response_latency
+= sf_res
.second
* clockPeriod();
703 DPRINTF(CoherentXBar
, "%s: src %s %s 0x%x SF size: %i lat: %i\n",
704 __func__
, masterPorts
[master_port_id
]->name(), pkt
->cmdString(),
705 pkt
->getAddr(), sf_res
.first
.size(), sf_res
.second
);
706 snoop_result
= forwardAtomic(pkt
, InvalidPortID
, master_port_id
,
709 snoop_result
= forwardAtomic(pkt
, InvalidPortID
);
711 MemCmd snoop_response_cmd
= snoop_result
.first
;
712 snoop_response_latency
+= snoop_result
.second
;
714 if (snoop_response_cmd
!= MemCmd::InvalidCmd
)
715 pkt
->cmd
= snoop_response_cmd
;
717 // add the response snoop data
718 if (pkt
->isResponse()) {
722 // @todo: Not setting header time
723 pkt
->payloadDelay
= snoop_response_latency
;
724 return snoop_response_latency
;
727 std::pair
<MemCmd
, Tick
>
728 CoherentXBar::forwardAtomic(PacketPtr pkt
, PortID exclude_slave_port_id
,
729 PortID source_master_port_id
,
730 const std::vector
<QueuedSlavePort
*>& dests
)
732 // the packet may be changed on snoops, record the original
733 // command to enable us to restore it between snoops so that
734 // additional snoops can take place properly
735 MemCmd orig_cmd
= pkt
->cmd
;
736 MemCmd snoop_response_cmd
= MemCmd::InvalidCmd
;
737 Tick snoop_response_latency
= 0;
739 // snoops should only happen if the system isn't bypassing caches
740 assert(!system
->bypassCaches());
744 for (const auto& p
: dests
) {
745 // we could have gotten this request from a snooping master
746 // (corresponding to our own slave port that is also in
747 // snoopPorts) and should not send it back to where it came
749 if (exclude_slave_port_id
!= InvalidPortID
&&
750 p
->getId() == exclude_slave_port_id
)
753 Tick latency
= p
->sendAtomicSnoop(pkt
);
756 // in contrast to a functional access, we have to keep on
757 // going as all snoopers must be updated even if we get a
759 if (!pkt
->isResponse())
762 // response from snoop agent
763 assert(pkt
->cmd
!= orig_cmd
);
764 assert(pkt
->cacheResponding());
765 // should only happen once
766 assert(snoop_response_cmd
== MemCmd::InvalidCmd
);
767 // save response state
768 snoop_response_cmd
= pkt
->cmd
;
769 snoop_response_latency
= latency
;
772 // Handle responses by the snoopers and differentiate between
773 // responses to requests from above and snoops from below
774 if (source_master_port_id
!= InvalidPortID
) {
775 // Getting a response for a snoop from below
776 assert(exclude_slave_port_id
== InvalidPortID
);
777 snoopFilter
->updateSnoopForward(pkt
, *p
,
778 *masterPorts
[source_master_port_id
]);
780 // Getting a response for a request from above
781 assert(source_master_port_id
== InvalidPortID
);
782 snoopFilter
->updateSnoopResponse(pkt
, *p
,
783 *slavePorts
[exclude_slave_port_id
]);
786 // restore original packet state for remaining snoopers
791 snoopFanout
.sample(fanout
);
793 // the packet is restored as part of the loop and any potential
794 // snoop response is part of the returned pair
795 return std::make_pair(snoop_response_cmd
, snoop_response_latency
);
799 CoherentXBar::recvFunctional(PacketPtr pkt
, PortID slave_port_id
)
801 if (!pkt
->isPrint()) {
802 // don't do DPRINTFs on PrintReq as it clutters up the output
803 DPRINTF(CoherentXBar
,
804 "recvFunctional: packet src %s addr 0x%x cmd %s\n",
805 slavePorts
[slave_port_id
]->name(), pkt
->getAddr(),
809 if (!system
->bypassCaches()) {
810 // forward to all snoopers but the source
811 forwardFunctional(pkt
, slave_port_id
);
814 // there is no need to continue if the snooping has found what we
815 // were looking for and the packet is already a response
816 if (!pkt
->isResponse()) {
817 // since our slave ports are queued ports we need to check them as well
818 for (const auto& p
: slavePorts
) {
819 // if we find a response that has the data, then the
820 // downstream caches/memories may be out of date, so simply stop
822 if (p
->checkFunctional(pkt
)) {
823 if (pkt
->needsResponse())
829 PortID dest_id
= findPort(pkt
->getAddr());
831 masterPorts
[dest_id
]->sendFunctional(pkt
);
836 CoherentXBar::recvFunctionalSnoop(PacketPtr pkt
, PortID master_port_id
)
838 if (!pkt
->isPrint()) {
839 // don't do DPRINTFs on PrintReq as it clutters up the output
840 DPRINTF(CoherentXBar
,
841 "recvFunctionalSnoop: packet src %s addr 0x%x cmd %s\n",
842 masterPorts
[master_port_id
]->name(), pkt
->getAddr(),
846 for (const auto& p
: slavePorts
) {
847 if (p
->checkFunctional(pkt
)) {
848 if (pkt
->needsResponse())
854 // forward to all snoopers
855 forwardFunctional(pkt
, InvalidPortID
);
859 CoherentXBar::forwardFunctional(PacketPtr pkt
, PortID exclude_slave_port_id
)
861 // snoops should only happen if the system isn't bypassing caches
862 assert(!system
->bypassCaches());
864 for (const auto& p
: snoopPorts
) {
865 // we could have gotten this request from a snooping master
866 // (corresponding to our own slave port that is also in
867 // snoopPorts) and should not send it back to where it came
869 if (exclude_slave_port_id
== InvalidPortID
||
870 p
->getId() != exclude_slave_port_id
)
871 p
->sendFunctionalSnoop(pkt
);
873 // if we get a response we are done
874 if (pkt
->isResponse()) {
881 CoherentXBar::regStats()
883 // register the stats of the base class and our layers
884 BaseXBar::regStats();
885 for (auto l
: reqLayers
)
887 for (auto l
: respLayers
)
889 for (auto l
: snoopLayers
)
893 .name(name() + ".snoops")
894 .desc("Total snoops (count)")
898 .init(0, snoopPorts
.size(), 1)
899 .name(name() + ".snoop_fanout")
900 .desc("Request fanout histogram")
905 CoherentXBarParams::create()
907 return new CoherentXBar(this);