coherent_xbar.cc (12334:e0ab29a34764) coherent_xbar.cc (12341:6eebba99d117)
1/*
2 * Copyright (c) 2011-2017 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) 2006 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 * Authors: Ali Saidi
41 * Andreas Hansson
42 * William Wang
43 */
44
45/**
46 * @file
47 * Definition of a crossbar object.
48 */
49
50#include "mem/coherent_xbar.hh"
51
52#include "base/logging.hh"
53#include "base/trace.hh"
54#include "debug/AddrRanges.hh"
55#include "debug/CoherentXBar.hh"
56#include "sim/system.hh"
57
58CoherentXBar::CoherentXBar(const CoherentXBarParams *p)
59 : BaseXBar(p), system(p->system), snoopFilter(p->snoop_filter),
60 snoopResponseLatency(p->snoop_response_latency),
1/*
2 * Copyright (c) 2011-2017 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) 2006 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 * Authors: Ali Saidi
41 * Andreas Hansson
42 * William Wang
43 */
44
45/**
46 * @file
47 * Definition of a crossbar object.
48 */
49
50#include "mem/coherent_xbar.hh"
51
52#include "base/logging.hh"
53#include "base/trace.hh"
54#include "debug/AddrRanges.hh"
55#include "debug/CoherentXBar.hh"
56#include "sim/system.hh"
57
58CoherentXBar::CoherentXBar(const CoherentXBarParams *p)
59 : BaseXBar(p), system(p->system), snoopFilter(p->snoop_filter),
60 snoopResponseLatency(p->snoop_response_latency),
61 pointOfCoherency(p->point_of_coherency)
61 pointOfCoherency(p->point_of_coherency),
62 pointOfUnification(p->point_of_unification)
62{
63 // create the ports based on the size of the master and slave
64 // vector ports, and the presence of the default port, the ports
65 // are enumerated starting from zero
66 for (int i = 0; i < p->port_master_connection_count; ++i) {
67 std::string portName = csprintf("%s.master[%d]", name(), i);
68 MasterPort* bp = new CoherentXBarMasterPort(portName, *this, i);
69 masterPorts.push_back(bp);
70 reqLayers.push_back(new ReqLayer(*bp, *this,
71 csprintf(".reqLayer%d", i)));
72 snoopLayers.push_back(new SnoopRespLayer(*bp, *this,
73 csprintf(".snoopLayer%d", i)));
74 }
75
76 // see if we have a default slave device connected and if so add
77 // our corresponding master port
78 if (p->port_default_connection_count) {
79 defaultPortID = masterPorts.size();
80 std::string portName = name() + ".default";
81 MasterPort* bp = new CoherentXBarMasterPort(portName, *this,
82 defaultPortID);
83 masterPorts.push_back(bp);
84 reqLayers.push_back(new ReqLayer(*bp, *this, csprintf(".reqLayer%d",
85 defaultPortID)));
86 snoopLayers.push_back(new SnoopRespLayer(*bp, *this,
87 csprintf(".snoopLayer%d",
88 defaultPortID)));
89 }
90
91 // create the slave ports, once again starting at zero
92 for (int i = 0; i < p->port_slave_connection_count; ++i) {
93 std::string portName = csprintf("%s.slave[%d]", name(), i);
94 QueuedSlavePort* bp = new CoherentXBarSlavePort(portName, *this, i);
95 slavePorts.push_back(bp);
96 respLayers.push_back(new RespLayer(*bp, *this,
97 csprintf(".respLayer%d", i)));
98 snoopRespPorts.push_back(new SnoopRespPort(*bp, *this));
99 }
100
101 clearPortCache();
102}
103
104CoherentXBar::~CoherentXBar()
105{
106 for (auto l: reqLayers)
107 delete l;
108 for (auto l: respLayers)
109 delete l;
110 for (auto l: snoopLayers)
111 delete l;
112 for (auto p: snoopRespPorts)
113 delete p;
114}
115
116void
117CoherentXBar::init()
118{
119 BaseXBar::init();
120
121 // iterate over our slave ports and determine which of our
122 // neighbouring master ports are snooping and add them as snoopers
123 for (const auto& p: slavePorts) {
124 // check if the connected master port is snooping
125 if (p->isSnooping()) {
126 DPRINTF(AddrRanges, "Adding snooping master %s\n",
127 p->getMasterPort().name());
128 snoopPorts.push_back(p);
129 }
130 }
131
132 if (snoopPorts.empty())
133 warn("CoherentXBar %s has no snooping ports attached!\n", name());
134
135 // inform the snoop filter about the slave ports so it can create
136 // its own internal representation
137 if (snoopFilter)
138 snoopFilter->setSlavePorts(slavePorts);
139}
140
141bool
142CoherentXBar::recvTimingReq(PacketPtr pkt, PortID slave_port_id)
143{
144 // determine the source port based on the id
145 SlavePort *src_port = slavePorts[slave_port_id];
146
147 // remember if the packet is an express snoop
148 bool is_express_snoop = pkt->isExpressSnoop();
149 bool cache_responding = pkt->cacheResponding();
150 // for normal requests, going downstream, the express snoop flag
151 // and the cache responding flag should always be the same
152 assert(is_express_snoop == cache_responding);
153
154 // determine the destination based on the address
155 PortID master_port_id = findPort(pkt->getAddr());
156
157 // test if the crossbar should be considered occupied for the current
158 // port, and exclude express snoops from the check
159 if (!is_express_snoop && !reqLayers[master_port_id]->tryTiming(src_port)) {
160 DPRINTF(CoherentXBar, "%s: src %s packet %s BUSY\n", __func__,
161 src_port->name(), pkt->print());
162 return false;
163 }
164
165 DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__,
166 src_port->name(), pkt->print());
167
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();
172
173 // store the old header delay so we can restore it if needed
174 Tick old_header_delay = pkt->headerDelay;
175
176 // a request sees the frontend and forward latency
177 Tick xbar_delay = (frontendLatency + forwardLatency) * clockPeriod();
178
179 // set the packet header and payload delay
180 calcPacketTiming(pkt, xbar_delay);
181
182 // determine how long to be crossbar layer is busy
183 Tick packetFinishTime = clockEdge(Cycles(1)) + pkt->payloadDelay;
184
185 if (!system->bypassCaches()) {
186 assert(pkt->snoopDelay == 0);
187
188 // the packet is a memory-mapped request and should be
189 // broadcasted to our snoopers but the source
190 if (snoopFilter) {
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, "%s: src %s packet %s SF size: %i lat: %i\n",
198 __func__, src_port->name(), pkt->print(),
199 sf_res.first.size(), sf_res.second);
200
201 if (pkt->isEviction()) {
202 // for block-evicting packets, i.e. writebacks and
203 // clean evictions, there is no need to snoop up, as
204 // all we do is determine if the block is cached or
205 // not, instead just set it here based on the snoop
206 // filter result
207 if (!sf_res.first.empty())
208 pkt->setBlockCached();
209 } else {
210 forwardTiming(pkt, slave_port_id, sf_res.first);
211 }
212 } else {
213 forwardTiming(pkt, slave_port_id);
214 }
215
216 // add the snoop delay to our header delay, and then reset it
217 pkt->headerDelay += pkt->snoopDelay;
218 pkt->snoopDelay = 0;
219 }
220
221 // set up a sensible starting point
222 bool success = true;
223
224 // remember if the packet will generate a snoop response by
225 // checking if a cache set the cacheResponding flag during the
226 // snooping above
227 const bool expect_snoop_resp = !cache_responding && pkt->cacheResponding();
228 bool expect_response = pkt->needsResponse() && !pkt->cacheResponding();
229
230 const bool sink_packet = sinkPacket(pkt);
231
232 // in certain cases the crossbar is responsible for responding
233 bool respond_directly = false;
234 // store the original address as an address mapper could possibly
235 // modify the address upon a sendTimingRequest
236 const Addr addr(pkt->getAddr());
237 if (sink_packet) {
238 DPRINTF(CoherentXBar, "%s: Not forwarding %s\n", __func__,
239 pkt->print());
240 } else {
241 // determine if we are forwarding the packet, or responding to
242 // it
243 if (!pointOfCoherency || pkt->isRead() || pkt->isWrite()) {
244 // if we are passing on, rather than sinking, a packet to
245 // which an upstream cache has committed to responding,
246 // the line was needs writable, and the responding only
247 // had an Owned copy, so we need to immidiately let the
248 // downstream caches know, bypass any flow control
249 if (pkt->cacheResponding()) {
250 pkt->setExpressSnoop();
251 }
252
253 // since it is a normal request, attempt to send the packet
254 success = masterPorts[master_port_id]->sendTimingReq(pkt);
255 } else {
256 // no need to forward, turn this packet around and respond
257 // directly
258 assert(pkt->needsResponse());
259
260 respond_directly = true;
261 assert(!expect_snoop_resp);
262 expect_response = false;
263 }
264 }
265
266 if (snoopFilter && !system->bypassCaches()) {
267 // Let the snoop filter know about the success of the send operation
268 snoopFilter->finishRequest(!success, addr, pkt->isSecure());
269 }
270
271 // check if we were successful in sending the packet onwards
272 if (!success) {
273 // express snoops should never be forced to retry
274 assert(!is_express_snoop);
275
276 // restore the header delay
277 pkt->headerDelay = old_header_delay;
278
279 DPRINTF(CoherentXBar, "%s: src %s packet %s RETRY\n", __func__,
280 src_port->name(), pkt->print());
281
282 // update the layer state and schedule an idle event
283 reqLayers[master_port_id]->failedTiming(src_port,
284 clockEdge(Cycles(1)));
285 } else {
286 // express snoops currently bypass the crossbar state entirely
287 if (!is_express_snoop) {
288 // if this particular request will generate a snoop
289 // response
290 if (expect_snoop_resp) {
291 // we should never have an exsiting request outstanding
292 assert(outstandingSnoop.find(pkt->req) ==
293 outstandingSnoop.end());
294 outstandingSnoop.insert(pkt->req);
295
296 // basic sanity check on the outstanding snoops
297 panic_if(outstandingSnoop.size() > 512,
298 "Outstanding snoop requests exceeded 512\n");
299 }
300
301 // remember where to route the normal response to
302 if (expect_response || expect_snoop_resp) {
303 assert(routeTo.find(pkt->req) == routeTo.end());
304 routeTo[pkt->req] = slave_port_id;
305
306 panic_if(routeTo.size() > 512,
307 "Routing table exceeds 512 packets\n");
308 }
309
310 // update the layer state and schedule an idle event
311 reqLayers[master_port_id]->succeededTiming(packetFinishTime);
312 }
313
314 // stats updates only consider packets that were successfully sent
315 pktCount[slave_port_id][master_port_id]++;
316 pktSize[slave_port_id][master_port_id] += pkt_size;
317 transDist[pkt_cmd]++;
318
319 if (is_express_snoop) {
320 snoops++;
321 snoopTraffic += pkt_size;
322 }
323 }
324
325 if (sink_packet)
326 // queue the packet for deletion
327 pendingDelete.reset(pkt);
328
329 if (respond_directly) {
330 assert(pkt->needsResponse());
331 assert(success);
332
333 pkt->makeResponse();
334
335 if (snoopFilter && !system->bypassCaches()) {
336 // let the snoop filter inspect the response and update its state
337 snoopFilter->updateResponse(pkt, *slavePorts[slave_port_id]);
338 }
339
340 Tick response_time = clockEdge() + pkt->headerDelay;
341 pkt->headerDelay = 0;
342
343 slavePorts[slave_port_id]->schedTimingResp(pkt, response_time);
344 }
345
346 return success;
347}
348
349bool
350CoherentXBar::recvTimingResp(PacketPtr pkt, PortID master_port_id)
351{
352 // determine the source port based on the id
353 MasterPort *src_port = masterPorts[master_port_id];
354
355 // determine the destination
356 const auto route_lookup = routeTo.find(pkt->req);
357 assert(route_lookup != routeTo.end());
358 const PortID slave_port_id = route_lookup->second;
359 assert(slave_port_id != InvalidPortID);
360 assert(slave_port_id < respLayers.size());
361
362 // test if the crossbar should be considered occupied for the
363 // current port
364 if (!respLayers[slave_port_id]->tryTiming(src_port)) {
365 DPRINTF(CoherentXBar, "%s: src %s packet %s BUSY\n", __func__,
366 src_port->name(), pkt->print());
367 return false;
368 }
369
370 DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__,
371 src_port->name(), pkt->print());
372
373 // store size and command as they might be modified when
374 // forwarding the packet
375 unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0;
376 unsigned int pkt_cmd = pkt->cmdToIndex();
377
378 // a response sees the response latency
379 Tick xbar_delay = responseLatency * clockPeriod();
380
381 // set the packet header and payload delay
382 calcPacketTiming(pkt, xbar_delay);
383
384 // determine how long to be crossbar layer is busy
385 Tick packetFinishTime = clockEdge(Cycles(1)) + pkt->payloadDelay;
386
387 if (snoopFilter && !system->bypassCaches()) {
388 // let the snoop filter inspect the response and update its state
389 snoopFilter->updateResponse(pkt, *slavePorts[slave_port_id]);
390 }
391
392 // send the packet through the destination slave port and pay for
393 // any outstanding header delay
394 Tick latency = pkt->headerDelay;
395 pkt->headerDelay = 0;
396 slavePorts[slave_port_id]->schedTimingResp(pkt, curTick() + latency);
397
398 // remove the request from the routing table
399 routeTo.erase(route_lookup);
400
401 respLayers[slave_port_id]->succeededTiming(packetFinishTime);
402
403 // stats updates
404 pktCount[slave_port_id][master_port_id]++;
405 pktSize[slave_port_id][master_port_id] += pkt_size;
406 transDist[pkt_cmd]++;
407
408 return true;
409}
410
411void
412CoherentXBar::recvTimingSnoopReq(PacketPtr pkt, PortID master_port_id)
413{
414 DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__,
415 masterPorts[master_port_id]->name(), pkt->print());
416
417 // update stats here as we know the forwarding will succeed
418 unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0;
419 transDist[pkt->cmdToIndex()]++;
420 snoops++;
421 snoopTraffic += pkt_size;
422
423 // we should only see express snoops from caches
424 assert(pkt->isExpressSnoop());
425
426 // set the packet header and payload delay, for now use forward latency
427 // @todo Assess the choice of latency further
428 calcPacketTiming(pkt, forwardLatency * clockPeriod());
429
430 // remember if a cache has already committed to responding so we
431 // can see if it changes during the snooping
432 const bool cache_responding = pkt->cacheResponding();
433
434 assert(pkt->snoopDelay == 0);
435
436 if (snoopFilter) {
437 // let the Snoop Filter work its magic and guide probing
438 auto sf_res = snoopFilter->lookupSnoop(pkt);
439 // the time required by a packet to be delivered through
440 // the xbar has to be charged also with to lookup latency
441 // of the snoop filter
442 pkt->headerDelay += sf_res.second * clockPeriod();
443 DPRINTF(CoherentXBar, "%s: src %s packet %s SF size: %i lat: %i\n",
444 __func__, masterPorts[master_port_id]->name(), pkt->print(),
445 sf_res.first.size(), sf_res.second);
446
447 // forward to all snoopers
448 forwardTiming(pkt, InvalidPortID, sf_res.first);
449 } else {
450 forwardTiming(pkt, InvalidPortID);
451 }
452
453 // add the snoop delay to our header delay, and then reset it
454 pkt->headerDelay += pkt->snoopDelay;
455 pkt->snoopDelay = 0;
456
457 // if we can expect a response, remember how to route it
458 if (!cache_responding && pkt->cacheResponding()) {
459 assert(routeTo.find(pkt->req) == routeTo.end());
460 routeTo[pkt->req] = master_port_id;
461 }
462
463 // a snoop request came from a connected slave device (one of
464 // our master ports), and if it is not coming from the slave
465 // device responsible for the address range something is
466 // wrong, hence there is nothing further to do as the packet
467 // would be going back to where it came from
468 assert(master_port_id == findPort(pkt->getAddr()));
469}
470
471bool
472CoherentXBar::recvTimingSnoopResp(PacketPtr pkt, PortID slave_port_id)
473{
474 // determine the source port based on the id
475 SlavePort* src_port = slavePorts[slave_port_id];
476
477 // get the destination
478 const auto route_lookup = routeTo.find(pkt->req);
479 assert(route_lookup != routeTo.end());
480 const PortID dest_port_id = route_lookup->second;
481 assert(dest_port_id != InvalidPortID);
482
483 // determine if the response is from a snoop request we
484 // created as the result of a normal request (in which case it
485 // should be in the outstandingSnoop), or if we merely forwarded
486 // someone else's snoop request
487 const bool forwardAsSnoop = outstandingSnoop.find(pkt->req) ==
488 outstandingSnoop.end();
489
490 // test if the crossbar should be considered occupied for the
491 // current port, note that the check is bypassed if the response
492 // is being passed on as a normal response since this is occupying
493 // the response layer rather than the snoop response layer
494 if (forwardAsSnoop) {
495 assert(dest_port_id < snoopLayers.size());
496 if (!snoopLayers[dest_port_id]->tryTiming(src_port)) {
497 DPRINTF(CoherentXBar, "%s: src %s packet %s BUSY\n", __func__,
498 src_port->name(), pkt->print());
499 return false;
500 }
501 } else {
502 // get the master port that mirrors this slave port internally
503 MasterPort* snoop_port = snoopRespPorts[slave_port_id];
504 assert(dest_port_id < respLayers.size());
505 if (!respLayers[dest_port_id]->tryTiming(snoop_port)) {
506 DPRINTF(CoherentXBar, "%s: src %s packet %s BUSY\n", __func__,
507 snoop_port->name(), pkt->print());
508 return false;
509 }
510 }
511
512 DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__,
513 src_port->name(), pkt->print());
514
515 // store size and command as they might be modified when
516 // forwarding the packet
517 unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0;
518 unsigned int pkt_cmd = pkt->cmdToIndex();
519
520 // responses are never express snoops
521 assert(!pkt->isExpressSnoop());
522
523 // a snoop response sees the snoop response latency, and if it is
524 // forwarded as a normal response, the response latency
525 Tick xbar_delay =
526 (forwardAsSnoop ? snoopResponseLatency : responseLatency) *
527 clockPeriod();
528
529 // set the packet header and payload delay
530 calcPacketTiming(pkt, xbar_delay);
531
532 // determine how long to be crossbar layer is busy
533 Tick packetFinishTime = clockEdge(Cycles(1)) + pkt->payloadDelay;
534
535 // forward it either as a snoop response or a normal response
536 if (forwardAsSnoop) {
537 // this is a snoop response to a snoop request we forwarded,
538 // e.g. coming from the L1 and going to the L2, and it should
539 // be forwarded as a snoop response
540
541 if (snoopFilter) {
542 // update the probe filter so that it can properly track the line
543 snoopFilter->updateSnoopForward(pkt, *slavePorts[slave_port_id],
544 *masterPorts[dest_port_id]);
545 }
546
547 bool success M5_VAR_USED =
548 masterPorts[dest_port_id]->sendTimingSnoopResp(pkt);
549 pktCount[slave_port_id][dest_port_id]++;
550 pktSize[slave_port_id][dest_port_id] += pkt_size;
551 assert(success);
552
553 snoopLayers[dest_port_id]->succeededTiming(packetFinishTime);
554 } else {
555 // we got a snoop response on one of our slave ports,
556 // i.e. from a coherent master connected to the crossbar, and
557 // since we created the snoop request as part of recvTiming,
558 // this should now be a normal response again
559 outstandingSnoop.erase(pkt->req);
560
561 // this is a snoop response from a coherent master, hence it
562 // should never go back to where the snoop response came from,
563 // but instead to where the original request came from
564 assert(slave_port_id != dest_port_id);
565
566 if (snoopFilter) {
567 // update the probe filter so that it can properly track the line
568 snoopFilter->updateSnoopResponse(pkt, *slavePorts[slave_port_id],
569 *slavePorts[dest_port_id]);
570 }
571
572 DPRINTF(CoherentXBar, "%s: src %s packet %s FWD RESP\n", __func__,
573 src_port->name(), pkt->print());
574
575 // as a normal response, it should go back to a master through
576 // one of our slave ports, we also pay for any outstanding
577 // header latency
578 Tick latency = pkt->headerDelay;
579 pkt->headerDelay = 0;
580 slavePorts[dest_port_id]->schedTimingResp(pkt, curTick() + latency);
581
582 respLayers[dest_port_id]->succeededTiming(packetFinishTime);
583 }
584
585 // remove the request from the routing table
586 routeTo.erase(route_lookup);
587
588 // stats updates
589 transDist[pkt_cmd]++;
590 snoops++;
591 snoopTraffic += pkt_size;
592
593 return true;
594}
595
596
597void
598CoherentXBar::forwardTiming(PacketPtr pkt, PortID exclude_slave_port_id,
599 const std::vector<QueuedSlavePort*>& dests)
600{
601 DPRINTF(CoherentXBar, "%s for %s\n", __func__, pkt->print());
602
603 // snoops should only happen if the system isn't bypassing caches
604 assert(!system->bypassCaches());
605
606 unsigned fanout = 0;
607
608 for (const auto& p: dests) {
609 // we could have gotten this request from a snooping master
610 // (corresponding to our own slave port that is also in
611 // snoopPorts) and should not send it back to where it came
612 // from
613 if (exclude_slave_port_id == InvalidPortID ||
614 p->getId() != exclude_slave_port_id) {
615 // cache is not allowed to refuse snoop
616 p->sendTimingSnoopReq(pkt);
617 fanout++;
618 }
619 }
620
621 // Stats for fanout of this forward operation
622 snoopFanout.sample(fanout);
623}
624
625void
626CoherentXBar::recvReqRetry(PortID master_port_id)
627{
628 // responses and snoop responses never block on forwarding them,
629 // so the retry will always be coming from a port to which we
630 // tried to forward a request
631 reqLayers[master_port_id]->recvRetry();
632}
633
634Tick
635CoherentXBar::recvAtomic(PacketPtr pkt, PortID slave_port_id)
636{
637 DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__,
638 slavePorts[slave_port_id]->name(), pkt->print());
639
640 unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0;
641 unsigned int pkt_cmd = pkt->cmdToIndex();
642
643 MemCmd snoop_response_cmd = MemCmd::InvalidCmd;
644 Tick snoop_response_latency = 0;
645
646 if (!system->bypassCaches()) {
647 // forward to all snoopers but the source
648 std::pair<MemCmd, Tick> snoop_result;
649 if (snoopFilter) {
650 // check with the snoop filter where to forward this packet
651 auto sf_res =
652 snoopFilter->lookupRequest(pkt, *slavePorts[slave_port_id]);
653 snoop_response_latency += sf_res.second * clockPeriod();
654 DPRINTF(CoherentXBar, "%s: src %s packet %s SF size: %i lat: %i\n",
655 __func__, slavePorts[slave_port_id]->name(), pkt->print(),
656 sf_res.first.size(), sf_res.second);
657
658 // let the snoop filter know about the success of the send
659 // operation, and do it even before sending it onwards to
660 // avoid situations where atomic upward snoops sneak in
661 // between and change the filter state
662 snoopFilter->finishRequest(false, pkt->getAddr(), pkt->isSecure());
663
664 if (pkt->isEviction()) {
665 // for block-evicting packets, i.e. writebacks and
666 // clean evictions, there is no need to snoop up, as
667 // all we do is determine if the block is cached or
668 // not, instead just set it here based on the snoop
669 // filter result
670 if (!sf_res.first.empty())
671 pkt->setBlockCached();
672 } else {
673 snoop_result = forwardAtomic(pkt, slave_port_id, InvalidPortID,
674 sf_res.first);
675 }
676 } else {
677 snoop_result = forwardAtomic(pkt, slave_port_id);
678 }
679 snoop_response_cmd = snoop_result.first;
680 snoop_response_latency += snoop_result.second;
681 }
682
683 // set up a sensible default value
684 Tick response_latency = 0;
685
686 const bool sink_packet = sinkPacket(pkt);
687
688 // even if we had a snoop response, we must continue and also
689 // perform the actual request at the destination
690 PortID master_port_id = findPort(pkt->getAddr());
691
692 if (sink_packet) {
693 DPRINTF(CoherentXBar, "%s: Not forwarding %s\n", __func__,
694 pkt->print());
695 } else {
696 if (!pointOfCoherency || pkt->isRead() || pkt->isWrite()) {
697 // forward the request to the appropriate destination
698 response_latency = masterPorts[master_port_id]->sendAtomic(pkt);
699 } else {
700 // if it does not need a response we sink the packet above
701 assert(pkt->needsResponse());
702
703 pkt->makeResponse();
704 }
705 }
706
707 // stats updates for the request
708 pktCount[slave_port_id][master_port_id]++;
709 pktSize[slave_port_id][master_port_id] += pkt_size;
710 transDist[pkt_cmd]++;
711
712
713 // if lower levels have replied, tell the snoop filter
714 if (!system->bypassCaches() && snoopFilter && pkt->isResponse()) {
715 snoopFilter->updateResponse(pkt, *slavePorts[slave_port_id]);
716 }
717
718 // if we got a response from a snooper, restore it here
719 if (snoop_response_cmd != MemCmd::InvalidCmd) {
720 // no one else should have responded
721 assert(!pkt->isResponse());
722 pkt->cmd = snoop_response_cmd;
723 response_latency = snoop_response_latency;
724 }
725
726 // add the response data
727 if (pkt->isResponse()) {
728 pkt_size = pkt->hasData() ? pkt->getSize() : 0;
729 pkt_cmd = pkt->cmdToIndex();
730
731 // stats updates
732 pktCount[slave_port_id][master_port_id]++;
733 pktSize[slave_port_id][master_port_id] += pkt_size;
734 transDist[pkt_cmd]++;
735 }
736
737 // @todo: Not setting header time
738 pkt->payloadDelay = response_latency;
739 return response_latency;
740}
741
742Tick
743CoherentXBar::recvAtomicSnoop(PacketPtr pkt, PortID master_port_id)
744{
745 DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__,
746 masterPorts[master_port_id]->name(), pkt->print());
747
748 // add the request snoop data
749 unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0;
750 snoops++;
751 snoopTraffic += pkt_size;
752
753 // forward to all snoopers
754 std::pair<MemCmd, Tick> snoop_result;
755 Tick snoop_response_latency = 0;
756 if (snoopFilter) {
757 auto sf_res = snoopFilter->lookupSnoop(pkt);
758 snoop_response_latency += sf_res.second * clockPeriod();
759 DPRINTF(CoherentXBar, "%s: src %s packet %s SF size: %i lat: %i\n",
760 __func__, masterPorts[master_port_id]->name(), pkt->print(),
761 sf_res.first.size(), sf_res.second);
762 snoop_result = forwardAtomic(pkt, InvalidPortID, master_port_id,
763 sf_res.first);
764 } else {
765 snoop_result = forwardAtomic(pkt, InvalidPortID);
766 }
767 MemCmd snoop_response_cmd = snoop_result.first;
768 snoop_response_latency += snoop_result.second;
769
770 if (snoop_response_cmd != MemCmd::InvalidCmd)
771 pkt->cmd = snoop_response_cmd;
772
773 // add the response snoop data
774 if (pkt->isResponse()) {
775 snoops++;
776 }
777
778 // @todo: Not setting header time
779 pkt->payloadDelay = snoop_response_latency;
780 return snoop_response_latency;
781}
782
783std::pair<MemCmd, Tick>
784CoherentXBar::forwardAtomic(PacketPtr pkt, PortID exclude_slave_port_id,
785 PortID source_master_port_id,
786 const std::vector<QueuedSlavePort*>& dests)
787{
788 // the packet may be changed on snoops, record the original
789 // command to enable us to restore it between snoops so that
790 // additional snoops can take place properly
791 MemCmd orig_cmd = pkt->cmd;
792 MemCmd snoop_response_cmd = MemCmd::InvalidCmd;
793 Tick snoop_response_latency = 0;
794
795 // snoops should only happen if the system isn't bypassing caches
796 assert(!system->bypassCaches());
797
798 unsigned fanout = 0;
799
800 for (const auto& p: dests) {
801 // we could have gotten this request from a snooping master
802 // (corresponding to our own slave port that is also in
803 // snoopPorts) and should not send it back to where it came
804 // from
805 if (exclude_slave_port_id != InvalidPortID &&
806 p->getId() == exclude_slave_port_id)
807 continue;
808
809 Tick latency = p->sendAtomicSnoop(pkt);
810 fanout++;
811
812 // in contrast to a functional access, we have to keep on
813 // going as all snoopers must be updated even if we get a
814 // response
815 if (!pkt->isResponse())
816 continue;
817
818 // response from snoop agent
819 assert(pkt->cmd != orig_cmd);
820 assert(pkt->cacheResponding());
821 // should only happen once
822 assert(snoop_response_cmd == MemCmd::InvalidCmd);
823 // save response state
824 snoop_response_cmd = pkt->cmd;
825 snoop_response_latency = latency;
826
827 if (snoopFilter) {
828 // Handle responses by the snoopers and differentiate between
829 // responses to requests from above and snoops from below
830 if (source_master_port_id != InvalidPortID) {
831 // Getting a response for a snoop from below
832 assert(exclude_slave_port_id == InvalidPortID);
833 snoopFilter->updateSnoopForward(pkt, *p,
834 *masterPorts[source_master_port_id]);
835 } else {
836 // Getting a response for a request from above
837 assert(source_master_port_id == InvalidPortID);
838 snoopFilter->updateSnoopResponse(pkt, *p,
839 *slavePorts[exclude_slave_port_id]);
840 }
841 }
842 // restore original packet state for remaining snoopers
843 pkt->cmd = orig_cmd;
844 }
845
846 // Stats for fanout
847 snoopFanout.sample(fanout);
848
849 // the packet is restored as part of the loop and any potential
850 // snoop response is part of the returned pair
851 return std::make_pair(snoop_response_cmd, snoop_response_latency);
852}
853
854void
855CoherentXBar::recvFunctional(PacketPtr pkt, PortID slave_port_id)
856{
857 if (!pkt->isPrint()) {
858 // don't do DPRINTFs on PrintReq as it clutters up the output
859 DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__,
860 slavePorts[slave_port_id]->name(), pkt->print());
861 }
862
863 if (!system->bypassCaches()) {
864 // forward to all snoopers but the source
865 forwardFunctional(pkt, slave_port_id);
866 }
867
868 // there is no need to continue if the snooping has found what we
869 // were looking for and the packet is already a response
870 if (!pkt->isResponse()) {
871 // since our slave ports are queued ports we need to check them as well
872 for (const auto& p : slavePorts) {
873 // if we find a response that has the data, then the
874 // downstream caches/memories may be out of date, so simply stop
875 // here
876 if (p->checkFunctional(pkt)) {
877 if (pkt->needsResponse())
878 pkt->makeResponse();
879 return;
880 }
881 }
882
883 PortID dest_id = findPort(pkt->getAddr());
884
885 masterPorts[dest_id]->sendFunctional(pkt);
886 }
887}
888
889void
890CoherentXBar::recvFunctionalSnoop(PacketPtr pkt, PortID master_port_id)
891{
892 if (!pkt->isPrint()) {
893 // don't do DPRINTFs on PrintReq as it clutters up the output
894 DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__,
895 masterPorts[master_port_id]->name(), pkt->print());
896 }
897
898 for (const auto& p : slavePorts) {
899 if (p->checkFunctional(pkt)) {
900 if (pkt->needsResponse())
901 pkt->makeResponse();
902 return;
903 }
904 }
905
906 // forward to all snoopers
907 forwardFunctional(pkt, InvalidPortID);
908}
909
910void
911CoherentXBar::forwardFunctional(PacketPtr pkt, PortID exclude_slave_port_id)
912{
913 // snoops should only happen if the system isn't bypassing caches
914 assert(!system->bypassCaches());
915
916 for (const auto& p: snoopPorts) {
917 // we could have gotten this request from a snooping master
918 // (corresponding to our own slave port that is also in
919 // snoopPorts) and should not send it back to where it came
920 // from
921 if (exclude_slave_port_id == InvalidPortID ||
922 p->getId() != exclude_slave_port_id)
923 p->sendFunctionalSnoop(pkt);
924
925 // if we get a response we are done
926 if (pkt->isResponse()) {
927 break;
928 }
929 }
930}
931
932bool
933CoherentXBar::sinkPacket(const PacketPtr pkt) const
934{
935 // we can sink the packet if:
936 // 1) the crossbar is the point of coherency, and a cache is
937 // responding after being snooped
938 // 2) the crossbar is the point of coherency, and the packet is a
939 // coherency packet (not a read or a write) that does not
940 // require a response
941 // 3) this is a clean evict or clean writeback, but the packet is
942 // found in a cache above this crossbar
943 // 4) a cache is responding after being snooped, and the packet
944 // either does not need the block to be writable, or the cache
945 // that has promised to respond (setting the cache responding
946 // flag) is providing writable and thus had a Modified block,
947 // and no further action is needed
948 return (pointOfCoherency && pkt->cacheResponding()) ||
949 (pointOfCoherency && !(pkt->isRead() || pkt->isWrite()) &&
950 !pkt->needsResponse()) ||
951 (pkt->isCleanEviction() && pkt->isBlockCached()) ||
952 (pkt->cacheResponding() &&
953 (!pkt->needsWritable() || pkt->responderHadWritable()));
954}
955
956void
957CoherentXBar::regStats()
958{
959 // register the stats of the base class and our layers
960 BaseXBar::regStats();
961 for (auto l: reqLayers)
962 l->regStats();
963 for (auto l: respLayers)
964 l->regStats();
965 for (auto l: snoopLayers)
966 l->regStats();
967
968 snoops
969 .name(name() + ".snoops")
970 .desc("Total snoops (count)")
971 ;
972
973 snoopTraffic
974 .name(name() + ".snoopTraffic")
975 .desc("Total snoop traffic (bytes)")
976 ;
977
978 snoopFanout
979 .init(0, snoopPorts.size(), 1)
980 .name(name() + ".snoop_fanout")
981 .desc("Request fanout histogram")
982 ;
983}
984
985CoherentXBar *
986CoherentXBarParams::create()
987{
988 return new CoherentXBar(this);
989}
63{
64 // create the ports based on the size of the master and slave
65 // vector ports, and the presence of the default port, the ports
66 // are enumerated starting from zero
67 for (int i = 0; i < p->port_master_connection_count; ++i) {
68 std::string portName = csprintf("%s.master[%d]", name(), i);
69 MasterPort* bp = new CoherentXBarMasterPort(portName, *this, i);
70 masterPorts.push_back(bp);
71 reqLayers.push_back(new ReqLayer(*bp, *this,
72 csprintf(".reqLayer%d", i)));
73 snoopLayers.push_back(new SnoopRespLayer(*bp, *this,
74 csprintf(".snoopLayer%d", i)));
75 }
76
77 // see if we have a default slave device connected and if so add
78 // our corresponding master port
79 if (p->port_default_connection_count) {
80 defaultPortID = masterPorts.size();
81 std::string portName = name() + ".default";
82 MasterPort* bp = new CoherentXBarMasterPort(portName, *this,
83 defaultPortID);
84 masterPorts.push_back(bp);
85 reqLayers.push_back(new ReqLayer(*bp, *this, csprintf(".reqLayer%d",
86 defaultPortID)));
87 snoopLayers.push_back(new SnoopRespLayer(*bp, *this,
88 csprintf(".snoopLayer%d",
89 defaultPortID)));
90 }
91
92 // create the slave ports, once again starting at zero
93 for (int i = 0; i < p->port_slave_connection_count; ++i) {
94 std::string portName = csprintf("%s.slave[%d]", name(), i);
95 QueuedSlavePort* bp = new CoherentXBarSlavePort(portName, *this, i);
96 slavePorts.push_back(bp);
97 respLayers.push_back(new RespLayer(*bp, *this,
98 csprintf(".respLayer%d", i)));
99 snoopRespPorts.push_back(new SnoopRespPort(*bp, *this));
100 }
101
102 clearPortCache();
103}
104
105CoherentXBar::~CoherentXBar()
106{
107 for (auto l: reqLayers)
108 delete l;
109 for (auto l: respLayers)
110 delete l;
111 for (auto l: snoopLayers)
112 delete l;
113 for (auto p: snoopRespPorts)
114 delete p;
115}
116
117void
118CoherentXBar::init()
119{
120 BaseXBar::init();
121
122 // iterate over our slave ports and determine which of our
123 // neighbouring master ports are snooping and add them as snoopers
124 for (const auto& p: slavePorts) {
125 // check if the connected master port is snooping
126 if (p->isSnooping()) {
127 DPRINTF(AddrRanges, "Adding snooping master %s\n",
128 p->getMasterPort().name());
129 snoopPorts.push_back(p);
130 }
131 }
132
133 if (snoopPorts.empty())
134 warn("CoherentXBar %s has no snooping ports attached!\n", name());
135
136 // inform the snoop filter about the slave ports so it can create
137 // its own internal representation
138 if (snoopFilter)
139 snoopFilter->setSlavePorts(slavePorts);
140}
141
142bool
143CoherentXBar::recvTimingReq(PacketPtr pkt, PortID slave_port_id)
144{
145 // determine the source port based on the id
146 SlavePort *src_port = slavePorts[slave_port_id];
147
148 // remember if the packet is an express snoop
149 bool is_express_snoop = pkt->isExpressSnoop();
150 bool cache_responding = pkt->cacheResponding();
151 // for normal requests, going downstream, the express snoop flag
152 // and the cache responding flag should always be the same
153 assert(is_express_snoop == cache_responding);
154
155 // determine the destination based on the address
156 PortID master_port_id = findPort(pkt->getAddr());
157
158 // test if the crossbar should be considered occupied for the current
159 // port, and exclude express snoops from the check
160 if (!is_express_snoop && !reqLayers[master_port_id]->tryTiming(src_port)) {
161 DPRINTF(CoherentXBar, "%s: src %s packet %s BUSY\n", __func__,
162 src_port->name(), pkt->print());
163 return false;
164 }
165
166 DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__,
167 src_port->name(), pkt->print());
168
169 // store size and command as they might be modified when
170 // forwarding the packet
171 unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0;
172 unsigned int pkt_cmd = pkt->cmdToIndex();
173
174 // store the old header delay so we can restore it if needed
175 Tick old_header_delay = pkt->headerDelay;
176
177 // a request sees the frontend and forward latency
178 Tick xbar_delay = (frontendLatency + forwardLatency) * clockPeriod();
179
180 // set the packet header and payload delay
181 calcPacketTiming(pkt, xbar_delay);
182
183 // determine how long to be crossbar layer is busy
184 Tick packetFinishTime = clockEdge(Cycles(1)) + pkt->payloadDelay;
185
186 if (!system->bypassCaches()) {
187 assert(pkt->snoopDelay == 0);
188
189 // the packet is a memory-mapped request and should be
190 // broadcasted to our snoopers but the source
191 if (snoopFilter) {
192 // check with the snoop filter where to forward this packet
193 auto sf_res = snoopFilter->lookupRequest(pkt, *src_port);
194 // the time required by a packet to be delivered through
195 // the xbar has to be charged also with to lookup latency
196 // of the snoop filter
197 pkt->headerDelay += sf_res.second * clockPeriod();
198 DPRINTF(CoherentXBar, "%s: src %s packet %s SF size: %i lat: %i\n",
199 __func__, src_port->name(), pkt->print(),
200 sf_res.first.size(), sf_res.second);
201
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
207 // filter result
208 if (!sf_res.first.empty())
209 pkt->setBlockCached();
210 } else {
211 forwardTiming(pkt, slave_port_id, sf_res.first);
212 }
213 } else {
214 forwardTiming(pkt, slave_port_id);
215 }
216
217 // add the snoop delay to our header delay, and then reset it
218 pkt->headerDelay += pkt->snoopDelay;
219 pkt->snoopDelay = 0;
220 }
221
222 // set up a sensible starting point
223 bool success = true;
224
225 // remember if the packet will generate a snoop response by
226 // checking if a cache set the cacheResponding flag during the
227 // snooping above
228 const bool expect_snoop_resp = !cache_responding && pkt->cacheResponding();
229 bool expect_response = pkt->needsResponse() && !pkt->cacheResponding();
230
231 const bool sink_packet = sinkPacket(pkt);
232
233 // in certain cases the crossbar is responsible for responding
234 bool respond_directly = false;
235 // store the original address as an address mapper could possibly
236 // modify the address upon a sendTimingRequest
237 const Addr addr(pkt->getAddr());
238 if (sink_packet) {
239 DPRINTF(CoherentXBar, "%s: Not forwarding %s\n", __func__,
240 pkt->print());
241 } else {
242 // determine if we are forwarding the packet, or responding to
243 // it
244 if (!pointOfCoherency || pkt->isRead() || pkt->isWrite()) {
245 // if we are passing on, rather than sinking, a packet to
246 // which an upstream cache has committed to responding,
247 // the line was needs writable, and the responding only
248 // had an Owned copy, so we need to immidiately let the
249 // downstream caches know, bypass any flow control
250 if (pkt->cacheResponding()) {
251 pkt->setExpressSnoop();
252 }
253
254 // since it is a normal request, attempt to send the packet
255 success = masterPorts[master_port_id]->sendTimingReq(pkt);
256 } else {
257 // no need to forward, turn this packet around and respond
258 // directly
259 assert(pkt->needsResponse());
260
261 respond_directly = true;
262 assert(!expect_snoop_resp);
263 expect_response = false;
264 }
265 }
266
267 if (snoopFilter && !system->bypassCaches()) {
268 // Let the snoop filter know about the success of the send operation
269 snoopFilter->finishRequest(!success, addr, pkt->isSecure());
270 }
271
272 // check if we were successful in sending the packet onwards
273 if (!success) {
274 // express snoops should never be forced to retry
275 assert(!is_express_snoop);
276
277 // restore the header delay
278 pkt->headerDelay = old_header_delay;
279
280 DPRINTF(CoherentXBar, "%s: src %s packet %s RETRY\n", __func__,
281 src_port->name(), pkt->print());
282
283 // update the layer state and schedule an idle event
284 reqLayers[master_port_id]->failedTiming(src_port,
285 clockEdge(Cycles(1)));
286 } else {
287 // express snoops currently bypass the crossbar state entirely
288 if (!is_express_snoop) {
289 // if this particular request will generate a snoop
290 // response
291 if (expect_snoop_resp) {
292 // we should never have an exsiting request outstanding
293 assert(outstandingSnoop.find(pkt->req) ==
294 outstandingSnoop.end());
295 outstandingSnoop.insert(pkt->req);
296
297 // basic sanity check on the outstanding snoops
298 panic_if(outstandingSnoop.size() > 512,
299 "Outstanding snoop requests exceeded 512\n");
300 }
301
302 // remember where to route the normal response to
303 if (expect_response || expect_snoop_resp) {
304 assert(routeTo.find(pkt->req) == routeTo.end());
305 routeTo[pkt->req] = slave_port_id;
306
307 panic_if(routeTo.size() > 512,
308 "Routing table exceeds 512 packets\n");
309 }
310
311 // update the layer state and schedule an idle event
312 reqLayers[master_port_id]->succeededTiming(packetFinishTime);
313 }
314
315 // stats updates only consider packets that were successfully sent
316 pktCount[slave_port_id][master_port_id]++;
317 pktSize[slave_port_id][master_port_id] += pkt_size;
318 transDist[pkt_cmd]++;
319
320 if (is_express_snoop) {
321 snoops++;
322 snoopTraffic += pkt_size;
323 }
324 }
325
326 if (sink_packet)
327 // queue the packet for deletion
328 pendingDelete.reset(pkt);
329
330 if (respond_directly) {
331 assert(pkt->needsResponse());
332 assert(success);
333
334 pkt->makeResponse();
335
336 if (snoopFilter && !system->bypassCaches()) {
337 // let the snoop filter inspect the response and update its state
338 snoopFilter->updateResponse(pkt, *slavePorts[slave_port_id]);
339 }
340
341 Tick response_time = clockEdge() + pkt->headerDelay;
342 pkt->headerDelay = 0;
343
344 slavePorts[slave_port_id]->schedTimingResp(pkt, response_time);
345 }
346
347 return success;
348}
349
350bool
351CoherentXBar::recvTimingResp(PacketPtr pkt, PortID master_port_id)
352{
353 // determine the source port based on the id
354 MasterPort *src_port = masterPorts[master_port_id];
355
356 // determine the destination
357 const auto route_lookup = routeTo.find(pkt->req);
358 assert(route_lookup != routeTo.end());
359 const PortID slave_port_id = route_lookup->second;
360 assert(slave_port_id != InvalidPortID);
361 assert(slave_port_id < respLayers.size());
362
363 // test if the crossbar should be considered occupied for the
364 // current port
365 if (!respLayers[slave_port_id]->tryTiming(src_port)) {
366 DPRINTF(CoherentXBar, "%s: src %s packet %s BUSY\n", __func__,
367 src_port->name(), pkt->print());
368 return false;
369 }
370
371 DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__,
372 src_port->name(), pkt->print());
373
374 // store size and command as they might be modified when
375 // forwarding the packet
376 unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0;
377 unsigned int pkt_cmd = pkt->cmdToIndex();
378
379 // a response sees the response latency
380 Tick xbar_delay = responseLatency * clockPeriod();
381
382 // set the packet header and payload delay
383 calcPacketTiming(pkt, xbar_delay);
384
385 // determine how long to be crossbar layer is busy
386 Tick packetFinishTime = clockEdge(Cycles(1)) + pkt->payloadDelay;
387
388 if (snoopFilter && !system->bypassCaches()) {
389 // let the snoop filter inspect the response and update its state
390 snoopFilter->updateResponse(pkt, *slavePorts[slave_port_id]);
391 }
392
393 // send the packet through the destination slave port and pay for
394 // any outstanding header delay
395 Tick latency = pkt->headerDelay;
396 pkt->headerDelay = 0;
397 slavePorts[slave_port_id]->schedTimingResp(pkt, curTick() + latency);
398
399 // remove the request from the routing table
400 routeTo.erase(route_lookup);
401
402 respLayers[slave_port_id]->succeededTiming(packetFinishTime);
403
404 // stats updates
405 pktCount[slave_port_id][master_port_id]++;
406 pktSize[slave_port_id][master_port_id] += pkt_size;
407 transDist[pkt_cmd]++;
408
409 return true;
410}
411
412void
413CoherentXBar::recvTimingSnoopReq(PacketPtr pkt, PortID master_port_id)
414{
415 DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__,
416 masterPorts[master_port_id]->name(), pkt->print());
417
418 // update stats here as we know the forwarding will succeed
419 unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0;
420 transDist[pkt->cmdToIndex()]++;
421 snoops++;
422 snoopTraffic += pkt_size;
423
424 // we should only see express snoops from caches
425 assert(pkt->isExpressSnoop());
426
427 // set the packet header and payload delay, for now use forward latency
428 // @todo Assess the choice of latency further
429 calcPacketTiming(pkt, forwardLatency * clockPeriod());
430
431 // remember if a cache has already committed to responding so we
432 // can see if it changes during the snooping
433 const bool cache_responding = pkt->cacheResponding();
434
435 assert(pkt->snoopDelay == 0);
436
437 if (snoopFilter) {
438 // let the Snoop Filter work its magic and guide probing
439 auto sf_res = snoopFilter->lookupSnoop(pkt);
440 // the time required by a packet to be delivered through
441 // the xbar has to be charged also with to lookup latency
442 // of the snoop filter
443 pkt->headerDelay += sf_res.second * clockPeriod();
444 DPRINTF(CoherentXBar, "%s: src %s packet %s SF size: %i lat: %i\n",
445 __func__, masterPorts[master_port_id]->name(), pkt->print(),
446 sf_res.first.size(), sf_res.second);
447
448 // forward to all snoopers
449 forwardTiming(pkt, InvalidPortID, sf_res.first);
450 } else {
451 forwardTiming(pkt, InvalidPortID);
452 }
453
454 // add the snoop delay to our header delay, and then reset it
455 pkt->headerDelay += pkt->snoopDelay;
456 pkt->snoopDelay = 0;
457
458 // if we can expect a response, remember how to route it
459 if (!cache_responding && pkt->cacheResponding()) {
460 assert(routeTo.find(pkt->req) == routeTo.end());
461 routeTo[pkt->req] = master_port_id;
462 }
463
464 // a snoop request came from a connected slave device (one of
465 // our master ports), and if it is not coming from the slave
466 // device responsible for the address range something is
467 // wrong, hence there is nothing further to do as the packet
468 // would be going back to where it came from
469 assert(master_port_id == findPort(pkt->getAddr()));
470}
471
472bool
473CoherentXBar::recvTimingSnoopResp(PacketPtr pkt, PortID slave_port_id)
474{
475 // determine the source port based on the id
476 SlavePort* src_port = slavePorts[slave_port_id];
477
478 // get the destination
479 const auto route_lookup = routeTo.find(pkt->req);
480 assert(route_lookup != routeTo.end());
481 const PortID dest_port_id = route_lookup->second;
482 assert(dest_port_id != InvalidPortID);
483
484 // determine if the response is from a snoop request we
485 // created as the result of a normal request (in which case it
486 // should be in the outstandingSnoop), or if we merely forwarded
487 // someone else's snoop request
488 const bool forwardAsSnoop = outstandingSnoop.find(pkt->req) ==
489 outstandingSnoop.end();
490
491 // test if the crossbar should be considered occupied for the
492 // current port, note that the check is bypassed if the response
493 // is being passed on as a normal response since this is occupying
494 // the response layer rather than the snoop response layer
495 if (forwardAsSnoop) {
496 assert(dest_port_id < snoopLayers.size());
497 if (!snoopLayers[dest_port_id]->tryTiming(src_port)) {
498 DPRINTF(CoherentXBar, "%s: src %s packet %s BUSY\n", __func__,
499 src_port->name(), pkt->print());
500 return false;
501 }
502 } else {
503 // get the master port that mirrors this slave port internally
504 MasterPort* snoop_port = snoopRespPorts[slave_port_id];
505 assert(dest_port_id < respLayers.size());
506 if (!respLayers[dest_port_id]->tryTiming(snoop_port)) {
507 DPRINTF(CoherentXBar, "%s: src %s packet %s BUSY\n", __func__,
508 snoop_port->name(), pkt->print());
509 return false;
510 }
511 }
512
513 DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__,
514 src_port->name(), pkt->print());
515
516 // store size and command as they might be modified when
517 // forwarding the packet
518 unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0;
519 unsigned int pkt_cmd = pkt->cmdToIndex();
520
521 // responses are never express snoops
522 assert(!pkt->isExpressSnoop());
523
524 // a snoop response sees the snoop response latency, and if it is
525 // forwarded as a normal response, the response latency
526 Tick xbar_delay =
527 (forwardAsSnoop ? snoopResponseLatency : responseLatency) *
528 clockPeriod();
529
530 // set the packet header and payload delay
531 calcPacketTiming(pkt, xbar_delay);
532
533 // determine how long to be crossbar layer is busy
534 Tick packetFinishTime = clockEdge(Cycles(1)) + pkt->payloadDelay;
535
536 // forward it either as a snoop response or a normal response
537 if (forwardAsSnoop) {
538 // this is a snoop response to a snoop request we forwarded,
539 // e.g. coming from the L1 and going to the L2, and it should
540 // be forwarded as a snoop response
541
542 if (snoopFilter) {
543 // update the probe filter so that it can properly track the line
544 snoopFilter->updateSnoopForward(pkt, *slavePorts[slave_port_id],
545 *masterPorts[dest_port_id]);
546 }
547
548 bool success M5_VAR_USED =
549 masterPorts[dest_port_id]->sendTimingSnoopResp(pkt);
550 pktCount[slave_port_id][dest_port_id]++;
551 pktSize[slave_port_id][dest_port_id] += pkt_size;
552 assert(success);
553
554 snoopLayers[dest_port_id]->succeededTiming(packetFinishTime);
555 } else {
556 // we got a snoop response on one of our slave ports,
557 // i.e. from a coherent master connected to the crossbar, and
558 // since we created the snoop request as part of recvTiming,
559 // this should now be a normal response again
560 outstandingSnoop.erase(pkt->req);
561
562 // this is a snoop response from a coherent master, hence it
563 // should never go back to where the snoop response came from,
564 // but instead to where the original request came from
565 assert(slave_port_id != dest_port_id);
566
567 if (snoopFilter) {
568 // update the probe filter so that it can properly track the line
569 snoopFilter->updateSnoopResponse(pkt, *slavePorts[slave_port_id],
570 *slavePorts[dest_port_id]);
571 }
572
573 DPRINTF(CoherentXBar, "%s: src %s packet %s FWD RESP\n", __func__,
574 src_port->name(), pkt->print());
575
576 // as a normal response, it should go back to a master through
577 // one of our slave ports, we also pay for any outstanding
578 // header latency
579 Tick latency = pkt->headerDelay;
580 pkt->headerDelay = 0;
581 slavePorts[dest_port_id]->schedTimingResp(pkt, curTick() + latency);
582
583 respLayers[dest_port_id]->succeededTiming(packetFinishTime);
584 }
585
586 // remove the request from the routing table
587 routeTo.erase(route_lookup);
588
589 // stats updates
590 transDist[pkt_cmd]++;
591 snoops++;
592 snoopTraffic += pkt_size;
593
594 return true;
595}
596
597
598void
599CoherentXBar::forwardTiming(PacketPtr pkt, PortID exclude_slave_port_id,
600 const std::vector<QueuedSlavePort*>& dests)
601{
602 DPRINTF(CoherentXBar, "%s for %s\n", __func__, pkt->print());
603
604 // snoops should only happen if the system isn't bypassing caches
605 assert(!system->bypassCaches());
606
607 unsigned fanout = 0;
608
609 for (const auto& p: dests) {
610 // we could have gotten this request from a snooping master
611 // (corresponding to our own slave port that is also in
612 // snoopPorts) and should not send it back to where it came
613 // from
614 if (exclude_slave_port_id == InvalidPortID ||
615 p->getId() != exclude_slave_port_id) {
616 // cache is not allowed to refuse snoop
617 p->sendTimingSnoopReq(pkt);
618 fanout++;
619 }
620 }
621
622 // Stats for fanout of this forward operation
623 snoopFanout.sample(fanout);
624}
625
626void
627CoherentXBar::recvReqRetry(PortID master_port_id)
628{
629 // responses and snoop responses never block on forwarding them,
630 // so the retry will always be coming from a port to which we
631 // tried to forward a request
632 reqLayers[master_port_id]->recvRetry();
633}
634
635Tick
636CoherentXBar::recvAtomic(PacketPtr pkt, PortID slave_port_id)
637{
638 DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__,
639 slavePorts[slave_port_id]->name(), pkt->print());
640
641 unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0;
642 unsigned int pkt_cmd = pkt->cmdToIndex();
643
644 MemCmd snoop_response_cmd = MemCmd::InvalidCmd;
645 Tick snoop_response_latency = 0;
646
647 if (!system->bypassCaches()) {
648 // forward to all snoopers but the source
649 std::pair<MemCmd, Tick> snoop_result;
650 if (snoopFilter) {
651 // check with the snoop filter where to forward this packet
652 auto sf_res =
653 snoopFilter->lookupRequest(pkt, *slavePorts[slave_port_id]);
654 snoop_response_latency += sf_res.second * clockPeriod();
655 DPRINTF(CoherentXBar, "%s: src %s packet %s SF size: %i lat: %i\n",
656 __func__, slavePorts[slave_port_id]->name(), pkt->print(),
657 sf_res.first.size(), sf_res.second);
658
659 // let the snoop filter know about the success of the send
660 // operation, and do it even before sending it onwards to
661 // avoid situations where atomic upward snoops sneak in
662 // between and change the filter state
663 snoopFilter->finishRequest(false, pkt->getAddr(), pkt->isSecure());
664
665 if (pkt->isEviction()) {
666 // for block-evicting packets, i.e. writebacks and
667 // clean evictions, there is no need to snoop up, as
668 // all we do is determine if the block is cached or
669 // not, instead just set it here based on the snoop
670 // filter result
671 if (!sf_res.first.empty())
672 pkt->setBlockCached();
673 } else {
674 snoop_result = forwardAtomic(pkt, slave_port_id, InvalidPortID,
675 sf_res.first);
676 }
677 } else {
678 snoop_result = forwardAtomic(pkt, slave_port_id);
679 }
680 snoop_response_cmd = snoop_result.first;
681 snoop_response_latency += snoop_result.second;
682 }
683
684 // set up a sensible default value
685 Tick response_latency = 0;
686
687 const bool sink_packet = sinkPacket(pkt);
688
689 // even if we had a snoop response, we must continue and also
690 // perform the actual request at the destination
691 PortID master_port_id = findPort(pkt->getAddr());
692
693 if (sink_packet) {
694 DPRINTF(CoherentXBar, "%s: Not forwarding %s\n", __func__,
695 pkt->print());
696 } else {
697 if (!pointOfCoherency || pkt->isRead() || pkt->isWrite()) {
698 // forward the request to the appropriate destination
699 response_latency = masterPorts[master_port_id]->sendAtomic(pkt);
700 } else {
701 // if it does not need a response we sink the packet above
702 assert(pkt->needsResponse());
703
704 pkt->makeResponse();
705 }
706 }
707
708 // stats updates for the request
709 pktCount[slave_port_id][master_port_id]++;
710 pktSize[slave_port_id][master_port_id] += pkt_size;
711 transDist[pkt_cmd]++;
712
713
714 // if lower levels have replied, tell the snoop filter
715 if (!system->bypassCaches() && snoopFilter && pkt->isResponse()) {
716 snoopFilter->updateResponse(pkt, *slavePorts[slave_port_id]);
717 }
718
719 // if we got a response from a snooper, restore it here
720 if (snoop_response_cmd != MemCmd::InvalidCmd) {
721 // no one else should have responded
722 assert(!pkt->isResponse());
723 pkt->cmd = snoop_response_cmd;
724 response_latency = snoop_response_latency;
725 }
726
727 // add the response data
728 if (pkt->isResponse()) {
729 pkt_size = pkt->hasData() ? pkt->getSize() : 0;
730 pkt_cmd = pkt->cmdToIndex();
731
732 // stats updates
733 pktCount[slave_port_id][master_port_id]++;
734 pktSize[slave_port_id][master_port_id] += pkt_size;
735 transDist[pkt_cmd]++;
736 }
737
738 // @todo: Not setting header time
739 pkt->payloadDelay = response_latency;
740 return response_latency;
741}
742
743Tick
744CoherentXBar::recvAtomicSnoop(PacketPtr pkt, PortID master_port_id)
745{
746 DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__,
747 masterPorts[master_port_id]->name(), pkt->print());
748
749 // add the request snoop data
750 unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0;
751 snoops++;
752 snoopTraffic += pkt_size;
753
754 // forward to all snoopers
755 std::pair<MemCmd, Tick> snoop_result;
756 Tick snoop_response_latency = 0;
757 if (snoopFilter) {
758 auto sf_res = snoopFilter->lookupSnoop(pkt);
759 snoop_response_latency += sf_res.second * clockPeriod();
760 DPRINTF(CoherentXBar, "%s: src %s packet %s SF size: %i lat: %i\n",
761 __func__, masterPorts[master_port_id]->name(), pkt->print(),
762 sf_res.first.size(), sf_res.second);
763 snoop_result = forwardAtomic(pkt, InvalidPortID, master_port_id,
764 sf_res.first);
765 } else {
766 snoop_result = forwardAtomic(pkt, InvalidPortID);
767 }
768 MemCmd snoop_response_cmd = snoop_result.first;
769 snoop_response_latency += snoop_result.second;
770
771 if (snoop_response_cmd != MemCmd::InvalidCmd)
772 pkt->cmd = snoop_response_cmd;
773
774 // add the response snoop data
775 if (pkt->isResponse()) {
776 snoops++;
777 }
778
779 // @todo: Not setting header time
780 pkt->payloadDelay = snoop_response_latency;
781 return snoop_response_latency;
782}
783
784std::pair<MemCmd, Tick>
785CoherentXBar::forwardAtomic(PacketPtr pkt, PortID exclude_slave_port_id,
786 PortID source_master_port_id,
787 const std::vector<QueuedSlavePort*>& dests)
788{
789 // the packet may be changed on snoops, record the original
790 // command to enable us to restore it between snoops so that
791 // additional snoops can take place properly
792 MemCmd orig_cmd = pkt->cmd;
793 MemCmd snoop_response_cmd = MemCmd::InvalidCmd;
794 Tick snoop_response_latency = 0;
795
796 // snoops should only happen if the system isn't bypassing caches
797 assert(!system->bypassCaches());
798
799 unsigned fanout = 0;
800
801 for (const auto& p: dests) {
802 // we could have gotten this request from a snooping master
803 // (corresponding to our own slave port that is also in
804 // snoopPorts) and should not send it back to where it came
805 // from
806 if (exclude_slave_port_id != InvalidPortID &&
807 p->getId() == exclude_slave_port_id)
808 continue;
809
810 Tick latency = p->sendAtomicSnoop(pkt);
811 fanout++;
812
813 // in contrast to a functional access, we have to keep on
814 // going as all snoopers must be updated even if we get a
815 // response
816 if (!pkt->isResponse())
817 continue;
818
819 // response from snoop agent
820 assert(pkt->cmd != orig_cmd);
821 assert(pkt->cacheResponding());
822 // should only happen once
823 assert(snoop_response_cmd == MemCmd::InvalidCmd);
824 // save response state
825 snoop_response_cmd = pkt->cmd;
826 snoop_response_latency = latency;
827
828 if (snoopFilter) {
829 // Handle responses by the snoopers and differentiate between
830 // responses to requests from above and snoops from below
831 if (source_master_port_id != InvalidPortID) {
832 // Getting a response for a snoop from below
833 assert(exclude_slave_port_id == InvalidPortID);
834 snoopFilter->updateSnoopForward(pkt, *p,
835 *masterPorts[source_master_port_id]);
836 } else {
837 // Getting a response for a request from above
838 assert(source_master_port_id == InvalidPortID);
839 snoopFilter->updateSnoopResponse(pkt, *p,
840 *slavePorts[exclude_slave_port_id]);
841 }
842 }
843 // restore original packet state for remaining snoopers
844 pkt->cmd = orig_cmd;
845 }
846
847 // Stats for fanout
848 snoopFanout.sample(fanout);
849
850 // the packet is restored as part of the loop and any potential
851 // snoop response is part of the returned pair
852 return std::make_pair(snoop_response_cmd, snoop_response_latency);
853}
854
855void
856CoherentXBar::recvFunctional(PacketPtr pkt, PortID slave_port_id)
857{
858 if (!pkt->isPrint()) {
859 // don't do DPRINTFs on PrintReq as it clutters up the output
860 DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__,
861 slavePorts[slave_port_id]->name(), pkt->print());
862 }
863
864 if (!system->bypassCaches()) {
865 // forward to all snoopers but the source
866 forwardFunctional(pkt, slave_port_id);
867 }
868
869 // there is no need to continue if the snooping has found what we
870 // were looking for and the packet is already a response
871 if (!pkt->isResponse()) {
872 // since our slave ports are queued ports we need to check them as well
873 for (const auto& p : slavePorts) {
874 // if we find a response that has the data, then the
875 // downstream caches/memories may be out of date, so simply stop
876 // here
877 if (p->checkFunctional(pkt)) {
878 if (pkt->needsResponse())
879 pkt->makeResponse();
880 return;
881 }
882 }
883
884 PortID dest_id = findPort(pkt->getAddr());
885
886 masterPorts[dest_id]->sendFunctional(pkt);
887 }
888}
889
890void
891CoherentXBar::recvFunctionalSnoop(PacketPtr pkt, PortID master_port_id)
892{
893 if (!pkt->isPrint()) {
894 // don't do DPRINTFs on PrintReq as it clutters up the output
895 DPRINTF(CoherentXBar, "%s: src %s packet %s\n", __func__,
896 masterPorts[master_port_id]->name(), pkt->print());
897 }
898
899 for (const auto& p : slavePorts) {
900 if (p->checkFunctional(pkt)) {
901 if (pkt->needsResponse())
902 pkt->makeResponse();
903 return;
904 }
905 }
906
907 // forward to all snoopers
908 forwardFunctional(pkt, InvalidPortID);
909}
910
911void
912CoherentXBar::forwardFunctional(PacketPtr pkt, PortID exclude_slave_port_id)
913{
914 // snoops should only happen if the system isn't bypassing caches
915 assert(!system->bypassCaches());
916
917 for (const auto& p: snoopPorts) {
918 // we could have gotten this request from a snooping master
919 // (corresponding to our own slave port that is also in
920 // snoopPorts) and should not send it back to where it came
921 // from
922 if (exclude_slave_port_id == InvalidPortID ||
923 p->getId() != exclude_slave_port_id)
924 p->sendFunctionalSnoop(pkt);
925
926 // if we get a response we are done
927 if (pkt->isResponse()) {
928 break;
929 }
930 }
931}
932
933bool
934CoherentXBar::sinkPacket(const PacketPtr pkt) const
935{
936 // we can sink the packet if:
937 // 1) the crossbar is the point of coherency, and a cache is
938 // responding after being snooped
939 // 2) the crossbar is the point of coherency, and the packet is a
940 // coherency packet (not a read or a write) that does not
941 // require a response
942 // 3) this is a clean evict or clean writeback, but the packet is
943 // found in a cache above this crossbar
944 // 4) a cache is responding after being snooped, and the packet
945 // either does not need the block to be writable, or the cache
946 // that has promised to respond (setting the cache responding
947 // flag) is providing writable and thus had a Modified block,
948 // and no further action is needed
949 return (pointOfCoherency && pkt->cacheResponding()) ||
950 (pointOfCoherency && !(pkt->isRead() || pkt->isWrite()) &&
951 !pkt->needsResponse()) ||
952 (pkt->isCleanEviction() && pkt->isBlockCached()) ||
953 (pkt->cacheResponding() &&
954 (!pkt->needsWritable() || pkt->responderHadWritable()));
955}
956
957void
958CoherentXBar::regStats()
959{
960 // register the stats of the base class and our layers
961 BaseXBar::regStats();
962 for (auto l: reqLayers)
963 l->regStats();
964 for (auto l: respLayers)
965 l->regStats();
966 for (auto l: snoopLayers)
967 l->regStats();
968
969 snoops
970 .name(name() + ".snoops")
971 .desc("Total snoops (count)")
972 ;
973
974 snoopTraffic
975 .name(name() + ".snoopTraffic")
976 .desc("Total snoop traffic (bytes)")
977 ;
978
979 snoopFanout
980 .init(0, snoopPorts.size(), 1)
981 .name(name() + ".snoop_fanout")
982 .desc("Request fanout histogram")
983 ;
984}
985
986CoherentXBar *
987CoherentXBarParams::create()
988{
989 return new CoherentXBar(this);
990}