gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
53 : m_uncompressed_trace(NULL),
54 m_uncompressed_trace_size(0),
55 m_block_size_bytes(RubySystem::getBlockSizeBytes())
56{
57}
58
59CacheRecorder::CacheRecorder(uint8_t* uncompressed_trace,
60 uint64_t uncompressed_trace_size,
61 std::vector<RubyPort*>& ruby_port_map,
62 uint64_t block_size_bytes)
63 : m_uncompressed_trace(uncompressed_trace),
64 m_uncompressed_trace_size(uncompressed_trace_size),
65 m_ruby_port_map(ruby_port_map), m_bytes_read(0),
66 m_records_read(0), m_records_flushed(0),
67 m_block_size_bytes(block_size_bytes)
68
69{
70 if (m_uncompressed_trace != NULL) {
72 // Block sizes larger than when the trace was recorded are not
73 // supported, as we cannot reliably turn accesses to smaller blocks
74 // into larger ones.
75 panic("Recorded cache block size (%d) < current block size (%d) !!",
77 }
78 }
79}
80
82{
83 if (m_uncompressed_trace != NULL) {
84 delete [] m_uncompressed_trace;
86 }
87 m_ruby_port_map.clear();
88}
89
90void
92{
93 if (m_records_flushed < m_records.size()) {
96 auto req = std::make_shared<Request>(rec->m_data_address,
100 Packet *pkt = new Packet(req, requestType);
101 pkt->req->setReqInstSeqNum(m_records_flushed);
102
103
104 RubyPort* m_ruby_port_ptr = m_ruby_port_map[rec->m_cntrl_id];
105 assert(m_ruby_port_ptr != NULL);
106 m_ruby_port_ptr->makeRequest(pkt);
107
108 DPRINTF(RubyCacheTrace, "Flushing %s\n", *rec);
109
110 } else {
111 if (m_records_flushed > 0) {
112 exitSimLoop("Finished Drain", 0);
113 }
114 DPRINTF(RubyCacheTrace, "Flushed all %d records\n", m_records_flushed);
115 }
116}
117
118void
120{
122 TraceRecord* traceRecord = (TraceRecord*) (m_uncompressed_trace +
124
125 DPRINTF(RubyCacheTrace, "Issuing %s\n", *traceRecord);
126
127 for (int rec_bytes_read = 0; rec_bytes_read < m_block_size_bytes;
128 rec_bytes_read += RubySystem::getBlockSizeBytes()) {
129 RequestPtr req;
130 MemCmd::Command requestType;
131
132 if (traceRecord->m_type == RubyRequestType_LD) {
133 requestType = MemCmd::ReadReq;
134 req = std::make_shared<Request>(
135 traceRecord->m_data_address + rec_bytes_read,
138 } else if (traceRecord->m_type == RubyRequestType_IFETCH) {
139 requestType = MemCmd::ReadReq;
140 req = std::make_shared<Request>(
141 traceRecord->m_data_address + rec_bytes_read,
144 } else {
145 requestType = MemCmd::WriteReq;
146 req = std::make_shared<Request>(
147 traceRecord->m_data_address + rec_bytes_read,
150 }
151
152 Packet *pkt = new Packet(req, requestType);
153 pkt->dataStatic(traceRecord->m_data + rec_bytes_read);
154 pkt->req->setReqInstSeqNum(m_records_read);
155
156
157 RubyPort* m_ruby_port_ptr =
158 m_ruby_port_map[traceRecord->m_cntrl_id];
159 assert(m_ruby_port_ptr != NULL);
160 m_ruby_port_ptr->makeRequest(pkt);
161 }
162
165 } else {
166 exitSimLoop("Finished Warmup", 0);
167 DPRINTF(RubyCacheTrace, "Fetched all %d records\n", m_records_read);
168 }
169}
170
171void
172CacheRecorder::addRecord(int cntrl, Addr data_addr, Addr pc_addr,
173 RubyRequestType type, Tick time, DataBlock& data)
174{
175 TraceRecord* rec = (TraceRecord*)malloc(sizeof(TraceRecord) +
177 rec->m_cntrl_id = cntrl;
178 rec->m_time = time;
179 rec->m_data_address = data_addr;
180 rec->m_pc_address = pc_addr;
181 rec->m_type = type;
182 memcpy(rec->m_data, data.getData(0, m_block_size_bytes),
184
185 DPRINTF(RubyCacheTrace, "Inside addRecord with cntrl id %d and type %d\n",
186 cntrl, type);
187 m_records.push_back(rec);
188}
189
190uint64_t
191CacheRecorder::aggregateRecords(uint8_t **buf, uint64_t total_size)
192{
193 std::sort(m_records.begin(), m_records.end(), compareTraceRecords);
194
195 int size = m_records.size();
196 uint64_t current_size = 0;
197 int record_size = sizeof(TraceRecord) + m_block_size_bytes;
198
199 for (int i = 0; i < size; ++i) {
200 // Determine if we need to expand the buffer size
201 if (current_size + record_size > total_size) {
202 uint8_t* new_buf = new (std::nothrow) uint8_t[total_size * 2];
203 if (new_buf == NULL) {
204 fatal("Unable to allocate buffer of size %s\n",
205 total_size * 2);
206 }
207 total_size = total_size * 2;
208 uint8_t* old_buf = *buf;
209 memcpy(new_buf, old_buf, current_size);
210 *buf = new_buf;
211 delete [] old_buf;
212 }
213
214 // Copy the current record into the buffer
215 memcpy(&((*buf)[current_size]), m_records[i], record_size);
216 current_size += record_size;
217
218 free(m_records[i]);
219 m_records[i] = NULL;
220 }
221
222 m_records.clear();
223 return current_size;
224}
225
226uint64_t
228{
229 return m_records.size();
230}
231
232} // namespace ruby
233} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:210
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:279
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
static uint32_t getBlockSizeBytes()
Definition RubySystem.hh:72
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 - Pranith Kumar Copyright (c) 2020 Inria 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 Tue Jun 18 2024 16:24:05 for gem5 by doxygen 1.11.0