gem5  v21.0.1.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
serial_link.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2013 ARM Limited
3  * All rights reserved
4  *
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.
13  *
14  * Copyright (c) 2006 The Regents of The University of Michigan
15  * Copyright (c) 2015 The University of Bologna
16  * All rights reserved.
17  *
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.
28  *
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.
40  */
41 
48 #include "mem/serial_link.hh"
49 
50 #include "base/trace.hh"
51 #include "debug/SerialLink.hh"
52 #include "params/SerialLink.hh"
53 
55 SerialLinkResponsePort(const std::string& _name,
56  SerialLink& _serial_link,
57  SerialLinkRequestPort& _mem_side_port,
58  Cycles _delay, int _resp_limit,
60  _ranges)
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)
67 {
68 }
69 
71  _name, SerialLink& _serial_link,
73  _cpu_side_port, Cycles _delay,
74  int _req_limit)
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)
78 {
79 }
80 
81 SerialLink::SerialLink(const SerialLinkParams &p)
82  : ClockedObject(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),
89 {
90 }
91 
92 Port&
93 SerialLink::getPort(const std::string &if_name, PortID idx)
94 {
95  if (if_name == "mem_side_port")
96  return mem_side_port;
97  else if (if_name == "cpu_side_port")
98  return cpu_side_port;
99  else
100  // pass it along to our super class
101  return ClockedObject::getPort(if_name, idx);
102 }
103 
104 void
106 {
107  // make sure both sides are connected and have the same block size
109  fatal("Both ports of a serial_link must be connected.\n");
110 
111  // notify the request side of our address ranges
113 }
114 
115 bool
117 {
119 }
120 
121 bool
123 {
124  return transmitList.size() == reqQueueLimit;
125 }
126 
127 bool
129 {
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());
134 
135  DPRINTF(SerialLink, "Request queue size: %d\n", transmitList.size());
136 
137  // @todo: We need to pay for this and not just zero it out
138  pkt->headerDelay = pkt->payloadDelay = 0;
139 
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);
149 
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
154  // response.
156 
157  return true;
158 }
159 
160 bool
162 {
163  DPRINTF(SerialLink, "recvTimingReq: %s addr 0x%x\n",
164  pkt->cmdString(), pkt->getAddr());
165 
166  // we should not see a timing request if we are already in a retry
167  assert(!retryReq);
168 
169  DPRINTF(SerialLink, "Response queue size: %d outresp: %d\n",
170  transmitList.size(), outstandingResponses);
171 
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");
175  retryReq = true;
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");
183  retryReq = true;
184  } else {
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;
189 
190  // no need to set retryReq to false as this is already the
191  // case
192  }
193  }
194 
195  if (!retryReq) {
196  // @todo: We need to pay for this and not just zero it out
197  pkt->headerDelay = pkt->payloadDelay = 0;
198 
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
205  // only.
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);
210 
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.
217  }
218  }
219 
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
224  return !retryReq;
225 }
226 
227 void
229 {
230  if (retryReq) {
231  DPRINTF(SerialLink, "Request waiting for retry, now retrying\n");
232  retryReq = false;
233  sendRetryReq();
234  }
235 }
236 
237 void
239 {
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
243  // packet.
244  if (transmitList.empty()) {
245  serial_link.schedule(sendEvent, when);
246  }
247 
248  assert(transmitList.size() != reqQueueLimit);
249 
250  transmitList.emplace_back(DeferredPacket(pkt, when));
251 }
252 
253 
254 void
256 {
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
260  // packet.
261  if (transmitList.empty()) {
262  serial_link.schedule(sendEvent, when);
263  }
264 
265  transmitList.emplace_back(DeferredPacket(pkt, when));
266 }
267 
268 void
270 {
271  assert(!transmitList.empty());
272 
273  DeferredPacket req = transmitList.front();
274 
275  assert(req.tick <= curTick());
276 
277  PacketPtr pkt = req.pkt;
278 
279  DPRINTF(SerialLink, "trySend request addr 0x%x, queue size %d\n",
280  pkt->getAddr(), transmitList.size());
281 
282  if (sendTimingReq(pkt)) {
283  // send successful
284  transmitList.pop_front();
285 
286  DPRINTF(SerialLink, "trySend request successful\n");
287 
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");
292 
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));
298  }
299 
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
305  }
306 
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
309 }
310 
311 void
313 {
314  assert(!transmitList.empty());
315 
316  DeferredPacket resp = transmitList.front();
317 
318  assert(resp.tick <= curTick());
319 
320  PacketPtr pkt = resp.pkt;
321 
322  DPRINTF(SerialLink, "trySend response addr 0x%x, outstanding %d\n",
323  pkt->getAddr(), outstandingResponses);
324 
325  if (sendTimingResp(pkt)) {
326  // send successful
327  transmitList.pop_front();
328  DPRINTF(SerialLink, "trySend response successful\n");
329 
330  assert(outstandingResponses != 0);
331  --outstandingResponses;
332 
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");
337 
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));
343  }
344 
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");
350  retryReq = false;
351  sendRetryReq();
352  }
353  }
354 
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
357 }
358 
359 void
361 {
362  trySendTiming();
363 }
364 
365 void
367 {
368  trySendTiming();
369 }
370 
371 Tick
373 {
374  return delay * serial_link.clockPeriod() + mem_side_port.sendAtomic(pkt);
375 }
376 
377 void
379 {
380  pkt->pushLabel(name());
381 
382  // check the response queue
383  for (auto i = transmitList.begin(); i != transmitList.end(); ++i) {
384  if (pkt->trySatisfyFunctional((*i).pkt)) {
385  pkt->makeResponse();
386  return;
387  }
388  }
389 
390  // also check the memory-side port's request queue
392  return;
393  }
394 
395  pkt->popLabel();
396 
397  // fall through if pkt still not satisfied
399 }
400 
401 bool
403 {
404  bool found = false;
405  auto i = transmitList.begin();
406 
407  while (i != transmitList.end() && !found) {
408  if (pkt->trySatisfyFunctional((*i).pkt)) {
409  pkt->makeResponse();
410  found = true;
411  }
412  ++i;
413  }
414 
415  return found;
416 }
417 
420 {
421  return ranges;
422 }
ArmISA::sendEvent
void sendEvent(ThreadContext *tc)
Send an event (SEV) to a specific PE if there isn't already a pending event.
Definition: utility.cc:103
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:183
ResponsePort
A ResponsePort is a specialization of a port.
Definition: port.hh:265
Packet::cacheResponding
bool cacheResponding() const
Definition: packet.hh:620
Packet::getAddr
Addr getAddr() const
Definition: packet.hh:755
Packet::payloadDelay
uint32_t payloadDelay
The extra pipelining delay from seeing the packet until the end of payload is transmitted by the comp...
Definition: packet.hh:413
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:59
PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:243
Packet::pushLabel
void pushLabel(const std::string &lbl)
Push label for PrintReq (safe to call unconditionally).
Definition: packet.hh:1394
std::vector< AddrRange >
Packet::getSize
unsigned getSize() const
Definition: packet.hh:765
RequestPort::sendFunctional
void sendFunctional(PacketPtr pkt) const
Send a functional request packet, where the data is instantly updated everywhere in the memory system...
Definition: port.hh:482
Packet::headerDelay
uint32_t headerDelay
The extra delay from seeing the packet until the header is transmitted.
Definition: packet.hh:395
ClockedObject
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
Definition: clocked_object.hh:231
divCeil
T divCeil(const T &a, const U &b)
Definition: intmath.hh:114
SimObject::getPort
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
Definition: sim_object.cc:120
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:237
Packet::cmdString
const std::string & cmdString() const
Return the string name of the cmd field (for debugging and tracing).
Definition: packet.hh:552
Port
Ports are used to interface objects to each other.
Definition: port.hh:56
Packet::needsResponse
bool needsResponse() const
Definition: packet.hh:571
RequestPort
A RequestPort is a specialisation of a Port, which implements the default protocol for the three diff...
Definition: port.hh:74
Packet::makeResponse
void makeResponse()
Take a request packet and modify it in place to be suitable for returning as a response to that reque...
Definition: packet.hh:1005
SimObject::name
virtual const std::string name() const
Definition: sim_object.hh:182
ArmISA::t
Bitfield< 5 > t
Definition: miscregs_types.hh:67
Clocked::ticksToCycles
Cycles ticksToCycles(Tick t) const
Definition: clocked_object.hh:219
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:258
Port::isConnected
bool isConnected() const
Is this port currently connected to a peer?
Definition: port.hh:128
Cycles
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:79
curTick
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:43
trace.hh
RequestPort::sendAtomic
Tick sendAtomic(PacketPtr pkt)
Send an atomic request packet, where the data is moved and the state is updated in zero time,...
Definition: port.hh:461
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
std::list< AddrRange >
ResponsePort::sendRangeChange
void sendRangeChange() const
Called by the owner to send a range change.
Definition: port.hh:293
Packet::trySatisfyFunctional
bool trySatisfyFunctional(PacketPtr other)
Check a functional request against a memory value stored in another packet (i.e.
Definition: packet.hh:1332
Packet::popLabel
void popLabel()
Pop label for PrintReq (safe to call unconditionally).
Definition: packet.hh:1404

Generated on Tue Jun 22 2021 15:28:30 for gem5 by doxygen 1.8.17