Skip to content

Commit

Permalink
tracer: Add initial version of a very basic tracer
Browse files Browse the repository at this point in the history
  • Loading branch information
thommythomaso committed Aug 11, 2022
1 parent dfd2361 commit fe3f305
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 0 deletions.
101 changes: 101 additions & 0 deletions src/include/idma/tracer.svh
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright 2022 ETH Zurich and University of Bologna.
// Solderpad Hardware License, Version 0.51, see LICENSE for details.
// SPDX-License-Identifier: SHL-0.51
//
// Thomas Benz <[email protected]>

// Macro holding all the resources for the iDMA backend tracer
`ifndef IDMA_TRACER_SVH_
`define IDMA_TRACER_SVH_

// largest type to trace
`define IDMA_TRACER_MAX_TYPE_WIDTH 1024
`define IDMA_TRACER_MAX_TYPE logic [`IDMA_TRACER_MAX_TYPE_WIDTH-1:0]

// string assembly function
`define IDMA_TRACER_STR_ASSEMBLY(__dict, __cond) \
if(__cond) begin \
trace = $sformatf("%s'%s':{", trace, `"__dict`"); \
foreach(__dict``[key]) trace = $sformatf("%s'%s': 0x%0x,", trace, key, __dict``[key]); \
trace = $sformatf("%s},", trace); \
end

// helper to clear a condition
`define IDMA_TRACER_CLEAR_COND(__cond) \
if(__cond) begin \
__cond = ~__cond; \
end

// The tracer for the iDMA
`define IDMA_TRACER(__backend_inst, __out_f_name) \
`ifndef SYNTHESYS \
`ifndef VERILATOR \
initial begin : inital_tracer \
automatic bit first_iter = 1; \
automatic integer tf; \
automatic `IDMA_TRACER_MAX_TYPE cnst [string]; \
automatic `IDMA_TRACER_MAX_TYPE meta [string]; \
automatic `IDMA_TRACER_MAX_TYPE busy [string]; \
automatic `IDMA_TRACER_MAX_TYPE axib [string]; \
automatic string trace; \
#0; \
tf = $fopen(__out_f_name, "w"); \
$display("[Tracer] Logging iDMA backend %s to %s", `"__backend_inst`", __out_f_name); \
forever begin \
@(posedge __backend_inst``.clk_i); \
if(__backend_inst``.rst_ni & |__backend_inst``.busy_o) begin \
/* Trace */ \
trace = "{"; \
/* Constants */ \
cnst = '{ \
"inst" : `"__backend_inst`", \
"data_width" : __backend_inst``.DataWidth, \
"addr_width" : __backend_inst``.AddrWidth, \
"user_width" : __backend_inst``.UserWidth, \
"axi_id_width" : __backend_inst``.AxiIdWidth, \
"num_ax_in_flight" : __backend_inst``.NumAxInFlight, \
"buffer_depth" : __backend_inst``.BufferDepth, \
"tf_len_width" : __backend_inst``.TFLenWidth, \
"mem_sys_depth" : __backend_inst``.MemSysDepth, \
"rw_coupling_avail" : __backend_inst``.RAWCouplingAvail, \
"mask_invalid_data" : __backend_inst``.MaskInvalidData, \
"hardware_legalizer" : __backend_inst``.HardwareLegalizer, \
"reject_zero_transfers" : __backend_inst``.RejectZeroTransfers, \
"error_cap" : __backend_inst``.ErrorCap, \
"print_fifo_info" : __backend_inst``.PrintFifoInfo \
}; \
meta = '{ \
"time" : $time() \
}; \
busy = '{ \
"buffer" : __backend_inst``.busy_o.buffer_busy, \
"r_dp" : __backend_inst``.busy_o.r_dp_busy, \
"w_dp" : __backend_inst``.busy_o.w_dp_busy, \
"r_leg" : __backend_inst``.busy_o.r_leg_busy, \
"w_leg" : __backend_inst``.busy_o.w_leg_busy, \
"eh_fsm" : __backend_inst``.busy_o.eh_fsm_busy, \
"eh_cnt" : __backend_inst``.busy_o.eh_cnt_busy, \
"raw_coupler" : __backend_inst``.busy_o.raw_coupler_busy \
}; \
axib = '{ \
"w_valid" : __backend_inst``.axi_req_o.w_valid, \
"w_ready" : __backend_inst``.axi_rsp_i.w_ready, \
"w_strb" : __backend_inst``.axi_req_o.w.strb, \
"r_valid" : __backend_inst``.axi_rsp_i.r_valid, \
"r_ready" : __backend_inst``.axi_req_o.r_ready \
}; \
/* Assembly */ \
`IDMA_TRACER_STR_ASSEMBLY(cnst, first_iter); \
`IDMA_TRACER_STR_ASSEMBLY(meta, 1); \
`IDMA_TRACER_STR_ASSEMBLY(busy, 1); \
`IDMA_TRACER_STR_ASSEMBLY(axib, 1); \
`IDMA_TRACER_CLEAR_COND(first_iter); \
/* Commit */ \
$fwrite(tf, $sformatf("%s}\n", trace)); \
end \
end \
end \
`endif \
`endif

`endif
7 changes: 7 additions & 0 deletions test/tb_idma_backend.sv
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
`timescale 1ns/1ns
`include "axi/typedef.svh"
`include "idma/typedef.svh"
`include "idma/tracer.svh"

module tb_idma_backend import idma_pkg::*; #(
parameter int unsigned BufferDepth = 3,
Expand Down Expand Up @@ -104,6 +105,12 @@ module tb_idma_backend import idma_pkg::*; #(
idma_busy_t busy;


//--------------------------------------
// DMA Tracer
//--------------------------------------
`IDMA_TRACER(i_idma_backend, "logs/idma_backend_trace.log");


//--------------------------------------
// DMA Driver
//--------------------------------------
Expand Down
31 changes: 31 additions & 0 deletions util/trace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python3
# Copyright 2022 ETH Zurich and University of Bologna.
# Solderpad Hardware License, Version 0.51, see LICENSE for details.
# SPDX-License-Identifier: SHL-0.51

# Author: Thomas Benz <[email protected]>

"""Functions used to parse and evaluate iDMA trace files."""
import ast
import sys
from pprint import pprint as pp


def trace_file (fn : str) -> list:
"""Reads a trace file and returns it as a list of dict objects"""

# resulting list of trace events
trace = []

# read and parse file
with open(fn, 'r', encoding='utf8') as tf:
for line in tf:
trace_dict = ast.literal_eval(line)
trace.append(trace_dict)

return trace


if __name__ == '__main__':
_, filename = sys.argv
pp(trace_file(filename))

0 comments on commit fe3f305

Please sign in to comment.