gem5  v22.0.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  * 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 <fstream>
35 
36 #include "base/trace.hh"
37 #include "debug/AMDGPUDevice.hh"
38 #include "mem/packet_access.hh"
39 
40 namespace gem5
41 {
42 
43 void
44 AMDMMIOReader::readMMIOTrace(std::string trace_file)
45 {
46  std::ifstream tracefile(trace_file);
47  std::string line, token;
48 
49  mtrace.event = 0;
50  mtrace.size = 0;
51  mtrace.bar = 0;
52  mtrace.addr = 0;
53  mtrace.data = 0;
54 
55  trace_index = 0;
56 
57  while (std::getline(tracefile, line)) {
58  std::stringstream l(line);
60 
61  while (std::getline(l, token, ' '))
62  tokens.push_back(token);
63 
64  if (traceIsRead(tokens) && isRelevant(tokens)) {
65  traceParseTokens(tokens);
67  recordMtrace();
68  }
69  }
70  }
71 
73 }
74 
75 void
77 {
78  uint64_t value = 0;
79 
80  /* If the offset exists for this BAR, return the value, otherwise 0. */
81  if (trace_BARs[barnum].count(offset) > 0 &&
82  trace_BARs[barnum][offset].size() > 0) {
83 
84  value = std::get<1>(std::get<1>(trace_BARs[barnum][offset].front()));
85  DPRINTF(AMDGPUDevice, "Read MMIO %d\n", trace_cur_index);
86  DPRINTF(AMDGPUDevice, "Reading from trace with offset: %#x on BAR %#x"
87  ". Progress is: %#f\n", offset, barnum,
88  float(trace_cur_index)/float(trace_final_index));
89 
90  /* Leave at least one value for this offset. */
91  if (trace_BARs[barnum][offset].size() > 1) {
92  trace_BARs[barnum][offset].pop_front();
93  }
95  }
96 
97  // Write the read value to the packet
98  pkt->setUintX(value, ByteOrder::little);
99 }
100 
101 void
103 {
104  /* If the offset exists for this BAR, verify the value, otherwise 0. */
105  if (trace_BARs[barnum].count(offset) > 0 &&
106  trace_BARs[barnum][offset].size() > 0 &&
107  trace_cur_index == std::get<0>(trace_BARs[barnum][offset].front())) {
108 
109  DPRINTF(AMDGPUDevice, "Write matches trace with offset: %#x on "
110  "BAR %#x. Progress is: %#f\n", offset, barnum,
111  float(trace_cur_index)/float(trace_final_index));
112  trace_BARs[barnum][offset].pop_front();
113  trace_cur_index++;
114  }
115 }
116 
117 } // namespace gem5
gem5::AMDMMIOReader::MmioTrace::data
uint64_t data
Definition: mmio_reader.hh:111
gem5::AMDMMIOReader::mtrace
struct gem5::AMDMMIOReader::MmioTrace mtrace
gem5::AMDMMIOReader::isRelevant
bool isRelevant(std::vector< std::string > tokens)
Definition: mmio_reader.hh:143
gem5::AMDMMIOReader::trace_final_index
uint64_t trace_final_index
Definition: mmio_reader.hh:101
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:102
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:44
gem5::AMDMMIOReader::MmioTrace::bar
uint16_t bar
Definition: mmio_reader.hh:109
gem5::scmi::token
token
Definition: scmi_platform.hh:81
gem5::AMDMMIOReader::MmioTrace::event
char event
Definition: mmio_reader.hh:107
gem5::AMDMMIOReader::trace_cur_index
uint64_t trace_cur_index
Definition: mmio_reader.hh:102
gem5::AMDMMIOReader::MmioTrace::size
uint16_t size
Definition: mmio_reader.hh:108
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:186
gem5::X86ISA::count
count
Definition: misc.hh:703
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:291
gem5::AMDMMIOReader::MmioTrace::addr
uint64_t addr
Definition: mmio_reader.hh:110
gem5::ArmISA::offset
Bitfield< 23, 0 > offset
Definition: types.hh:144
gem5::AMDGPUDevice
Device model for an AMD GPU.
Definition: amdgpu_device.hh:60
gem5::AMDMMIOReader::traceIsRead
bool traceIsRead(std::vector< std::string > tokens) const
Definition: mmio_reader.hh:117
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:183
packet_access.hh
gem5::AMDMMIOReader::trace_BARs
trace_BAR_t trace_BARs[6]
Definition: mmio_reader.hh:97
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:76
gem5::VegaISA::l
Bitfield< 55 > l
Definition: pagetable.hh:54
gem5::AMDMMIOReader::trace_index
uint64_t trace_index
Definition: mmio_reader.hh:100
trace.hh
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
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:357
gem5::AMDMMIOReader::recordMtrace
void recordMtrace()
Definition: mmio_reader.hh:204
mmio_reader.hh

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