gem5  v22.0.0.2
memory_manager.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  */
32 
34 
35 #include <memory>
36 
37 #include "base/chunk_generator.hh"
38 #include "debug/AMDGPUMem.hh"
39 #include "params/AMDGPUMemoryManager.hh"
40 #include "sim/system.hh"
41 
42 namespace gem5
43 {
44 
45 AMDGPUMemoryManager::AMDGPUMemoryManager(const AMDGPUMemoryManagerParams &p)
46  : ClockedObject(p), _gpuMemPort(csprintf("%s-port", name()), this),
47  cacheLineSize(p.system->cacheLineSize()),
48  _requestorId(p.system->getRequestorId(this))
49 {
50 }
51 
52 void
54  Request::Flags flag, Event *callback)
55 {
56  assert(data);
57 
58  ChunkGenerator gen(addr, size, cacheLineSize);
59  for (; !gen.done(); gen.next()) {
60  RequestPtr req = std::make_shared<Request>(gen.addr(), gen.size(),
61  flag, _requestorId);
62 
63  PacketPtr pkt = Packet::createWrite(req);
64  uint8_t *dataPtr = new uint8_t[gen.size()];
65  std::memcpy(dataPtr, data + (gen.complete()/sizeof(uint8_t)),
66  gen.size());
67  pkt->dataDynamic<uint8_t>(dataPtr);
68 
69  // We only want to issue the callback on the last request completing.
70  if (gen.last()) {
71  pkt->pushSenderState(new GPUMemPort::SenderState(callback, addr));
72  } else {
73  pkt->pushSenderState(new GPUMemPort::SenderState(nullptr, addr));
74  }
75 
76  if (!_gpuMemPort.sendTimingReq(pkt)) {
77  DPRINTF(AMDGPUMem, "Request to %#lx needs retry\n", gen.addr());
78  _gpuMemPort.retries.push_back(pkt);
79  } else {
80  DPRINTF(AMDGPUMem, "Write request to %#lx sent\n", gen.addr());
81  }
82  }
83 }
84 
85 bool
87 {
88  // Retrieve sender state
89  [[maybe_unused]] SenderState *sender_state =
90  safe_cast<SenderState*>(pkt->senderState);
91 
92  DPRINTF(AMDGPUMem, "Recveived Response for %#x\n", sender_state->_addr);
93 
94  // Check if there is a callback event and if so call it
95  if (sender_state->_callback) {
96  sender_state->_callback->process();
97  delete sender_state->_callback;
98  }
99 
100  delete pkt->senderState;
101  delete pkt;
102  return true;
103 }
104 
105 void
107 {
108  for (const auto &pkt : retries) {
109  if (!sendTimingReq(pkt)) {
110  break;
111  } else {
112  DPRINTF(AMDGPUMem, "Retry for %#lx sent\n", pkt->getAddr());
113  retries.pop_front();
114  }
115  }
116 }
117 
118 } // namespace gem5
gem5::AMDGPUMemoryManager::GPUMemPort::SenderState::_addr
Addr _addr
Definition: memory_manager.hh:65
gem5::AMDGPUMemoryManager::GPUMemPort::SenderState::_callback
Event * _callback
Definition: memory_manager.hh:64
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
system.hh
data
const char data[]
Definition: circlebuf.test.cc:48
gem5::ChunkGenerator::next
bool next()
Advance generator to next chunk.
Definition: chunk_generator.hh:185
gem5::ChunkGenerator::complete
Addr complete() const
Number of bytes we have already chunked up.
Definition: chunk_generator.hh:132
gem5::Packet::pushSenderState
void pushSenderState(SenderState *sender_state)
Push a new sender state to the packet and make the current sender state the predecessor of the new on...
Definition: packet.cc:330
gem5::Packet::createWrite
static PacketPtr createWrite(const RequestPtr &req)
Definition: packet.hh:1026
gem5::X86ISA::system
Bitfield< 15 > system
Definition: misc.hh:997
gem5::AMDGPUMemoryManager::AMDGPUMemoryManager
AMDGPUMemoryManager(const AMDGPUMemoryManagerParams &p)
Definition: memory_manager.cc:45
gem5::AMDGPUMemoryManager::GPUMemPort::recvReqRetry
void recvReqRetry() override
Called by the peer if sendTimingReq was called on this peer (causing recvTimingReq to be called on th...
Definition: memory_manager.cc:106
gem5::csprintf
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:161
gem5::ChunkGenerator::last
bool last() const
Is this the last chunk?
Definition: chunk_generator.hh:149
gem5::ChunkGenerator::size
Addr size() const
Return size in bytes of current chunk.
Definition: chunk_generator.hh:125
gem5::ChunkGenerator
This class takes an arbitrary memory region (address/length pair) and generates a series of appropria...
Definition: chunk_generator.hh:59
gem5::AMDGPUMemoryManager::GPUMemPort::recvTimingResp
bool recvTimingResp(PacketPtr pkt) override
Receive a timing response from the peer.
Definition: memory_manager.cc:86
memory_manager.hh
gem5::Flags< FlagsType >
gem5::ChunkGenerator::done
bool done() const
Are we done? That is, did the last call to next() advance past the end of the region?
Definition: chunk_generator.hh:141
gem5::VegaISA::p
Bitfield< 54 > p
Definition: pagetable.hh:70
gem5::AMDGPUMemoryManager::_requestorId
const RequestorID _requestorId
Definition: memory_manager.hh:73
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:186
gem5::Event
Definition: eventq.hh:251
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:291
gem5::AMDGPUMemoryManager::GPUMemPort::retries
std::deque< PacketPtr > retries
Definition: memory_manager.hh:68
gem5::Event::process
virtual void process()=0
gem5::RequestPtr
std::shared_ptr< Request > RequestPtr
Definition: request.hh:92
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::Packet::senderState
SenderState * senderState
This packet's sender state.
Definition: packet.hh:542
name
const std::string & name()
Definition: trace.cc:49
gem5::ClockedObject
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
Definition: clocked_object.hh:234
gem5::AMDGPUMemoryManager::_gpuMemPort
GPUMemPort _gpuMemPort
Definition: memory_manager.hh:71
gem5::AMDGPUMemoryManager::writeRequest
void writeRequest(Addr addr, uint8_t *data, int size, Request::Flags flag=0, Event *callback=nullptr)
Write size amount of data to device memory at addr using flags and callback.
Definition: memory_manager.cc:53
gem5::ChunkGenerator::addr
Addr addr() const
Return starting address of current chunk.
Definition: chunk_generator.hh:119
gem5::Packet::dataDynamic
void dataDynamic(T *p)
Set the data pointer to a value that should have delete [] called on it.
Definition: packet.hh:1185
chunk_generator.hh
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::AMDGPUMemoryManager::cacheLineSize
const int cacheLineSize
Definition: memory_manager.hh:72
gem5::AMDGPUMemoryManager::GPUMemPort::SenderState
Definition: memory_manager.hh:58
gem5::X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:84

Generated on Thu Jul 28 2022 13:32:30 for gem5 by doxygen 1.8.17