gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CacheRecorder.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1999-2012 Mark D. Hill and David A. Wood
3  * Copyright (c) 2010 Advanced Micro Devices, Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met: redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer;
10  * redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution;
13  * neither the name of the copyright holders nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
31 
32 #include "debug/RubyCacheTrace.hh"
35 
36 namespace gem5
37 {
38 
39 namespace ruby
40 {
41 
42 void
43 TraceRecord::print(std::ostream& out) const
44 {
45  out << "[TraceRecord: Node, " << m_cntrl_id << ", "
46  << m_data_address << ", " << m_pc_address << ", "
47  << m_type << ", Time: " << m_time << "]";
48 }
49 
51  : m_uncompressed_trace(NULL),
52  m_uncompressed_trace_size(0),
53  m_block_size_bytes(RubySystem::getBlockSizeBytes())
54 {
55 }
56 
57 CacheRecorder::CacheRecorder(uint8_t* uncompressed_trace,
58  uint64_t uncompressed_trace_size,
59  std::vector<Sequencer*>& seq_map,
60  uint64_t block_size_bytes)
61  : m_uncompressed_trace(uncompressed_trace),
62  m_uncompressed_trace_size(uncompressed_trace_size),
63  m_seq_map(seq_map), m_bytes_read(0), m_records_read(0),
64  m_records_flushed(0), m_block_size_bytes(block_size_bytes)
65 {
66  if (m_uncompressed_trace != NULL) {
68  // Block sizes larger than when the trace was recorded are not
69  // supported, as we cannot reliably turn accesses to smaller blocks
70  // into larger ones.
71  panic("Recorded cache block size (%d) < current block size (%d) !!",
73  }
74  }
75 }
76 
78 {
79  if (m_uncompressed_trace != NULL) {
80  delete [] m_uncompressed_trace;
81  m_uncompressed_trace = NULL;
82  }
83  m_seq_map.clear();
84 }
85 
86 void
88 {
89  if (m_records_flushed < m_records.size()) {
92  auto req = std::make_shared<Request>(rec->m_data_address,
95  MemCmd::Command requestType = MemCmd::FlushReq;
96  Packet *pkt = new Packet(req, requestType);
97 
98  Sequencer* m_sequencer_ptr = m_seq_map[rec->m_cntrl_id];
99  assert(m_sequencer_ptr != NULL);
100  m_sequencer_ptr->makeRequest(pkt);
101 
102  DPRINTF(RubyCacheTrace, "Flushing %s\n", *rec);
103  } else {
104  DPRINTF(RubyCacheTrace, "Flushed all %d records\n", m_records_flushed);
105  }
106 }
107 
108 void
110 {
112  TraceRecord* traceRecord = (TraceRecord*) (m_uncompressed_trace +
113  m_bytes_read);
114 
115  DPRINTF(RubyCacheTrace, "Issuing %s\n", *traceRecord);
116 
117  for (int rec_bytes_read = 0; rec_bytes_read < m_block_size_bytes;
118  rec_bytes_read += RubySystem::getBlockSizeBytes()) {
119  RequestPtr req;
120  MemCmd::Command requestType;
121 
122  if (traceRecord->m_type == RubyRequestType_LD) {
123  requestType = MemCmd::ReadReq;
124  req = std::make_shared<Request>(
125  traceRecord->m_data_address + rec_bytes_read,
128  } else if (traceRecord->m_type == RubyRequestType_IFETCH) {
129  requestType = MemCmd::ReadReq;
130  req = std::make_shared<Request>(
131  traceRecord->m_data_address + rec_bytes_read,
134  } else {
135  requestType = MemCmd::WriteReq;
136  req = std::make_shared<Request>(
137  traceRecord->m_data_address + rec_bytes_read,
140  }
141 
142  Packet *pkt = new Packet(req, requestType);
143  pkt->dataStatic(traceRecord->m_data + rec_bytes_read);
144 
145  Sequencer* m_sequencer_ptr = m_seq_map[traceRecord->m_cntrl_id];
146  assert(m_sequencer_ptr != NULL);
147  m_sequencer_ptr->makeRequest(pkt);
148  }
149 
151  m_records_read++;
152  } else {
153  DPRINTF(RubyCacheTrace, "Fetched all %d records\n", m_records_read);
154  }
155 }
156 
157 void
158 CacheRecorder::addRecord(int cntrl, Addr data_addr, Addr pc_addr,
159  RubyRequestType type, Tick time, DataBlock& data)
160 {
161  TraceRecord* rec = (TraceRecord*)malloc(sizeof(TraceRecord) +
163  rec->m_cntrl_id = cntrl;
164  rec->m_time = time;
165  rec->m_data_address = data_addr;
166  rec->m_pc_address = pc_addr;
167  rec->m_type = type;
168  memcpy(rec->m_data, data.getData(0, m_block_size_bytes),
170 
171  m_records.push_back(rec);
172 }
173 
174 uint64_t
175 CacheRecorder::aggregateRecords(uint8_t **buf, uint64_t total_size)
176 {
177  std::sort(m_records.begin(), m_records.end(), compareTraceRecords);
178 
179  int size = m_records.size();
180  uint64_t current_size = 0;
181  int record_size = sizeof(TraceRecord) + m_block_size_bytes;
182 
183  for (int i = 0; i < size; ++i) {
184  // Determine if we need to expand the buffer size
185  if (current_size + record_size > total_size) {
186  uint8_t* new_buf = new (std::nothrow) uint8_t[total_size * 2];
187  if (new_buf == NULL) {
188  fatal("Unable to allocate buffer of size %s\n",
189  total_size * 2);
190  }
191  total_size = total_size * 2;
192  uint8_t* old_buf = *buf;
193  memcpy(new_buf, old_buf, current_size);
194  *buf = new_buf;
195  delete [] old_buf;
196  }
197 
198  // Copy the current record into the buffer
199  memcpy(&((*buf)[current_size]), m_records[i], record_size);
200  current_size += record_size;
201 
202  free(m_records[i]);
203  m_records[i] = NULL;
204  }
205 
206  m_records.clear();
207  return current_size;
208 }
209 
210 uint64_t
212 {
213  return m_records.size();
214 }
215 
216 } // namespace ruby
217 } // namespace gem5
gem5::ruby::TraceRecord
Class for recording cache contents.
Definition: CacheRecorder.hh:60
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:200
gem5::Request::funcRequestorId
@ funcRequestorId
This requestor id is used for functional requests that don't come from a particular device.
Definition: request.hh:279
gem5::ruby::Sequencer
Definition: Sequencer.hh:86
gem5::ruby::CacheRecorder::m_records_flushed
uint64_t m_records_flushed
Definition: CacheRecorder.hh:120
data
const char data[]
Definition: circlebuf.test.cc:48
gem5::ruby::Sequencer::makeRequest
RequestStatus makeRequest(PacketPtr pkt) override
Definition: Sequencer.cc:754
gem5::ruby::CacheRecorder::m_seq_map
std::vector< Sequencer * > m_seq_map
Definition: CacheRecorder.hh:117
gem5::ruby::TraceRecord::m_data
uint8_t m_data[0]
Definition: CacheRecorder.hh:68
gem5::MemCmd::FlushReq
@ FlushReq
Definition: packet.hh:143
gem5::ruby::CacheRecorder::m_records
std::vector< TraceRecord * > m_records
Definition: CacheRecorder.hh:114
gem5::ruby::CacheRecorder::m_block_size_bytes
uint64_t m_block_size_bytes
Definition: CacheRecorder.hh:121
gem5::ruby::CacheRecorder::enqueueNextFlushRequest
void enqueueNextFlushRequest()
Function for flushing the memory contents of the caches to the main memory.
Definition: CacheRecorder.cc:87
gem5::MemCmd::Command
Command
List of all commands associated with a packet.
Definition: packet.hh:84
gem5::ruby::RubySystem::getBlockSizeBytes
static uint32_t getBlockSizeBytes()
Definition: RubySystem.hh:72
std::vector
STL vector class.
Definition: stl.hh:37
gem5::ruby::CacheRecorder::m_bytes_read
uint64_t m_bytes_read
Definition: CacheRecorder.hh:118
gem5::ruby::CacheRecorder::aggregateRecords
uint64_t aggregateRecords(uint8_t **data, uint64_t size)
Definition: CacheRecorder.cc:175
gem5::ruby::CacheRecorder::enqueueNextFetchRequest
void enqueueNextFetchRequest()
Function for fetching warming up the memory and the caches.
Definition: CacheRecorder.cc:109
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:67
gem5::ruby::TraceRecord::print
void print(std::ostream &out) const
Definition: CacheRecorder.cc:43
gem5::ruby::CacheRecorder::CacheRecorder
CacheRecorder()
Definition: CacheRecorder.cc:50
gem5::Packet::dataStatic
void dataStatic(T *p)
Set the data pointer to the following value that should not be freed.
Definition: packet.hh:1175
gem5::ruby::CacheRecorder::m_uncompressed_trace
uint8_t * m_uncompressed_trace
Definition: CacheRecorder.hh:115
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:210
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
gem5::ruby::TraceRecord::m_cntrl_id
int m_cntrl_id
Definition: CacheRecorder.hh:63
gem5::probing::Packet
ProbePointArg< PacketInfo > Packet
Packet probe point.
Definition: mem.hh:108
gem5::Tick
uint64_t Tick
Tick count type.
Definition: types.hh:58
gem5::X86ISA::type
type
Definition: misc.hh:734
gem5::ruby::CacheRecorder::getNumRecords
uint64_t getNumRecords() const
Definition: CacheRecorder.cc:211
gem5::RequestPtr
std::shared_ptr< Request > RequestPtr
Definition: request.hh:92
gem5::MemCmd::ReadReq
@ ReadReq
Definition: packet.hh:87
gem5::ruby::TraceRecord::m_time
Tick m_time
Definition: CacheRecorder.hh:64
gem5::ruby::TraceRecord::m_pc_address
Addr m_pc_address
Definition: CacheRecorder.hh:66
RubySystem.hh
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::ruby::TraceRecord::m_data_address
Addr m_data_address
Definition: CacheRecorder.hh:65
gem5::ruby::RubySystem
Definition: RubySystem.hh:63
gem5::ruby::CacheRecorder::addRecord
void addRecord(int cntrl, Addr data_addr, Addr pc_addr, RubyRequestType type, Tick time, DataBlock &data)
Definition: CacheRecorder.cc:158
gem5::ruby::TraceRecord::m_type
RubyRequestType m_type
Definition: CacheRecorder.hh:67
gem5::Request::INST_FETCH
@ INST_FETCH
The request was an instruction fetch.
Definition: request.hh:115
gem5::MemCmd::WriteReq
@ WriteReq
Definition: packet.hh:90
gem5::ruby::CacheRecorder::~CacheRecorder
~CacheRecorder()
Definition: CacheRecorder.cc:77
gem5::ruby::DataBlock
Definition: DataBlock.hh:60
CacheRecorder.hh
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::ruby::compareTraceRecords
bool compareTraceRecords(const TraceRecord *n1, const TraceRecord *n2)
Definition: CacheRecorder.hh:125
gem5::ruby::CacheRecorder::m_uncompressed_trace_size
uint64_t m_uncompressed_trace_size
Definition: CacheRecorder.hh:116
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:188
gem5::ruby::CacheRecorder::m_records_read
uint64_t m_records_read
Definition: CacheRecorder.hh:119
Sequencer.hh

Generated on Sun Jul 30 2023 01:56:59 for gem5 by doxygen 1.8.17