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 non-coherent crossbar object.
50 #include "base/misc.hh"
51 #include "base/trace.hh"
52 #include "debug/NoncoherentXBar.hh"
53 #include "debug/XBar.hh"
54 #include "mem/noncoherent_xbar.hh"
56 NoncoherentXBar::NoncoherentXBar(const NoncoherentXBarParams
*p
)
59 // create the ports based on the size of the master and slave
60 // vector ports, and the presence of the default port, the ports
61 // are enumerated starting from zero
62 for (int i
= 0; i
< p
->port_master_connection_count
; ++i
) {
63 std::string portName
= csprintf("%s.master[%d]", name(), i
);
64 MasterPort
* bp
= new NoncoherentXBarMasterPort(portName
, *this, i
);
65 masterPorts
.push_back(bp
);
66 reqLayers
.push_back(new ReqLayer(*bp
, *this,
67 csprintf(".reqLayer%d", i
)));
70 // see if we have a default slave device connected and if so add
71 // our corresponding master port
72 if (p
->port_default_connection_count
) {
73 defaultPortID
= masterPorts
.size();
74 std::string portName
= name() + ".default";
75 MasterPort
* bp
= new NoncoherentXBarMasterPort(portName
, *this,
77 masterPorts
.push_back(bp
);
78 reqLayers
.push_back(new ReqLayer(*bp
, *this, csprintf(".reqLayer%d",
82 // create the slave ports, once again starting at zero
83 for (int i
= 0; i
< p
->port_slave_connection_count
; ++i
) {
84 std::string portName
= csprintf("%s.slave[%d]", name(), i
);
85 QueuedSlavePort
* bp
= new NoncoherentXBarSlavePort(portName
, *this, i
);
86 slavePorts
.push_back(bp
);
87 respLayers
.push_back(new RespLayer(*bp
, *this,
88 csprintf(".respLayer%d", i
)));
94 NoncoherentXBar::~NoncoherentXBar()
96 for (auto l
: reqLayers
)
98 for (auto l
: respLayers
)
103 NoncoherentXBar::recvTimingReq(PacketPtr pkt
, PortID slave_port_id
)
105 // determine the source port based on the id
106 SlavePort
*src_port
= slavePorts
[slave_port_id
];
108 // we should never see express snoops on a non-coherent crossbar
109 assert(!pkt
->isExpressSnoop());
111 // determine the destination based on the address
112 PortID master_port_id
= findPort(pkt
->getAddr());
114 // test if the layer should be considered occupied for the current
116 if (!reqLayers
[master_port_id
]->tryTiming(src_port
)) {
117 DPRINTF(NoncoherentXBar
, "recvTimingReq: src %s %s 0x%x BUSY\n",
118 src_port
->name(), pkt
->cmdString(), pkt
->getAddr());
122 DPRINTF(NoncoherentXBar
, "recvTimingReq: src %s %s 0x%x\n",
123 src_port
->name(), pkt
->cmdString(), pkt
->getAddr());
125 // store size and command as they might be modified when
126 // forwarding the packet
127 unsigned int pkt_size
= pkt
->hasData() ? pkt
->getSize() : 0;
128 unsigned int pkt_cmd
= pkt
->cmdToIndex();
130 // store the old header delay so we can restore it if needed
131 Tick old_header_delay
= pkt
->headerDelay
;
133 // a request sees the frontend and forward latency
134 Tick xbar_delay
= (frontendLatency
+ forwardLatency
) * clockPeriod();
136 // set the packet header and payload delay
137 calcPacketTiming(pkt
, xbar_delay
);
139 // determine how long to be crossbar layer is busy
140 Tick packetFinishTime
= clockEdge(Cycles(1)) + pkt
->payloadDelay
;
142 // before forwarding the packet (and possibly altering it),
143 // remember if we are expecting a response
144 const bool expect_response
= pkt
->needsResponse() &&
145 !pkt
->memInhibitAsserted();
147 // since it is a normal request, attempt to send the packet
148 bool success
= masterPorts
[master_port_id
]->sendTimingReq(pkt
);
151 // inhibited packets should never be forced to retry
152 assert(!pkt
->memInhibitAsserted());
154 DPRINTF(NoncoherentXBar
, "recvTimingReq: src %s %s 0x%x RETRY\n",
155 src_port
->name(), pkt
->cmdString(), pkt
->getAddr());
157 // restore the header delay as it is additive
158 pkt
->headerDelay
= old_header_delay
;
160 // occupy until the header is sent
161 reqLayers
[master_port_id
]->failedTiming(src_port
,
162 clockEdge(Cycles(1)));
167 // remember where to route the response to
168 if (expect_response
) {
169 assert(routeTo
.find(pkt
->req
) == routeTo
.end());
170 routeTo
[pkt
->req
] = slave_port_id
;
173 reqLayers
[master_port_id
]->succeededTiming(packetFinishTime
);
176 pktCount
[slave_port_id
][master_port_id
]++;
177 pktSize
[slave_port_id
][master_port_id
] += pkt_size
;
178 transDist
[pkt_cmd
]++;
184 NoncoherentXBar::recvTimingResp(PacketPtr pkt
, PortID master_port_id
)
186 // determine the source port based on the id
187 MasterPort
*src_port
= masterPorts
[master_port_id
];
189 // determine the destination
190 const auto route_lookup
= routeTo
.find(pkt
->req
);
191 assert(route_lookup
!= routeTo
.end());
192 const PortID slave_port_id
= route_lookup
->second
;
193 assert(slave_port_id
!= InvalidPortID
);
194 assert(slave_port_id
< respLayers
.size());
196 // test if the layer should be considered occupied for the current
198 if (!respLayers
[slave_port_id
]->tryTiming(src_port
)) {
199 DPRINTF(NoncoherentXBar
, "recvTimingResp: src %s %s 0x%x BUSY\n",
200 src_port
->name(), pkt
->cmdString(), pkt
->getAddr());
204 DPRINTF(NoncoherentXBar
, "recvTimingResp: src %s %s 0x%x\n",
205 src_port
->name(), pkt
->cmdString(), pkt
->getAddr());
207 // store size and command as they might be modified when
208 // forwarding the packet
209 unsigned int pkt_size
= pkt
->hasData() ? pkt
->getSize() : 0;
210 unsigned int pkt_cmd
= pkt
->cmdToIndex();
212 // a response sees the response latency
213 Tick xbar_delay
= responseLatency
* clockPeriod();
215 // set the packet header and payload delay
216 calcPacketTiming(pkt
, xbar_delay
);
218 // determine how long to be crossbar layer is busy
219 Tick packetFinishTime
= clockEdge(Cycles(1)) + pkt
->payloadDelay
;
221 // send the packet through the destination slave port, and pay for
222 // any outstanding latency
223 Tick latency
= pkt
->headerDelay
;
224 pkt
->headerDelay
= 0;
225 slavePorts
[slave_port_id
]->schedTimingResp(pkt
, curTick() + latency
);
227 // remove the request from the routing table
228 routeTo
.erase(route_lookup
);
230 respLayers
[slave_port_id
]->succeededTiming(packetFinishTime
);
233 pktCount
[slave_port_id
][master_port_id
]++;
234 pktSize
[slave_port_id
][master_port_id
] += pkt_size
;
235 transDist
[pkt_cmd
]++;
241 NoncoherentXBar::recvReqRetry(PortID master_port_id
)
243 // responses never block on forwarding them, so the retry will
244 // always be coming from a port to which we tried to forward a
246 reqLayers
[master_port_id
]->recvRetry();
250 NoncoherentXBar::recvAtomic(PacketPtr pkt
, PortID slave_port_id
)
252 DPRINTF(NoncoherentXBar
, "recvAtomic: packet src %s addr 0x%x cmd %s\n",
253 slavePorts
[slave_port_id
]->name(), pkt
->getAddr(),
256 unsigned int pkt_size
= pkt
->hasData() ? pkt
->getSize() : 0;
257 unsigned int pkt_cmd
= pkt
->cmdToIndex();
259 // determine the destination port
260 PortID master_port_id
= findPort(pkt
->getAddr());
262 // stats updates for the request
263 pktCount
[slave_port_id
][master_port_id
]++;
264 pktSize
[slave_port_id
][master_port_id
] += pkt_size
;
265 transDist
[pkt_cmd
]++;
267 // forward the request to the appropriate destination
268 Tick response_latency
= masterPorts
[master_port_id
]->sendAtomic(pkt
);
270 // add the response data
271 if (pkt
->isResponse()) {
272 pkt_size
= pkt
->hasData() ? pkt
->getSize() : 0;
273 pkt_cmd
= pkt
->cmdToIndex();
276 pktCount
[slave_port_id
][master_port_id
]++;
277 pktSize
[slave_port_id
][master_port_id
] += pkt_size
;
278 transDist
[pkt_cmd
]++;
281 // @todo: Not setting first-word time
282 pkt
->payloadDelay
= response_latency
;
283 return response_latency
;
287 NoncoherentXBar::recvFunctional(PacketPtr pkt
, PortID slave_port_id
)
289 if (!pkt
->isPrint()) {
290 // don't do DPRINTFs on PrintReq as it clutters up the output
291 DPRINTF(NoncoherentXBar
,
292 "recvFunctional: packet src %s addr 0x%x cmd %s\n",
293 slavePorts
[slave_port_id
]->name(), pkt
->getAddr(),
297 // since our slave ports are queued ports we need to check them as well
298 for (const auto& p
: slavePorts
) {
299 // if we find a response that has the data, then the
300 // downstream caches/memories may be out of date, so simply stop
302 if (p
->checkFunctional(pkt
)) {
303 if (pkt
->needsResponse())
309 // determine the destination port
310 PortID dest_id
= findPort(pkt
->getAddr());
312 // forward the request to the appropriate destination
313 masterPorts
[dest_id
]->sendFunctional(pkt
);
317 NoncoherentXBarParams::create()
319 return new NoncoherentXBar(this);
323 NoncoherentXBar::regStats()
325 // register the stats of the base class and our layers
326 BaseXBar::regStats();
327 for (auto l
: reqLayers
)
329 for (auto l
: respLayers
)