gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
xbar.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2015 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) 2002-2005 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: Ron Dreslinski
41  * Ali Saidi
42  * Andreas Hansson
43  * William Wang
44  */
45 
51 #ifndef __MEM_XBAR_HH__
52 #define __MEM_XBAR_HH__
53 
54 #include <deque>
55 #include <unordered_map>
56 
57 #include "base/addr_range_map.hh"
58 #include "base/types.hh"
59 #include "mem/mem_object.hh"
60 #include "mem/qport.hh"
61 #include "params/BaseXBar.hh"
62 #include "sim/stats.hh"
63 
73 class BaseXBar : public MemObject
74 {
75 
76  protected:
77 
92  template <typename SrcType, typename DstType>
93  class Layer : public Drainable
94  {
95 
96  public:
97 
106  Layer(DstType& _port, BaseXBar& _xbar, const std::string& _name);
107 
117  DrainState drain() override;
118 
122  const std::string name() const { return xbar.name() + _name; }
123 
124 
135  bool tryTiming(SrcType* src_port);
136 
144  void succeededTiming(Tick busy_time);
145 
155  void failedTiming(SrcType* src_port, Tick busy_time);
156 
158  void occupyLayer(Tick until);
159 
164  void retryWaiting();
165 
171  void recvRetry();
172 
176  void regStats();
177 
178  protected:
179 
186  virtual void sendRetry(SrcType* retry_port) = 0;
187 
188  private:
189 
191  DstType& port;
192 
195 
197  std::string _name;
198 
215  enum State { IDLE, BUSY, RETRY };
216 
219 
225 
230  SrcType* waitingForPeer;
231 
237  void releaseLayer();
238 
241 
249 
250  };
251 
252  class ReqLayer : public Layer<SlavePort,MasterPort>
253  {
254  public:
262  ReqLayer(MasterPort& _port, BaseXBar& _xbar, const std::string& _name) :
263  Layer(_port, _xbar, _name) {}
264 
265  protected:
266 
267  void sendRetry(SlavePort* retry_port)
268  { retry_port->sendRetryReq(); }
269  };
270 
271  class RespLayer : public Layer<MasterPort,SlavePort>
272  {
273  public:
281  RespLayer(SlavePort& _port, BaseXBar& _xbar, const std::string& _name) :
282  Layer(_port, _xbar, _name) {}
283 
284  protected:
285 
286  void sendRetry(MasterPort* retry_port)
287  { retry_port->sendRetryResp(); }
288  };
289 
290  class SnoopRespLayer : public Layer<SlavePort,MasterPort>
291  {
292  public:
301  const std::string& _name) :
302  Layer(_port, _xbar, _name) {}
303 
304  protected:
305 
306  void sendRetry(SlavePort* retry_port)
307  { retry_port->sendRetrySnoopResp(); }
308  };
309 
320  const uint32_t width;
321 
323 
330  std::unordered_map<RequestPtr, PortID> routeTo;
331 
334 
336 
343  virtual void recvRangeChange(PortID master_port_id);
344 
352 
353  // Cache for the findPort function storing recently used ports from portMap
354  struct PortCache {
355  bool valid;
358  };
359 
361 
362  // Checks the cache and returns the id of the port that has the requested
363  // address within its range
364  inline PortID checkPortCache(Addr addr) const {
365  if (portCache[0].valid && portCache[0].range.contains(addr)) {
366  return portCache[0].id;
367  }
368  if (portCache[1].valid && portCache[1].range.contains(addr)) {
369  return portCache[1].id;
370  }
371  if (portCache[2].valid && portCache[2].range.contains(addr)) {
372  return portCache[2].id;
373  }
374 
375  return InvalidPortID;
376  }
377 
378  // Clears the earliest entry of the cache and inserts a new port entry
379  inline void updatePortCache(short id, const AddrRange& range) {
380  portCache[2].valid = portCache[1].valid;
381  portCache[2].id = portCache[1].id;
382  portCache[2].range = portCache[1].range;
383 
384  portCache[1].valid = portCache[0].valid;
385  portCache[1].id = portCache[0].id;
386  portCache[1].range = portCache[0].range;
387 
388  portCache[0].valid = true;
389  portCache[0].id = id;
390  portCache[0].range = range;
391  }
392 
393  // Clears the cache. Needs to be called in constructor.
394  inline void clearPortCache() {
395  portCache[2].valid = false;
396  portCache[1].valid = false;
397  portCache[0].valid = false;
398  }
399 
406 
416  void calcPacketTiming(PacketPtr pkt, Tick header_delay);
417 
426 
430 
433 
438  const bool useDefaultRange;
439 
440  BaseXBar(const BaseXBarParams *p);
441 
454 
455  public:
456 
457  virtual ~BaseXBar();
458 
459  virtual void init();
460 
462  BaseMasterPort& getMasterPort(const std::string& if_name,
463  PortID idx = InvalidPortID);
464  BaseSlavePort& getSlavePort(const std::string& if_name,
465  PortID idx = InvalidPortID);
466 
467  virtual void regStats();
468 
469 };
470 
471 #endif //__MEM_XBAR_HH__
A MasterPort is a specialisation of a BaseMasterPort, which implements the default protocol for the t...
Definition: port.hh:167
State
We declare an enum to track the state of the layer.
Definition: xbar.hh:215
RespLayer(SlavePort &_port, BaseXBar &_xbar, const std::string &_name)
Create a response layer and give it a name.
Definition: xbar.hh:281
AddrRange range
Definition: xbar.hh:357
void recvRetry()
Handle a retry from a neighbouring module.
Definition: xbar.cc:300
PortID findPort(Addr addr)
Find which port connected to this crossbar (if any) should be given a packet with this address...
Definition: xbar.cc:324
virtual void regStats()
Register statistics for this object.
Definition: xbar.cc:543
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
const std::string name() const
Get the crossbar layer's name.
Definition: xbar.hh:122
void updatePortCache(short id, const AddrRange &range)
Definition: xbar.hh:379
EventWrapper< Layer,&Layer::releaseLayer > releaseEvent
event used to schedule a release of the layer
Definition: xbar.hh:240
const PortID InvalidPortID
Definition: types.hh:182
DrainState
Object drain/handover states.
Definition: drain.hh:71
Stats::Formula utilization
Definition: xbar.hh:248
PortID defaultPortID
Port that handles requests that don't match any of the interfaces.
Definition: xbar.hh:432
ip6_addr_t addr
Definition: inet.hh:335
MemObject declaration.
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:330
const Cycles responseLatency
Cycles of response latency.
Definition: xbar.hh:318
A vector of scalar stats.
Definition: statistics.hh:2499
PortCache portCache[3]
Definition: xbar.hh:360
A SlavePort is a specialisation of a port.
Definition: port.hh:331
virtual void sendRetryResp()
Send a retry to the slave port that previously attempted a sendTimingResp to this master port and fai...
Definition: port.cc:194
std::vector< bool > gotAddrRanges
Remember for each of the master ports of the crossbar if we got an address range from the connected s...
Definition: xbar.hh:424
virtual void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: xbar.cc:80
void sendRetrySnoopResp()
Send a retry to the master port that previously attempted a sendTimingSnoopResp to this slave port an...
Definition: port.cc:271
A BaseSlavePort is a protocol-agnostic slave port, responsible only for the structural connection to ...
Definition: port.hh:139
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2475
SnoopRespLayer(MasterPort &_port, BaseXBar &_xbar, const std::string &_name)
Create a snoop response layer and give it a name.
Definition: xbar.hh:300
void sendRetry(MasterPort *retry_port)
Sending the actual retry, in a manner specific to the individual layers.
Definition: xbar.hh:286
AddrRangeMap< PortID > portMap
Definition: xbar.hh:322
The base crossbar contains the common elements of the non-coherent and coherent crossbar.
Definition: xbar.hh:73
void succeededTiming(Tick busy_time)
Deal with a destination port accepting a packet by potentially removing the source port from the retr...
Definition: xbar.cc:207
PortID checkPortCache(Addr addr) const
Definition: xbar.hh:364
Interface for objects that might require draining before checkpointing.
Definition: drain.hh:223
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
Definition: addr_range.hh:72
AddrRangeList xbarRanges
all contigous ranges seen by this crossbar
Definition: xbar.hh:333
A layer is an internal crossbar arbitration point with its own flow control.
Definition: xbar.hh:93
Declaration of the queued port.
virtual ~BaseXBar()
Definition: xbar.cc:70
const uint32_t width
the width of the xbar in bytes
Definition: xbar.hh:320
void sendRetry(SlavePort *retry_port)
Sending the actual retry, in a manner specific to the individual layers.
Definition: xbar.hh:267
uint64_t Tick
Tick count type.
Definition: types.hh:63
Stats::Vector transDist
Stats for transaction distribution and data passing through the crossbar.
Definition: xbar.hh:451
BaseXBar(const BaseXBarParams *p)
Definition: xbar.cc:58
ReqLayer(MasterPort &_port, BaseXBar &_xbar, const std::string &_name)
Create a request layer and give it a name.
Definition: xbar.hh:262
std::string _name
A name for this layer.
Definition: xbar.hh:197
void calcPacketTiming(PacketPtr pkt, Tick header_delay)
Calculate the timing parameters for the packet.
Definition: xbar.cc:109
void sendRetry(SlavePort *retry_port)
Sending the actual retry, in a manner specific to the individual layers.
Definition: xbar.hh:306
DstType & port
The destination port this layer converges at.
Definition: xbar.hh:191
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
std::deque< SrcType * > waitingForLayer
A deque of ports that retry should be called on because the original send was delayed due to a busy l...
Definition: xbar.hh:224
void failedTiming(SrcType *src_port, Tick busy_time)
Deal with a destination port not accepting a packet by potentially adding the source port to the retr...
Definition: xbar.cc:219
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:245
const Cycles frontendLatency
Cycles of front-end pipeline including the delay to accept the request and to decode the address...
Definition: xbar.hh:314
bool gotAllAddrRanges
Definition: xbar.hh:425
A formula for statistics that is calculated when printed.
Definition: statistics.hh:2895
BaseSlavePort & getSlavePort(const std::string &if_name, PortID idx=InvalidPortID)
Get a slave port with a given name and index.
Definition: xbar.cc:98
std::vector< MasterPort * > masterPorts
Definition: xbar.hh:429
virtual void sendRetry(SrcType *retry_port)=0
Sending the actual retry, in a manner specific to the individual layers.
BaseXBar & xbar
The crossbar this layer is a part of.
Definition: xbar.hh:194
std::vector< QueuedSlavePort * > slavePorts
The master and slave ports of the crossbar.
Definition: xbar.hh:428
virtual const std::string name() const
Definition: sim_object.hh:117
void occupyLayer(Tick until)
Occupy the layer until until.
Definition: xbar.cc:155
void releaseLayer()
Release the layer after being occupied and return to an idle state where we proceed to send a retry t...
Definition: xbar.cc:241
void sendRetryReq()
Send a retry to the master port that previously attempted a sendTimingReq to this slave port and fail...
Definition: port.cc:265
The MemObject class extends the ClockedObject with accessor functions to get its master and slave por...
Definition: mem_object.hh:60
DrainState drain() override
Drain according to the normal semantics, so that the crossbar can tell the layer to drain...
Definition: xbar.cc:592
A BaseMasterPort is a protocol-agnostic master port, responsible only for the structural connection t...
Definition: port.hh:115
Layer(DstType &_port, BaseXBar &_xbar, const std::string &_name)
Create a layer and give it a name.
Definition: xbar.cc:147
void regStats()
Register stats for the layer.
Definition: xbar.cc:607
bool tryTiming(SrcType *src_port)
Determine if the layer accepts a packet from a specific port.
Definition: xbar.cc:176
Stats::Scalar occupancy
Stats for occupancy and utilization.
Definition: xbar.hh:247
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:181
const Cycles forwardLatency
Cycles of forward latency.
Definition: xbar.hh:316
AddrRangeList getAddrRanges() const
Return the address ranges the crossbar is responsible for.
Definition: xbar.cc:525
void clearPortCache()
Definition: xbar.hh:394
A 2-Dimensional vecto of scalar stats.
Definition: statistics.hh:2515
Bitfield< 11 > id
Definition: miscregs.hh:124
AddrRange defaultRange
Definition: xbar.hh:335
Bitfield< 0 > p
Stats::Vector2d pktSize
Definition: xbar.hh:453
SrcType * waitingForPeer
Track who is waiting for the retry when receiving it from a peer.
Definition: xbar.hh:230
const bool useDefaultRange
If true, use address range provided by default device.
Definition: xbar.hh:438
void retryWaiting()
Send a retry to the port at the head of waitingForLayer.
Definition: xbar.cc:265
virtual void recvRangeChange(PortID master_port_id)
Function called by the port when the crossbar is recieving a range change.
Definition: xbar.cc:364
Stats::Vector2d pktCount
Definition: xbar.hh:452
State state
track the state of the layer
Definition: xbar.hh:218
BaseMasterPort & getMasterPort(const std::string &if_name, PortID idx=InvalidPortID)
A function used to return the port associated with this object.
Definition: xbar.cc:85

Generated on Fri Jun 9 2017 13:03:51 for gem5 by doxygen 1.8.6