gem5  v20.1.0.0
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 using namespace std;
37 
38 void
39 TraceRecord::print(ostream& out) const
40 {
41  out << "[TraceRecord: Node, " << m_cntrl_id << ", "
42  << m_data_address << ", " << m_pc_address << ", "
43  << m_type << ", Time: " << m_time << "]";
44 }
45 
47  : m_uncompressed_trace(NULL),
48  m_uncompressed_trace_size(0),
49  m_block_size_bytes(RubySystem::getBlockSizeBytes())
50 {
51 }
52 
53 CacheRecorder::CacheRecorder(uint8_t* uncompressed_trace,
54  uint64_t uncompressed_trace_size,
55  std::vector<Sequencer*>& seq_map,
56  uint64_t block_size_bytes)
57  : m_uncompressed_trace(uncompressed_trace),
58  m_uncompressed_trace_size(uncompressed_trace_size),
59  m_seq_map(seq_map), m_bytes_read(0), m_records_read(0),
60  m_records_flushed(0), m_block_size_bytes(block_size_bytes)
61 {
62  if (m_uncompressed_trace != NULL) {
64  // Block sizes larger than when the trace was recorded are not
65  // supported, as we cannot reliably turn accesses to smaller blocks
66  // into larger ones.
67  panic("Recorded cache block size (%d) < current block size (%d) !!",
69  }
70  }
71 }
72 
74 {
75  if (m_uncompressed_trace != NULL) {
76  delete [] m_uncompressed_trace;
77  m_uncompressed_trace = NULL;
78  }
79  m_seq_map.clear();
80 }
81 
82 void
84 {
85  if (m_records_flushed < m_records.size()) {
88  auto req = std::make_shared<Request>(rec->m_data_address,
91  MemCmd::Command requestType = MemCmd::FlushReq;
92  Packet *pkt = new Packet(req, requestType);
93 
94  Sequencer* m_sequencer_ptr = m_seq_map[rec->m_cntrl_id];
95  assert(m_sequencer_ptr != NULL);
96  m_sequencer_ptr->makeRequest(pkt);
97 
98  DPRINTF(RubyCacheTrace, "Flushing %s\n", *rec);
99  } else {
100  DPRINTF(RubyCacheTrace, "Flushed all %d records\n", m_records_flushed);
101  }
102 }
103 
104 void
106 {
108  TraceRecord* traceRecord = (TraceRecord*) (m_uncompressed_trace +
109  m_bytes_read);
110 
111  DPRINTF(RubyCacheTrace, "Issuing %s\n", *traceRecord);
112 
113  for (int rec_bytes_read = 0; rec_bytes_read < m_block_size_bytes;
114  rec_bytes_read += RubySystem::getBlockSizeBytes()) {
115  RequestPtr req;
116  MemCmd::Command requestType;
117 
118  if (traceRecord->m_type == RubyRequestType_LD) {
119  requestType = MemCmd::ReadReq;
120  req = std::make_shared<Request>(
121  traceRecord->m_data_address + rec_bytes_read,
124  } else if (traceRecord->m_type == RubyRequestType_IFETCH) {
125  requestType = MemCmd::ReadReq;
126  req = std::make_shared<Request>(
127  traceRecord->m_data_address + rec_bytes_read,
130  } else {
131  requestType = MemCmd::WriteReq;
132  req = std::make_shared<Request>(
133  traceRecord->m_data_address + rec_bytes_read,
136  }
137 
138  Packet *pkt = new Packet(req, requestType);
139  pkt->dataStatic(traceRecord->m_data + rec_bytes_read);
140 
141  Sequencer* m_sequencer_ptr = m_seq_map[traceRecord->m_cntrl_id];
142  assert(m_sequencer_ptr != NULL);
143  m_sequencer_ptr->makeRequest(pkt);
144  }
145 
147  m_records_read++;
148  } else {
149  DPRINTF(RubyCacheTrace, "Fetched all %d records\n", m_records_read);
150  }
151 }
152 
153 void
154 CacheRecorder::addRecord(int cntrl, Addr data_addr, Addr pc_addr,
155  RubyRequestType type, Tick time, DataBlock& data)
156 {
157  TraceRecord* rec = (TraceRecord*)malloc(sizeof(TraceRecord) +
159  rec->m_cntrl_id = cntrl;
160  rec->m_time = time;
161  rec->m_data_address = data_addr;
162  rec->m_pc_address = pc_addr;
163  rec->m_type = type;
164  memcpy(rec->m_data, data.getData(0, m_block_size_bytes),
166 
167  m_records.push_back(rec);
168 }
169 
170 uint64_t
171 CacheRecorder::aggregateRecords(uint8_t **buf, uint64_t total_size)
172 {
173  std::sort(m_records.begin(), m_records.end(), compareTraceRecords);
174 
175  int size = m_records.size();
176  uint64_t current_size = 0;
177  int record_size = sizeof(TraceRecord) + m_block_size_bytes;
178 
179  for (int i = 0; i < size; ++i) {
180  // Determine if we need to expand the buffer size
181  if (current_size + record_size > total_size) {
182  uint8_t* new_buf = new (nothrow) uint8_t[total_size * 2];
183  if (new_buf == NULL) {
184  fatal("Unable to allocate buffer of size %s\n",
185  total_size * 2);
186  }
187  total_size = total_size * 2;
188  uint8_t* old_buf = *buf;
189  memcpy(new_buf, old_buf, current_size);
190  *buf = new_buf;
191  delete [] old_buf;
192  }
193 
194  // Copy the current record into the buffer
195  memcpy(&((*buf)[current_size]), m_records[i], record_size);
196  current_size += record_size;
197 
198  free(m_records[i]);
199  m_records[i] = NULL;
200  }
201 
202  m_records.clear();
203  return current_size;
204 }
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:183
CacheRecorder::aggregateRecords
uint64_t aggregateRecords(uint8_t **data, uint64_t size)
Definition: CacheRecorder.cc:171
TraceRecord::m_data
uint8_t m_data[0]
Definition: CacheRecorder.hh:61
RubySystem::getBlockSizeBytes
static uint32_t getBlockSizeBytes()
Definition: RubySystem.hh:62
data
const char data[]
Definition: circlebuf.test.cc:42
Sequencer
Definition: Sequencer.hh:80
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
CacheRecorder::enqueueNextFetchRequest
void enqueueNextFetchRequest()
Function for fetching warming up the memory and the caches.
Definition: CacheRecorder.cc:105
CacheRecorder::enqueueNextFlushRequest
void enqueueNextFlushRequest()
Function for flushing the memory contents of the caches to the main memory.
Definition: CacheRecorder.cc:83
CacheRecorder::m_records_read
uint64_t m_records_read
Definition: CacheRecorder.hh:110
TraceRecord::m_time
Tick m_time
Definition: CacheRecorder.hh:57
type
uint8_t type
Definition: inet.hh:421
MemCmd::ReadReq
@ ReadReq
Definition: packet.hh:82
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
CacheRecorder::m_uncompressed_trace
uint8_t * m_uncompressed_trace
Definition: CacheRecorder.hh:106
MemCmd::FlushReq
@ FlushReq
Definition: packet.hh:132
TraceRecord::m_data_address
Addr m_data_address
Definition: CacheRecorder.hh:58
RequestPtr
std::shared_ptr< Request > RequestPtr
Definition: request.hh:82
Sequencer::makeRequest
RequestStatus makeRequest(PacketPtr pkt) override
Definition: Sequencer.cc:578
std::vector< Sequencer * >
CacheRecorder::CacheRecorder
CacheRecorder()
Definition: CacheRecorder.cc:46
CacheRecorder::addRecord
void addRecord(int cntrl, Addr data_addr, Addr pc_addr, RubyRequestType type, Tick time, DataBlock &data)
Definition: CacheRecorder.cc:154
TraceRecord::m_cntrl_id
int m_cntrl_id
Definition: CacheRecorder.hh:56
Request::INST_FETCH
@ INST_FETCH
The request was an instruction fetch.
Definition: request.hh:104
CacheRecorder::m_block_size_bytes
uint64_t m_block_size_bytes
Definition: CacheRecorder.hh:112
DataBlock
Definition: DataBlock.hh:40
CacheRecorder::m_uncompressed_trace_size
uint64_t m_uncompressed_trace_size
Definition: CacheRecorder.hh:107
MemCmd::Command
Command
List of all commands associated with a packet.
Definition: packet.hh:79
MemCmd::WriteReq
@ WriteReq
Definition: packet.hh:85
compareTraceRecords
bool compareTraceRecords(const TraceRecord *n1, const TraceRecord *n2)
Definition: CacheRecorder.hh:116
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
RubySystem
Definition: RubySystem.hh:52
CacheRecorder::m_records
std::vector< TraceRecord * > m_records
Definition: CacheRecorder.hh:105
CacheRecorder::m_records_flushed
uint64_t m_records_flushed
Definition: CacheRecorder.hh:111
TraceRecord::m_type
RubyRequestType m_type
Definition: CacheRecorder.hh:60
CacheRecorder::m_bytes_read
uint64_t m_bytes_read
Definition: CacheRecorder.hh:109
TraceRecord::m_pc_address
Addr m_pc_address
Definition: CacheRecorder.hh:59
RubySystem.hh
ProbePoints::Packet
ProbePointArg< PacketInfo > Packet
Packet probe point.
Definition: mem.hh:103
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
CacheRecorder::m_seq_map
std::vector< Sequencer * > m_seq_map
Definition: CacheRecorder.hh:108
TraceRecord::print
void print(std::ostream &out) const
Definition: CacheRecorder.cc:39
Request::funcRequestorId
@ funcRequestorId
This requestor id is used for functional requests that don't come from a particular device.
Definition: request.hh:248
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
Packet::dataStatic
void dataStatic(T *p)
Set the data pointer to the following value that should not be freed.
Definition: packet.hh:1107
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:257
CacheRecorder::~CacheRecorder
~CacheRecorder()
Definition: CacheRecorder.cc:73
TraceRecord
Class for recording cache contents.
Definition: CacheRecorder.hh:54
CacheRecorder.hh
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171
Sequencer.hh

Generated on Wed Sep 30 2020 14:02:13 for gem5 by doxygen 1.8.17