serial_link.cc revision 11185
13170Sstever@eecs.umich.edu/* 25254Sksewell@umich.edu * Copyright (c) 2011-2013 ARM Limited 35254Sksewell@umich.edu * All rights reserved 43170Sstever@eecs.umich.edu * 55254Sksewell@umich.edu * The license below extends only to copyright in the software and shall 65254Sksewell@umich.edu * not be construed as granting a license to any other intellectual 75254Sksewell@umich.edu * property including but not limited to intellectual property relating 85254Sksewell@umich.edu * to a hardware implementation of the functionality of the software 95254Sksewell@umich.edu * licensed hereunder. You may use the software subject to the license 105254Sksewell@umich.edu * terms below provided that you ensure that this notice is replicated 115254Sksewell@umich.edu * unmodified and in its entirety in all distributions of the software, 125254Sksewell@umich.edu * modified or unmodified, in source code or in binary form. 135254Sksewell@umich.edu * 145254Sksewell@umich.edu * Copyright (c) 2006 The Regents of The University of Michigan 153170Sstever@eecs.umich.edu * Copyright (c) 2015 The University of Bologna 165254Sksewell@umich.edu * All rights reserved. 175254Sksewell@umich.edu * 185254Sksewell@umich.edu * Redistribution and use in source and binary forms, with or without 195254Sksewell@umich.edu * modification, are permitted provided that the following conditions are 205254Sksewell@umich.edu * met: redistributions of source code must retain the above copyright 215254Sksewell@umich.edu * notice, this list of conditions and the following disclaimer; 225254Sksewell@umich.edu * redistributions in binary form must reproduce the above copyright 235254Sksewell@umich.edu * notice, this list of conditions and the following disclaimer in the 245254Sksewell@umich.edu * documentation and/or other materials provided with the distribution; 255254Sksewell@umich.edu * neither the name of the copyright holders nor the names of its 265254Sksewell@umich.edu * contributors may be used to endorse or promote products derived from 273170Sstever@eecs.umich.edu * this software without specific prior written permission. 285254Sksewell@umich.edu * 293170Sstever@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 303170Sstever@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 313170Sstever@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 323170Sstever@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 333170Sstever@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 343170Sstever@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 353170Sstever@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 363170Sstever@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 373170Sstever@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 383170Sstever@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 393170Sstever@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 406329Sgblack@eecs.umich.edu * 414661Sksewell@umich.edu * Authors: Ali Saidi 424661Sksewell@umich.edu * Steve Reinhardt 438232Snate@binkert.org * Andreas Hansson 443170Sstever@eecs.umich.edu * Erfan Azarkhish 453170Sstever@eecs.umich.edu */ 463170Sstever@eecs.umich.edu 473170Sstever@eecs.umich.edu/** 486378Sgblack@eecs.umich.edu * @file 493170Sstever@eecs.umich.edu * Implementation of the SerialLink Class, modeling Hybrid-Memory-Cube's 503170Sstever@eecs.umich.edu * serial interface. 513170Sstever@eecs.umich.edu */ 523170Sstever@eecs.umich.edu 537783SGiacomo.Gabrielli@arm.com#include "mem/serial_link.hh" 547783SGiacomo.Gabrielli@arm.com 556378Sgblack@eecs.umich.edu#include "base/trace.hh" 566378Sgblack@eecs.umich.edu#include "debug/SerialLink.hh" 575715Shsul@eecs.umich.edu#include "params/SerialLink.hh" 583170Sstever@eecs.umich.edu 593170Sstever@eecs.umich.edu 603170Sstever@eecs.umich.eduSerialLink::SerialLinkSlavePort::SerialLinkSlavePort(const std::string& _name, 613170Sstever@eecs.umich.edu SerialLink& _serial_link, 623170Sstever@eecs.umich.edu SerialLinkMasterPort& _masterPort, 633170Sstever@eecs.umich.edu Cycles _delay, int _resp_limit, 644661Sksewell@umich.edu const std::vector<AddrRange>& 654661Sksewell@umich.edu _ranges) 664661Sksewell@umich.edu : SlavePort(_name, &_serial_link), serial_link(_serial_link), 674661Sksewell@umich.edu masterPort(_masterPort), delay(_delay), 684661Sksewell@umich.edu ranges(_ranges.begin(), _ranges.end()), 694661Sksewell@umich.edu outstandingResponses(0), retryReq(false), 707783SGiacomo.Gabrielli@arm.com respQueueLimit(_resp_limit), sendEvent(*this) 717783SGiacomo.Gabrielli@arm.com{ 724661Sksewell@umich.edu} 734661Sksewell@umich.edu 744661Sksewell@umich.eduSerialLink::SerialLinkMasterPort::SerialLinkMasterPort(const std::string& 754661Sksewell@umich.edu _name, SerialLink& _serial_link, 764661Sksewell@umich.edu SerialLinkSlavePort& _slavePort, 777783SGiacomo.Gabrielli@arm.com Cycles _delay, int _req_limit) 784661Sksewell@umich.edu : MasterPort(_name, &_serial_link), serial_link(_serial_link), 794661Sksewell@umich.edu slavePort(_slavePort), delay(_delay), reqQueueLimit(_req_limit), 804661Sksewell@umich.edu sendEvent(*this) 814661Sksewell@umich.edu{ 824661Sksewell@umich.edu} 834661Sksewell@umich.edu 844661Sksewell@umich.eduSerialLink::SerialLink(SerialLinkParams *p) 854661Sksewell@umich.edu : MemObject(p), 866425Sksewell@umich.edu slavePort(p->name + ".slave", *this, masterPort, 875714Shsul@eecs.umich.edu ticksToCycles(p->delay), p->resp_size, p->ranges), 884661Sksewell@umich.edu masterPort(p->name + ".master", *this, slavePort, 897823Ssteve.reinhardt@amd.com ticksToCycles(p->delay), p->req_size), 904661Sksewell@umich.edu num_lanes(p->num_lanes) 914661Sksewell@umich.edu{ 924661Sksewell@umich.edu} 936378Sgblack@eecs.umich.edu 946378Sgblack@eecs.umich.eduBaseMasterPort& 955715Shsul@eecs.umich.eduSerialLink::getMasterPort(const std::string &if_name, PortID idx) 964661Sksewell@umich.edu{ 976378Sgblack@eecs.umich.edu if (if_name == "master") 986378Sgblack@eecs.umich.edu return masterPort; 995715Shsul@eecs.umich.edu else 1004661Sksewell@umich.edu // pass it along to our super class 1014661Sksewell@umich.edu return MemObject::getMasterPort(if_name, idx); 1024661Sksewell@umich.edu} 1034661Sksewell@umich.edu 1044661Sksewell@umich.eduBaseSlavePort& 1054661Sksewell@umich.eduSerialLink::getSlavePort(const std::string &if_name, PortID idx) 1063170Sstever@eecs.umich.edu{ 1073170Sstever@eecs.umich.edu if (if_name == "slave") 1083170Sstever@eecs.umich.edu return slavePort; 1093170Sstever@eecs.umich.edu else 1103170Sstever@eecs.umich.edu // pass it along to our super class 1113170Sstever@eecs.umich.edu return MemObject::getSlavePort(if_name, idx); 112} 113 114void 115SerialLink::init() 116{ 117 // make sure both sides are connected and have the same block size 118 if (!slavePort.isConnected() || !masterPort.isConnected()) 119 fatal("Both ports of a serial_link must be connected.\n"); 120 121 // notify the master side of our address ranges 122 slavePort.sendRangeChange(); 123} 124 125bool 126SerialLink::SerialLinkSlavePort::respQueueFull() const 127{ 128 return outstandingResponses == respQueueLimit; 129} 130 131bool 132SerialLink::SerialLinkMasterPort::reqQueueFull() const 133{ 134 return transmitList.size() == reqQueueLimit; 135} 136 137bool 138SerialLink::SerialLinkMasterPort::recvTimingResp(PacketPtr pkt) 139{ 140 // all checks are done when the request is accepted on the slave 141 // side, so we are guaranteed to have space for the response 142 DPRINTF(SerialLink, "recvTimingResp: %s addr 0x%x\n", 143 pkt->cmdString(), pkt->getAddr()); 144 145 DPRINTF(SerialLink, "Request queue size: %d\n", transmitList.size()); 146 147 // @todo: We need to pay for this and not just zero it out 148 pkt->headerDelay = pkt->payloadDelay = 0; 149 150 // This is similar to what happens for the request packets: 151 // The serializer will start serialization as soon as it receives the 152 // first flit, but the deserializer (at the host side in this case), will 153 // have to wait to receive the whole packet. So we only account for the 154 // deserialization latency. 155 Cycles cycles = delay; 156 cycles += Cycles(divCeil(pkt->getSize() * 8, serial_link.num_lanes)); 157 Tick t = serial_link.clockEdge(cycles); 158 159 //@todo: If the processor sends two uncached requests towards HMC and the 160 // second one is smaller than the first one. It may happen that the second 161 // one crosses this link faster than the first one (because the packet 162 // waits in the link based on its size). This can reorder the received 163 // response. 164 slavePort.schedTimingResp(pkt, t); 165 166 return true; 167} 168 169bool 170SerialLink::SerialLinkSlavePort::recvTimingReq(PacketPtr pkt) 171{ 172 DPRINTF(SerialLink, "recvTimingReq: %s addr 0x%x\n", 173 pkt->cmdString(), pkt->getAddr()); 174 175 // we should not see a timing request if we are already in a retry 176 assert(!retryReq); 177 178 DPRINTF(SerialLink, "Response queue size: %d outresp: %d\n", 179 transmitList.size(), outstandingResponses); 180 181 // if the request queue is full then there is no hope 182 if (masterPort.reqQueueFull()) { 183 DPRINTF(SerialLink, "Request queue full\n"); 184 retryReq = true; 185 } else if ( !retryReq ) { 186 // look at the response queue if we expect to see a response 187 bool expects_response = pkt->needsResponse() && 188 !pkt->memInhibitAsserted(); 189 if (expects_response) { 190 if (respQueueFull()) { 191 DPRINTF(SerialLink, "Response queue full\n"); 192 retryReq = true; 193 } else { 194 // ok to send the request with space for the response 195 DPRINTF(SerialLink, "Reserving space for response\n"); 196 assert(outstandingResponses != respQueueLimit); 197 ++outstandingResponses; 198 199 // no need to set retryReq to false as this is already the 200 // case 201 } 202 } 203 204 if (!retryReq) { 205 // @todo: We need to pay for this and not just zero it out 206 pkt->headerDelay = pkt->payloadDelay = 0; 207 208 // We assume that the serializer component at the transmitter side 209 // does not need to receive the whole packet to start the 210 // serialization (this assumption is consistent with the HMC 211 // standard). But the deserializer waits for the complete packet 212 // to check its integrity first. So everytime a packet crosses a 213 // serial link, we should account for its deserialization latency 214 // only. 215 Cycles cycles = delay; 216 cycles += Cycles(divCeil(pkt->getSize() * 8, 217 serial_link.num_lanes)); 218 Tick t = serial_link.clockEdge(cycles); 219 220 //@todo: If the processor sends two uncached requests towards HMC 221 // and the second one is smaller than the first one. It may happen 222 // that the second one crosses this link faster than the first one 223 // (because the packet waits in the link based on its size). 224 // This can reorder the received response. 225 masterPort.schedTimingReq(pkt, t); 226 } 227 } 228 229 // remember that we are now stalling a packet and that we have to 230 // tell the sending master to retry once space becomes available, 231 // we make no distinction whether the stalling is due to the 232 // request queue or response queue being full 233 return !retryReq; 234} 235 236void 237SerialLink::SerialLinkSlavePort::retryStalledReq() 238{ 239 if (retryReq) { 240 DPRINTF(SerialLink, "Request waiting for retry, now retrying\n"); 241 retryReq = false; 242 sendRetryReq(); 243 } 244} 245 246void 247SerialLink::SerialLinkMasterPort::schedTimingReq(PacketPtr pkt, Tick when) 248{ 249 // If we're about to put this packet at the head of the queue, we 250 // need to schedule an event to do the transmit. Otherwise there 251 // should already be an event scheduled for sending the head 252 // packet. 253 if (transmitList.empty()) { 254 serial_link.schedule(sendEvent, when); 255 } 256 257 assert(transmitList.size() != reqQueueLimit); 258 259 transmitList.emplace_back(DeferredPacket(pkt, when)); 260} 261 262 263void 264SerialLink::SerialLinkSlavePort::schedTimingResp(PacketPtr pkt, Tick when) 265{ 266 // If we're about to put this packet at the head of the queue, we 267 // need to schedule an event to do the transmit. Otherwise there 268 // should already be an event scheduled for sending the head 269 // packet. 270 if (transmitList.empty()) { 271 serial_link.schedule(sendEvent, when); 272 } 273 274 transmitList.emplace_back(DeferredPacket(pkt, when)); 275} 276 277void 278SerialLink::SerialLinkMasterPort::trySendTiming() 279{ 280 assert(!transmitList.empty()); 281 282 DeferredPacket req = transmitList.front(); 283 284 assert(req.tick <= curTick()); 285 286 PacketPtr pkt = req.pkt; 287 288 DPRINTF(SerialLink, "trySend request addr 0x%x, queue size %d\n", 289 pkt->getAddr(), transmitList.size()); 290 291 if (sendTimingReq(pkt)) { 292 // send successful 293 transmitList.pop_front(); 294 295 DPRINTF(SerialLink, "trySend request successful\n"); 296 297 // If there are more packets to send, schedule event to try again. 298 if (!transmitList.empty()) { 299 DeferredPacket next_req = transmitList.front(); 300 DPRINTF(SerialLink, "Scheduling next send\n"); 301 302 // Make sure bandwidth limitation is met 303 Cycles cycles = Cycles(divCeil(pkt->getSize() * 8, 304 serial_link.num_lanes)); 305 Tick t = serial_link.clockEdge(cycles); 306 serial_link.schedule(sendEvent, std::max(next_req.tick, t)); 307 } 308 309 // if we have stalled a request due to a full request queue, 310 // then send a retry at this point, also note that if the 311 // request we stalled was waiting for the response queue 312 // rather than the request queue we might stall it again 313 slavePort.retryStalledReq(); 314 } 315 316 // if the send failed, then we try again once we receive a retry, 317 // and therefore there is no need to take any action 318} 319 320void 321SerialLink::SerialLinkSlavePort::trySendTiming() 322{ 323 assert(!transmitList.empty()); 324 325 DeferredPacket resp = transmitList.front(); 326 327 assert(resp.tick <= curTick()); 328 329 PacketPtr pkt = resp.pkt; 330 331 DPRINTF(SerialLink, "trySend response addr 0x%x, outstanding %d\n", 332 pkt->getAddr(), outstandingResponses); 333 334 if (sendTimingResp(pkt)) { 335 // send successful 336 transmitList.pop_front(); 337 DPRINTF(SerialLink, "trySend response successful\n"); 338 339 assert(outstandingResponses != 0); 340 --outstandingResponses; 341 342 // If there are more packets to send, schedule event to try again. 343 if (!transmitList.empty()) { 344 DeferredPacket next_resp = transmitList.front(); 345 DPRINTF(SerialLink, "Scheduling next send\n"); 346 347 // Make sure bandwidth limitation is met 348 Cycles cycles = Cycles(divCeil(pkt->getSize() * 8, 349 serial_link.num_lanes)); 350 Tick t = serial_link.clockEdge(cycles); 351 serial_link.schedule(sendEvent, std::max(next_resp.tick, t)); 352 } 353 354 // if there is space in the request queue and we were stalling 355 // a request, it will definitely be possible to accept it now 356 // since there is guaranteed space in the response queue 357 if (!masterPort.reqQueueFull() && retryReq) { 358 DPRINTF(SerialLink, "Request waiting for retry, now retrying\n"); 359 retryReq = false; 360 sendRetryReq(); 361 } 362 } 363 364 // if the send failed, then we try again once we receive a retry, 365 // and therefore there is no need to take any action 366} 367 368void 369SerialLink::SerialLinkMasterPort::recvReqRetry() 370{ 371 trySendTiming(); 372} 373 374void 375SerialLink::SerialLinkSlavePort::recvRespRetry() 376{ 377 trySendTiming(); 378} 379 380Tick 381SerialLink::SerialLinkSlavePort::recvAtomic(PacketPtr pkt) 382{ 383 return delay * serial_link.clockPeriod() + masterPort.sendAtomic(pkt); 384} 385 386void 387SerialLink::SerialLinkSlavePort::recvFunctional(PacketPtr pkt) 388{ 389 pkt->pushLabel(name()); 390 391 // check the response queue 392 for (auto i = transmitList.begin(); i != transmitList.end(); ++i) { 393 if (pkt->checkFunctional((*i).pkt)) { 394 pkt->makeResponse(); 395 return; 396 } 397 } 398 399 // also check the master port's request queue 400 if (masterPort.checkFunctional(pkt)) { 401 return; 402 } 403 404 pkt->popLabel(); 405 406 // fall through if pkt still not satisfied 407 masterPort.sendFunctional(pkt); 408} 409 410bool 411SerialLink::SerialLinkMasterPort::checkFunctional(PacketPtr pkt) 412{ 413 bool found = false; 414 auto i = transmitList.begin(); 415 416 while(i != transmitList.end() && !found) { 417 if (pkt->checkFunctional((*i).pkt)) { 418 pkt->makeResponse(); 419 found = true; 420 } 421 ++i; 422 } 423 424 return found; 425} 426 427AddrRangeList 428SerialLink::SerialLinkSlavePort::getAddrRanges() const 429{ 430 return ranges; 431} 432 433SerialLink * 434SerialLinkParams::create() 435{ 436 return new SerialLink(this); 437} 438