gem5  v21.2.1.1
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  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its
16  * contributors may be used to endorse or promote products derived from this
17  * software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
33 
34 #include "debug/ProtocolTest.hh"
35 
36 namespace gem5
37 {
38 
40  : TesterThread(_params)
41 {
42  threadName = "DmaThread(Thread ID " + std::to_string(threadId) + ")";
43  threadEvent.setDesc("DmaThread tick");
44  assert(numLanes == 1);
45 }
46 
48 {
49 
50 }
51 
52 void
54 {
55  assert(curAction);
57  // we should not have any outstanding fence or atomic op at this point
58  assert(pendingFenceCount == 0);
59  assert(pendingAtomicCount == 0);
60 
61  // DMA thread is a scalar thread so always set lane to zero. This allows
62  // us to reuse the API for GPU threads rather than have a specific API
63  // for scalar tester threads
64  int lane = 0;
65 
66  Location location = curAction->getLocation(lane);
67  assert(location >= AddressManager::INVALID_LOCATION);
68 
69  if (location >= 0) {
70  Addr address = addrManager->getAddress(location);
71  DPRINTF(ProtocolTest, "%s Episode %d: Issuing Load - Addr %s\n",
72  this->getName(), curEpisode->getEpisodeId(),
73  ruby::printAddress(address));
74 
75  int load_size = sizeof(Value);
76 
77  // for now, assert address is 4-byte aligned
78  assert(address % load_size == 0);
79 
80  auto req = std::make_shared<Request>(address, load_size,
81  0, tester->requestorId(),
82  0, threadId, nullptr);
83  req->setPaddr(address);
84  req->setReqInstSeqNum(tester->getActionSeqNum());
85 
86  PacketPtr pkt = new Packet(req, MemCmd::ReadReq);
87  uint8_t* data = new uint8_t[load_size];
88  pkt->dataDynamic(data);
90 
91  if (!port->sendTimingReq(pkt)) {
92  panic("Not expected failed sendTimingReq\n");
93  }
94 
95  // insert an outstanding load
96  addOutstandingReqs(outstandingLoads, address, lane, location);
97 
98  // increment the number of outstanding ld_st requests
100  }
101 }
102 
103 void
105 {
106  assert(curAction);
108  // we should not have any outstanding fence or atomic op at this point
109  assert(pendingFenceCount == 0);
110  assert(pendingAtomicCount == 0);
111 
112  // DMA thread is a scalar thread so always set lane to zero. This allows
113  // us to reuse the API for GPU threads rather than have a specific API
114  // for scalar tester threads
115  int lane = 0;
116 
117  Location location = curAction->getLocation(lane);
118  assert(location >= AddressManager::INVALID_LOCATION);
119 
120  if (location >= 0) {
121  // prepare the next value to store
122  Value new_value = addrManager->getLoggedValue(location) + 1;
123 
124  Addr address = addrManager->getAddress(location);
125  // must be aligned with store size
126  assert(address % sizeof(Value) == 0);
127 
128  DPRINTF(ProtocolTest, "%s Episode %d: Issuing Store - Addr %s - "
129  "Value %d\n", this->getName(),
131  new_value);
132 
133  auto req = std::make_shared<Request>(address, sizeof(Value),
134  0, tester->requestorId(), 0,
135  threadId, nullptr);
136  req->setPaddr(address);
137  req->setReqInstSeqNum(tester->getActionSeqNum());
138 
139  PacketPtr pkt = new Packet(req, MemCmd::WriteReq);
140  uint8_t *writeData = new uint8_t[sizeof(Value)];
141  for (int j = 0; j < sizeof(Value); ++j) {
142  writeData[j] = ((uint8_t*)&new_value)[j];
143  }
144  pkt->dataDynamic(writeData);
145  pkt->senderState = new ProtocolTester::SenderState(this);
146 
147  if (!port->sendTimingReq(pkt)) {
148  panic("Not expecting a failed sendTimingReq\n");
149  }
150 
151  // add an outstanding store
152  addOutstandingReqs(outstandingStores, address, lane, location,
153  new_value);
154 
155  // increment the number of outstanding ld_st requests
157  }
158 }
159 
160 void
162 {
163  DPRINTF(ProtocolTest, "Issuing Atomic Op ...\n");
164 
165  assert(curAction);
167  // we should not have any outstanding ops at this point
168  assert(pendingFenceCount == 0);
169  assert(pendingLdStCount == 0);
170  assert(pendingAtomicCount == 0);
171 
172  // no-op: No DMA protocol exists with Atomics
173 }
174 
175 void
177 {
178  DPRINTF(ProtocolTest, "Issuing Acquire Op ...\n");
179 
180  assert(curAction);
182  // we should not have any outstanding ops at this point
183  assert(pendingFenceCount == 0);
184  assert(pendingLdStCount == 0);
185  assert(pendingAtomicCount == 0);
186 
187  // no-op: Acquire does not apply to DMA threads
188 }
189 
190 void
192 {
193  DPRINTF(ProtocolTest, "Issuing Release Op ...\n");
194 
195  assert(curAction);
197  // we should not have any outstanding ops at this point
198  assert(pendingFenceCount == 0);
199  assert(pendingLdStCount == 0);
200  assert(pendingAtomicCount == 0);
201 
202  // no-op: Release does not apply to DMA threads
203 }
204 
205 void
207 {
208  assert(pkt);
209  MemCmd resp_cmd = pkt->cmd;
210  Addr addr = pkt->getAddr();
211 
212  DPRINTF(ProtocolTest, "%s Episode %d: hitCallback - Command %s -"
213  " Addr %s\n", this->getName(), curEpisode->getEpisodeId(),
214  resp_cmd.toString(), ruby::printAddress(addr));
215 
216  if (resp_cmd == MemCmd::SwapResp) {
217  // response to a pending atomic
218  assert(pendingAtomicCount > 0);
219  assert(pendingLdStCount == 0);
220  assert(outstandingAtomics.count(addr) > 0);
221 
222  // get return data
223  Value value = *(pkt->getPtr<Value>());
224 
225  // validate atomic op return
227  assert(req.lane == 0);
228  validateAtomicResp(req.origLoc, req.lane, value);
229 
230  // update log table
232  curEpisode->getEpisodeId(), value,
233  curTick(),
234  0);
235 
236  // this Atomic is done
238  } else if (resp_cmd == MemCmd::ReadResp) {
239  // response to a pending read
240  assert(pendingLdStCount > 0);
241  assert(pendingAtomicCount == 0);
242  assert(outstandingLoads.count(addr) > 0);
243 
244  // get return data
245  Value value = *(pkt->getPtr<Value>());
247  assert(req.lane == 0);
248  validateLoadResp(req.origLoc, req.lane, value);
249 
250  // this Read is done
252  } else if (resp_cmd == MemCmd::WriteResp) {
253  // response to a pending write
254  assert(pendingLdStCount > 0);
255  assert(pendingAtomicCount == 0);
256 
257  // no need to validate Write response
258  // just pop it from the outstanding req table so that subsequent
259  // requests dependent on this write can proceed
260  // note that unlike GpuWavefront we do decrement pendingLdStCount here
261  // since the write is guaranteed to be completed in downstream memory.
262  assert(outstandingStores.count(addr) > 0);
265 
266  // update log table
269  req.storedValue,
270  curTick(),
271  0);
272 
273  // the Write is now done
275  } else {
276  panic("UnsupportedMemCmd response type: %s",
277  resp_cmd.toString().c_str());
278  }
279 
280  delete pkt->senderState;
281  delete pkt;
282 
283  // record the last active cycle to check for deadlock
285 
286  // we may be able to issue an action. Let's check
287  if (!threadEvent.scheduled()) {
288  scheduleWakeup();
289  }
290 }
291 
292 } // 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:93
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:53
gem5::TesterThread::port
ProtocolTester::SeqPort * port
Definition: tester_thread.hh:146
gem5::TesterThread::curAction
const Episode::Action * curAction
Definition: tester_thread.hh:158
gem5::Episode::Action::getType
Type getType() const
Definition: episode.hh:66
gem5::TesterThread::pendingAtomicCount
int pendingAtomicCount
Definition: tester_thread.hh:163
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:162
gem5::TesterThread::outstandingAtomics
OutstandingReqTable outstandingAtomics
Definition: tester_thread.hh:174
gem5::MemCmd::SwapResp
@ SwapResp
Definition: packet.hh:116
gem5::TesterThread::threadEvent
TesterThreadEvent threadEvent
Definition: tester_thread.hh:98
gem5::TesterThread::OutstandingReq::origLoc
Location origLoc
Definition: tester_thread.hh:123
gem5::TesterThread::lastActiveCycle
Cycles lastActiveCycle
Definition: tester_thread.hh:166
gem5::TesterThread
Definition: tester_thread.hh:49
gem5::TesterThread::pendingLdStCount
int pendingLdStCount
Definition: tester_thread.hh:161
gem5::MemCmd
Definition: packet.hh:75
gem5::ProtocolTester::requestorId
RequestorID requestorId()
Definition: protocol_tester.hh:122
dma_thread.hh
gem5::DmaThread::~DmaThread
virtual ~DmaThread()
Definition: dma_thread.cc:47
gem5::TesterThread::getName
const std::string & getName() const
Definition: tester_thread.hh:70
gem5::ArmISA::j
Bitfield< 24 > j
Definition: misc_types.hh:57
gem5::TesterThread::outstandingStores
OutstandingReqTable outstandingStores
Definition: tester_thread.hh:173
gem5::DmaThread::issueReleaseOp
void issueReleaseOp()
Definition: dma_thread.cc:191
gem5::TesterThread::popOutstandingReq
OutstandingReq popOutstandingReq(OutstandingReqTable &req_table, Addr address)
Definition: tester_thread.cc:308
gem5::MemCmd::WriteResp
@ WriteResp
Definition: packet.hh:90
gem5::DmaThread::Location
AddressManager::Location Location
Definition: dma_thread.hh:48
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:136
gem5::probing::Packet
ProbePointArg< PacketInfo > Packet
Packet probe point.
Definition: mem.hh:109
gem5::TesterThread::numLanes
int numLanes
Definition: tester_thread.hh:138
gem5::TesterThread::validateLoadResp
void validateLoadResp(Location loc, int lane, Value ret_val)
Definition: tester_thread.cc:358
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:413
gem5::ProtocolTester::getActionSeqNum
int getActionSeqNum()
Definition: protocol_tester.hh:137
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:151
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:289
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:144
gem5::Packet::senderState
SenderState * senderState
This packet's sender state.
Definition: packet.hh:534
gem5::TesterThread::OutstandingReq::storedValue
Value storedValue
Definition: tester_thread.hh:124
gem5::AddressManager::INVALID_LOCATION
static const int INVALID_LOCATION
Definition: address_manager.hh:152
gem5::TesterThread::OutstandingReq::lane
int lane
Definition: tester_thread.hh:122
gem5::TesterThread::addOutstandingReqs
void addOutstandingReqs(OutstandingReqTable &req_table, Addr addr, int lane, Location loc, Value stored_val=AddressManager::INVALID_VALUE)
Definition: tester_thread.cc:291
gem5::TesterThread::outstandingLoads
OutstandingReqTable outstandingLoads
Definition: tester_thread.hh:172
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:49
gem5::Episode::Action::Type::ACQUIRE
@ ACQUIRE
gem5::DmaThread::Params
DmaThreadParams Params
Definition: dma_thread.hh:44
gem5::DmaThread::hitCallback
void hitCallback(PacketPtr pkt)
Definition: dma_thread.cc:206
gem5::DmaThread::issueAtomicOps
void issueAtomicOps()
Definition: dma_thread.cc:161
gem5::TesterThread::curEpisode
Episode * curEpisode
Definition: tester_thread.hh:156
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:85
gem5::DmaThread::issueStoreOps
void issueStoreOps()
Definition: dma_thread.cc:104
gem5::DmaThread::issueAcquireOp
void issueAcquireOp()
Definition: dma_thread.cc:176
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:334
gem5::DmaThread::DmaThread
DmaThread(const Params &_params)
Definition: dma_thread.cc:39
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: tlb.cc:60
gem5::AddressManager::getLoggedValue
Value getLoggedValue(Location loc) const
Definition: address_manager.cc:421
gem5::TesterThread::OutstandingReq
Definition: tester_thread.hh:120
gem5::TesterThread::tester
ProtocolTester * tester
Definition: tester_thread.hh:142
gem5::TesterThread::threadName
std::string threadName
Definition: tester_thread.hh:140
gem5::TesterThread::scheduleWakeup
void scheduleWakeup()
Definition: tester_thread.cc:112
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:178
gem5::AddressManager::getAddress
Addr getAddress(Location loc)
Definition: address_manager.cc:88
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 Wed May 4 2022 12:13:55 for gem5 by doxygen 1.8.17