Reformat MemTraceReader
This commit is contained in:
@@ -63,8 +63,7 @@ void MemTraceReader::parse() {
|
|||||||
// Try to read a memory request that might have happened at a given cycle, on a
|
// Try to read a memory request that might have happened at a given cycle, on a
|
||||||
// given SIMD lane (= "thread"). In case no request happened at that point,
|
// given SIMD lane (= "thread"). In case no request happened at that point,
|
||||||
// return an empty line with .valid = false.
|
// return an empty line with .valid = false.
|
||||||
MemTraceLine MemTraceReader::read_trace_at(const long cycle,
|
MemTraceLine MemTraceReader::read_trace_at(const long cycle, const int lane_id,
|
||||||
const int lane_id,
|
|
||||||
unsigned char trace_read_ready) {
|
unsigned char trace_read_ready) {
|
||||||
MemTraceLine line;
|
MemTraceLine line;
|
||||||
line.valid = false;
|
line.valid = false;
|
||||||
@@ -79,43 +78,39 @@ MemTraceLine MemTraceReader::read_trace_at(const long cycle,
|
|||||||
// It should always be guaranteed that we consumed all of the past lines, and
|
// It should always be guaranteed that we consumed all of the past lines, and
|
||||||
// the next line is in the future.
|
// the next line is in the future.
|
||||||
if (line.cycle < cycle) {
|
if (line.cycle < cycle) {
|
||||||
// fprintf(stderr, "line.cycle=%ld, cycle=%ld\n", line.cycle, cycle);
|
|
||||||
printf("cycle=%ld, some lines are left in past Fatal", cycle);
|
printf("cycle=%ld, some lines are left in past Fatal", cycle);
|
||||||
assert(false && "some trace lines are left unread in the past");
|
assert(false && "some trace lines are left unread in the past");
|
||||||
return MemTraceLine{};
|
return MemTraceLine{};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.lane_id != lane_id) {
|
|
||||||
line.valid = false;
|
|
||||||
}
|
|
||||||
if (line.cycle > cycle) {
|
if (line.cycle > cycle) {
|
||||||
// We haven't reached the cycle mark specified in this line yet, so we don't
|
// We haven't reached the cycle mark specified in this line yet, so we don't
|
||||||
// read it right now.
|
// read it right now.
|
||||||
return MemTraceLine{};
|
return MemTraceLine{};
|
||||||
|
} else if (line.lane_id != lane_id) {
|
||||||
|
return MemTraceLine{};
|
||||||
} else if (line.cycle == cycle && line.lane_id == lane_id) {
|
} else if (line.cycle == cycle && line.lane_id == lane_id) {
|
||||||
|
|
||||||
if (trace_read_ready){
|
if (trace_read_ready) {
|
||||||
printf("Fire! cycle=%ld, valid=%d, %s addr=%lx, size=%d \n", cycle,
|
printf("Fire! cycle=%ld, valid=%d, %s addr=%lx, size=%d \n", cycle,
|
||||||
line.valid, (line.is_store ? "STORE" : "LOAD"), line.address,
|
line.valid, (line.is_store ? "STORE" : "LOAD"), line.address,
|
||||||
line.log_data_size);
|
line.log_data_size);
|
||||||
|
|
||||||
// FIXME! Currently lane_id is assumed to be in round-robin order, e.g.
|
// NOTE: Currently lane_id is assumed to be in always-increasing order,
|
||||||
// 0->1->2->3->0->..., both in the trace file and the order the caller calls
|
// e.g. 0->1->2->3->0->..., both in the trace file and the order the
|
||||||
// this function. If this is not true, we cannot simply monotonically
|
// caller calls this function. If this is not true, we cannot simply
|
||||||
// increment read_pos.
|
// monotonically increment read_pos. lane_id need not be contiguous, e.g.
|
||||||
// Only advance pointer when cycle and threa_id both match
|
// 0->1->3 is fine.
|
||||||
// now increaseing sequence is fine (0, 1, 3), but unordered is not fine (0, 3, 1)
|
|
||||||
++read_pos;
|
++read_pos;
|
||||||
}
|
} else { // we do not want to advance read_pos
|
||||||
else { // we do not want to advance read_pos
|
|
||||||
printf("All Lanes Blocked on this cycle! cycle=%ld \n", cycle);
|
printf("All Lanes Blocked on this cycle! cycle=%ld \n", cycle);
|
||||||
}
|
}
|
||||||
|
|
||||||
return line;
|
return line;
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(!"unreachable");
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" void memtrace_init(const char *filename) {
|
extern "C" void memtrace_init(const char *filename) {
|
||||||
#ifndef NO_VPI
|
#ifndef NO_VPI
|
||||||
@@ -155,13 +150,6 @@ extern "C" void memtrace_query(unsigned char trace_read_ready,
|
|||||||
// printf("memtrace_query(cycle=%ld, tid=%d)\n", trace_read_cycle,
|
// printf("memtrace_query(cycle=%ld, tid=%d)\n", trace_read_cycle,
|
||||||
// trace_read_lane_id);
|
// trace_read_lane_id);
|
||||||
|
|
||||||
/* we can't return immediately, even if trace is ready, we still want to find out
|
|
||||||
if we are suppose to generate valid req on this clock cycle
|
|
||||||
if (!trace_read_ready) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
auto line = reader->read_trace_at(trace_read_cycle, trace_read_lane_id, trace_read_ready);
|
auto line = reader->read_trace_at(trace_read_cycle, trace_read_lane_id, trace_read_ready);
|
||||||
*trace_read_valid = line.valid;
|
*trace_read_valid = line.valid;
|
||||||
*trace_read_address = line.address;
|
*trace_read_address = line.address;
|
||||||
|
|||||||
@@ -102,7 +102,8 @@ extern "C" void memtracelogger_log(int handle,
|
|||||||
.data = trace_log_data,
|
.data = trace_log_data,
|
||||||
.log_data_size = trace_log_size};
|
.log_data_size = trace_log_size};
|
||||||
|
|
||||||
assert(0 <= handle && handle < loggers.size() && "wrong trace logger handle");
|
assert(0 <= handle && static_cast<size_t>(handle) < loggers.size() &&
|
||||||
|
"wrong trace logger handle");
|
||||||
auto logger = loggers[handle].get();
|
auto logger = loggers[handle].get();
|
||||||
logger->write_line_to_trace(line);
|
logger->write_line_to_trace(line);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user