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.
44 * Implementation of the SerialLink Class, modeling Hybrid-Memory-Cube's
48 #include "mem/serial_link.hh"
50 #include "base/trace.hh"
51 #include "debug/SerialLink.hh"
52 #include "params/SerialLink.hh"
54 SerialLink::SerialLinkResponsePort::
55 SerialLinkResponsePort(const std::string
& _name
,
56 SerialLink
& _serial_link
,
57 SerialLinkRequestPort
& _mem_side_port
,
58 Cycles _delay
, int _resp_limit
,
59 const std::vector
<AddrRange
>&
61 : ResponsePort(_name
, &_serial_link
), serial_link(_serial_link
),
62 mem_side_port(_mem_side_port
), delay(_delay
),
63 ranges(_ranges
.begin(), _ranges
.end()),
64 outstandingResponses(0), retryReq(false),
65 respQueueLimit(_resp_limit
),
66 sendEvent([this]{ trySendTiming(); }, _name
)
70 SerialLink::SerialLinkRequestPort::SerialLinkRequestPort(const std::string
&
71 _name
, SerialLink
& _serial_link
,
72 SerialLinkResponsePort
&
73 _cpu_side_port
, Cycles _delay
,
75 : RequestPort(_name
, &_serial_link
), serial_link(_serial_link
),
76 cpu_side_port(_cpu_side_port
), delay(_delay
), reqQueueLimit(_req_limit
),
77 sendEvent([this]{ trySendTiming(); }, _name
)
81 SerialLink::SerialLink(const SerialLinkParams
&p
)
83 cpu_side_port(p
.name
+ ".cpu_side_port", *this, mem_side_port
,
84 ticksToCycles(p
.delay
), p
.resp_size
, p
.ranges
),
85 mem_side_port(p
.name
+ ".mem_side_port", *this, cpu_side_port
,
86 ticksToCycles(p
.delay
), p
.req_size
),
87 num_lanes(p
.num_lanes
),
88 link_speed(p
.link_speed
)
93 SerialLink::getPort(const std::string
&if_name
, PortID idx
)
95 if (if_name
== "mem_side_port")
97 else if (if_name
== "cpu_side_port")
100 // pass it along to our super class
101 return ClockedObject::getPort(if_name
, idx
);
107 // make sure both sides are connected and have the same block size
108 if (!cpu_side_port
.isConnected() || !mem_side_port
.isConnected())
109 fatal("Both ports of a serial_link must be connected.\n");
111 // notify the request side of our address ranges
112 cpu_side_port
.sendRangeChange();
116 SerialLink::SerialLinkResponsePort::respQueueFull() const
118 return outstandingResponses
== respQueueLimit
;
122 SerialLink::SerialLinkRequestPort::reqQueueFull() const
124 return transmitList
.size() == reqQueueLimit
;
128 SerialLink::SerialLinkRequestPort::recvTimingResp(PacketPtr pkt
)
130 // all checks are done when the request is accepted on the response
131 // side, so we are guaranteed to have space for the response
132 DPRINTF(SerialLink
, "recvTimingResp: %s addr 0x%x\n",
133 pkt
->cmdString(), pkt
->getAddr());
135 DPRINTF(SerialLink
, "Request queue size: %d\n", transmitList
.size());
137 // @todo: We need to pay for this and not just zero it out
138 pkt
->headerDelay
= pkt
->payloadDelay
= 0;
140 // This is similar to what happens for the request packets:
141 // The serializer will start serialization as soon as it receives the
142 // first flit, but the deserializer (at the host side in this case), will
143 // have to wait to receive the whole packet. So we only account for the
144 // deserialization latency.
145 Cycles cycles
= delay
;
146 cycles
+= Cycles(divCeil(pkt
->getSize() * 8, serial_link
.num_lanes
147 * serial_link
.link_speed
));
148 Tick t
= serial_link
.clockEdge(cycles
);
150 //@todo: If the processor sends two uncached requests towards HMC and the
151 // second one is smaller than the first one. It may happen that the second
152 // one crosses this link faster than the first one (because the packet
153 // waits in the link based on its size). This can reorder the received
155 cpu_side_port
.schedTimingResp(pkt
, t
);
161 SerialLink::SerialLinkResponsePort::recvTimingReq(PacketPtr pkt
)
163 DPRINTF(SerialLink
, "recvTimingReq: %s addr 0x%x\n",
164 pkt
->cmdString(), pkt
->getAddr());
166 // we should not see a timing request if we are already in a retry
169 DPRINTF(SerialLink
, "Response queue size: %d outresp: %d\n",
170 transmitList
.size(), outstandingResponses
);
172 // if the request queue is full then there is no hope
173 if (mem_side_port
.reqQueueFull()) {
174 DPRINTF(SerialLink
, "Request queue full\n");
176 } else if ( !retryReq
) {
177 // look at the response queue if we expect to see a response
178 bool expects_response
= pkt
->needsResponse() &&
179 !pkt
->cacheResponding();
180 if (expects_response
) {
181 if (respQueueFull()) {
182 DPRINTF(SerialLink
, "Response queue full\n");
185 // ok to send the request with space for the response
186 DPRINTF(SerialLink
, "Reserving space for response\n");
187 assert(outstandingResponses
!= respQueueLimit
);
188 ++outstandingResponses
;
190 // no need to set retryReq to false as this is already the
196 // @todo: We need to pay for this and not just zero it out
197 pkt
->headerDelay
= pkt
->payloadDelay
= 0;
199 // We assume that the serializer component at the transmitter side
200 // does not need to receive the whole packet to start the
201 // serialization (this assumption is consistent with the HMC
202 // standard). But the deserializer waits for the complete packet
203 // to check its integrity first. So everytime a packet crosses a
204 // serial link, we should account for its deserialization latency
206 Cycles cycles
= delay
;
207 cycles
+= Cycles(divCeil(pkt
->getSize() * 8,
208 serial_link
.num_lanes
* serial_link
.link_speed
));
209 Tick t
= serial_link
.clockEdge(cycles
);
211 //@todo: If the processor sends two uncached requests towards HMC
212 // and the second one is smaller than the first one. It may happen
213 // that the second one crosses this link faster than the first one
214 // (because the packet waits in the link based on its size).
215 // This can reorder the received response.
216 mem_side_port
.schedTimingReq(pkt
, t
);
220 // remember that we are now stalling a packet and that we have to
221 // tell the sending requestor to retry once space becomes available,
222 // we make no distinction whether the stalling is due to the
223 // request queue or response queue being full
228 SerialLink::SerialLinkResponsePort::retryStalledReq()
231 DPRINTF(SerialLink
, "Request waiting for retry, now retrying\n");
238 SerialLink::SerialLinkRequestPort::schedTimingReq(PacketPtr pkt
, Tick when
)
240 // If we're about to put this packet at the head of the queue, we
241 // need to schedule an event to do the transmit. Otherwise there
242 // should already be an event scheduled for sending the head
244 if (transmitList
.empty()) {
245 serial_link
.schedule(sendEvent
, when
);
248 assert(transmitList
.size() != reqQueueLimit
);
250 transmitList
.emplace_back(DeferredPacket(pkt
, when
));
255 SerialLink::SerialLinkResponsePort::schedTimingResp(PacketPtr pkt
, Tick when
)
257 // If we're about to put this packet at the head of the queue, we
258 // need to schedule an event to do the transmit. Otherwise there
259 // should already be an event scheduled for sending the head
261 if (transmitList
.empty()) {
262 serial_link
.schedule(sendEvent
, when
);
265 transmitList
.emplace_back(DeferredPacket(pkt
, when
));
269 SerialLink::SerialLinkRequestPort::trySendTiming()
271 assert(!transmitList
.empty());
273 DeferredPacket req
= transmitList
.front();
275 assert(req
.tick
<= curTick());
277 PacketPtr pkt
= req
.pkt
;
279 DPRINTF(SerialLink
, "trySend request addr 0x%x, queue size %d\n",
280 pkt
->getAddr(), transmitList
.size());
282 if (sendTimingReq(pkt
)) {
284 transmitList
.pop_front();
286 DPRINTF(SerialLink
, "trySend request successful\n");
288 // If there are more packets to send, schedule event to try again.
289 if (!transmitList
.empty()) {
290 DeferredPacket next_req
= transmitList
.front();
291 DPRINTF(SerialLink
, "Scheduling next send\n");
293 // Make sure bandwidth limitation is met
294 Cycles cycles
= Cycles(divCeil(pkt
->getSize() * 8,
295 serial_link
.num_lanes
* serial_link
.link_speed
));
296 Tick t
= serial_link
.clockEdge(cycles
);
297 serial_link
.schedule(sendEvent
, std::max(next_req
.tick
, t
));
300 // if we have stalled a request due to a full request queue,
301 // then send a retry at this point, also note that if the
302 // request we stalled was waiting for the response queue
303 // rather than the request queue we might stall it again
304 cpu_side_port
.retryStalledReq();
307 // if the send failed, then we try again once we receive a retry,
308 // and therefore there is no need to take any action
312 SerialLink::SerialLinkResponsePort::trySendTiming()
314 assert(!transmitList
.empty());
316 DeferredPacket resp
= transmitList
.front();
318 assert(resp
.tick
<= curTick());
320 PacketPtr pkt
= resp
.pkt
;
322 DPRINTF(SerialLink
, "trySend response addr 0x%x, outstanding %d\n",
323 pkt
->getAddr(), outstandingResponses
);
325 if (sendTimingResp(pkt
)) {
327 transmitList
.pop_front();
328 DPRINTF(SerialLink
, "trySend response successful\n");
330 assert(outstandingResponses
!= 0);
331 --outstandingResponses
;
333 // If there are more packets to send, schedule event to try again.
334 if (!transmitList
.empty()) {
335 DeferredPacket next_resp
= transmitList
.front();
336 DPRINTF(SerialLink
, "Scheduling next send\n");
338 // Make sure bandwidth limitation is met
339 Cycles cycles
= Cycles(divCeil(pkt
->getSize() * 8,
340 serial_link
.num_lanes
* serial_link
.link_speed
));
341 Tick t
= serial_link
.clockEdge(cycles
);
342 serial_link
.schedule(sendEvent
, std::max(next_resp
.tick
, t
));
345 // if there is space in the request queue and we were stalling
346 // a request, it will definitely be possible to accept it now
347 // since there is guaranteed space in the response queue
348 if (!mem_side_port
.reqQueueFull() && retryReq
) {
349 DPRINTF(SerialLink
, "Request waiting for retry, now retrying\n");
355 // if the send failed, then we try again once we receive a retry,
356 // and therefore there is no need to take any action
360 SerialLink::SerialLinkRequestPort::recvReqRetry()
366 SerialLink::SerialLinkResponsePort::recvRespRetry()
372 SerialLink::SerialLinkResponsePort::recvAtomic(PacketPtr pkt
)
374 return delay
* serial_link
.clockPeriod() + mem_side_port
.sendAtomic(pkt
);
378 SerialLink::SerialLinkResponsePort::recvFunctional(PacketPtr pkt
)
380 pkt
->pushLabel(name());
382 // check the response queue
383 for (auto i
= transmitList
.begin(); i
!= transmitList
.end(); ++i
) {
384 if (pkt
->trySatisfyFunctional((*i
).pkt
)) {
390 // also check the memory-side port's request queue
391 if (mem_side_port
.trySatisfyFunctional(pkt
)) {
397 // fall through if pkt still not satisfied
398 mem_side_port
.sendFunctional(pkt
);
402 SerialLink::SerialLinkRequestPort::trySatisfyFunctional(PacketPtr pkt
)
405 auto i
= transmitList
.begin();
407 while (i
!= transmitList
.end() && !found
) {
408 if (pkt
->trySatisfyFunctional((*i
).pkt
)) {
419 SerialLink::SerialLinkResponsePort::getAddrRanges() const
425 SerialLinkParams::create() const
427 return new SerialLink(*this);