gem5  v21.1.0.2
mmio_reader.hh
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 
34 #ifndef __DEV_AMDGPU_MMIO_READER_HH__
35 #define __DEV_AMDGPU_MMIO_READER_HH__
36 
37 #include <cstdint>
38 #include <list>
39 #include <string>
40 #include <tuple>
41 #include <unordered_map>
42 #include <vector>
43 
44 #include "base/logging.hh"
45 #include "mem/packet.hh"
46 
47 namespace gem5
48 {
49 
65 {
66  private:
72  const uint64_t BAR0 = 0x2400000000;
73  const uint64_t BAR2 = 0x2200000000;
74  const uint32_t BAR5 = 0xecf00000;
75  const uint32_t ROM = 0xc0000;
76 
77  /* Sizes based on Vega Frontier Edition */
78  const uint64_t BAR0_SIZE = 0x400000000; // 16GB
79  const uint64_t BAR2_SIZE = 0x200000; // 2MB
80  const uint32_t BAR5_SIZE = 0x80000; // 512kB
81  const uint32_t ROM_SIZE = 0x20000; // 128kB
82 
92  /* trace_entry containing (3), (4), and (5). */
93  typedef std::tuple<uint64_t, std::tuple<char, uint64_t>> trace_entry_t;
94 
95  /* Trace entries are recorded as a list for each offset in a given BAR. */
96  typedef std::unordered_map<uint32_t, std::list<trace_entry_t>> trace_BAR_t;
97 
98  /* There are 7 BARs (BAR0-BAR5 + expansion ROM) */
100 
101  /* Indexes used to print driver loading progress. */
102  uint64_t trace_index;
104  uint64_t trace_cur_index;
105 
106  /* An entry in the MMIO trace. */
107  struct MmioTrace
108  {
109  char event;
110  uint16_t size;
111  uint16_t bar;
112  uint64_t addr;
113  uint64_t data;
114  uint64_t index;
115  } mtrace;
116 
117  /* Lines in the MMIO trace we care about begin with R, W, or UNKNOWN. */
118  bool
120  {
121  return tokens[0] == "R";
122  }
123 
124  bool
126  {
127  return tokens[0] == "W";
128  }
129 
130  bool
132  {
133  return tokens[0] == "UNKNOWN";
134  }
135 
136  /* Checks if this line of trace is W/R/UNKNOWN */
137  bool
139  {
140  return tokens[0] == "R" || tokens[0] == "W" || tokens[0] == "UNKNOWN";
141  }
142 
143  /* Checks if this line of trace is in a BAR we care about (0, 2, 5) */
144  bool
146  {
147  uint64_t addr = strtoull(tokens[4].c_str(), nullptr, 16);
148  uint16_t bar = traceGetBAR(addr);
149  return (bar == 0 || bar == 2 || bar == 5);
150  }
151 
152  uint8_t
153  traceGetBAR(uint64_t addr)
154  {
155  if (BAR0 <= addr && addr < (BAR0 + BAR0_SIZE)) {
156  return 0;
157  } else if (BAR2 <= addr && addr < (BAR2 + BAR2_SIZE)) {
158  return 2;
159  } else if (BAR5 <= addr && addr < (BAR5 + BAR5_SIZE)) {
160  return 5;
161  } else if (ROM <= addr && addr < (ROM + ROM_SIZE)) {
162  return 6;
163  } else {
164  return -1;
165  }
166  }
167 
168  uint64_t
170  {
171  if (addr >= BAR0 && addr < (BAR0 + BAR0_SIZE)) {
172  return addr - BAR0;
173  } else if (addr >= BAR2 && addr < (BAR2 + BAR2_SIZE)) {
174  return addr - BAR2;
175  } else if (addr >= BAR5 && addr < (BAR5 + BAR5_SIZE)) {
176  return addr - BAR5;
177  } else if (addr >= ROM && addr < (ROM + ROM_SIZE)) {
178  return addr - ROM;
179  } else {
180  panic("Can't find offset for the address in MMIO trace!");
181  }
182  }
183 
184  void
186  {
187  if (traceIsRead(tokens) || traceIsWrite(tokens)) {
188  mtrace.event = traceIsRead(tokens) ? 'R' : 'W';
189  mtrace.size = strtoul(tokens[1].c_str(), nullptr, 10);
190  mtrace.addr = strtoull(tokens[4].c_str(), nullptr, 16);
191  mtrace.data = strtoull(tokens[5].c_str(), nullptr, 16);
192  }
193  else if (traceIsUnknown(tokens)) {
194  mtrace.event = 'U';
195  mtrace.size = 0;
196  mtrace.addr = strtoull(tokens[3].c_str(), nullptr, 16);
197  mtrace.data = 0;
198  }
200 
202  trace_index++;
203  }
204 
205  void
207  {
208  trace_entry_t trace_entry;
209  trace_entry = std::make_tuple(mtrace.index,
210  std::make_tuple(mtrace.event, mtrace.data));
211 
212  uint16_t barnum = mtrace.bar;
213  uint64_t offset = traceGetOffset(mtrace.addr);
214 
215  trace_BARs[barnum][offset].push_back(trace_entry);
216  }
217 
218  public:
221 
228  void readMMIOTrace(std::string trace_file);
229 
238  void readFromTrace(PacketPtr pkt, int barnum, Addr offset);
239 
249  void writeFromTrace(PacketPtr pkt, int barnum, Addr offset);
250 };
251 
252 } // namespace gem5
253 
254 #endif // __DEV_AMDGPU_MMIO_READER_HH__
gem5::AMDMMIOReader::MmioTrace::data
uint64_t data
Definition: mmio_reader.hh:113
gem5::AMDMMIOReader::~AMDMMIOReader
~AMDMMIOReader()
Definition: mmio_reader.hh:220
gem5::AMDMMIOReader::ROM
const uint32_t ROM
Definition: mmio_reader.hh:75
gem5::AMDMMIOReader::trace_BAR_t
std::unordered_map< uint32_t, std::list< trace_entry_t > > trace_BAR_t
Definition: mmio_reader.hh:96
gem5::AMDMMIOReader::mtrace
struct gem5::AMDMMIOReader::MmioTrace mtrace
gem5::AMDMMIOReader::BAR2
const uint64_t BAR2
Definition: mmio_reader.hh:73
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::MmioTrace
Definition: mmio_reader.hh:107
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
gem5::AMDMMIOReader::BAR5_SIZE
const uint32_t BAR5_SIZE
Definition: mmio_reader.hh:80
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::AMDMMIOReader::traceIsUnknown
bool traceIsUnknown(std::vector< std::string > tokens) const
Definition: mmio_reader.hh:131
packet.hh
gem5::AMDMMIOReader::MmioTrace::event
char event
Definition: mmio_reader.hh:109
gem5::AMDMMIOReader::BAR0_SIZE
const uint64_t BAR0_SIZE
Definition: mmio_reader.hh:78
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
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::AMDMMIOReader::isIO
bool isIO(std::vector< std::string > tokens) const
Definition: mmio_reader.hh:138
gem5::ArmISA::offset
Bitfield< 23, 0 > offset
Definition: types.hh:144
gem5::AMDMMIOReader::traceIsRead
bool traceIsRead(std::vector< std::string > tokens) const
Definition: mmio_reader.hh:119
gem5::AMDMMIOReader
Helper class to read Linux kernel MMIO trace from amdgpu modprobes.
Definition: mmio_reader.hh:64
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
gem5::AMDMMIOReader::BAR2_SIZE
const uint64_t BAR2_SIZE
Definition: mmio_reader.hh:79
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::AMDMMIOReader
AMDMMIOReader()
Definition: mmio_reader.hh:219
gem5::AMDMMIOReader::MmioTrace::index
uint64_t index
Definition: mmio_reader.hh:114
logging.hh
gem5::AMDMMIOReader::trace_index
uint64_t trace_index
Definition: mmio_reader.hh:102
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::AMDMMIOReader::BAR0
const uint64_t BAR0
These are the BAR values from the system where the trace is collected.
Definition: mmio_reader.hh:72
gem5::AMDMMIOReader::traceIsWrite
bool traceIsWrite(std::vector< std::string > tokens) const
Definition: mmio_reader.hh:125
gem5::AMDMMIOReader::ROM_SIZE
const uint32_t ROM_SIZE
Definition: mmio_reader.hh:81
gem5::AMDMMIOReader::trace_entry_t
std::tuple< uint64_t, std::tuple< char, uint64_t > > trace_entry_t
The information we want from each relevant line of trace are: (1) The BAR number where the accessed a...
Definition: mmio_reader.hh:93
gem5::AMDMMIOReader::traceGetOffset
uint64_t traceGetOffset(uint64_t addr)
Definition: mmio_reader.hh:169
gem5::AMDMMIOReader::traceGetBAR
uint8_t traceGetBAR(uint64_t addr)
Definition: mmio_reader.hh:153
gem5::AMDMMIOReader::recordMtrace
void recordMtrace()
Definition: mmio_reader.hh:206
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:177
gem5::X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:84
gem5::AMDMMIOReader::BAR5
const uint32_t BAR5
Definition: mmio_reader.hh:74

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