gem5  v22.1.0.0
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
#define DPRINTF(x,...)
Definition: trace.hh:186
Device model for an AMD GPU.
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
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
uint64_t trace_cur_index
Definition: mmio_reader.hh:102
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
trace_BAR_t trace_BARs[6]
Definition: mmio_reader.hh:97
bool isRelevant(std::vector< std::string > tokens)
Definition: mmio_reader.hh:143
bool traceIsRead(std::vector< std::string > tokens) const
Definition: mmio_reader.hh:117
void traceParseTokens(std::vector< std::string > tokens)
Definition: mmio_reader.hh:183
uint64_t trace_final_index
Definition: mmio_reader.hh:101
struct gem5::AMDMMIOReader::MmioTrace mtrace
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
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:361
Bitfield< 23, 0 > offset
Definition: types.hh:144
Bitfield< 55 > l
Definition: pagetable.hh:54
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147

Generated on Wed Dec 21 2022 10:22:32 for gem5 by doxygen 1.9.1