gem5 v24.1.0.1
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"
33#include "mem/packet.hh"
36#include "sim/sim_exit.hh"
37
38namespace gem5
39{
40
41namespace ruby
42{
43
44void
45TraceRecord::print(std::ostream& out) const
46{
47 out << "[TraceRecord: Node, " << m_cntrl_id << ", "
48 << m_data_address << ", " << m_pc_address << ", "
49 << m_type << ", Time: " << m_time << "]";
50}
51
52CacheRecorder::CacheRecorder(uint8_t* uncompressed_trace,
53 uint64_t uncompressed_trace_size,
54 std::vector<RubyPort*>& ruby_port_map,
55 uint64_t trace_block_size_bytes,
56 uint64_t system_block_size_bytes)
57 : m_uncompressed_trace(uncompressed_trace),
58 m_uncompressed_trace_size(uncompressed_trace_size),
59 m_ruby_port_map(ruby_port_map), m_bytes_read(0),
60 m_records_read(0), m_records_flushed(0),
61 m_block_size_bytes(trace_block_size_bytes)
62
63{
64 if (m_uncompressed_trace != NULL) {
65 if (m_block_size_bytes < system_block_size_bytes) {
66 // Block sizes larger than when the trace was recorded are not
67 // supported, as we cannot reliably turn accesses to smaller blocks
68 // into larger ones.
69 panic("Recorded cache block size (%d) < current block size (%d) !!",
70 m_block_size_bytes, system_block_size_bytes);
71 }
72 }
73}
74
76{
77 if (m_uncompressed_trace != NULL) {
78 delete [] m_uncompressed_trace;
80 }
81 m_ruby_port_map.clear();
82}
83
84void
86{
87 if (m_records_flushed < m_records.size()) {
90 auto req = std::make_shared<Request>(rec->m_data_address,
94 Packet *pkt = new Packet(req, requestType);
95 pkt->req->setReqInstSeqNum(m_records_flushed);
96
97
98 RubyPort* m_ruby_port_ptr = m_ruby_port_map[rec->m_cntrl_id];
99 assert(m_ruby_port_ptr != NULL);
100 m_ruby_port_ptr->makeRequest(pkt);
101
102 DPRINTF(RubyCacheTrace, "Flushing %s\n", *rec);
103
104 } else {
105 if (m_records_flushed > 0) {
106 exitSimLoop("Finished Drain", 0);
107 }
108 DPRINTF(RubyCacheTrace, "Flushed all %d records\n", m_records_flushed);
109 }
110}
111
112void
114{
116 TraceRecord* traceRecord = (TraceRecord*) (m_uncompressed_trace +
118
119 DPRINTF(RubyCacheTrace, "Issuing %s\n", *traceRecord);
120
121 for (int rec_bytes_read = 0; rec_bytes_read < m_block_size_bytes;
122 rec_bytes_read += m_block_size_bytes) {
123 RequestPtr req;
124 MemCmd::Command requestType;
125
126 if (traceRecord->m_type == RubyRequestType_LD) {
127 requestType = MemCmd::ReadReq;
128 req = std::make_shared<Request>(
129 traceRecord->m_data_address + rec_bytes_read,
132 } else if (traceRecord->m_type == RubyRequestType_IFETCH) {
133 requestType = MemCmd::ReadReq;
134 req = std::make_shared<Request>(
135 traceRecord->m_data_address + rec_bytes_read,
138 } else {
139 requestType = MemCmd::WriteReq;
140 req = std::make_shared<Request>(
141 traceRecord->m_data_address + rec_bytes_read,
144 }
145
146 Packet *pkt = new Packet(req, requestType);
147 pkt->dataStatic(traceRecord->m_data + rec_bytes_read);
148 pkt->req->setReqInstSeqNum(m_records_read);
149
150
151 RubyPort* m_ruby_port_ptr =
152 m_ruby_port_map[traceRecord->m_cntrl_id];
153 assert(m_ruby_port_ptr != NULL);
154 m_ruby_port_ptr->makeRequest(pkt);
155 }
156
159 } else {
160 exitSimLoop("Finished Warmup", 0);
161 DPRINTF(RubyCacheTrace, "Fetched all %d records\n", m_records_read);
162 }
163}
164
165void
166CacheRecorder::addRecord(int cntrl, Addr data_addr, Addr pc_addr,
167 RubyRequestType type, Tick time, DataBlock& data)
168{
169 TraceRecord* rec = (TraceRecord*)malloc(sizeof(TraceRecord) +
171 rec->m_cntrl_id = cntrl;
172 rec->m_time = time;
173 rec->m_data_address = data_addr;
174 rec->m_pc_address = pc_addr;
175 rec->m_type = type;
176 memcpy(rec->m_data, data.getData(0, m_block_size_bytes),
178
179 DPRINTF(RubyCacheTrace, "Inside addRecord with cntrl id %d and type %d\n",
180 cntrl, type);
181 m_records.push_back(rec);
182}
183
184uint64_t
185CacheRecorder::aggregateRecords(uint8_t **buf, uint64_t total_size)
186{
187 std::sort(m_records.begin(), m_records.end(), compareTraceRecords);
188
189 int size = m_records.size();
190 uint64_t current_size = 0;
191 int record_size = sizeof(TraceRecord) + m_block_size_bytes;
192
193 for (int i = 0; i < size; ++i) {
194 // Determine if we need to expand the buffer size
195 if (current_size + record_size > total_size) {
196 uint8_t* new_buf = new (std::nothrow) uint8_t[total_size * 2];
197 if (new_buf == NULL) {
198 fatal("Unable to allocate buffer of size %s\n",
199 total_size * 2);
200 }
201 total_size = total_size * 2;
202 uint8_t* old_buf = *buf;
203 memcpy(new_buf, old_buf, current_size);
204 *buf = new_buf;
205 delete [] old_buf;
206 }
207
208 // Copy the current record into the buffer
209 memcpy(&((*buf)[current_size]), m_records[i], record_size);
210 current_size += record_size;
211
212 free(m_records[i]);
213 m_records[i] = NULL;
214 }
215
216 m_records.clear();
217 return current_size;
218}
219
220uint64_t
222{
223 return m_records.size();
224}
225
226} // namespace ruby
227} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:209
const char data[]
Command
List of all commands associated with a packet.
Definition packet.hh:85
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
void dataStatic(T *p)
Set the data pointer to the following value that should not be freed.
Definition packet.hh:1175
RequestPtr req
A pointer to the original request.
Definition packet.hh:377
@ INST_FETCH
The request was an instruction fetch.
Definition request.hh:115
@ funcRequestorId
This requestor id is used for functional requests that don't come from a particular device.
Definition request.hh:282
uint64_t aggregateRecords(uint8_t **data, uint64_t size)
uint64_t getNumRecords() const
void addRecord(int cntrl, Addr data_addr, Addr pc_addr, RubyRequestType type, Tick time, DataBlock &data)
std::vector< TraceRecord * > m_records
void enqueueNextFetchRequest()
Function for fetching warming up the memory and the caches.
void enqueueNextFlushRequest()
Function for flushing the memory contents of the caches to the main memory.
std::vector< RubyPort * > m_ruby_port_map
virtual RequestStatus makeRequest(PacketPtr pkt)=0
Class for recording cache contents.
void print(std::ostream &out) const
STL vector class.
Definition stl.hh:37
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
#define fatal(...)
This implements a cprintf based fatal() function.
Definition logging.hh:200
Bitfield< 7 > i
Definition misc_types.hh:67
bool compareTraceRecords(const TraceRecord *n1, const TraceRecord *n2)
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
std::shared_ptr< Request > RequestPtr
Definition request.hh:94
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
uint64_t Tick
Tick count type.
Definition types.hh:58
void exitSimLoop(const std::string &message, int exit_code, Tick when, Tick repeat, bool serialize)
Schedule an event to exit the simulation loop (returning to Python) at the end of the current cycle (...
Definition sim_events.cc:88
Declaration of the Packet class.

Generated on Mon Jan 13 2025 04:28:41 for gem5 by doxygen 1.9.8