gem5  v21.1.0.2
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 
38 namespace gem5
39 {
40 
42  : TesterThread(_params)
43 {
44  threadName = "DmaThread(Thread ID " + std::to_string(threadId) + ")";
45  threadEvent.setDesc("DmaThread tick");
46  assert(numLanes == 1);
47 }
48 
50 {
51 
52 }
53 
54 void
56 {
57  assert(curAction);
59  // we should not have any outstanding fence or atomic op at this point
60  assert(pendingFenceCount == 0);
61  assert(pendingAtomicCount == 0);
62 
63  // DMA thread is a scalar thread so always set lane to zero. This allows
64  // us to reuse the API for GPU threads rather than have a specific API
65  // for scalar tester threads
66  int lane = 0;
67 
68  Location location = curAction->getLocation(lane);
69  assert(location >= AddressManager::INVALID_LOCATION);
70 
71  if (location >= 0) {
72  Addr address = addrManager->getAddress(location);
73  DPRINTF(ProtocolTest, "%s Episode %d: Issuing Load - Addr %s\n",
74  this->getName(), curEpisode->getEpisodeId(),
75  ruby::printAddress(address));
76 
77  int load_size = sizeof(Value);
78 
79  // for now, assert address is 4-byte aligned
80  assert(address % load_size == 0);
81 
82  auto req = std::make_shared<Request>(address, load_size,
83  0, tester->requestorId(),
84  0, threadId, nullptr);
85  req->setPaddr(address);
86  req->setReqInstSeqNum(tester->getActionSeqNum());
87 
88  PacketPtr pkt = new Packet(req, MemCmd::ReadReq);
89  uint8_t* data = new uint8_t[load_size];
90  pkt->dataDynamic(data);
92 
93  if (!port->sendTimingReq(pkt)) {
94  panic("Not expected failed sendTimingReq\n");
95  }
96 
97  // insert an outstanding load
98  addOutstandingReqs(outstandingLoads, address, lane, location);
99 
100  // increment the number of outstanding ld_st requests
102  }
103 }
104 
105 void
107 {
108  assert(curAction);
110  // we should not have any outstanding fence or atomic op at this point
111  assert(pendingFenceCount == 0);
112  assert(pendingAtomicCount == 0);
113 
114  // DMA thread is a scalar thread so always set lane to zero. This allows
115  // us to reuse the API for GPU threads rather than have a specific API
116  // for scalar tester threads
117  int lane = 0;
118 
119  Location location = curAction->getLocation(lane);
120  assert(location >= AddressManager::INVALID_LOCATION);
121 
122  if (location >= 0) {
123  // prepare the next value to store
124  Value new_value = addrManager->getLoggedValue(location) + 1;
125 
126  Addr address = addrManager->getAddress(location);
127  // must be aligned with store size
128  assert(address % sizeof(Value) == 0);
129 
130  DPRINTF(ProtocolTest, "%s Episode %d: Issuing Store - Addr %s - "
131  "Value %d\n", this->getName(),
133  new_value);
134 
135  auto req = std::make_shared<Request>(address, sizeof(Value),
136  0, tester->requestorId(), 0,
137  threadId, nullptr);
138  req->setPaddr(address);
139  req->setReqInstSeqNum(tester->getActionSeqNum());
140 
141  PacketPtr pkt = new Packet(req, MemCmd::WriteReq);
142  uint8_t *writeData = new uint8_t[sizeof(Value)];
143  for (int j = 0; j < sizeof(Value); ++j) {
144  writeData[j] = ((uint8_t*)&new_value)[j];
145  }
146  pkt->dataDynamic(writeData);
147  pkt->senderState = new ProtocolTester::SenderState(this);
148 
149  if (!port->sendTimingReq(pkt)) {
150  panic("Not expecting a failed sendTimingReq\n");
151  }
152 
153  // add an outstanding store
154  addOutstandingReqs(outstandingStores, address, lane, location,
155  new_value);
156 
157  // increment the number of outstanding ld_st requests
159  }
160 }
161 
162 void
164 {
165  DPRINTF(ProtocolTest, "Issuing Atomic Op ...\n");
166 
167  assert(curAction);
169  // we should not have any outstanding ops at this point
170  assert(pendingFenceCount == 0);
171  assert(pendingLdStCount == 0);
172  assert(pendingAtomicCount == 0);
173 
174  // no-op: No DMA protocol exists with Atomics
175 }
176 
177 void
179 {
180  DPRINTF(ProtocolTest, "Issuing Acquire Op ...\n");
181 
182  assert(curAction);
184  // we should not have any outstanding ops at this point
185  assert(pendingFenceCount == 0);
186  assert(pendingLdStCount == 0);
187  assert(pendingAtomicCount == 0);
188 
189  // no-op: Acquire does not apply to DMA threads
190 }
191 
192 void
194 {
195  DPRINTF(ProtocolTest, "Issuing Release Op ...\n");
196 
197  assert(curAction);
199  // we should not have any outstanding ops at this point
200  assert(pendingFenceCount == 0);
201  assert(pendingLdStCount == 0);
202  assert(pendingAtomicCount == 0);
203 
204  // no-op: Release does not apply to DMA threads
205 }
206 
207 void
209 {
210  assert(pkt);
211  MemCmd resp_cmd = pkt->cmd;
212  Addr addr = pkt->getAddr();
213 
214  DPRINTF(ProtocolTest, "%s Episode %d: hitCallback - Command %s -"
215  " Addr %s\n", this->getName(), curEpisode->getEpisodeId(),
216  resp_cmd.toString(), ruby::printAddress(addr));
217 
218  if (resp_cmd == MemCmd::SwapResp) {
219  // response to a pending atomic
220  assert(pendingAtomicCount > 0);
221  assert(pendingLdStCount == 0);
222  assert(outstandingAtomics.count(addr) > 0);
223 
224  // get return data
225  Value value = *(pkt->getPtr<Value>());
226 
227  // validate atomic op return
229  assert(req.lane == 0);
230  validateAtomicResp(req.origLoc, req.lane, value);
231 
232  // update log table
234  curEpisode->getEpisodeId(), value,
235  curTick(),
236  0);
237 
238  // this Atomic is done
240  } else if (resp_cmd == MemCmd::ReadResp) {
241  // response to a pending read
242  assert(pendingLdStCount > 0);
243  assert(pendingAtomicCount == 0);
244  assert(outstandingLoads.count(addr) > 0);
245 
246  // get return data
247  Value value = *(pkt->getPtr<Value>());
249  assert(req.lane == 0);
250  validateLoadResp(req.origLoc, req.lane, value);
251 
252  // this Read is done
254  } else if (resp_cmd == MemCmd::WriteResp) {
255  // response to a pending write
256  assert(pendingLdStCount > 0);
257  assert(pendingAtomicCount == 0);
258 
259  // no need to validate Write response
260  // just pop it from the outstanding req table so that subsequent
261  // requests dependent on this write can proceed
262  // note that unlike GpuWavefront we do decrement pendingLdStCount here
263  // since the write is guaranteed to be completed in downstream memory.
264  assert(outstandingStores.count(addr) > 0);
267 
268  // update log table
271  req.storedValue,
272  curTick(),
273  0);
274 
275  // the Write is now done
277  } else {
278  panic("UnsupportedMemCmd response type: %s",
279  resp_cmd.toString().c_str());
280  }
281 
282  delete pkt->senderState;
283  delete pkt;
284 
285  // record the last active cycle to check for deadlock
287 
288  // we may be able to issue an action. Let's check
289  if (!threadEvent.scheduled()) {
290  scheduleWakeup();
291  }
292 }
293 
294 } // namespace gem5
gem5::curTick
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:46
gem5::TesterThread::TesterThreadEvent::setDesc
void setDesc(std::string _description)
Definition: tester_thread.hh:95
gem5::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:495
data
const char data[]
Definition: circlebuf.test.cc:48
gem5::Clocked::curCycle
Cycles curCycle() const
Determine the current cycle, corresponding to a tick aligned to a clock edge.
Definition: clocked_object.hh:195
gem5::ruby::printAddress
std::string printAddress(Addr addr)
Definition: Address.cc:80
gem5::Episode::Action::Type::STORE
@ STORE
gem5::DmaThread::issueLoadOps
void issueLoadOps()
Definition: dma_thread.cc:55
gem5::TesterThread::port
ProtocolTester::SeqPort * port
Definition: tester_thread.hh:148
gem5::TesterThread::curAction
const Episode::Action * curAction
Definition: tester_thread.hh:160
gem5::Episode::Action::getType
Type getType() const
Definition: episode.hh:68
gem5::TesterThread::pendingAtomicCount
int pendingAtomicCount
Definition: tester_thread.hh:165
sc_dt::to_string
const std::string to_string(sc_enc enc)
Definition: sc_fxdefs.cc:91
gem5::TesterThread::pendingFenceCount
int pendingFenceCount
Definition: tester_thread.hh:164
gem5::TesterThread::outstandingAtomics
OutstandingReqTable outstandingAtomics
Definition: tester_thread.hh:176
gem5::MemCmd::SwapResp
@ SwapResp
Definition: packet.hh:116
gem5::TesterThread::threadEvent
TesterThreadEvent threadEvent
Definition: tester_thread.hh:100
gem5::TesterThread::OutstandingReq::origLoc
Location origLoc
Definition: tester_thread.hh:125
gem5::TesterThread::lastActiveCycle
Cycles lastActiveCycle
Definition: tester_thread.hh:168
gem5::TesterThread
Definition: tester_thread.hh:51
gem5::TesterThread::pendingLdStCount
int pendingLdStCount
Definition: tester_thread.hh:163
gem5::MemCmd
Definition: packet.hh:75
gem5::ProtocolTester::requestorId
RequestorID requestorId()
Definition: protocol_tester.hh:124
dma_thread.hh
gem5::DmaThread::~DmaThread
virtual ~DmaThread()
Definition: dma_thread.cc:49
gem5::TesterThread::getName
const std::string & getName() const
Definition: tester_thread.hh:72
gem5::ArmISA::j
Bitfield< 24 > j
Definition: misc_types.hh:57
gem5::TesterThread::outstandingStores
OutstandingReqTable outstandingStores
Definition: tester_thread.hh:175
gem5::DmaThread::issueReleaseOp
void issueReleaseOp()
Definition: dma_thread.cc:193
gem5::TesterThread::popOutstandingReq
OutstandingReq popOutstandingReq(OutstandingReqTable &req_table, Addr address)
Definition: tester_thread.cc:310
gem5::MemCmd::WriteResp
@ WriteResp
Definition: packet.hh:90
gem5::DmaThread::Location
AddressManager::Location Location
Definition: dma_thread.hh:50
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:186
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:283
gem5::TesterThread::threadId
int threadId
Definition: tester_thread.hh:138
gem5::probing::Packet
ProbePointArg< PacketInfo > Packet
Packet probe point.
Definition: mem.hh:109
gem5::TesterThread::numLanes
int numLanes
Definition: tester_thread.hh:140
gem5::TesterThread::validateLoadResp
void validateLoadResp(Location loc, int lane, Value ret_val)
Definition: tester_thread.cc:360
gem5::MemCmd::ReadReq
@ ReadReq
Definition: packet.hh:86
gem5::AddressManager::updateLogTable
void updateLogTable(Location loc, int threadId, int episodeId, Value new_value, Tick curTick, int cuId=-1)
Definition: address_manager.cc:415
gem5::ProtocolTester::getActionSeqNum
int getActionSeqNum()
Definition: protocol_tester.hh:139
gem5::Episode::Action::Type::ATOMIC
@ ATOMIC
gem5::Episode::Action::Type::RELEASE
@ RELEASE
gem5::AddressManager::INVALID_VALUE
static const int INVALID_VALUE
Definition: address_manager.hh:153
gem5::Packet::cmd
MemCmd cmd
The command field of the packet.
Definition: packet.hh:361
gem5::Episode::Action::getLocation
Location getLocation(int lane) const
Definition: episode.cc:291
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::TesterThread::addrManager
AddressManager * addrManager
Definition: tester_thread.hh:146
gem5::Packet::senderState
SenderState * senderState
This packet's sender state.
Definition: packet.hh:534
gem5::TesterThread::OutstandingReq::storedValue
Value storedValue
Definition: tester_thread.hh:126
gem5::AddressManager::INVALID_LOCATION
static const int INVALID_LOCATION
Definition: address_manager.hh:154
gem5::TesterThread::OutstandingReq::lane
int lane
Definition: tester_thread.hh:124
gem5::TesterThread::addOutstandingReqs
void addOutstandingReqs(OutstandingReqTable &req_table, Addr addr, int lane, Location loc, Value stored_val=AddressManager::INVALID_VALUE)
Definition: tester_thread.cc:293
gem5::TesterThread::outstandingLoads
OutstandingReqTable outstandingLoads
Definition: tester_thread.hh:174
gem5::MemCmd::toString
const std::string & toString() const
Return the string to a cmd given by idx.
Definition: packet.hh:265
gem5::DmaThread::Value
AddressManager::Value Value
Definition: dma_thread.hh:51
gem5::Episode::Action::Type::ACQUIRE
@ ACQUIRE
gem5::DmaThread::Params
DmaThreadParams Params
Definition: dma_thread.hh:46
gem5::DmaThread::hitCallback
void hitCallback(PacketPtr pkt)
Definition: dma_thread.cc:208
gem5::DmaThread::issueAtomicOps
void issueAtomicOps()
Definition: dma_thread.cc:163
gem5::TesterThread::curEpisode
Episode * curEpisode
Definition: tester_thread.hh:158
gem5::MemCmd::ReadResp
@ ReadResp
Definition: packet.hh:87
gem5::Packet::dataDynamic
void dataDynamic(T *p)
Set the data pointer to a value that should have delete [] called on it.
Definition: packet.hh:1172
gem5::MemCmd::WriteReq
@ WriteReq
Definition: packet.hh:89
gem5::Episode::getEpisodeId
int getEpisodeId() const
Definition: episode.hh:87
gem5::DmaThread::issueStoreOps
void issueStoreOps()
Definition: dma_thread.cc:106
gem5::DmaThread::issueAcquireOp
void issueAcquireOp()
Definition: dma_thread.cc:178
gem5::Packet::getAddr
Addr getAddr() const
Definition: packet.hh:781
gem5::TesterThread::validateAtomicResp
void validateAtomicResp(Location loc, int lane, Value ret_val)
Definition: tester_thread.cc:336
gem5::DmaThread::DmaThread
DmaThread(const Params &_params)
Definition: dma_thread.cc:41
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::AddressManager::getLoggedValue
Value getLoggedValue(Location loc) const
Definition: address_manager.cc:423
gem5::TesterThread::OutstandingReq
Definition: tester_thread.hh:122
gem5::TesterThread::tester
ProtocolTester * tester
Definition: tester_thread.hh:144
gem5::TesterThread::threadName
std::string threadName
Definition: tester_thread.hh:142
gem5::TesterThread::scheduleWakeup
void scheduleWakeup()
Definition: tester_thread.cc:114
gem5::Episode::Action::Type::LOAD
@ LOAD
gem5::Event::scheduled
bool scheduled() const
Determine if the current event is scheduled.
Definition: eventq.hh:465
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:177
gem5::AddressManager::getAddress
Addr getAddress(Location loc)
Definition: address_manager.cc:90
gem5::X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:84
gem5::SenderState
RubyTester::SenderState SenderState
Definition: Check.cc:40
gem5::Packet::getPtr
T * getPtr()
get a pointer to the data ptr.
Definition: packet.hh:1184

Generated on Tue Sep 21 2021 12:25:09 for gem5 by doxygen 1.8.17