gem5  v21.0.1.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
dma_thread.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 Advanced Micro Devices, Inc.
3  * All rights reserved.
4  *
5  * For use for simulation and test purposes only
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  *
17  * 3. Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived from this
19  * software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
35 
36 #include "debug/ProtocolTest.hh"
37 
39  : TesterThread(_params)
40 {
41  threadName = "DmaThread(Thread ID " + std::to_string(threadId) + ")";
42  threadEvent.setDesc("DmaThread tick");
43  assert(numLanes == 1);
44 }
45 
47 {
48 
49 }
50 
51 void
53 {
54  assert(curAction);
56  // we should not have any outstanding fence or atomic op at this point
57  assert(pendingFenceCount == 0);
58  assert(pendingAtomicCount == 0);
59 
60  // DMA thread is a scalar thread so always set lane to zero. This allows
61  // us to reuse the API for GPU threads rather than have a specific API
62  // for scalar tester threads
63  int lane = 0;
64 
65  Location location = curAction->getLocation(lane);
66  assert(location >= AddressManager::INVALID_LOCATION);
67 
68  if (location >= 0) {
69  Addr address = addrManager->getAddress(location);
70  DPRINTF(ProtocolTest, "%s Episode %d: Issuing Load - Addr %s\n",
71  this->getName(), curEpisode->getEpisodeId(),
72  printAddress(address));
73 
74  int load_size = sizeof(Value);
75 
76  // for now, assert address is 4-byte aligned
77  assert(address % load_size == 0);
78 
79  auto req = std::make_shared<Request>(address, load_size,
80  0, tester->requestorId(),
81  0, threadId, nullptr);
82  req->setPaddr(address);
83  req->setReqInstSeqNum(tester->getActionSeqNum());
84 
85  PacketPtr pkt = new Packet(req, MemCmd::ReadReq);
86  uint8_t* data = new uint8_t[load_size];
87  pkt->dataDynamic(data);
89 
90  if (!port->sendTimingReq(pkt)) {
91  panic("Not expected failed sendTimingReq\n");
92  }
93 
94  // insert an outstanding load
95  addOutstandingReqs(outstandingLoads, address, lane, location);
96 
97  // increment the number of outstanding ld_st requests
99  }
100 }
101 
102 void
104 {
105  assert(curAction);
107  // we should not have any outstanding fence or atomic op at this point
108  assert(pendingFenceCount == 0);
109  assert(pendingAtomicCount == 0);
110 
111  // DMA thread is a scalar thread so always set lane to zero. This allows
112  // us to reuse the API for GPU threads rather than have a specific API
113  // for scalar tester threads
114  int lane = 0;
115 
116  Location location = curAction->getLocation(lane);
117  assert(location >= AddressManager::INVALID_LOCATION);
118 
119  if (location >= 0) {
120  // prepare the next value to store
121  Value new_value = addrManager->getLoggedValue(location) + 1;
122 
123  Addr address = addrManager->getAddress(location);
124  // must be aligned with store size
125  assert(address % sizeof(Value) == 0);
126 
127  DPRINTF(ProtocolTest, "%s Episode %d: Issuing Store - Addr %s - "
128  "Value %d\n", this->getName(),
129  curEpisode->getEpisodeId(), printAddress(address),
130  new_value);
131 
132  auto req = std::make_shared<Request>(address, sizeof(Value),
133  0, tester->requestorId(), 0,
134  threadId, nullptr);
135  req->setPaddr(address);
136  req->setReqInstSeqNum(tester->getActionSeqNum());
137 
138  PacketPtr pkt = new Packet(req, MemCmd::WriteReq);
139  uint8_t *writeData = new uint8_t[sizeof(Value)];
140  for (int j = 0; j < sizeof(Value); ++j) {
141  writeData[j] = ((uint8_t*)&new_value)[j];
142  }
143  pkt->dataDynamic(writeData);
144  pkt->senderState = new ProtocolTester::SenderState(this);
145 
146  if (!port->sendTimingReq(pkt)) {
147  panic("Not expecting a failed sendTimingReq\n");
148  }
149 
150  // add an outstanding store
151  addOutstandingReqs(outstandingStores, address, lane, location,
152  new_value);
153 
154  // increment the number of outstanding ld_st requests
156  }
157 }
158 
159 void
161 {
162  DPRINTF(ProtocolTest, "Issuing Atomic Op ...\n");
163 
164  assert(curAction);
166  // we should not have any outstanding ops at this point
167  assert(pendingFenceCount == 0);
168  assert(pendingLdStCount == 0);
169  assert(pendingAtomicCount == 0);
170 
171  // no-op: No DMA protocol exists with Atomics
172 }
173 
174 void
176 {
177  DPRINTF(ProtocolTest, "Issuing Acquire Op ...\n");
178 
179  assert(curAction);
181  // we should not have any outstanding ops at this point
182  assert(pendingFenceCount == 0);
183  assert(pendingLdStCount == 0);
184  assert(pendingAtomicCount == 0);
185 
186  // no-op: Acquire does not apply to DMA threads
187 }
188 
189 void
191 {
192  DPRINTF(ProtocolTest, "Issuing Release Op ...\n");
193 
194  assert(curAction);
196  // we should not have any outstanding ops at this point
197  assert(pendingFenceCount == 0);
198  assert(pendingLdStCount == 0);
199  assert(pendingAtomicCount == 0);
200 
201  // no-op: Release does not apply to DMA threads
202 }
203 
204 void
206 {
207  assert(pkt);
208  MemCmd resp_cmd = pkt->cmd;
209  Addr addr = pkt->getAddr();
210 
211  DPRINTF(ProtocolTest, "%s Episode %d: hitCallback - Command %s -"
212  " Addr %s\n", this->getName(), curEpisode->getEpisodeId(),
213  resp_cmd.toString(), printAddress(addr));
214 
215  if (resp_cmd == MemCmd::SwapResp) {
216  // response to a pending atomic
217  assert(pendingAtomicCount > 0);
218  assert(pendingLdStCount == 0);
219  assert(outstandingAtomics.count(addr) > 0);
220 
221  // get return data
222  Value value = *(pkt->getPtr<Value>());
223 
224  // validate atomic op return
226  assert(req.lane == 0);
227  validateAtomicResp(req.origLoc, req.lane, value);
228 
229  // update log table
231  curEpisode->getEpisodeId(), value,
232  curTick(),
233  0);
234 
235  // this Atomic is done
237  } else if (resp_cmd == MemCmd::ReadResp) {
238  // response to a pending read
239  assert(pendingLdStCount > 0);
240  assert(pendingAtomicCount == 0);
241  assert(outstandingLoads.count(addr) > 0);
242 
243  // get return data
244  Value value = *(pkt->getPtr<Value>());
246  assert(req.lane == 0);
247  validateLoadResp(req.origLoc, req.lane, value);
248 
249  // this Read is done
251  } else if (resp_cmd == MemCmd::WriteResp) {
252  // response to a pending write
253  assert(pendingLdStCount > 0);
254  assert(pendingAtomicCount == 0);
255 
256  // no need to validate Write response
257  // just pop it from the outstanding req table so that subsequent
258  // requests dependent on this write can proceed
259  // note that unlike GpuWavefront we do decrement pendingLdStCount here
260  // since the write is guaranteed to be completed in downstream memory.
261  assert(outstandingStores.count(addr) > 0);
264 
265  // update log table
268  req.storedValue,
269  curTick(),
270  0);
271 
272  // the Write is now done
274  } else {
275  panic("UnsupportedMemCmd response type: %s",
276  resp_cmd.toString().c_str());
277  }
278 
279  delete pkt->senderState;
280  delete pkt;
281 
282  // record the last active cycle to check for deadlock
284 
285  // we may be able to issue an action. Let's check
286  if (!threadEvent.scheduled()) {
287  scheduleWakeup();
288  }
289 }
Episode::Action::getLocation
Location getLocation(int lane) const
Definition: episode.cc:288
ProtocolTester::requestorId
RequestorID requestorId()
Definition: protocol_tester.hh:121
TesterThread::outstandingStores
OutstandingReqTable outstandingStores
Definition: tester_thread.hh:172
Event::scheduled
bool scheduled() const
Determine if the current event is scheduled.
Definition: eventq.hh:462
TesterThread::pendingFenceCount
int pendingFenceCount
Definition: tester_thread.hh:161
data
const char data[]
Definition: circlebuf.test.cc:47
Packet::getAddr
Addr getAddr() const
Definition: packet.hh:755
TesterThread::TesterThreadEvent::setDesc
void setDesc(std::string _description)
Definition: tester_thread.hh:92
TesterThread
Definition: tester_thread.hh:48
AddressManager::getAddress
Addr getAddress(Location loc)
Definition: address_manager.cc:87
sc_dt::to_string
const std::string to_string(sc_enc enc)
Definition: sc_fxdefs.cc:91
MemCmd::ReadReq
@ ReadReq
Definition: packet.hh:83
TesterThread::numLanes
int numLanes
Definition: tester_thread.hh:137
Episode::Action::Type::LOAD
@ LOAD
TesterThread::OutstandingReq::origLoc
Location origLoc
Definition: tester_thread.hh:122
TesterThread::pendingAtomicCount
int pendingAtomicCount
Definition: tester_thread.hh:162
Packet::dataDynamic
void dataDynamic(T *p)
Set the data pointer to a value that should have delete [] called on it.
Definition: packet.hh:1146
TesterThread::addrManager
AddressManager * addrManager
Definition: tester_thread.hh:143
Episode::Action::getType
Type getType() const
Definition: episode.hh:63
DmaThread::~DmaThread
virtual ~DmaThread()
Definition: dma_thread.cc:46
DmaThread::issueStoreOps
void issueStoreOps()
Definition: dma_thread.cc:103
TesterThread::OutstandingReq::lane
int lane
Definition: tester_thread.hh:121
TesterThread::outstandingLoads
OutstandingReqTable outstandingLoads
Definition: tester_thread.hh:171
ProtocolTester::getActionSeqNum
int getActionSeqNum()
Definition: protocol_tester.hh:136
dma_thread.hh
MemCmd::WriteReq
@ WriteReq
Definition: packet.hh:86
TesterThread::OutstandingReq
Definition: tester_thread.hh:119
ArmISA::j
Bitfield< 24 > j
Definition: miscregs_types.hh:54
TesterThread::threadName
std::string threadName
Definition: tester_thread.hh:139
AddressManager::getLoggedValue
Value getLoggedValue(Location loc) const
Definition: address_manager.cc:420
RequestPort::sendTimingReq
bool sendTimingReq(PacketPtr pkt)
Attempt to send a timing request to the responder port by calling its corresponding receive function.
Definition: port.hh:492
MemCmd::toString
const std::string & toString() const
Return the string to a cmd given by idx.
Definition: packet.hh:240
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:237
SenderState
RubyTester::SenderState SenderState
Definition: Check.cc:37
MemCmd
Definition: packet.hh:72
DmaThread::issueReleaseOp
void issueReleaseOp()
Definition: dma_thread.cc:190
TesterThread::curEpisode
Episode * curEpisode
Definition: tester_thread.hh:155
Episode::Action::Type::RELEASE
@ RELEASE
Clocked::curCycle
Cycles curCycle() const
Determine the current cycle, corresponding to a tick aligned to a clock edge.
Definition: clocked_object.hh:192
MemCmd::SwapResp
@ SwapResp
Definition: packet.hh:113
DmaThread::DmaThread
DmaThread(const Params &_params)
Definition: dma_thread.cc:38
Episode::Action::Type::ACQUIRE
@ ACQUIRE
DmaThread::Params
DmaThreadParams Params
Definition: dma_thread.hh:43
TesterThread::lastActiveCycle
Cycles lastActiveCycle
Definition: tester_thread.hh:165
DmaThread::issueLoadOps
void issueLoadOps()
Definition: dma_thread.cc:52
TesterThread::curAction
const Episode::Action * curAction
Definition: tester_thread.hh:157
TesterThread::popOutstandingReq
OutstandingReq popOutstandingReq(OutstandingReqTable &req_table, Addr address)
Definition: tester_thread.cc:307
ProbePoints::Packet
ProbePointArg< PacketInfo > Packet
Packet probe point.
Definition: mem.hh:103
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:148
TesterThread::validateAtomicResp
void validateAtomicResp(Location loc, int lane, Value ret_val)
Definition: tester_thread.cc:333
X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:80
Packet::cmd
MemCmd cmd
The command field of the packet.
Definition: packet.hh:336
TesterThread::threadId
int threadId
Definition: tester_thread.hh:135
DmaThread::Value
AddressManager::Value Value
Definition: dma_thread.hh:48
TesterThread::outstandingAtomics
OutstandingReqTable outstandingAtomics
Definition: tester_thread.hh:173
Episode::Action::Type::STORE
@ STORE
TesterThread::OutstandingReq::storedValue
Value storedValue
Definition: tester_thread.hh:123
MemCmd::WriteResp
@ WriteResp
Definition: packet.hh:87
TesterThread::scheduleWakeup
void scheduleWakeup()
Definition: tester_thread.cc:111
DmaThread::issueAcquireOp
void issueAcquireOp()
Definition: dma_thread.cc:175
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:258
DmaThread::hitCallback
void hitCallback(PacketPtr pkt)
Definition: dma_thread.cc:205
DmaThread::Location
AddressManager::Location Location
Definition: dma_thread.hh:47
TesterThread::threadEvent
TesterThreadEvent threadEvent
Definition: tester_thread.hh:97
Packet::getPtr
T * getPtr()
get a pointer to the data ptr.
Definition: packet.hh:1158
MemCmd::ReadResp
@ ReadResp
Definition: packet.hh:84
curTick
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:43
TesterThread::pendingLdStCount
int pendingLdStCount
Definition: tester_thread.hh:160
Packet::senderState
SenderState * senderState
This packet's sender state.
Definition: packet.hh:509
TesterThread::addOutstandingReqs
void addOutstandingReqs(OutstandingReqTable &req_table, Addr addr, int lane, Location loc, Value stored_val=AddressManager::INVALID_VALUE)
Definition: tester_thread.cc:290
TesterThread::getName
const std::string & getName() const
Definition: tester_thread.hh:69
AddressManager::updateLogTable
void updateLogTable(Location loc, int threadId, int episodeId, Value new_value, Tick curTick, int cuId=-1)
Definition: address_manager.cc:412
DmaThread::issueAtomicOps
void issueAtomicOps()
Definition: dma_thread.cc:160
AddressManager::INVALID_LOCATION
static const int INVALID_LOCATION
Definition: address_manager.hh:151
TesterThread::tester
ProtocolTester * tester
Definition: tester_thread.hh:141
Episode::getEpisodeId
int getEpisodeId() const
Definition: episode.hh:82
printAddress
std::string printAddress(Addr addr)
Definition: Address.cc:74
TesterThread::port
ProtocolTester::SeqPort * port
Definition: tester_thread.hh:145
TesterThread::validateLoadResp
void validateLoadResp(Location loc, int lane, Value ret_val)
Definition: tester_thread.cc:357
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171
Episode::Action::Type::ATOMIC
@ ATOMIC
AddressManager::INVALID_VALUE
static const int INVALID_VALUE
Definition: address_manager.hh:150

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