Jump to content

Is there any way to quickly find where a systemc program hanged at? Usually happened in fifo read or write, but can't know which fifo is full or empty.


Recommended Posts

Posted
As shown below, when a large system contain too much fifo read and write and thread, it's hard to find where the simulation hanged at.
Is there any way to quickly find the hang?
void xx_b_transport(int id, xx_struct_t &t, sc_time &delay)
{
     reg_fifo.write(t);
}

 

Posted

Use GDB and set breakpoints liberally.

Or:

  1. set SC_REPORT_INFO to include SC_INTERRUPT
  2. scatter SC_REPORT_INFO_VERB into your code describing what's about to happen with a verbosity of SC_DEBUG
  3. set verbosity to SC_DEBUG
  4. use GDB and set one breakpoint on sc_interrupt

You can also derive a "debug_fifo" from "sc_fifo" and add functionality to monitor reads and writes. Perhaps put a timeout on the wait and issue periodic messages as time progresses from waiting reads and writes.

Posted

Hi David, thanks for the reply, but I do not quite understand,

below is an example, I comment all fifo write, then the FIFO read should be blocked, how can know this without using cout?

another issue is, where to set the breakpoint. I didn't find the related code.

  1. use GDB and set one breakpoint on sc_interrupt

#include <systemc>
using namespace sc_core;

SC_MODULE(FIFO) {
  sc_fifo<int> f1, f2, f3;
  SC_CTOR(FIFO) : f1(2), f2(2), f3(2) {  // fifo with size 2
    SC_THREAD(generator1);
    SC_THREAD(consumer1);

    SC_THREAD(generator2);
    SC_THREAD(consumer2);

    SC_THREAD(generator3);
    SC_THREAD(consumer3);
  }
  void generator1() {  // blocking write
    int v = 0;
    while (true) {
      //   f1.write(v); // same as f = v, which is not recommended.
      std::cout << sc_time_stamp() << ": generator1 writes " << v++
                << std::endl;
      wait(1, SC_SEC);  // write every 1 s
    }
  }
  void consumer1() {  // blocking read
    int v = -1;
    while (true) {
      SC_REPORT_INFO_VERB("consumer1", "before read", 1);
      f1.read(v);  // same as v = int(f), which is not recommended; or, v =
                   // f1.read();
      SC_REPORT_INFO_VERB("consumer1", "after read", 1);
      std::cout << sc_time_stamp() << ": consumer1 reads " << v << std::endl;
      wait(3, SC_SEC);  // read every 3 s, fifo will fill up soon
    }
  }
  void generator2() {  // non-blocking write
    int v = 0;
    while (true) {
      while (f2.nb_write(v) == false) {  // nb write until succeeded
        wait(f2.data_read_event());  // if not successful, wait for data read (a
                                     // fifo slot becomes available)
      }
      std::cout << sc_time_stamp() << ": generator2 writes " << v++
                << std::endl;
      wait(1, SC_SEC);  // write every 1 s
    }
  }
  void consumer2() {  // non-blocking read
    int v = -1;
    while (true) {
      while (f2.nb_read(v) == false) {
        wait(f2.data_written_event());
      }
      std::cout << sc_time_stamp() << ": consumer2 reads " << v << std::endl;
      wait(3, SC_SEC);  // read every 3 s, fifo will fill up soon
    }
  }
  void generator3() {  // free/available slots before/after write
    int v = 0;
    while (true) {
      std::cout << sc_time_stamp()
                << ": generator3, before write, #free/#available="
                << f3.num_free() << "/" << f3.num_available() << std::endl;
      //   f3.write(v++);
      std::cout << sc_time_stamp()
                << ": generator3, after write, #free/#available="
                << f3.num_free() << "/" << f3.num_available() << std::endl;
      wait(1, SC_SEC);
    }
  }
  void consumer3() {  // free/available slots before/after read
    int v = -1;
    while (true) {
      std::cout << sc_time_stamp()
                << ": consumer3, before read, #free/#available="
                << f3.num_free() << "/" << f3.num_available() << std::endl;
      SC_REPORT_INFO_VERB("consumer3", "before read", 1);
      f3.read(v);
      SC_REPORT_INFO_VERB("consumer3", "after read", 1);
      std::cout << sc_time_stamp()
                << ": consumer3, after read, #free/#available=" << f3.num_free()
                << "/" << f3.num_available() << std::endl;
      wait(3, SC_SEC);  // read every 3 s, fifo will fill up soon
    }
  }
};

int sc_main(int, char*[]) {
  sc_report_handler::set_log_file_name("report.log");
  sc_report_handler::set_actions("writer", SC_INFO, SC_INTERRUPT);
  sc_report_handler::set_verbosity_level(SC_DEBUG);
  FIFO fifo("fifo");
  SC_REPORT_INFO("main", "simulation starts");
  sc_start(10000, SC_SEC);
  SC_REPORT_INFO("main", "simulation ends");
  return 0;
}
 

 

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...