svinco Posted March 2, 2017 Report Share Posted March 2, 2017 Dear all, is it possible to apply standard SystemC tracing to tlm_extensions? I defined my own tlm extension to add a reset and a value fields to the standard payload: class reg_extension : public tlm::tlm_extension<reg_extension>{ public: reg_extension(); tlm::tlm_extension_base* clone() const ; void copy_from(tlm::tlm_extension_base const &); bool reset; sc_bv<16> value; }; Then, my testbench declares and uses it to carry data to/from the target: class testbench : public sc_module , public virtual tlm::tlm_bw_transport_if<> { public: tlm::tlm_initiator_socket<> initiator_socket; reg_extension * payload_data; ... } void testbench::run() { tlm::tlm_generic_payload * trans; sc_time time; mem = new mem_manager(); trans = mem->allocate(); payload_data = new reg_extension; payload_data->value = sc_bv<16>("00001111"); payload_data->reset = 1; trans->set_data_length(sizeof(register_data_t)); trans->set_auto_extension(payload_data); trans->set_address(0); trans->set_write(); initiator_socket->b_transport(*trans, time); ... } In my main, I try to apply standard tracing: int main(int argc, char* argv[]) { toplevel top("top"); sc_trace_file* fp = sc_create_vcd_trace_file("wave"); fp->set_time_unit(1, SC_NS); sc_trace(fp, top.tb.payload_data->reset, "reset" ); sc_trace(fp, top.tb.payload_data->value, "value" ); sc_start(); sc_close_vcd_trace_file(fp); return 0; } The code compiles correctly, but: with SystemC 2.2.0, the generated trace is weird (see attached - I truncated the value as it had far too many digits) things get worse when compiling with SystemC 2.3.0, as the execution returns this error: Quote Note: VCD trace timescale unit is set by user to 1.000000e-09 sec. terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc Aborted My impression is that memory is somehow not managed - this would explain the wrong size for the value field, the huge correponding value, and the bad_alloc. Please note that I forced some wait invocations to advance simulation time, so that write operations onto the extension fields occur at different simulation times. Thank you in advance, Regards, S. wave.vcd Quote Link to comment Share on other sites More sharing options...
Philipp A Hartmann Posted April 11, 2017 Report Share Posted April 11, 2017 Hi S., The biggest issue in your code is that you set up the tracing before you initialize the "payload_data" pointer. Nothing good can come out of this. Secondly, sc_trace requires stable memory locations to trace, as it stores a pointer internally. So you can't easily reallocate the extension over and over again (or even later than the sc_trace call). Instead, I would suggest to reuse the extension across transactions and move it to a plain member in the class (changes added below): On 02/03/2017 at 7:12 PM, svinco said: class testbench : public sc_module , public virtual tlm::tlm_bw_transport_if<> { public: tlm::tlm_initiator_socket<> initiator_socket; // reg_extension * payload_data; reg_extension payload_data; // <-- data member ... } void testbench::run() { tlm::tlm_generic_payload * trans; sc_time time; mem = new mem_manager(); trans = mem->allocate(); // payload_data = new reg_extension; // payload_data->value = sc_bv<16>("00001111"); // payload_data->reset = 1; payload_data.value = sc_bv<16>("00001111"); payload_data.reset = 1; trans->set_data_length(sizeof(register_data_t)); // trans->set_auto_extension(payload_data); trans->set_extension(&payload_data); trans->set_address(0); trans->set_write(); initiator_socket->b_transport(*trans, time); ... // unset extension (no cleanup as it is a member of the module) trans->clear_extension(&payload_data); } Hope that helps, Philipp Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.