gem5  v20.1.0.0
mem_delay.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018, 2020 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  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #include "mem/mem_delay.hh"
39 
40 #include "params/MemDelay.hh"
41 #include "params/SimpleMemDelay.hh"
42 
43 MemDelay::MemDelay(const MemDelayParams *p)
44  : ClockedObject(p),
45  requestPort(name() + "-mem_side_port", *this),
46  responsePort(name() + "-cpu_side_port", *this),
47  reqQueue(*this, requestPort),
48  respQueue(*this, responsePort),
49  snoopRespQueue(*this, requestPort)
50 {
51 }
52 
53 void
55 {
57  fatal("Memory delay is not connected on both sides.\n");
58 }
59 
60 
61 Port &
62 MemDelay::getPort(const std::string &if_name, PortID idx)
63 {
64  if (if_name == "mem_side_port") {
65  return requestPort;
66  } else if (if_name == "cpu_side_port") {
67  return responsePort;
68  } else {
69  return ClockedObject::getPort(if_name, idx);
70  }
71 }
72 
73 bool
75 {
76  return responsePort.trySatisfyFunctional(pkt) ||
78 }
79 
80 MemDelay::RequestPort::RequestPort(const std::string &_name, MemDelay &_parent)
81  : QueuedRequestPort(_name, &_parent,
82  _parent.reqQueue, _parent.snoopRespQueue),
83  parent(_parent)
84 {
85 }
86 
87 bool
89 {
90  // technically the packet only reaches us after the header delay,
91  // and typically we also need to deserialise any payload
92  const Tick receive_delay = pkt->headerDelay + pkt->payloadDelay;
93  pkt->headerDelay = pkt->payloadDelay = 0;
94 
95  const Tick when = curTick() + parent.delayResp(pkt) + receive_delay;
96 
97  parent.responsePort.schedTimingResp(pkt, when);
98 
99  return true;
100 }
101 
102 void
104 {
105  if (parent.trySatisfyFunctional(pkt)) {
106  pkt->makeResponse();
107  } else {
108  parent.responsePort.sendFunctionalSnoop(pkt);
109  }
110 }
111 
112 Tick
114 {
115  const Tick delay = parent.delaySnoopResp(pkt);
116 
117  return delay + parent.responsePort.sendAtomicSnoop(pkt);
118 }
119 
120 void
122 {
123  parent.responsePort.sendTimingSnoopReq(pkt);
124 }
125 
126 
128 ResponsePort(const std::string &_name, MemDelay &_parent)
129  : QueuedResponsePort(_name, &_parent, _parent.respQueue),
130  parent(_parent)
131 {
132 }
133 
134 Tick
136 {
137  const Tick delay = parent.delayReq(pkt) + parent.delayResp(pkt);
138 
139  return delay + parent.requestPort.sendAtomic(pkt);
140 }
141 
142 bool
144 {
145  // technically the packet only reaches us after the header
146  // delay, and typically we also need to deserialise any
147  // payload
148  Tick receive_delay = pkt->headerDelay + pkt->payloadDelay;
149  pkt->headerDelay = pkt->payloadDelay = 0;
150 
151  const Tick when = curTick() + parent.delayReq(pkt) + receive_delay;
152 
153  parent.requestPort.schedTimingReq(pkt, when);
154 
155  return true;
156 }
157 
158 void
160 {
161  if (parent.trySatisfyFunctional(pkt)) {
162  pkt->makeResponse();
163  } else {
164  parent.requestPort.sendFunctional(pkt);
165  }
166 }
167 
168 bool
170 {
171  const Tick when = curTick() + parent.delaySnoopResp(pkt);
172 
173  parent.requestPort.schedTimingSnoopResp(pkt, when);
174 
175  return true;
176 }
177 
178 
179 
180 SimpleMemDelay::SimpleMemDelay(const SimpleMemDelayParams *p)
181  : MemDelay(p),
182  readReqDelay(p->read_req),
183  readRespDelay(p->read_resp),
184  writeReqDelay(p->write_req),
185  writeRespDelay(p->write_resp)
186 {
187 }
188 
189 Tick
191 {
192  if (pkt->isRead()) {
193  return readReqDelay;
194  } else if (pkt->isWrite()) {
195  return writeReqDelay;
196  } else {
197  return 0;
198  }
199 }
200 
201 Tick
203 {
204  if (pkt->isRead()) {
205  return readRespDelay;
206  } else if (pkt->isWrite()) {
207  return writeRespDelay;
208  } else {
209  return 0;
210  }
211 }
212 
213 
215 SimpleMemDelayParams::create()
216 {
217  return new SimpleMemDelay(this);
218 }
SimpleMemDelay::writeRespDelay
const Tick writeRespDelay
Definition: mem_delay.hh:177
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:183
MemDelay::RequestPort::RequestPort
RequestPort(const std::string &_name, MemDelay &_parent)
Definition: mem_delay.cc:80
SimpleMemDelay::writeReqDelay
const Tick writeReqDelay
Definition: mem_delay.hh:176
SimpleMemDelay
Delay packets by a constant time.
Definition: mem_delay.hh:163
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:412
MemDelay::ResponsePort::recvAtomic
Tick recvAtomic(PacketPtr pkt) override
Receive an atomic request packet from the peer.
Definition: mem_delay.cc:135
Packet::isRead
bool isRead() const
Definition: packet.hh:556
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
MemDelay::respQueue
RespPacketQueue respQueue
Definition: mem_delay.hh:129
mem_delay.hh
PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:237
MemDelay::requestPort
RequestPort requestPort
Definition: mem_delay.hh:125
MemDelay::RequestPort::recvTimingResp
bool recvTimingResp(PacketPtr pkt) override
Receive a timing response from the peer.
Definition: mem_delay.cc:88
Packet::headerDelay
uint32_t headerDelay
The extra delay from seeing the packet until the header is transmitted.
Definition: packet.hh:394
MemDelay::ResponsePort::recvTimingSnoopResp
bool recvTimingSnoopResp(PacketPtr pkt) override
Receive a timing snoop response from the peer.
Definition: mem_delay.cc:169
SimpleMemDelay::readReqDelay
const Tick readReqDelay
Definition: mem_delay.hh:173
ClockedObject
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
Definition: clocked_object.hh:231
MemDelay::ResponsePort::recvFunctional
void recvFunctional(PacketPtr pkt) override
Receive a functional request packet from the peer.
Definition: mem_delay.cc:159
MemDelay::ResponsePort::recvTimingReq
bool recvTimingReq(PacketPtr pkt) override
Receive a timing request from the peer.
Definition: mem_delay.cc:143
MemDelay::MemDelay
MemDelay(const MemDelayParams *params)
Definition: mem_delay.cc:43
SimpleMemDelay::SimpleMemDelay
SimpleMemDelay(const SimpleMemDelayParams *params)
Definition: mem_delay.cc:180
QueuedRequestPort
The QueuedRequestPort combines two queues, a request queue and a snoop response queue,...
Definition: qport.hh:106
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:123
Port
Ports are used to interface objects to each other.
Definition: port.hh:56
QueuedResponsePort
A queued port is a port that has an infinite queue for outgoing packets and thus decouples the module...
Definition: qport.hh:58
SimpleMemDelay::delayResp
Tick delayResp(PacketPtr pkt) override
Delay a response by some number of ticks.
Definition: mem_delay.cc:202
MemDelay::RequestPort::recvFunctionalSnoop
void recvFunctionalSnoop(PacketPtr pkt) override
Receive a functional snoop request packet from the peer.
Definition: mem_delay.cc:103
MemDelay
This abstract component provides a mechanism to delay packets.
Definition: mem_delay.hh:62
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:1004
name
const std::string & name()
Definition: trace.cc:50
MemDelay::RequestPort::recvAtomicSnoop
Tick recvAtomicSnoop(PacketPtr pkt) override
Receive an atomic snoop request packet from our peer.
Definition: mem_delay.cc:113
QueuedRequestPort::trySatisfyFunctional
bool trySatisfyFunctional(PacketPtr pkt)
Check the list of buffered packets against the supplied functional request.
Definition: qport.hh:160
MemDelay::RequestPort::recvTimingSnoopReq
void recvTimingSnoopReq(PacketPtr pkt) override
Receive a timing snoop request from the peer.
Definition: mem_delay.cc:121
MemDelay::getPort
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
Definition: mem_delay.cc:62
MemDelay::trySatisfyFunctional
bool trySatisfyFunctional(PacketPtr pkt)
Definition: mem_delay.cc:74
MemDelay::init
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: mem_delay.cc:54
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:257
Port::isConnected
bool isConnected() const
Is this port currently connected to a peer?
Definition: port.hh:128
Packet::isWrite
bool isWrite() const
Definition: packet.hh:557
QueuedResponsePort::trySatisfyFunctional
bool trySatisfyFunctional(PacketPtr pkt)
Check the list of buffered packets against the supplied functional request.
Definition: qport.hh:95
MemDelay::responsePort
ResponsePort responsePort
Definition: mem_delay.hh:126
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
MemDelay::ResponsePort::ResponsePort
ResponsePort(const std::string &_name, MemDelay &_parent)
Definition: mem_delay.cc:128
SimpleMemDelay::readRespDelay
const Tick readRespDelay
Definition: mem_delay.hh:174
SimpleMemDelay::delayReq
Tick delayReq(PacketPtr pkt) override
Delay a request by some number of ticks.
Definition: mem_delay.cc:190
curTick
Tick curTick()
The current simulated tick.
Definition: core.hh:45

Generated on Wed Sep 30 2020 14:02:13 for gem5 by doxygen 1.8.17