2 * Copyright (c) 2011-2013 ARM Limited
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.
14 * Copyright (c) 2006 The Regents of The University of Michigan
15 * Copyright (c) 2015 The University of Bologna
16 * All rights reserved.
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;
22 * redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution;
25 * neither the name of the copyright holders nor the names of its
26 * contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49 * Implementation of the SerialLink Class, modeling Hybrid-Memory-Cube's
53 #include "mem/serial_link.hh"
55 #include "base/trace.hh"
56 #include "debug/SerialLink.hh"
57 #include "params/SerialLink.hh"
60 SerialLink::SerialLinkSlavePort::SerialLinkSlavePort(const std::string
& _name
,
61 SerialLink
& _serial_link
,
62 SerialLinkMasterPort
& _masterPort
,
63 Cycles _delay
, int _resp_limit
,
64 const std::vector
<AddrRange
>&
66 : SlavePort(_name
, &_serial_link
), serial_link(_serial_link
),
67 masterPort(_masterPort
), delay(_delay
),
68 ranges(_ranges
.begin(), _ranges
.end()),
69 outstandingResponses(0), retryReq(false),
70 respQueueLimit(_resp_limit
), sendEvent(*this)
74 SerialLink::SerialLinkMasterPort::SerialLinkMasterPort(const std::string
&
75 _name
, SerialLink
& _serial_link
,
76 SerialLinkSlavePort
& _slavePort
,
77 Cycles _delay
, int _req_limit
)
78 : MasterPort(_name
, &_serial_link
), serial_link(_serial_link
),
79 slavePort(_slavePort
), delay(_delay
), reqQueueLimit(_req_limit
),
84 SerialLink::SerialLink(SerialLinkParams
*p
)
86 slavePort(p
->name
+ ".slave", *this, masterPort
,
87 ticksToCycles(p
->delay
), p
->resp_size
, p
->ranges
),
88 masterPort(p
->name
+ ".master", *this, slavePort
,
89 ticksToCycles(p
->delay
), p
->req_size
),
90 num_lanes(p
->num_lanes
)
95 SerialLink::getMasterPort(const std::string
&if_name
, PortID idx
)
97 if (if_name
== "master")
100 // pass it along to our super class
101 return MemObject::getMasterPort(if_name
, idx
);
105 SerialLink::getSlavePort(const std::string
&if_name
, PortID idx
)
107 if (if_name
== "slave")
110 // pass it along to our super class
111 return MemObject::getSlavePort(if_name
, idx
);
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");
121 // notify the master side of our address ranges
122 slavePort
.sendRangeChange();
126 SerialLink::SerialLinkSlavePort::respQueueFull() const
128 return outstandingResponses
== respQueueLimit
;
132 SerialLink::SerialLinkMasterPort::reqQueueFull() const
134 return transmitList
.size() == reqQueueLimit
;
138 SerialLink::SerialLinkMasterPort::recvTimingResp(PacketPtr pkt
)
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());
145 DPRINTF(SerialLink
, "Request queue size: %d\n", transmitList
.size());
147 // @todo: We need to pay for this and not just zero it out
148 pkt
->headerDelay
= pkt
->payloadDelay
= 0;
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
);
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
164 slavePort
.schedTimingResp(pkt
, t
);
170 SerialLink::SerialLinkSlavePort::recvTimingReq(PacketPtr pkt
)
172 DPRINTF(SerialLink
, "recvTimingReq: %s addr 0x%x\n",
173 pkt
->cmdString(), pkt
->getAddr());
175 // we should not see a timing request if we are already in a retry
178 DPRINTF(SerialLink
, "Response queue size: %d outresp: %d\n",
179 transmitList
.size(), outstandingResponses
);
181 // if the request queue is full then there is no hope
182 if (masterPort
.reqQueueFull()) {
183 DPRINTF(SerialLink
, "Request queue full\n");
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
->cacheResponding();
189 if (expects_response
) {
190 if (respQueueFull()) {
191 DPRINTF(SerialLink
, "Response queue full\n");
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
;
199 // no need to set retryReq to false as this is already the
205 // @todo: We need to pay for this and not just zero it out
206 pkt
->headerDelay
= pkt
->payloadDelay
= 0;
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
215 Cycles cycles
= delay
;
216 cycles
+= Cycles(divCeil(pkt
->getSize() * 8,
217 serial_link
.num_lanes
));
218 Tick t
= serial_link
.clockEdge(cycles
);
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
);
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
237 SerialLink::SerialLinkSlavePort::retryStalledReq()
240 DPRINTF(SerialLink
, "Request waiting for retry, now retrying\n");
247 SerialLink::SerialLinkMasterPort::schedTimingReq(PacketPtr pkt
, Tick when
)
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
253 if (transmitList
.empty()) {
254 serial_link
.schedule(sendEvent
, when
);
257 assert(transmitList
.size() != reqQueueLimit
);
259 transmitList
.emplace_back(DeferredPacket(pkt
, when
));
264 SerialLink::SerialLinkSlavePort::schedTimingResp(PacketPtr pkt
, Tick when
)
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
270 if (transmitList
.empty()) {
271 serial_link
.schedule(sendEvent
, when
);
274 transmitList
.emplace_back(DeferredPacket(pkt
, when
));
278 SerialLink::SerialLinkMasterPort::trySendTiming()
280 assert(!transmitList
.empty());
282 DeferredPacket req
= transmitList
.front();
284 assert(req
.tick
<= curTick());
286 PacketPtr pkt
= req
.pkt
;
288 DPRINTF(SerialLink
, "trySend request addr 0x%x, queue size %d\n",
289 pkt
->getAddr(), transmitList
.size());
291 if (sendTimingReq(pkt
)) {
293 transmitList
.pop_front();
295 DPRINTF(SerialLink
, "trySend request successful\n");
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");
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
));
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();
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
321 SerialLink::SerialLinkSlavePort::trySendTiming()
323 assert(!transmitList
.empty());
325 DeferredPacket resp
= transmitList
.front();
327 assert(resp
.tick
<= curTick());
329 PacketPtr pkt
= resp
.pkt
;
331 DPRINTF(SerialLink
, "trySend response addr 0x%x, outstanding %d\n",
332 pkt
->getAddr(), outstandingResponses
);
334 if (sendTimingResp(pkt
)) {
336 transmitList
.pop_front();
337 DPRINTF(SerialLink
, "trySend response successful\n");
339 assert(outstandingResponses
!= 0);
340 --outstandingResponses
;
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");
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
));
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");
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
369 SerialLink::SerialLinkMasterPort::recvReqRetry()
375 SerialLink::SerialLinkSlavePort::recvRespRetry()
381 SerialLink::SerialLinkSlavePort::recvAtomic(PacketPtr pkt
)
383 return delay
* serial_link
.clockPeriod() + masterPort
.sendAtomic(pkt
);
387 SerialLink::SerialLinkSlavePort::recvFunctional(PacketPtr pkt
)
389 pkt
->pushLabel(name());
391 // check the response queue
392 for (auto i
= transmitList
.begin(); i
!= transmitList
.end(); ++i
) {
393 if (pkt
->checkFunctional((*i
).pkt
)) {
399 // also check the master port's request queue
400 if (masterPort
.checkFunctional(pkt
)) {
406 // fall through if pkt still not satisfied
407 masterPort
.sendFunctional(pkt
);
411 SerialLink::SerialLinkMasterPort::checkFunctional(PacketPtr pkt
)
414 auto i
= transmitList
.begin();
416 while(i
!= transmitList
.end() && !found
) {
417 if (pkt
->checkFunctional((*i
).pkt
)) {
428 SerialLink::SerialLinkSlavePort::getAddrRanges() const
434 SerialLinkParams::create()
436 return new SerialLink(this);