gem5  v20.0.0.2
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
noncoherent_xbar.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2015, 2018-2019 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 
46 #include "mem/noncoherent_xbar.hh"
47 
48 #include "base/logging.hh"
49 #include "base/trace.hh"
50 #include "debug/NoncoherentXBar.hh"
51 #include "debug/XBar.hh"
52 
53 NoncoherentXBar::NoncoherentXBar(const NoncoherentXBarParams *p)
54  : BaseXBar(p)
55 {
56  // create the ports based on the size of the master and slave
57  // vector ports, and the presence of the default port, the ports
58  // are enumerated starting from zero
59  for (int i = 0; i < p->port_master_connection_count; ++i) {
60  std::string portName = csprintf("%s.master[%d]", name(), i);
61  MasterPort* bp = new NoncoherentXBarMasterPort(portName, *this, i);
62  masterPorts.push_back(bp);
63  reqLayers.push_back(new ReqLayer(*bp, *this,
64  csprintf("reqLayer%d", i)));
65  }
66 
67  // see if we have a default slave device connected and if so add
68  // our corresponding master port
69  if (p->port_default_connection_count) {
70  defaultPortID = masterPorts.size();
71  std::string portName = name() + ".default";
72  MasterPort* bp = new NoncoherentXBarMasterPort(portName, *this,
74  masterPorts.push_back(bp);
75  reqLayers.push_back(new ReqLayer(*bp, *this, csprintf("reqLayer%d",
76  defaultPortID)));
77  }
78 
79  // create the slave ports, once again starting at zero
80  for (int i = 0; i < p->port_slave_connection_count; ++i) {
81  std::string portName = csprintf("%s.slave[%d]", name(), i);
82  QueuedSlavePort* bp = new NoncoherentXBarSlavePort(portName, *this, i);
83  slavePorts.push_back(bp);
84  respLayers.push_back(new RespLayer(*bp, *this,
85  csprintf("respLayer%d", i)));
86  }
87 }
88 
90 {
91  for (auto l: reqLayers)
92  delete l;
93  for (auto l: respLayers)
94  delete l;
95 }
96 
97 bool
99 {
100  // determine the source port based on the id
101  SlavePort *src_port = slavePorts[slave_port_id];
102 
103  // we should never see express snoops on a non-coherent crossbar
104  assert(!pkt->isExpressSnoop());
105 
106  // determine the destination based on the address
107  PortID master_port_id = findPort(pkt->getAddrRange());
108 
109  // test if the layer should be considered occupied for the current
110  // port
111  if (!reqLayers[master_port_id]->tryTiming(src_port)) {
112  DPRINTF(NoncoherentXBar, "recvTimingReq: src %s %s 0x%x BUSY\n",
113  src_port->name(), pkt->cmdString(), pkt->getAddr());
114  return false;
115  }
116 
117  DPRINTF(NoncoherentXBar, "recvTimingReq: src %s %s 0x%x\n",
118  src_port->name(), pkt->cmdString(), pkt->getAddr());
119 
120  // store size and command as they might be modified when
121  // forwarding the packet
122  unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0;
123  unsigned int pkt_cmd = pkt->cmdToIndex();
124 
125  // store the old header delay so we can restore it if needed
126  Tick old_header_delay = pkt->headerDelay;
127 
128  // a request sees the frontend and forward latency
129  Tick xbar_delay = (frontendLatency + forwardLatency) * clockPeriod();
130 
131  // set the packet header and payload delay
132  calcPacketTiming(pkt, xbar_delay);
133 
134  // determine how long to be crossbar layer is busy
135  Tick packetFinishTime = clockEdge(Cycles(1)) + pkt->payloadDelay;
136 
137  // before forwarding the packet (and possibly altering it),
138  // remember if we are expecting a response
139  const bool expect_response = pkt->needsResponse() &&
140  !pkt->cacheResponding();
141 
142  // since it is a normal request, attempt to send the packet
143  bool success = masterPorts[master_port_id]->sendTimingReq(pkt);
144 
145  if (!success) {
146  DPRINTF(NoncoherentXBar, "recvTimingReq: src %s %s 0x%x RETRY\n",
147  src_port->name(), pkt->cmdString(), pkt->getAddr());
148 
149  // restore the header delay as it is additive
150  pkt->headerDelay = old_header_delay;
151 
152  // occupy until the header is sent
153  reqLayers[master_port_id]->failedTiming(src_port,
154  clockEdge(Cycles(1)));
155 
156  return false;
157  }
158 
159  // remember where to route the response to
160  if (expect_response) {
161  assert(routeTo.find(pkt->req) == routeTo.end());
162  routeTo[pkt->req] = slave_port_id;
163  }
164 
165  reqLayers[master_port_id]->succeededTiming(packetFinishTime);
166 
167  // stats updates
168  pktCount[slave_port_id][master_port_id]++;
169  pktSize[slave_port_id][master_port_id] += pkt_size;
170  transDist[pkt_cmd]++;
171 
172  return true;
173 }
174 
175 bool
177 {
178  // determine the source port based on the id
179  MasterPort *src_port = masterPorts[master_port_id];
180 
181  // determine the destination
182  const auto route_lookup = routeTo.find(pkt->req);
183  assert(route_lookup != routeTo.end());
184  const PortID slave_port_id = route_lookup->second;
185  assert(slave_port_id != InvalidPortID);
186  assert(slave_port_id < respLayers.size());
187 
188  // test if the layer should be considered occupied for the current
189  // port
190  if (!respLayers[slave_port_id]->tryTiming(src_port)) {
191  DPRINTF(NoncoherentXBar, "recvTimingResp: src %s %s 0x%x BUSY\n",
192  src_port->name(), pkt->cmdString(), pkt->getAddr());
193  return false;
194  }
195 
196  DPRINTF(NoncoherentXBar, "recvTimingResp: src %s %s 0x%x\n",
197  src_port->name(), pkt->cmdString(), pkt->getAddr());
198 
199  // store size and command as they might be modified when
200  // forwarding the packet
201  unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0;
202  unsigned int pkt_cmd = pkt->cmdToIndex();
203 
204  // a response sees the response latency
205  Tick xbar_delay = responseLatency * clockPeriod();
206 
207  // set the packet header and payload delay
208  calcPacketTiming(pkt, xbar_delay);
209 
210  // determine how long to be crossbar layer is busy
211  Tick packetFinishTime = clockEdge(Cycles(1)) + pkt->payloadDelay;
212 
213  // send the packet through the destination slave port, and pay for
214  // any outstanding latency
215  Tick latency = pkt->headerDelay;
216  pkt->headerDelay = 0;
217  slavePorts[slave_port_id]->schedTimingResp(pkt, curTick() + latency);
218 
219  // remove the request from the routing table
220  routeTo.erase(route_lookup);
221 
222  respLayers[slave_port_id]->succeededTiming(packetFinishTime);
223 
224  // stats updates
225  pktCount[slave_port_id][master_port_id]++;
226  pktSize[slave_port_id][master_port_id] += pkt_size;
227  transDist[pkt_cmd]++;
228 
229  return true;
230 }
231 
232 void
234 {
235  // responses never block on forwarding them, so the retry will
236  // always be coming from a port to which we tried to forward a
237  // request
238  reqLayers[master_port_id]->recvRetry();
239 }
240 
241 Tick
243  MemBackdoorPtr *backdoor)
244 {
245  DPRINTF(NoncoherentXBar, "recvAtomic: packet src %s addr 0x%x cmd %s\n",
246  slavePorts[slave_port_id]->name(), pkt->getAddr(),
247  pkt->cmdString());
248 
249  unsigned int pkt_size = pkt->hasData() ? pkt->getSize() : 0;
250  unsigned int pkt_cmd = pkt->cmdToIndex();
251 
252  // determine the destination port
253  PortID master_port_id = findPort(pkt->getAddrRange());
254 
255  // stats updates for the request
256  pktCount[slave_port_id][master_port_id]++;
257  pktSize[slave_port_id][master_port_id] += pkt_size;
258  transDist[pkt_cmd]++;
259 
260  // forward the request to the appropriate destination
261  auto master = masterPorts[master_port_id];
262  Tick response_latency = backdoor ?
263  master->sendAtomicBackdoor(pkt, *backdoor) : master->sendAtomic(pkt);
264 
265  // add the response data
266  if (pkt->isResponse()) {
267  pkt_size = pkt->hasData() ? pkt->getSize() : 0;
268  pkt_cmd = pkt->cmdToIndex();
269 
270  // stats updates
271  pktCount[slave_port_id][master_port_id]++;
272  pktSize[slave_port_id][master_port_id] += pkt_size;
273  transDist[pkt_cmd]++;
274  }
275 
276  // @todo: Not setting first-word time
277  pkt->payloadDelay = response_latency;
278  return response_latency;
279 }
280 
281 void
283 {
284  if (!pkt->isPrint()) {
285  // don't do DPRINTFs on PrintReq as it clutters up the output
287  "recvFunctional: packet src %s addr 0x%x cmd %s\n",
288  slavePorts[slave_port_id]->name(), pkt->getAddr(),
289  pkt->cmdString());
290  }
291 
292  // since our slave ports are queued ports we need to check them as well
293  for (const auto& p : slavePorts) {
294  // if we find a response that has the data, then the
295  // downstream caches/memories may be out of date, so simply stop
296  // here
297  if (p->trySatisfyFunctional(pkt)) {
298  if (pkt->needsResponse())
299  pkt->makeResponse();
300  return;
301  }
302  }
303 
304  // determine the destination port
305  PortID dest_id = findPort(pkt->getAddrRange());
306 
307  // forward the request to the appropriate destination
308  masterPorts[dest_id]->sendFunctional(pkt);
309 }
310 
312 NoncoherentXBarParams::create()
313 {
314  return new NoncoherentXBar(this);
315 }
A MasterPort is a specialisation of a BaseMasterPort, which implements the default protocol for the t...
Definition: port.hh:71
#define DPRINTF(x,...)
Definition: trace.hh:222
bool isExpressSnoop() const
Definition: packet.hh:628
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:81
Declaration of the non-coherent crossbar slave port type, one will be instantiated for each of the ma...
virtual bool recvTimingResp(PacketPtr pkt, PortID master_port_id)
Bitfield< 7 > i
const PortID InvalidPortID
Definition: types.hh:236
std::vector< ReqLayer * > reqLayers
Declare the layers of this crossbar, one vector for requests and one for responses.
std::vector< RespLayer * > respLayers
PortID defaultPortID
Port that handles requests that don&#39;t match any of the interfaces.
Definition: xbar.hh:377
std::unordered_map< RequestPtr, PortID > routeTo
Remember where request packets came from so that we can route responses to the appropriate port...
Definition: xbar.hh:321
bool cacheResponding() const
Definition: packet.hh:585
const Cycles responseLatency
Definition: xbar.hh:309
A queued port is a port that has an infinite queue for outgoing packets and thus decouples the module...
Definition: qport.hh:58
A SlavePort is a specialisation of a port.
Definition: port.hh:254
Tick clockPeriod() const
NoncoherentXBar(const NoncoherentXBarParams *p)
virtual bool recvTimingReq(PacketPtr pkt, PortID slave_port_id)
The base crossbar contains the common elements of the non-coherent and coherent crossbar.
Definition: xbar.hh:68
RequestPtr req
A pointer to the original request.
Definition: packet.hh:321
void recvFunctional(PacketPtr pkt, PortID slave_port_id)
unsigned getSize() const
Definition: packet.hh:730
Tick curTick()
The current simulated tick.
Definition: core.hh:44
void recvReqRetry(PortID master_port_id)
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:158
bool needsResponse() const
Definition: packet.hh:536
uint32_t headerDelay
The extra delay from seeing the packet until the header is transmitted.
Definition: packet.hh:360
uint64_t Tick
Tick count type.
Definition: types.hh:61
Stats::Vector transDist
Stats for transaction distribution and data passing through the crossbar.
Definition: xbar.hh:396
bool isResponse() const
Definition: packet.hh:526
Addr getAddr() const
Definition: packet.hh:720
AddrRange getAddrRange() const
Get address range to which this packet belongs.
Definition: packet.cc:225
bool hasData() const
Definition: packet.hh:542
void calcPacketTiming(PacketPtr pkt, Tick header_delay)
Calculate the timing parameters for the packet.
Definition: xbar.cc:99
virtual ~NoncoherentXBar()
uint32_t payloadDelay
The extra pipelining delay from seeing the packet until the end of payload is transmitted by the comp...
Definition: packet.hh:378
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:249
const Cycles frontendLatency
Cycles of front-end pipeline including the delay to accept the request and to decode the address...
Definition: xbar.hh:307
Tick clockEdge(Cycles cycles=Cycles(0)) const
Determine the tick when a cycle begins, by default the current one, but the argument also enables the...
A non-coherent crossbar connects a number of non-snooping masters and slaves, and routes the request ...
int cmdToIndex() const
Return the index of this command.
Definition: packet.hh:520
std::vector< MasterPort * > masterPorts
Definition: xbar.hh:374
void makeResponse()
Take a request packet and modify it in place to be suitable for returning as a response to that reque...
Definition: packet.hh:931
virtual const std::string name() const
Definition: sim_object.hh:128
std::vector< QueuedSlavePort * > slavePorts
The master and slave ports of the crossbar.
Definition: xbar.hh:373
const std::string name() const
Return port name (for DPRINTF).
Definition: port.hh:102
PortID findPort(AddrRange addr_range)
Find which port connected to this crossbar (if any) should be given a packet with this address range...
Definition: xbar.cc:325
bool isPrint() const
Definition: packet.hh:550
Declaration of the crossbar master port type, one will be instantiated for each of the slave ports co...
Declaration of a non-coherent crossbar.
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:235
const Cycles forwardLatency
Definition: xbar.hh:308
Tick recvAtomicBackdoor(PacketPtr pkt, PortID slave_port_id, MemBackdoorPtr *backdoor=nullptr)
const std::string & cmdString() const
Return the string name of the cmd field (for debugging and tracing).
Definition: packet.hh:517
Bitfield< 0 > p
Stats::Vector2d pktSize
Definition: xbar.hh:398
Bitfield< 5 > l
Stats::Vector2d pktCount
Definition: xbar.hh:397

Generated on Mon Jun 8 2020 15:45:12 for gem5 by doxygen 1.8.13