gem5  v21.1.0.2
mmio_reader.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 <fstream>
37 
38 #include "base/trace.hh"
39 #include "debug/AMDGPUDevice.hh"
40 #include "mem/packet_access.hh"
41 
42 namespace gem5
43 {
44 
45 void
46 AMDMMIOReader::readMMIOTrace(std::string trace_file)
47 {
48  std::ifstream tracefile(trace_file);
49  std::string line, token;
50 
51  mtrace.event = 0;
52  mtrace.size = 0;
53  mtrace.bar = 0;
54  mtrace.addr = 0;
55  mtrace.data = 0;
56 
57  trace_index = 0;
58 
59  while (std::getline(tracefile, line)) {
60  std::stringstream l(line);
62 
63  while (std::getline(l, token, ' '))
64  tokens.push_back(token);
65 
66  if (traceIsRead(tokens) && isRelevant(tokens)) {
67  traceParseTokens(tokens);
69  recordMtrace();
70  }
71  }
72  }
73 
75 }
76 
77 void
79 {
80  uint64_t value = 0;
81 
82  /* If the offset exists for this BAR, return the value, otherwise 0. */
83  if (trace_BARs[barnum].count(offset) > 0 &&
84  trace_BARs[barnum][offset].size() > 0) {
85 
86  value = std::get<1>(std::get<1>(trace_BARs[barnum][offset].front()));
87  DPRINTF(AMDGPUDevice, "Read MMIO %d\n", trace_cur_index);
88  DPRINTF(AMDGPUDevice, "Reading from trace with offset: %#x on BAR %#x"
89  ". Progress is: %#f\n", offset, barnum,
90  float(trace_cur_index)/float(trace_final_index));
91 
92  /* Leave at least one value for this offset. */
93  if (trace_BARs[barnum][offset].size() > 1) {
94  trace_BARs[barnum][offset].pop_front();
95  }
97  }
98 
99  // Write the read value to the packet
100  pkt->setUintX(value, ByteOrder::little);
101 }
102 
103 void
105 {
106  /* If the offset exists for this BAR, verify the value, otherwise 0. */
107  if (trace_BARs[barnum].count(offset) > 0 &&
108  trace_BARs[barnum][offset].size() > 0 &&
109  trace_cur_index == std::get<0>(trace_BARs[barnum][offset].front())) {
110 
111  DPRINTF(AMDGPUDevice, "Write matches trace with offset: %#x on "
112  "BAR %#x. Progress is: %#f\n", offset, barnum,
113  float(trace_cur_index)/float(trace_final_index));
114  trace_BARs[barnum][offset].pop_front();
115  trace_cur_index++;
116  }
117 }
118 
119 } // namespace gem5
gem5::AMDMMIOReader::MmioTrace::data
uint64_t data
Definition: mmio_reader.hh:113
gem5::AMDMMIOReader::mtrace
struct gem5::AMDMMIOReader::MmioTrace mtrace
gem5::AMDMMIOReader::isRelevant
bool isRelevant(std::vector< std::string > tokens)
Definition: mmio_reader.hh:145
gem5::AMDMMIOReader::trace_final_index
uint64_t trace_final_index
Definition: mmio_reader.hh:103
gem5::AMDMMIOReader::writeFromTrace
void writeFromTrace(PacketPtr pkt, int barnum, Addr offset)
Get the next MMIO write from the trace file to an offset in a BAR and compare the value with the data...
Definition: mmio_reader.cc:104
std::vector< std::string >
gem5::AMDMMIOReader::readMMIOTrace
void readMMIOTrace(std::string trace_file)
Read an MMIO trace gathered from a real system and place the MMIO values read and written into the MM...
Definition: mmio_reader.cc:46
gem5::AMDMMIOReader::MmioTrace::bar
uint16_t bar
Definition: mmio_reader.hh:111
gem5::scmi::token
token
Definition: scmi_platform.hh:80
gem5::AMDMMIOReader::MmioTrace::event
char event
Definition: mmio_reader.hh:109
gem5::AMDMMIOReader::trace_cur_index
uint64_t trace_cur_index
Definition: mmio_reader.hh:104
gem5::AMDMMIOReader::MmioTrace::size
uint16_t size
Definition: mmio_reader.hh:110
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:186
gem5::X86ISA::count
count
Definition: misc.hh:709
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:283
gem5::AMDMMIOReader::MmioTrace::addr
uint64_t addr
Definition: mmio_reader.hh:112
gem5::MipsISA::l
Bitfield< 5 > l
Definition: pra_constants.hh:323
gem5::ArmISA::offset
Bitfield< 23, 0 > offset
Definition: types.hh:144
gem5::AMDGPUDevice
Device model for an AMD GPU.
Definition: amdgpu_device.hh:65
gem5::AMDMMIOReader::traceIsRead
bool traceIsRead(std::vector< std::string > tokens) const
Definition: mmio_reader.hh:119
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::AMDMMIOReader::traceParseTokens
void traceParseTokens(std::vector< std::string > tokens)
Definition: mmio_reader.hh:185
packet_access.hh
gem5::AMDMMIOReader::trace_BARs
trace_BAR_t trace_BARs[6]
Definition: mmio_reader.hh:99
gem5::AMDMMIOReader::readFromTrace
void readFromTrace(PacketPtr pkt, int barnum, Addr offset)
Get the next MMIO read from the trace file to an offset in a BAR and write the value to the packet pr...
Definition: mmio_reader.cc:78
gem5::AMDMMIOReader::trace_index
uint64_t trace_index
Definition: mmio_reader.hh:102
trace.hh
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::Packet::setUintX
void setUintX(uint64_t w, ByteOrder endian)
Set the value in the word w after truncating it to the length of the packet and then byteswapping it ...
Definition: packet.cc:351
gem5::AMDMMIOReader::recordMtrace
void recordMtrace()
Definition: mmio_reader.hh:206
mmio_reader.hh

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