coherent_xbar.hh revision 10719
16145SN/A/* 28683SN/A * Copyright (c) 2011-2015 ARM Limited 38683SN/A * All rights reserved 46145SN/A * 56145SN/A * The license below extends only to copyright in the software and shall 66145SN/A * not be construed as granting a license to any other intellectual 76145SN/A * property including but not limited to intellectual property relating 86145SN/A * to a hardware implementation of the functionality of the software 96145SN/A * licensed hereunder. You may use the software subject to the license 106145SN/A * terms below provided that you ensure that this notice is replicated 116145SN/A * unmodified and in its entirety in all distributions of the software, 126145SN/A * modified or unmodified, in source code or in binary form. 136145SN/A * 146145SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 156145SN/A * All rights reserved. 166145SN/A * 176145SN/A * Redistribution and use in source and binary forms, with or without 186145SN/A * modification, are permitted provided that the following conditions are 196145SN/A * met: redistributions of source code must retain the above copyright 206145SN/A * notice, this list of conditions and the following disclaimer; 216145SN/A * redistributions in binary form must reproduce the above copyright 226145SN/A * notice, this list of conditions and the following disclaimer in the 236145SN/A * documentation and/or other materials provided with the distribution; 246145SN/A * neither the name of the copyright holders nor the names of its 256145SN/A * contributors may be used to endorse or promote products derived from 266145SN/A * this software without specific prior written permission. 276145SN/A * 286145SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 296145SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 306145SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 317054SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 327054SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 336145SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 346145SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3512492Sodanrc@yahoo.com.br * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3612492Sodanrc@yahoo.com.br * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 376145SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 387456SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 397002SN/A * 4010302Snilay@cs.wisc.edu * Authors: Ron Dreslinski 418165SN/A * Ali Saidi 428683SN/A * Andreas Hansson 438683SN/A * William Wang 448683SN/A */ 456145SN/A 466890SN/A/** 476145SN/A * @file 488683SN/A * Declaration of a coherent crossbar. 498683SN/A */ 508683SN/A 518683SN/A#ifndef __MEM_COHERENT_XBAR_HH__ 528683SN/A#define __MEM_COHERENT_XBAR_HH__ 538683SN/A 548683SN/A#include "mem/snoop_filter.hh" 558683SN/A#include "mem/xbar.hh" 568683SN/A#include "params/CoherentXBar.hh" 5710302Snilay@cs.wisc.edu 5811025Snilay@cs.wisc.edu/** 5911025Snilay@cs.wisc.edu * A coherent crossbar connects a number of (potentially) snooping 608683SN/A * masters and slaves, and routes the request and response packets 618683SN/A * based on the address, and also forwards all requests to the 628683SN/A * snoopers and deals with the snoop responses. 638683SN/A * 648683SN/A * The coherent crossbar can be used as a template for modelling QPI, 658683SN/A * HyperTransport, ACE and coherent OCP buses, and is typically used 667054SN/A * for the L1-to-L2 buses and as the main system interconnect. @sa 677054SN/A * \ref gem5MemorySystem "gem5 Memory System" 687054SN/A */ 698683SN/Aclass CoherentXBar : public BaseXBar 708683SN/A{ 716145SN/A 728683SN/A protected: 738683SN/A 7410163SN/A /** 7510163SN/A * Declare the layers of this crossbar, one vector for requests, 7611025Snilay@cs.wisc.edu * one for responses, and one for snoop responses 7711025Snilay@cs.wisc.edu */ 788683SN/A std::vector<ReqLayer*> reqLayers; 7911061Snilay@cs.wisc.edu std::vector<RespLayer*> respLayers; 808683SN/A std::vector<SnoopRespLayer*> snoopLayers; 818683SN/A 828683SN/A /** 838683SN/A * Declaration of the coherent crossbar slave port type, one will 848683SN/A * be instantiated for each of the master ports connecting to the 858683SN/A * crossbar. 868683SN/A */ 878683SN/A class CoherentXBarSlavePort : public SlavePort 888683SN/A { 898683SN/A 908683SN/A private: 918683SN/A 928683SN/A /** A reference to the crossbar to which this port belongs. */ 938683SN/A CoherentXBar &xbar; 948683SN/A 958683SN/A public: 968683SN/A 978683SN/A CoherentXBarSlavePort(const std::string &_name, 988683SN/A CoherentXBar &_xbar, PortID _id) 996145SN/A : SlavePort(_name, &_xbar, _id), xbar(_xbar) 1007054SN/A { } 1017054SN/A 1027054SN/A protected: 1037054SN/A 1046145SN/A /** 1058683SN/A * When receiving a timing request, pass it to the crossbar. 1068683SN/A */ 1078683SN/A virtual bool recvTimingReq(PacketPtr pkt) 1088683SN/A { return xbar.recvTimingReq(pkt, id); } 1098683SN/A 1108683SN/A /** 1118683SN/A * When receiving a timing snoop response, pass it to the crossbar. 11210163SN/A */ 1136145SN/A virtual bool recvTimingSnoopResp(PacketPtr pkt) 1146145SN/A { return xbar.recvTimingSnoopResp(pkt, id); } 1158683SN/A 1168683SN/A /** 1178683SN/A * When receiving an atomic request, pass it to the crossbar. 1188683SN/A */ 1198683SN/A virtual Tick recvAtomic(PacketPtr pkt) 1208683SN/A { return xbar.recvAtomic(pkt, id); } 1217054SN/A 1228683SN/A /** 1236145SN/A * When receiving a functional request, pass it to the crossbar. 1247054SN/A */ 1257054SN/A virtual void recvFunctional(PacketPtr pkt) 1267054SN/A { xbar.recvFunctional(pkt, id); } 1276145SN/A 1286145SN/A /** 12912492Sodanrc@yahoo.com.br * 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 /** Function called by the port when the crossbar is recieving a Timing 279 request packet.*/ 280 bool recvTimingReq(PacketPtr pkt, PortID slave_port_id); 281 282 /** Function called by the port when the crossbar is recieving a Timing 283 response packet.*/ 284 bool recvTimingResp(PacketPtr pkt, PortID master_port_id); 285 286 /** Function called by the port when the crossbar is recieving a timing 287 snoop request.*/ 288 void recvTimingSnoopReq(PacketPtr pkt, PortID master_port_id); 289 290 /** Function called by the port when the crossbar is recieving a timing 291 snoop response.*/ 292 bool recvTimingSnoopResp(PacketPtr pkt, PortID slave_port_id); 293 294 /** Timing function called by port when it is once again able to process 295 * requests. */ 296 void recvReqRetry(PortID master_port_id); 297 298 /** 299 * Forward a timing packet to our snoopers, potentially excluding 300 * one of the connected coherent masters to avoid sending a packet 301 * back to where it came from. 302 * 303 * @param pkt Packet to forward 304 * @param exclude_slave_port_id Id of slave port to exclude 305 */ 306 void forwardTiming(PacketPtr pkt, PortID exclude_slave_port_id) { 307 forwardTiming(pkt, exclude_slave_port_id, snoopPorts); 308 } 309 310 /** 311 * Forward a timing packet to a selected list of snoopers, potentially 312 * excluding one of the connected coherent masters to avoid sending a packet 313 * back to where it came from. 314 * 315 * @param pkt Packet to forward 316 * @param exclude_slave_port_id Id of slave port to exclude 317 * @param dests Vector of destination ports for the forwarded pkt 318 */ 319 void forwardTiming(PacketPtr pkt, PortID exclude_slave_port_id, 320 const std::vector<SlavePort*>& dests); 321 322 /** Function called by the port when the crossbar is recieving a Atomic 323 transaction.*/ 324 Tick recvAtomic(PacketPtr pkt, PortID slave_port_id); 325 326 /** Function called by the port when the crossbar is recieving an 327 atomic snoop transaction.*/ 328 Tick recvAtomicSnoop(PacketPtr pkt, PortID master_port_id); 329 330 /** 331 * Forward an atomic packet to our snoopers, potentially excluding 332 * one of the connected coherent masters to avoid sending a packet 333 * back to where it came from. 334 * 335 * @param pkt Packet to forward 336 * @param exclude_slave_port_id Id of slave port to exclude 337 * 338 * @return a pair containing the snoop response and snoop latency 339 */ 340 std::pair<MemCmd, Tick> forwardAtomic(PacketPtr pkt, 341 PortID exclude_slave_port_id) 342 { 343 return forwardAtomic(pkt, exclude_slave_port_id, InvalidPortID, snoopPorts); 344 } 345 346 /** 347 * Forward an atomic packet to a selected list of snoopers, potentially 348 * excluding one of the connected coherent masters to avoid sending a packet 349 * back to where it came from. 350 * 351 * @param pkt Packet to forward 352 * @param exclude_slave_port_id Id of slave port to exclude 353 * @param source_master_port_id Id of the master port for snoops from below 354 * @param dests Vector of destination ports for the forwarded pkt 355 * 356 * @return a pair containing the snoop response and snoop latency 357 */ 358 std::pair<MemCmd, Tick> forwardAtomic(PacketPtr pkt, 359 PortID exclude_slave_port_id, 360 PortID source_master_port_id, 361 const std::vector<SlavePort*>& dests); 362 363 /** Function called by the port when the crossbar is recieving a Functional 364 transaction.*/ 365 void recvFunctional(PacketPtr pkt, PortID slave_port_id); 366 367 /** Function called by the port when the crossbar is recieving a functional 368 snoop transaction.*/ 369 void recvFunctionalSnoop(PacketPtr pkt, PortID master_port_id); 370 371 /** 372 * Forward a functional packet to our snoopers, potentially 373 * excluding one of the connected coherent masters to avoid 374 * sending a packet back to where it came from. 375 * 376 * @param pkt Packet to forward 377 * @param exclude_slave_port_id Id of slave port to exclude 378 */ 379 void forwardFunctional(PacketPtr pkt, PortID exclude_slave_port_id); 380 381 Stats::Scalar snoops; 382 Stats::Distribution snoopFanout; 383 384 public: 385 386 virtual void init(); 387 388 CoherentXBar(const CoherentXBarParams *p); 389 390 virtual ~CoherentXBar(); 391 392 unsigned int drain(DrainManager *dm); 393 394 virtual void regStats(); 395}; 396 397#endif //__MEM_COHERENT_XBAR_HH__ 398