coherent_xbar.hh revision 10656:bd376adfb7d4
1/* 2 * Copyright (c) 2011-2014 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 46/** 47 * @file 48 * Declaration of a coherent crossbar. 49 */ 50 51#ifndef __MEM_COHERENT_XBAR_HH__ 52#define __MEM_COHERENT_XBAR_HH__ 53 54#include "mem/snoop_filter.hh" 55#include "mem/xbar.hh" 56#include "params/CoherentXBar.hh" 57 58/** 59 * A coherent crossbar connects a number of (potentially) snooping 60 * masters and slaves, and routes the request and response packets 61 * based on the address, and also forwards all requests to the 62 * snoopers and deals with the snoop responses. 63 * 64 * The coherent crossbar can be used as a template for modelling QPI, 65 * HyperTransport, ACE and coherent OCP buses, and is typically used 66 * for the L1-to-L2 buses and as the main system interconnect. @sa 67 * \ref gem5MemorySystem "gem5 Memory System" 68 */ 69class CoherentXBar : public BaseXBar 70{ 71 72 protected: 73 74 /** 75 * Declare the layers of this crossbar, one vector for requests, 76 * one for responses, and one for snoop responses 77 */ 78 typedef Layer<SlavePort,MasterPort> ReqLayer; 79 typedef Layer<MasterPort,SlavePort> RespLayer; 80 typedef Layer<SlavePort,MasterPort> SnoopLayer; 81 std::vector<ReqLayer*> reqLayers; 82 std::vector<RespLayer*> respLayers; 83 std::vector<SnoopLayer*> snoopLayers; 84 85 /** 86 * Declaration of the coherent crossbar slave port type, one will 87 * be instantiated for each of the master ports connecting to the 88 * crossbar. 89 */ 90 class CoherentXBarSlavePort : public SlavePort 91 { 92 93 private: 94 95 /** A reference to the crossbar to which this port belongs. */ 96 CoherentXBar &xbar; 97 98 public: 99 100 CoherentXBarSlavePort(const std::string &_name, 101 CoherentXBar &_xbar, PortID _id) 102 : SlavePort(_name, &_xbar, _id), xbar(_xbar) 103 { } 104 105 protected: 106 107 /** 108 * When receiving a timing request, pass it to the crossbar. 109 */ 110 virtual bool recvTimingReq(PacketPtr pkt) 111 { return xbar.recvTimingReq(pkt, id); } 112 113 /** 114 * When receiving a timing snoop response, pass it to the crossbar. 115 */ 116 virtual bool recvTimingSnoopResp(PacketPtr pkt) 117 { return xbar.recvTimingSnoopResp(pkt, id); } 118 119 /** 120 * When receiving an atomic request, pass it to the crossbar. 121 */ 122 virtual Tick recvAtomic(PacketPtr pkt) 123 { return xbar.recvAtomic(pkt, id); } 124 125 /** 126 * When receiving a functional request, pass it to the crossbar. 127 */ 128 virtual void recvFunctional(PacketPtr pkt) 129 { xbar.recvFunctional(pkt, id); } 130 131 /** 132 * When receiving a retry, pass it to the crossbar. 133 */ 134 virtual void recvRetry() 135 { panic("Crossbar slave ports should never retry.\n"); } 136 137 /** 138 * Return the union of all adress ranges seen by this crossbar. 139 */ 140 virtual AddrRangeList getAddrRanges() const 141 { return xbar.getAddrRanges(); } 142 143 }; 144 145 /** 146 * Declaration of the coherent crossbar master port type, one will be 147 * instantiated for each of the slave interfaces connecting to the 148 * crossbar. 149 */ 150 class CoherentXBarMasterPort : public MasterPort 151 { 152 private: 153 /** A reference to the crossbar to which this port belongs. */ 154 CoherentXBar &xbar; 155 156 public: 157 158 CoherentXBarMasterPort(const std::string &_name, 159 CoherentXBar &_xbar, PortID _id) 160 : MasterPort(_name, &_xbar, _id), xbar(_xbar) 161 { } 162 163 protected: 164 165 /** 166 * Determine if this port should be considered a snooper. For 167 * a coherent crossbar master port this is always true. 168 * 169 * @return a boolean that is true if this port is snooping 170 */ 171 virtual bool isSnooping() const 172 { return true; } 173 174 /** 175 * When receiving a timing response, pass it to the crossbar. 176 */ 177 virtual bool recvTimingResp(PacketPtr pkt) 178 { return xbar.recvTimingResp(pkt, id); } 179 180 /** 181 * When receiving a timing snoop request, pass it to the crossbar. 182 */ 183 virtual void recvTimingSnoopReq(PacketPtr pkt) 184 { return xbar.recvTimingSnoopReq(pkt, id); } 185 186 /** 187 * When receiving an atomic snoop request, pass it to the crossbar. 188 */ 189 virtual Tick recvAtomicSnoop(PacketPtr pkt) 190 { return xbar.recvAtomicSnoop(pkt, id); } 191 192 /** 193 * When receiving a functional snoop request, pass it to the crossbar. 194 */ 195 virtual void recvFunctionalSnoop(PacketPtr pkt) 196 { xbar.recvFunctionalSnoop(pkt, id); } 197 198 /** When reciving a range change from the peer port (at id), 199 pass it to the crossbar. */ 200 virtual void recvRangeChange() 201 { xbar.recvRangeChange(id); } 202 203 /** When reciving a retry from the peer port (at id), 204 pass it to the crossbar. */ 205 virtual void recvRetry() 206 { xbar.recvRetry(id); } 207 208 }; 209 210 /** 211 * Internal class to bridge between an incoming snoop response 212 * from a slave port and forwarding it through an outgoing slave 213 * port. It is effectively a dangling master port. 214 */ 215 class SnoopRespPort : public MasterPort 216 { 217 218 private: 219 220 /** The port which we mirror internally. */ 221 SlavePort& slavePort; 222 223 public: 224 225 /** 226 * Create a snoop response port that mirrors a given slave port. 227 */ 228 SnoopRespPort(SlavePort& slave_port, CoherentXBar& _xbar) : 229 MasterPort(slave_port.name() + ".snoopRespPort", &_xbar), 230 slavePort(slave_port) { } 231 232 /** 233 * Override the sending of retries and pass them on through 234 * the mirrored slave port. 235 */ 236 void sendRetry() { 237 slavePort.sendRetry(); 238 } 239 240 /** 241 * Provided as necessary. 242 */ 243 void recvRetry() { panic("SnoopRespPort should never see retry\n"); } 244 245 /** 246 * Provided as necessary. 247 */ 248 bool recvTimingResp(PacketPtr pkt) 249 { 250 panic("SnoopRespPort should never see timing response\n"); 251 return false; 252 } 253 254 }; 255 256 std::vector<SnoopRespPort*> snoopRespPorts; 257 258 std::vector<SlavePort*> snoopPorts; 259 260 /** 261 * Store the outstanding requests that we are expecting snoop 262 * responses from so we can determine which snoop responses we 263 * generated and which ones were merely forwarded. 264 */ 265 m5::hash_set<RequestPtr> outstandingSnoop; 266 267 /** 268 * Keep a pointer to the system to be allow to querying memory system 269 * properties. 270 */ 271 System *system; 272 273 /** A snoop filter that tracks cache line residency and can restrict the 274 * broadcast needed for probes. NULL denotes an absent filter. */ 275 SnoopFilter *snoopFilter; 276 277 /** Function called by the port when the crossbar is recieving a Timing 278 request packet.*/ 279 bool recvTimingReq(PacketPtr pkt, PortID slave_port_id); 280 281 /** Function called by the port when the crossbar is recieving a Timing 282 response packet.*/ 283 bool recvTimingResp(PacketPtr pkt, PortID master_port_id); 284 285 /** Function called by the port when the crossbar is recieving a timing 286 snoop request.*/ 287 void recvTimingSnoopReq(PacketPtr pkt, PortID master_port_id); 288 289 /** Function called by the port when the crossbar is recieving a timing 290 snoop response.*/ 291 bool recvTimingSnoopResp(PacketPtr pkt, PortID slave_port_id); 292 293 /** Timing function called by port when it is once again able to process 294 * requests. */ 295 void recvRetry(PortID master_port_id); 296 297 /** 298 * Forward a timing packet to our snoopers, potentially excluding 299 * one of the connected coherent masters to avoid sending a packet 300 * back to where it came from. 301 * 302 * @param pkt Packet to forward 303 * @param exclude_slave_port_id Id of slave port to exclude 304 */ 305 void forwardTiming(PacketPtr pkt, PortID exclude_slave_port_id) { 306 forwardTiming(pkt, exclude_slave_port_id, snoopPorts); 307 } 308 309 /** 310 * Forward a timing packet to a selected list of snoopers, potentially 311 * excluding one of the connected coherent masters to avoid sending a packet 312 * back to where it came from. 313 * 314 * @param pkt Packet to forward 315 * @param exclude_slave_port_id Id of slave port to exclude 316 * @param dests Vector of destination ports for the forwarded pkt 317 */ 318 void forwardTiming(PacketPtr pkt, PortID exclude_slave_port_id, 319 const std::vector<SlavePort*>& dests); 320 321 /** Function called by the port when the crossbar is recieving a Atomic 322 transaction.*/ 323 Tick recvAtomic(PacketPtr pkt, PortID slave_port_id); 324 325 /** Function called by the port when the crossbar is recieving an 326 atomic snoop transaction.*/ 327 Tick recvAtomicSnoop(PacketPtr pkt, PortID master_port_id); 328 329 /** 330 * Forward an atomic packet to our snoopers, potentially excluding 331 * one of the connected coherent masters to avoid sending a packet 332 * back to where it came from. 333 * 334 * @param pkt Packet to forward 335 * @param exclude_slave_port_id Id of slave port to exclude 336 * 337 * @return a pair containing the snoop response and snoop latency 338 */ 339 std::pair<MemCmd, Tick> forwardAtomic(PacketPtr pkt, 340 PortID exclude_slave_port_id) 341 { 342 return forwardAtomic(pkt, exclude_slave_port_id, InvalidPortID, snoopPorts); 343 } 344 345 /** 346 * Forward an atomic packet to a selected list of snoopers, potentially 347 * excluding one of the connected coherent masters to avoid sending a packet 348 * back to where it came from. 349 * 350 * @param pkt Packet to forward 351 * @param exclude_slave_port_id Id of slave port to exclude 352 * @param source_master_port_id Id of the master port for snoops from below 353 * @param dests Vector of destination ports for the forwarded pkt 354 * 355 * @return a pair containing the snoop response and snoop latency 356 */ 357 std::pair<MemCmd, Tick> forwardAtomic(PacketPtr pkt, 358 PortID exclude_slave_port_id, 359 PortID source_master_port_id, 360 const std::vector<SlavePort*>& dests); 361 362 /** Function called by the port when the crossbar is recieving a Functional 363 transaction.*/ 364 void recvFunctional(PacketPtr pkt, PortID slave_port_id); 365 366 /** Function called by the port when the crossbar is recieving a functional 367 snoop transaction.*/ 368 void recvFunctionalSnoop(PacketPtr pkt, PortID master_port_id); 369 370 /** 371 * Forward a functional packet to our snoopers, potentially 372 * excluding one of the connected coherent masters to avoid 373 * sending a packet back to where it came from. 374 * 375 * @param pkt Packet to forward 376 * @param exclude_slave_port_id Id of slave port to exclude 377 */ 378 void forwardFunctional(PacketPtr pkt, PortID exclude_slave_port_id); 379 380 Stats::Scalar snoops; 381 Stats::Distribution snoopFanout; 382 383 public: 384 385 virtual void init(); 386 387 CoherentXBar(const CoherentXBarParams *p); 388 389 virtual ~CoherentXBar(); 390 391 unsigned int drain(DrainManager *dm); 392 393 virtual void regStats(); 394}; 395 396#endif //__MEM_COHERENT_XBAR_HH__ 397