coherent_xbar.hh revision 10883:9294c4a60251
12SN/A/* 21762SN/A * Copyright (c) 2011-2015 ARM Limited 32SN/A * All rights reserved 42SN/A * 52SN/A * The license below extends only to copyright in the software and shall 62SN/A * not be construed as granting a license to any other intellectual 72SN/A * property including but not limited to intellectual property relating 82SN/A * to a hardware implementation of the functionality of the software 92SN/A * licensed hereunder. You may use the software subject to the license 102SN/A * terms below provided that you ensure that this notice is replicated 112SN/A * unmodified and in its entirety in all distributions of the software, 122SN/A * modified or unmodified, in source code or in binary form. 132SN/A * 142SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 152SN/A * All rights reserved. 162SN/A * 172SN/A * Redistribution and use in source and binary forms, with or without 182SN/A * modification, are permitted provided that the following conditions are 192SN/A * met: redistributions of source code must retain the above copyright 202SN/A * notice, this list of conditions and the following disclaimer; 212SN/A * redistributions in binary form must reproduce the above copyright 222SN/A * notice, this list of conditions and the following disclaimer in the 232SN/A * documentation and/or other materials provided with the distribution; 242SN/A * neither the name of the copyright holders nor the names of its 252SN/A * contributors may be used to endorse or promote products derived from 262SN/A * this software without specific prior written permission. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 292665Ssaidi@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 302SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 312SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 322SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 332SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 342SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 352147SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 362147SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 372174SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 382147SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 392680Sktlim@umich.edu * 402132SN/A * Authors: Ron Dreslinski 412147SN/A * Ali Saidi 422132SN/A * Andreas Hansson 432147SN/A * William Wang 442147SN/A */ 452147SN/A 462147SN/A/** 472147SN/A * @file 482147SN/A * Declaration of a coherent crossbar. 492147SN/A */ 502147SN/A 512147SN/A#ifndef __MEM_COHERENT_XBAR_HH__ 522147SN/A#define __MEM_COHERENT_XBAR_HH__ 532147SN/A 542090SN/A#include "mem/snoop_filter.hh" 552147SN/A#include "mem/xbar.hh" 562175SN/A#include "params/CoherentXBar.hh" 572174SN/A 582680Sktlim@umich.edu/** 592201SN/A * A coherent crossbar connects a number of (potentially) snooping 602680Sktlim@umich.edu * masters and slaves, and routes the request and response packets 612174SN/A * based on the address, and also forwards all requests to the 622201SN/A * snoopers and deals with the snoop responses. 632201SN/A * 642168SN/A * The coherent crossbar can be used as a template for modelling QPI, 652168SN/A * HyperTransport, ACE and coherent OCP buses, and is typically used 662SN/A * for the L1-to-L2 buses and as the main system interconnect. @sa 672SN/A * \ref gem5MemorySystem "gem5 Memory System" 682168SN/A */ 692168SN/Aclass CoherentXBar : public BaseXBar 702612SN/A{ 712612SN/A 722612SN/A protected: 732612SN/A 742612SN/A /** 752612SN/A * Declare the layers of this crossbar, one vector for requests, 762612SN/A * one for responses, and one for snoop responses 772612SN/A */ 782612SN/A std::vector<ReqLayer*> reqLayers; 792612SN/A std::vector<RespLayer*> respLayers; 802680Sktlim@umich.edu std::vector<SnoopRespLayer*> snoopLayers; 812612SN/A 822612SN/A /** 832SN/A * Declaration of the coherent crossbar slave port type, one will 84 * be instantiated for each of the master ports connecting to the 85 * crossbar. 86 */ 87 class CoherentXBarSlavePort : public SlavePort 88 { 89 90 private: 91 92 /** A reference to the crossbar to which this port belongs. */ 93 CoherentXBar &xbar; 94 95 public: 96 97 CoherentXBarSlavePort(const std::string &_name, 98 CoherentXBar &_xbar, PortID _id) 99 : SlavePort(_name, &_xbar, _id), xbar(_xbar) 100 { } 101 102 protected: 103 104 /** 105 * When receiving a timing request, pass it to the crossbar. 106 */ 107 virtual bool recvTimingReq(PacketPtr pkt) 108 { return xbar.recvTimingReq(pkt, id); } 109 110 /** 111 * When receiving a timing snoop response, pass it to the crossbar. 112 */ 113 virtual bool recvTimingSnoopResp(PacketPtr pkt) 114 { return xbar.recvTimingSnoopResp(pkt, id); } 115 116 /** 117 * When receiving an atomic request, pass it to the crossbar. 118 */ 119 virtual Tick recvAtomic(PacketPtr pkt) 120 { return xbar.recvAtomic(pkt, id); } 121 122 /** 123 * When receiving a functional request, pass it to the crossbar. 124 */ 125 virtual void recvFunctional(PacketPtr pkt) 126 { xbar.recvFunctional(pkt, id); } 127 128 /** 129 * When receiving a retry, pass it to the crossbar. 130 */ 131 virtual void recvRespRetry() 132 { panic("Crossbar slave ports should never retry.\n"); } 133 134 /** 135 * Return the union of all adress ranges seen by this crossbar. 136 */ 137 virtual AddrRangeList getAddrRanges() const 138 { return xbar.getAddrRanges(); } 139 140 }; 141 142 /** 143 * Declaration of the coherent crossbar master port type, one will be 144 * instantiated for each of the slave interfaces connecting to the 145 * crossbar. 146 */ 147 class CoherentXBarMasterPort : public MasterPort 148 { 149 private: 150 /** A reference to the crossbar to which this port belongs. */ 151 CoherentXBar &xbar; 152 153 public: 154 155 CoherentXBarMasterPort(const std::string &_name, 156 CoherentXBar &_xbar, PortID _id) 157 : MasterPort(_name, &_xbar, _id), xbar(_xbar) 158 { } 159 160 protected: 161 162 /** 163 * Determine if this port should be considered a snooper. For 164 * a coherent crossbar master port this is always true. 165 * 166 * @return a boolean that is true if this port is snooping 167 */ 168 virtual bool isSnooping() const 169 { return true; } 170 171 /** 172 * When receiving a timing response, pass it to the crossbar. 173 */ 174 virtual bool recvTimingResp(PacketPtr pkt) 175 { return xbar.recvTimingResp(pkt, id); } 176 177 /** 178 * When receiving a timing snoop request, pass it to the crossbar. 179 */ 180 virtual void recvTimingSnoopReq(PacketPtr pkt) 181 { return xbar.recvTimingSnoopReq(pkt, id); } 182 183 /** 184 * When receiving an atomic snoop request, pass it to the crossbar. 185 */ 186 virtual Tick recvAtomicSnoop(PacketPtr pkt) 187 { return xbar.recvAtomicSnoop(pkt, id); } 188 189 /** 190 * When receiving a functional snoop request, pass it to the crossbar. 191 */ 192 virtual void recvFunctionalSnoop(PacketPtr pkt) 193 { xbar.recvFunctionalSnoop(pkt, id); } 194 195 /** When reciving a range change from the peer port (at id), 196 pass it to the crossbar. */ 197 virtual void recvRangeChange() 198 { xbar.recvRangeChange(id); } 199 200 /** When reciving a retry from the peer port (at id), 201 pass it to the crossbar. */ 202 virtual void recvReqRetry() 203 { xbar.recvReqRetry(id); } 204 205 }; 206 207 /** 208 * Internal class to bridge between an incoming snoop response 209 * from a slave port and forwarding it through an outgoing slave 210 * port. It is effectively a dangling master port. 211 */ 212 class SnoopRespPort : public MasterPort 213 { 214 215 private: 216 217 /** The port which we mirror internally. */ 218 SlavePort& slavePort; 219 220 public: 221 222 /** 223 * Create a snoop response port that mirrors a given slave port. 224 */ 225 SnoopRespPort(SlavePort& slave_port, CoherentXBar& _xbar) : 226 MasterPort(slave_port.name() + ".snoopRespPort", &_xbar), 227 slavePort(slave_port) { } 228 229 /** 230 * Override the sending of retries and pass them on through 231 * the mirrored slave port. 232 */ 233 void sendRetryResp() { 234 // forward it as a snoop response retry 235 slavePort.sendRetrySnoopResp(); 236 } 237 238 /** 239 * Provided as necessary. 240 */ 241 void recvReqRetry() { panic("SnoopRespPort should never see retry\n"); } 242 243 /** 244 * Provided as necessary. 245 */ 246 bool recvTimingResp(PacketPtr pkt) 247 { 248 panic("SnoopRespPort should never see timing response\n"); 249 return false; 250 } 251 252 }; 253 254 std::vector<SnoopRespPort*> snoopRespPorts; 255 256 std::vector<SlavePort*> snoopPorts; 257 258 /** 259 * Store the outstanding requests that we are expecting snoop 260 * responses from so we can determine which snoop responses we 261 * generated and which ones were merely forwarded. 262 */ 263 m5::hash_set<RequestPtr> outstandingSnoop; 264 265 /** 266 * Keep a pointer to the system to be allow to querying memory system 267 * properties. 268 */ 269 System *system; 270 271 /** A snoop filter that tracks cache line residency and can restrict the 272 * broadcast needed for probes. NULL denotes an absent filter. */ 273 SnoopFilter *snoopFilter; 274 275 /** Cycles of snoop response latency.*/ 276 const Cycles snoopResponseLatency; 277 278 /** 279 * @todo this is a temporary workaround until the 4-phase code is committed. 280 * upstream caches need this packet until true is returned, so hold it for 281 * deletion until a subsequent call 282 */ 283 std::vector<PacketPtr> pendingDelete; 284 285 /** Function called by the port when the crossbar is recieving a Timing 286 request packet.*/ 287 bool recvTimingReq(PacketPtr pkt, PortID slave_port_id); 288 289 /** Function called by the port when the crossbar is recieving a Timing 290 response packet.*/ 291 bool recvTimingResp(PacketPtr pkt, PortID master_port_id); 292 293 /** Function called by the port when the crossbar is recieving a timing 294 snoop request.*/ 295 void recvTimingSnoopReq(PacketPtr pkt, PortID master_port_id); 296 297 /** Function called by the port when the crossbar is recieving a timing 298 snoop response.*/ 299 bool recvTimingSnoopResp(PacketPtr pkt, PortID slave_port_id); 300 301 /** Timing function called by port when it is once again able to process 302 * requests. */ 303 void recvReqRetry(PortID master_port_id); 304 305 /** 306 * Forward a timing packet to our snoopers, potentially excluding 307 * one of the connected coherent masters to avoid sending a packet 308 * back to where it came from. 309 * 310 * @param pkt Packet to forward 311 * @param exclude_slave_port_id Id of slave port to exclude 312 */ 313 void forwardTiming(PacketPtr pkt, PortID exclude_slave_port_id) { 314 forwardTiming(pkt, exclude_slave_port_id, snoopPorts); 315 } 316 317 /** 318 * Forward a timing packet to a selected list of snoopers, potentially 319 * excluding one of the connected coherent masters to avoid sending a packet 320 * back to where it came from. 321 * 322 * @param pkt Packet to forward 323 * @param exclude_slave_port_id Id of slave port to exclude 324 * @param dests Vector of destination ports for the forwarded pkt 325 */ 326 void forwardTiming(PacketPtr pkt, PortID exclude_slave_port_id, 327 const std::vector<SlavePort*>& dests); 328 329 /** Function called by the port when the crossbar is recieving a Atomic 330 transaction.*/ 331 Tick recvAtomic(PacketPtr pkt, PortID slave_port_id); 332 333 /** Function called by the port when the crossbar is recieving an 334 atomic snoop transaction.*/ 335 Tick recvAtomicSnoop(PacketPtr pkt, PortID master_port_id); 336 337 /** 338 * Forward an atomic packet to our snoopers, potentially excluding 339 * one of the connected coherent masters to avoid sending a packet 340 * back to where it came from. 341 * 342 * @param pkt Packet to forward 343 * @param exclude_slave_port_id Id of slave port to exclude 344 * 345 * @return a pair containing the snoop response and snoop latency 346 */ 347 std::pair<MemCmd, Tick> forwardAtomic(PacketPtr pkt, 348 PortID exclude_slave_port_id) 349 { 350 return forwardAtomic(pkt, exclude_slave_port_id, InvalidPortID, snoopPorts); 351 } 352 353 /** 354 * Forward an atomic packet to a selected list of snoopers, potentially 355 * excluding one of the connected coherent masters to avoid sending a packet 356 * back to where it came from. 357 * 358 * @param pkt Packet to forward 359 * @param exclude_slave_port_id Id of slave port to exclude 360 * @param source_master_port_id Id of the master port for snoops from below 361 * @param dests Vector of destination ports for the forwarded pkt 362 * 363 * @return a pair containing the snoop response and snoop latency 364 */ 365 std::pair<MemCmd, Tick> forwardAtomic(PacketPtr pkt, 366 PortID exclude_slave_port_id, 367 PortID source_master_port_id, 368 const std::vector<SlavePort*>& dests); 369 370 /** Function called by the port when the crossbar is recieving a Functional 371 transaction.*/ 372 void recvFunctional(PacketPtr pkt, PortID slave_port_id); 373 374 /** Function called by the port when the crossbar is recieving a functional 375 snoop transaction.*/ 376 void recvFunctionalSnoop(PacketPtr pkt, PortID master_port_id); 377 378 /** 379 * Forward a functional packet to our snoopers, potentially 380 * excluding one of the connected coherent masters to avoid 381 * sending a packet back to where it came from. 382 * 383 * @param pkt Packet to forward 384 * @param exclude_slave_port_id Id of slave port to exclude 385 */ 386 void forwardFunctional(PacketPtr pkt, PortID exclude_slave_port_id); 387 388 Stats::Scalar snoops; 389 Stats::Distribution snoopFanout; 390 391 public: 392 393 virtual void init(); 394 395 CoherentXBar(const CoherentXBarParams *p); 396 397 virtual ~CoherentXBar(); 398 399 unsigned int drain(DrainManager *dm); 400 401 virtual void regStats(); 402}; 403 404#endif //__MEM_COHERENT_XBAR_HH__ 405