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 // @todo temporary hack to deal with memory corruption issue until
144 // 4-phase transactions are complete
145 for (int x
= 0; x
< pendingDelete
.size(); x
++)
146 delete pendingDelete
[x
];
147 pendingDelete
.clear();
149 // determine the source port based on the id
150 SlavePort
*src_port
= slavePorts
[slave_port_id
];
152 // remember if the packet is an express snoop
153 bool is_express_snoop
= pkt
->isExpressSnoop();
154 bool is_inhibited
= pkt
->memInhibitAsserted();
155 // for normal requests, going downstream, the express snoop flag
156 // and the inhibited flag should always be the same
157 assert(is_express_snoop
== is_inhibited
);
159 // determine the destination based on the address
160 PortID master_port_id
= findPort(pkt
->getAddr());
162 // test if the crossbar should be considered occupied for the current
163 // port, and exclude express snoops from the check
164 if (!is_express_snoop
&& !reqLayers
[master_port_id
]->tryTiming(src_port
)) {
165 DPRINTF(CoherentXBar
, "recvTimingReq: src %s %s 0x%x BUSY\n",
166 src_port
->name(), pkt
->cmdString(), pkt
->getAddr());
170 DPRINTF(CoherentXBar
, "recvTimingReq: src %s %s expr %d 0x%x\n",
171 src_port
->name(), pkt
->cmdString(), is_express_snoop
,
174 // store size and command as they might be modified when
175 // forwarding the packet
176 unsigned int pkt_size
= pkt
->hasData() ? pkt
->getSize() : 0;
177 unsigned int pkt_cmd
= pkt
->cmdToIndex();
179 // store the old header delay so we can restore it if needed
180 Tick old_header_delay
= pkt
->headerDelay
;
182 // a request sees the frontend and forward latency
183 Tick xbar_delay
= (frontendLatency
+ forwardLatency
) * clockPeriod();
185 // set the packet header and payload delay
186 calcPacketTiming(pkt
, xbar_delay
);
188 // determine how long to be crossbar layer is busy
189 Tick packetFinishTime
= clockEdge(Cycles(1)) + pkt
->payloadDelay
;
191 if (!system
->bypassCaches()) {
192 assert(pkt
->snoopDelay
== 0);
194 // the packet is a memory-mapped request and should be
195 // broadcasted to our snoopers but the source
197 // check with the snoop filter where to forward this packet
198 auto sf_res
= snoopFilter
->lookupRequest(pkt
, *src_port
);
199 // the time required by a packet to be delivered through
200 // the xbar has to be charged also with to lookup latency
201 // of the snoop filter
202 pkt
->headerDelay
+= sf_res
.second
* clockPeriod();
203 DPRINTF(CoherentXBar
, "recvTimingReq: src %s %s 0x%x"\
204 " SF size: %i lat: %i\n", src_port
->name(),
205 pkt
->cmdString(), pkt
->getAddr(), sf_res
.first
.size(),
207 forwardTiming(pkt
, slave_port_id
, sf_res
.first
);
209 forwardTiming(pkt
, slave_port_id
);
212 // add the snoop delay to our header delay, and then reset it
213 pkt
->headerDelay
+= pkt
->snoopDelay
;
217 // forwardTiming snooped into peer caches of the sender, and if
218 // this is a clean evict, but the packet is found in a cache, do
220 if (pkt
->cmd
== MemCmd::CleanEvict
&& pkt
->isBlockCached()) {
221 DPRINTF(CoherentXBar
, "recvTimingReq: Clean evict 0x%x still cached, "
222 "not forwarding\n", pkt
->getAddr());
224 // update the layer state and schedule an idle event
225 reqLayers
[master_port_id
]->succeededTiming(packetFinishTime
);
226 pendingDelete
.push_back(pkt
);
230 // remember if the packet will generate a snoop response
231 const bool expect_snoop_resp
= !is_inhibited
&& pkt
->memInhibitAsserted();
232 const bool expect_response
= pkt
->needsResponse() &&
233 !pkt
->memInhibitAsserted();
235 // since it is a normal request, attempt to send the packet
236 bool success
= masterPorts
[master_port_id
]->sendTimingReq(pkt
);
238 if (snoopFilter
&& !system
->bypassCaches()) {
239 // Let the snoop filter know about the success of the send operation
240 snoopFilter
->finishRequest(!success
, pkt
);
243 // check if we were successful in sending the packet onwards
245 // express snoops and inhibited packets should never be forced
247 assert(!is_express_snoop
);
248 assert(!pkt
->memInhibitAsserted());
250 // restore the header delay
251 pkt
->headerDelay
= old_header_delay
;
253 DPRINTF(CoherentXBar
, "recvTimingReq: src %s %s 0x%x RETRY\n",
254 src_port
->name(), pkt
->cmdString(), pkt
->getAddr());
256 // update the layer state and schedule an idle event
257 reqLayers
[master_port_id
]->failedTiming(src_port
,
258 clockEdge(Cycles(1)));
260 // express snoops currently bypass the crossbar state entirely
261 if (!is_express_snoop
) {
262 // if this particular request will generate a snoop
264 if (expect_snoop_resp
) {
265 // we should never have an exsiting request outstanding
266 assert(outstandingSnoop
.find(pkt
->req
) ==
267 outstandingSnoop
.end());
268 outstandingSnoop
.insert(pkt
->req
);
270 // basic sanity check on the outstanding snoops
271 panic_if(outstandingSnoop
.size() > 512,
272 "Outstanding snoop requests exceeded 512\n");
275 // remember where to route the normal response to
276 if (expect_response
|| expect_snoop_resp
) {
277 assert(routeTo
.find(pkt
->req
) == routeTo
.end());
278 routeTo
[pkt
->req
] = slave_port_id
;
280 panic_if(routeTo
.size() > 512,
281 "Routing table exceeds 512 packets\n");
284 // update the layer state and schedule an idle event
285 reqLayers
[master_port_id
]->succeededTiming(packetFinishTime
);
288 // stats updates only consider packets that were successfully sent
289 pktCount
[slave_port_id
][master_port_id
]++;
290 pktSize
[slave_port_id
][master_port_id
] += pkt_size
;
291 transDist
[pkt_cmd
]++;
293 if (is_express_snoop
)
301 CoherentXBar::recvTimingResp(PacketPtr pkt
, PortID master_port_id
)
303 // determine the source port based on the id
304 MasterPort
*src_port
= masterPorts
[master_port_id
];
306 // determine the destination
307 const auto route_lookup
= routeTo
.find(pkt
->req
);
308 assert(route_lookup
!= routeTo
.end());
309 const PortID slave_port_id
= route_lookup
->second
;
310 assert(slave_port_id
!= InvalidPortID
);
311 assert(slave_port_id
< respLayers
.size());
313 // test if the crossbar should be considered occupied for the
315 if (!respLayers
[slave_port_id
]->tryTiming(src_port
)) {
316 DPRINTF(CoherentXBar
, "recvTimingResp: src %s %s 0x%x BUSY\n",
317 src_port
->name(), pkt
->cmdString(), pkt
->getAddr());
321 DPRINTF(CoherentXBar
, "recvTimingResp: src %s %s 0x%x\n",
322 src_port
->name(), pkt
->cmdString(), pkt
->getAddr());
324 // store size and command as they might be modified when
325 // forwarding the packet
326 unsigned int pkt_size
= pkt
->hasData() ? pkt
->getSize() : 0;
327 unsigned int pkt_cmd
= pkt
->cmdToIndex();
329 // a response sees the response latency
330 Tick xbar_delay
= responseLatency
* clockPeriod();
332 // set the packet header and payload delay
333 calcPacketTiming(pkt
, xbar_delay
);
335 // determine how long to be crossbar layer is busy
336 Tick packetFinishTime
= clockEdge(Cycles(1)) + pkt
->payloadDelay
;
338 if (snoopFilter
&& !system
->bypassCaches()) {
339 // let the snoop filter inspect the response and update its state
340 snoopFilter
->updateResponse(pkt
, *slavePorts
[slave_port_id
]);
343 // send the packet through the destination slave port and pay for
344 // any outstanding header delay
345 Tick latency
= pkt
->headerDelay
;
346 pkt
->headerDelay
= 0;
347 slavePorts
[slave_port_id
]->schedTimingResp(pkt
, curTick() + latency
);
349 // remove the request from the routing table
350 routeTo
.erase(route_lookup
);
352 respLayers
[slave_port_id
]->succeededTiming(packetFinishTime
);
355 pktCount
[slave_port_id
][master_port_id
]++;
356 pktSize
[slave_port_id
][master_port_id
] += pkt_size
;
357 transDist
[pkt_cmd
]++;
363 CoherentXBar::recvTimingSnoopReq(PacketPtr pkt
, PortID master_port_id
)
365 DPRINTF(CoherentXBar
, "recvTimingSnoopReq: src %s %s 0x%x\n",
366 masterPorts
[master_port_id
]->name(), pkt
->cmdString(),
369 // update stats here as we know the forwarding will succeed
370 transDist
[pkt
->cmdToIndex()]++;
373 // we should only see express snoops from caches
374 assert(pkt
->isExpressSnoop());
376 // set the packet header and payload delay, for now use forward latency
377 // @todo Assess the choice of latency further
378 calcPacketTiming(pkt
, forwardLatency
* clockPeriod());
380 // remeber if the packet is inhibited so we can see if it changes
381 const bool is_inhibited
= pkt
->memInhibitAsserted();
383 assert(pkt
->snoopDelay
== 0);
386 // let the Snoop Filter work its magic and guide probing
387 auto sf_res
= snoopFilter
->lookupSnoop(pkt
);
388 // the time required by a packet to be delivered through
389 // the xbar has to be charged also with to lookup latency
390 // of the snoop filter
391 pkt
->headerDelay
+= sf_res
.second
* clockPeriod();
392 DPRINTF(CoherentXBar
, "recvTimingSnoopReq: src %s %s 0x%x"\
393 " SF size: %i lat: %i\n", masterPorts
[master_port_id
]->name(),
394 pkt
->cmdString(), pkt
->getAddr(), sf_res
.first
.size(),
397 // forward to all snoopers
398 forwardTiming(pkt
, InvalidPortID
, sf_res
.first
);
400 forwardTiming(pkt
, InvalidPortID
);
403 // add the snoop delay to our header delay, and then reset it
404 pkt
->headerDelay
+= pkt
->snoopDelay
;
407 // if we can expect a response, remember how to route it
408 if (!is_inhibited
&& pkt
->memInhibitAsserted()) {
409 assert(routeTo
.find(pkt
->req
) == routeTo
.end());
410 routeTo
[pkt
->req
] = master_port_id
;
413 // a snoop request came from a connected slave device (one of
414 // our master ports), and if it is not coming from the slave
415 // device responsible for the address range something is
416 // wrong, hence there is nothing further to do as the packet
417 // would be going back to where it came from
418 assert(master_port_id
== findPort(pkt
->getAddr()));
422 CoherentXBar::recvTimingSnoopResp(PacketPtr pkt
, PortID slave_port_id
)
424 // determine the source port based on the id
425 SlavePort
* src_port
= slavePorts
[slave_port_id
];
427 // get the destination
428 const auto route_lookup
= routeTo
.find(pkt
->req
);
429 assert(route_lookup
!= routeTo
.end());
430 const PortID dest_port_id
= route_lookup
->second
;
431 assert(dest_port_id
!= InvalidPortID
);
433 // determine if the response is from a snoop request we
434 // created as the result of a normal request (in which case it
435 // should be in the outstandingSnoop), or if we merely forwarded
436 // someone else's snoop request
437 const bool forwardAsSnoop
= outstandingSnoop
.find(pkt
->req
) ==
438 outstandingSnoop
.end();
440 // test if the crossbar should be considered occupied for the
441 // current port, note that the check is bypassed if the response
442 // is being passed on as a normal response since this is occupying
443 // the response layer rather than the snoop response layer
444 if (forwardAsSnoop
) {
445 assert(dest_port_id
< snoopLayers
.size());
446 if (!snoopLayers
[dest_port_id
]->tryTiming(src_port
)) {
447 DPRINTF(CoherentXBar
, "recvTimingSnoopResp: src %s %s 0x%x BUSY\n",
448 src_port
->name(), pkt
->cmdString(), pkt
->getAddr());
452 // get the master port that mirrors this slave port internally
453 MasterPort
* snoop_port
= snoopRespPorts
[slave_port_id
];
454 assert(dest_port_id
< respLayers
.size());
455 if (!respLayers
[dest_port_id
]->tryTiming(snoop_port
)) {
456 DPRINTF(CoherentXBar
, "recvTimingSnoopResp: src %s %s 0x%x BUSY\n",
457 snoop_port
->name(), pkt
->cmdString(), pkt
->getAddr());
462 DPRINTF(CoherentXBar
, "recvTimingSnoopResp: src %s %s 0x%x\n",
463 src_port
->name(), pkt
->cmdString(), pkt
->getAddr());
465 // store size and command as they might be modified when
466 // forwarding the packet
467 unsigned int pkt_size
= pkt
->hasData() ? pkt
->getSize() : 0;
468 unsigned int pkt_cmd
= pkt
->cmdToIndex();
470 // responses are never express snoops
471 assert(!pkt
->isExpressSnoop());
473 // a snoop response sees the snoop response latency, and if it is
474 // forwarded as a normal response, the response latency
476 (forwardAsSnoop
? snoopResponseLatency
: responseLatency
) *
479 // set the packet header and payload delay
480 calcPacketTiming(pkt
, xbar_delay
);
482 // determine how long to be crossbar layer is busy
483 Tick packetFinishTime
= clockEdge(Cycles(1)) + pkt
->payloadDelay
;
485 // forward it either as a snoop response or a normal response
486 if (forwardAsSnoop
) {
487 // this is a snoop response to a snoop request we forwarded,
488 // e.g. coming from the L1 and going to the L2, and it should
489 // be forwarded as a snoop response
492 // update the probe filter so that it can properly track the line
493 snoopFilter
->updateSnoopForward(pkt
, *slavePorts
[slave_port_id
],
494 *masterPorts
[dest_port_id
]);
497 bool success M5_VAR_USED
=
498 masterPorts
[dest_port_id
]->sendTimingSnoopResp(pkt
);
499 pktCount
[slave_port_id
][dest_port_id
]++;
500 pktSize
[slave_port_id
][dest_port_id
] += pkt_size
;
503 snoopLayers
[dest_port_id
]->succeededTiming(packetFinishTime
);
505 // we got a snoop response on one of our slave ports,
506 // i.e. from a coherent master connected to the crossbar, and
507 // since we created the snoop request as part of recvTiming,
508 // this should now be a normal response again
509 outstandingSnoop
.erase(pkt
->req
);
511 // this is a snoop response from a coherent master, hence it
512 // should never go back to where the snoop response came from,
513 // but instead to where the original request came from
514 assert(slave_port_id
!= dest_port_id
);
517 // update the probe filter so that it can properly track the line
518 snoopFilter
->updateSnoopResponse(pkt
, *slavePorts
[slave_port_id
],
519 *slavePorts
[dest_port_id
]);
522 DPRINTF(CoherentXBar
, "recvTimingSnoopResp: src %s %s 0x%x"\
523 " FWD RESP\n", src_port
->name(), pkt
->cmdString(),
526 // as a normal response, it should go back to a master through
527 // one of our slave ports, we also pay for any outstanding
529 Tick latency
= pkt
->headerDelay
;
530 pkt
->headerDelay
= 0;
531 slavePorts
[dest_port_id
]->schedTimingResp(pkt
, curTick() + latency
);
533 respLayers
[dest_port_id
]->succeededTiming(packetFinishTime
);
536 // remove the request from the routing table
537 routeTo
.erase(route_lookup
);
540 transDist
[pkt_cmd
]++;
548 CoherentXBar::forwardTiming(PacketPtr pkt
, PortID exclude_slave_port_id
,
549 const std::vector
<QueuedSlavePort
*>& dests
)
551 DPRINTF(CoherentXBar
, "%s for %s address %x size %d\n", __func__
,
552 pkt
->cmdString(), pkt
->getAddr(), pkt
->getSize());
554 // snoops should only happen if the system isn't bypassing caches
555 assert(!system
->bypassCaches());
559 for (const auto& p
: dests
) {
560 // we could have gotten this request from a snooping master
561 // (corresponding to our own slave port that is also in
562 // snoopPorts) and should not send it back to where it came
564 if (exclude_slave_port_id
== InvalidPortID
||
565 p
->getId() != exclude_slave_port_id
) {
566 // cache is not allowed to refuse snoop
567 p
->sendTimingSnoopReq(pkt
);
572 // Stats for fanout of this forward operation
573 snoopFanout
.sample(fanout
);
577 CoherentXBar::recvReqRetry(PortID master_port_id
)
579 // responses and snoop responses never block on forwarding them,
580 // so the retry will always be coming from a port to which we
581 // tried to forward a request
582 reqLayers
[master_port_id
]->recvRetry();
586 CoherentXBar::recvAtomic(PacketPtr pkt
, PortID slave_port_id
)
588 DPRINTF(CoherentXBar
, "recvAtomic: packet src %s addr 0x%x cmd %s\n",
589 slavePorts
[slave_port_id
]->name(), pkt
->getAddr(),
592 unsigned int pkt_size
= pkt
->hasData() ? pkt
->getSize() : 0;
593 unsigned int pkt_cmd
= pkt
->cmdToIndex();
595 MemCmd snoop_response_cmd
= MemCmd::InvalidCmd
;
596 Tick snoop_response_latency
= 0;
598 if (!system
->bypassCaches()) {
599 // forward to all snoopers but the source
600 std::pair
<MemCmd
, Tick
> snoop_result
;
602 // check with the snoop filter where to forward this packet
604 snoopFilter
->lookupRequest(pkt
, *slavePorts
[slave_port_id
]);
605 snoop_response_latency
+= sf_res
.second
* clockPeriod();
606 DPRINTF(CoherentXBar
, "%s: src %s %s 0x%x"\
607 " SF size: %i lat: %i\n", __func__
,
608 slavePorts
[slave_port_id
]->name(), pkt
->cmdString(),
609 pkt
->getAddr(), sf_res
.first
.size(), sf_res
.second
);
611 // let the snoop filter know about the success of the send
612 // operation, and do it even before sending it onwards to
613 // avoid situations where atomic upward snoops sneak in
614 // between and change the filter state
615 snoopFilter
->finishRequest(false, pkt
);
617 snoop_result
= forwardAtomic(pkt
, slave_port_id
, InvalidPortID
,
620 snoop_result
= forwardAtomic(pkt
, slave_port_id
);
622 snoop_response_cmd
= snoop_result
.first
;
623 snoop_response_latency
+= snoop_result
.second
;
626 // forwardAtomic snooped into peer caches of the sender, and if
627 // this is a clean evict, but the packet is found in a cache, do
629 if (pkt
->cmd
== MemCmd::CleanEvict
&& pkt
->isBlockCached()) {
630 DPRINTF(CoherentXBar
, "recvAtomic: Clean evict 0x%x still cached, "
631 "not forwarding\n", pkt
->getAddr());
635 // even if we had a snoop response, we must continue and also
636 // perform the actual request at the destination
637 PortID master_port_id
= findPort(pkt
->getAddr());
639 // stats updates for the request
640 pktCount
[slave_port_id
][master_port_id
]++;
641 pktSize
[slave_port_id
][master_port_id
] += pkt_size
;
642 transDist
[pkt_cmd
]++;
644 // forward the request to the appropriate destination
645 Tick response_latency
= masterPorts
[master_port_id
]->sendAtomic(pkt
);
647 // if lower levels have replied, tell the snoop filter
648 if (!system
->bypassCaches() && snoopFilter
&& pkt
->isResponse()) {
649 snoopFilter
->updateResponse(pkt
, *slavePorts
[slave_port_id
]);
652 // if we got a response from a snooper, restore it here
653 if (snoop_response_cmd
!= MemCmd::InvalidCmd
) {
654 // no one else should have responded
655 assert(!pkt
->isResponse());
656 pkt
->cmd
= snoop_response_cmd
;
657 response_latency
= snoop_response_latency
;
660 // add the response data
661 if (pkt
->isResponse()) {
662 pkt_size
= pkt
->hasData() ? pkt
->getSize() : 0;
663 pkt_cmd
= pkt
->cmdToIndex();
666 pktCount
[slave_port_id
][master_port_id
]++;
667 pktSize
[slave_port_id
][master_port_id
] += pkt_size
;
668 transDist
[pkt_cmd
]++;
671 // @todo: Not setting header time
672 pkt
->payloadDelay
= response_latency
;
673 return response_latency
;
677 CoherentXBar::recvAtomicSnoop(PacketPtr pkt
, PortID master_port_id
)
679 DPRINTF(CoherentXBar
, "recvAtomicSnoop: packet src %s addr 0x%x cmd %s\n",
680 masterPorts
[master_port_id
]->name(), pkt
->getAddr(),
683 // add the request snoop data
686 // forward to all snoopers
687 std::pair
<MemCmd
, Tick
> snoop_result
;
688 Tick snoop_response_latency
= 0;
690 auto sf_res
= snoopFilter
->lookupSnoop(pkt
);
691 snoop_response_latency
+= sf_res
.second
* clockPeriod();
692 DPRINTF(CoherentXBar
, "%s: src %s %s 0x%x SF size: %i lat: %i\n",
693 __func__
, masterPorts
[master_port_id
]->name(), pkt
->cmdString(),
694 pkt
->getAddr(), sf_res
.first
.size(), sf_res
.second
);
695 snoop_result
= forwardAtomic(pkt
, InvalidPortID
, master_port_id
,
698 snoop_result
= forwardAtomic(pkt
, InvalidPortID
);
700 MemCmd snoop_response_cmd
= snoop_result
.first
;
701 snoop_response_latency
+= snoop_result
.second
;
703 if (snoop_response_cmd
!= MemCmd::InvalidCmd
)
704 pkt
->cmd
= snoop_response_cmd
;
706 // add the response snoop data
707 if (pkt
->isResponse()) {
711 // @todo: Not setting header time
712 pkt
->payloadDelay
= snoop_response_latency
;
713 return snoop_response_latency
;
716 std::pair
<MemCmd
, Tick
>
717 CoherentXBar::forwardAtomic(PacketPtr pkt
, PortID exclude_slave_port_id
,
718 PortID source_master_port_id
,
719 const std::vector
<QueuedSlavePort
*>& dests
)
721 // the packet may be changed on snoops, record the original
722 // command to enable us to restore it between snoops so that
723 // additional snoops can take place properly
724 MemCmd orig_cmd
= pkt
->cmd
;
725 MemCmd snoop_response_cmd
= MemCmd::InvalidCmd
;
726 Tick snoop_response_latency
= 0;
728 // snoops should only happen if the system isn't bypassing caches
729 assert(!system
->bypassCaches());
733 for (const auto& p
: dests
) {
734 // we could have gotten this request from a snooping master
735 // (corresponding to our own slave port that is also in
736 // snoopPorts) and should not send it back to where it came
738 if (exclude_slave_port_id
!= InvalidPortID
&&
739 p
->getId() == exclude_slave_port_id
)
742 Tick latency
= p
->sendAtomicSnoop(pkt
);
745 // in contrast to a functional access, we have to keep on
746 // going as all snoopers must be updated even if we get a
748 if (!pkt
->isResponse())
751 // response from snoop agent
752 assert(pkt
->cmd
!= orig_cmd
);
753 assert(pkt
->memInhibitAsserted());
754 // should only happen once
755 assert(snoop_response_cmd
== MemCmd::InvalidCmd
);
756 // save response state
757 snoop_response_cmd
= pkt
->cmd
;
758 snoop_response_latency
= latency
;
761 // Handle responses by the snoopers and differentiate between
762 // responses to requests from above and snoops from below
763 if (source_master_port_id
!= InvalidPortID
) {
764 // Getting a response for a snoop from below
765 assert(exclude_slave_port_id
== InvalidPortID
);
766 snoopFilter
->updateSnoopForward(pkt
, *p
,
767 *masterPorts
[source_master_port_id
]);
769 // Getting a response for a request from above
770 assert(source_master_port_id
== InvalidPortID
);
771 snoopFilter
->updateSnoopResponse(pkt
, *p
,
772 *slavePorts
[exclude_slave_port_id
]);
775 // restore original packet state for remaining snoopers
780 snoopFanout
.sample(fanout
);
782 // the packet is restored as part of the loop and any potential
783 // snoop response is part of the returned pair
784 return std::make_pair(snoop_response_cmd
, snoop_response_latency
);
788 CoherentXBar::recvFunctional(PacketPtr pkt
, PortID slave_port_id
)
790 if (!pkt
->isPrint()) {
791 // don't do DPRINTFs on PrintReq as it clutters up the output
792 DPRINTF(CoherentXBar
,
793 "recvFunctional: packet src %s addr 0x%x cmd %s\n",
794 slavePorts
[slave_port_id
]->name(), pkt
->getAddr(),
798 if (!system
->bypassCaches()) {
799 // forward to all snoopers but the source
800 forwardFunctional(pkt
, slave_port_id
);
803 // there is no need to continue if the snooping has found what we
804 // were looking for and the packet is already a response
805 if (!pkt
->isResponse()) {
806 // since our slave ports are queued ports we need to check them as well
807 for (const auto& p
: slavePorts
) {
808 // if we find a response that has the data, then the
809 // downstream caches/memories may be out of date, so simply stop
811 if (p
->checkFunctional(pkt
)) {
812 if (pkt
->needsResponse())
818 PortID dest_id
= findPort(pkt
->getAddr());
820 masterPorts
[dest_id
]->sendFunctional(pkt
);
825 CoherentXBar::recvFunctionalSnoop(PacketPtr pkt
, PortID master_port_id
)
827 if (!pkt
->isPrint()) {
828 // don't do DPRINTFs on PrintReq as it clutters up the output
829 DPRINTF(CoherentXBar
,
830 "recvFunctionalSnoop: packet src %s addr 0x%x cmd %s\n",
831 masterPorts
[master_port_id
]->name(), pkt
->getAddr(),
835 // forward to all snoopers
836 forwardFunctional(pkt
, InvalidPortID
);
840 CoherentXBar::forwardFunctional(PacketPtr pkt
, PortID exclude_slave_port_id
)
842 // snoops should only happen if the system isn't bypassing caches
843 assert(!system
->bypassCaches());
845 for (const auto& p
: snoopPorts
) {
846 // we could have gotten this request from a snooping master
847 // (corresponding to our own slave port that is also in
848 // snoopPorts) and should not send it back to where it came
850 if (exclude_slave_port_id
== InvalidPortID
||
851 p
->getId() != exclude_slave_port_id
)
852 p
->sendFunctionalSnoop(pkt
);
854 // if we get a response we are done
855 if (pkt
->isResponse()) {
862 CoherentXBar::regStats()
864 // register the stats of the base class and our layers
865 BaseXBar::regStats();
866 for (auto l
: reqLayers
)
868 for (auto l
: respLayers
)
870 for (auto l
: snoopLayers
)
874 .name(name() + ".snoops")
875 .desc("Total snoops (count)")
879 .init(0, snoopPorts
.size(), 1)
880 .name(name() + ".snoop_fanout")
881 .desc("Request fanout histogram")
886 CoherentXBarParams::create()
888 return new CoherentXBar(this);